Merged 131680:131794 from DEV/mward/5.2.n-createperson to 5.2.N

REPO-892: make sure not all fields need to be supplied during create.
  REPO-892: throws error if fields exclusively belonging to Person (that are not part of PersonUpdate) are sent in request.
  REPO-892: cleaned up PersonUpdateJSONSerializer a little, by removing unnecessary 'fullVisibility' switch.
  REPO-892: improved test for optional fields; added test for too few fields.
  REPO-892: added tests (and impl where needed) for -ve response codes as given in the open api spec for create person.
  REPO-892: fixed broken test due to reuse of username.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131862 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2016-10-28 13:14:41 +00:00
parent 8328ca78ab
commit 96953c1bb7
4 changed files with 221 additions and 84 deletions

View File

@@ -39,6 +39,7 @@ import org.alfresco.rest.api.Sites;
import org.alfresco.rest.api.model.Company;
import org.alfresco.rest.api.model.Person;
import org.alfresco.rest.api.model.PersonUpdate;
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.service.cmr.repository.AssociationRef;
@@ -285,6 +286,19 @@ public class PeopleImpl implements People
@Override
public Person create(PersonUpdate person)
{
if (person.getUserName() == null)
{
throw new InvalidArgumentException("Field 'id' is null, but is required.");
}
// TODO: check, is this transaction safe?
// Unfortunately PersonService.createPerson(...) only throws an AlfrescoRuntimeException
// rather than a more specific exception and does not use a message ID either, so there's
// no sensible way to know that it was thrown due to the user already existing - hence this check here.
if (personService.personExists(person.getUserName()))
{
throw new ConstraintViolatedException("Person '"+person.getUserName()+"' already exists.");
}
Map<QName, Serializable> props = person.toProperties();
NodeRef nodeRef = personService.createPerson(props);