diff --git a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java index adb521cee9..79ad549d6b 100644 --- a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java +++ b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java @@ -583,6 +583,11 @@ public class PeopleImpl implements People savePersonDescription(person.getDescription(), personNodeRef); } + // Update custom aspects - do this *before* adding custom properties. The + // addition of custom properties may result in the auto-addition of aspects + // and we don't want to remove them during the update of explicitly specified aspects. + nodes.updateCustomAspects(personNodeRef, person.getAspectNames(), EXCLUDED_ASPECTS); + // Add custom properties if (person.getProperties() != null) { @@ -600,9 +605,6 @@ public class PeopleImpl implements People return null; } }); - - // Update custom aspects - nodes.updateCustomAspects(personNodeRef, person.getAspectNames(), EXCLUDED_ASPECTS); return getPerson(personId); } diff --git a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java index fd8f9c6682..28111328ba 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -750,6 +750,50 @@ public class TestPeople extends EnterpriseTestApi assertTrue(aspectNames.contains("papi:lunchable")); assertNull(person.getProperties()); } + + // Aspects and properties together + { + Person person = new Person(); + String personId = UUID.randomUUID().toString()+"@"+account1.getId(); + person.setUserName(personId); + person.setFirstName("Joe"); + person.setEmail(personId); + person.setEnabled(true); + person.setPassword("password123"); + // Start with no custom props/aspects + person.setProperties(null); + person.setAspectNames(null); + + person = people.create(person); + + assertNull(person.getAspectNames()); + assertNull(person.getProperties()); + + // Auto-add the papi:comms aspect, by setting its papi:jabber property, + // but explicitly add the papi:lunchable aspect. + String json = qjson( + "{" + + " `aspectNames`: [ " + + " `papi:lunchable` " + + " ], " + + " `properties`: { " + + " `papi:jabber`: `another@jabber.example.com`, " + + " `papi:lunch`: `sandwich` " + + " }" + + "}" + ); + + person = people.update(person.getId(), json, 200); + + // Were both aspects set? + List aspectNames = person.getAspectNames(); + assertEquals(2, aspectNames.size()); + assertTrue(aspectNames.contains("papi:lunchable")); + assertTrue(aspectNames.contains("papi:comms")); + assertEquals(2, person.getProperties().size()); + assertEquals("another@jabber.example.com", person.getProperties().get("papi:jabber")); + assertEquals("sandwich", person.getProperties().get("papi:lunch")); + } // Remove a property by setting it to null {