mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-892: ensure presence of mandatory fields
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131886 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -286,10 +286,7 @@ 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.");
|
||||
}
|
||||
validateCreatePersonData(person);
|
||||
|
||||
// TODO: check, is this transaction safe?
|
||||
// Unfortunately PersonService.createPerson(...) only throws an AlfrescoRuntimeException
|
||||
@@ -311,6 +308,22 @@ public class PeopleImpl implements People
|
||||
// return getPerson(person.getUserName());
|
||||
}
|
||||
|
||||
private void validateCreatePersonData(PersonUpdate person)
|
||||
{
|
||||
checkRequiredField("id", person.getUserName());
|
||||
checkRequiredField("firstName", person.getFirstName());
|
||||
checkRequiredField("email", person.getEmail());
|
||||
checkRequiredField("enabled", person.isEnabled());
|
||||
}
|
||||
|
||||
private void checkRequiredField(String fieldName, Object fieldValue)
|
||||
{
|
||||
if (fieldValue == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Field '"+fieldName+"' is null, but is required.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
public Person updatePerson(String personId, final Person person)
|
||||
|
@@ -225,15 +225,18 @@ public class TestPeople extends EnterpriseTestApi
|
||||
{
|
||||
PersonUpdate person = new PersonUpdate.Builder().
|
||||
id("joe.bloggs.2@"+account1.getId()).
|
||||
firstName("Joe").
|
||||
email("joe.bloggs.2@example.com").
|
||||
enabled(true).
|
||||
build();
|
||||
|
||||
Person p = people.create(person);
|
||||
|
||||
assertEquals("joe.bloggs.2@" + account1.getId(), p.getId());
|
||||
assertEquals(null, p.getFirstName());
|
||||
assertEquals("Joe", p.getFirstName());
|
||||
assertEquals(null, p.getLastName());
|
||||
assertEquals(null, p.getDescription());
|
||||
assertEquals(null, p.getEmail());
|
||||
assertEquals("joe.bloggs.2@example.com", p.getEmail());
|
||||
assertEquals(null, p.getSkypeId());
|
||||
assertEquals(null, p.getGoogleId());
|
||||
assertEquals(null, p.getInstantMessageId());
|
||||
@@ -250,7 +253,9 @@ public class TestPeople extends EnterpriseTestApi
|
||||
// -ve: not enough fields!
|
||||
{
|
||||
// Create a person with no fields set.
|
||||
PersonUpdate person = new PersonUpdate.Builder().build();
|
||||
PersonUpdate person = new PersonUpdate.Builder().
|
||||
id("joe.bloggs.2@"+account1.getId()).
|
||||
build();
|
||||
people.create(person, 400);
|
||||
}
|
||||
}
|
||||
@@ -292,6 +297,9 @@ public class TestPeople extends EnterpriseTestApi
|
||||
publicApiClient.setRequestContext(new RequestContext(account1.getId(), GUID.generate(), "password"));
|
||||
PersonUpdate person = new PersonUpdate.Builder().
|
||||
id("myUserName01@"+account1.getId()).
|
||||
firstName("Caroline").
|
||||
email("caroline.smithson@example.com").
|
||||
enabled(true).
|
||||
build();
|
||||
people.create(person, 401);
|
||||
}
|
||||
@@ -302,6 +310,9 @@ public class TestPeople extends EnterpriseTestApi
|
||||
publicApiClient.setRequestContext(new RequestContext(account2.getId(), apiUser));
|
||||
PersonUpdate person = new PersonUpdate.Builder().
|
||||
id("myUserName02@"+account2.getId()).
|
||||
firstName("Kieth").
|
||||
email("keith.smith@example.com").
|
||||
enabled(true).
|
||||
build();
|
||||
people.create(person, 403);
|
||||
|
||||
@@ -315,6 +326,9 @@ public class TestPeople extends EnterpriseTestApi
|
||||
publicApiClient.setRequestContext(new RequestContext(account1.getId(), account1Admin, "admin"));
|
||||
PersonUpdate person = new PersonUpdate.Builder().
|
||||
id("myUserName03@"+account1.getId()).
|
||||
firstName("Alison").
|
||||
email("alison.smythe@example.com").
|
||||
enabled(true).
|
||||
build();
|
||||
people.create(person);
|
||||
|
||||
|
Reference in New Issue
Block a user