diff --git a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java index df4d3613c8..e6e701ceb5 100644 --- a/source/java/org/alfresco/rest/api/impl/PeopleImpl.java +++ b/source/java/org/alfresco/rest/api/impl/PeopleImpl.java @@ -42,12 +42,7 @@ 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; -import org.alfresco.service.cmr.repository.ContentData; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.*; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.NoSuchPersonException; import org.alfresco.service.cmr.security.PersonService; @@ -156,7 +151,7 @@ public class PeopleImpl implements People return personId; } - protected void processPersonProperties(String userName, final Map nodeProps) + protected void processPersonProperties(final Map nodeProps) { if(!contentUsageService.getEnabled()) { @@ -165,6 +160,9 @@ public class PeopleImpl implements People nodeProps.remove(ContentModel.PROP_SIZE_CURRENT); } + // The person description is located in a separate content file located at cm:persondescription + // "Inline" this data, by removing the cm:persondescription property and adding a temporary property + // (Person.PROP_PERSON_DESCRIPTION) containing the actual content as a string. final ContentData personDescription = (ContentData)nodeProps.get(ContentModel.PROP_PERSONDESC); if(personDescription != null) { @@ -249,7 +247,7 @@ public class PeopleImpl implements People if (personNode != null) { Map nodeProps = nodeService.getProperties(personNode); - processPersonProperties(personId, nodeProps); + processPersonProperties(nodeProps); // TODO this needs to be run as admin but should we do this here? final String pId = personId; Boolean enabled = AuthenticationUtil.runAsSystem(new RunAsWork() @@ -298,9 +296,28 @@ public class PeopleImpl implements People } Map props = person.toProperties(); NodeRef nodeRef = personService.createPerson(props); + + // Write the contents of PersonUpdate.getDescription() text to a content file + // and store the content URL in ContentModel.PROP_PERSONDESC + if (person.getDescription() != null) + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() throws Exception + { + ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_PERSONDESC, true); + writer.putContent(person.getDescription()); + return null; + } + }); + } // Return a fresh retrieval props = nodeService.getProperties(nodeRef); + // Do not put this pseudo/temp-property into the bag before creating the person + // as it would be created as a residual property. + props.put(Person.PROP_PERSON_DESCRIPTION, person.getDescription()); final boolean enabled = personService.isEnabled(person.getUserName()); return new Person(nodeRef, props, enabled); diff --git a/source/java/org/alfresco/rest/api/model/PersonUpdate.java b/source/java/org/alfresco/rest/api/model/PersonUpdate.java index 60edfd1ce9..9881c235cc 100644 --- a/source/java/org/alfresco/rest/api/model/PersonUpdate.java +++ b/source/java/org/alfresco/rest/api/model/PersonUpdate.java @@ -217,9 +217,6 @@ public class PersonUpdate addToMap(properties, ContentModel.PROP_USERNAME, getUserName()); addToMap(properties, ContentModel.PROP_FIRSTNAME, getFirstName()); addToMap(properties, ContentModel.PROP_LASTNAME, getLastName()); - // What's the correct behaviour here? Store it as "content" somehow? - // so that it can be 'inlined' by the code in PeopleImpl.processPersonProperties ? - addToMap(properties, ContentModel.PROP_PERSONDESC, getDescription()); addToMap(properties, ContentModel.PROP_EMAIL, getEmail()); addToMap(properties, ContentModel.PROP_SKYPE, getSkypeId()); addToMap(properties, ContentModel.PROP_GOOGLEUSERNAME, getGoogleId()); 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 e4fb822352..583682480d 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -151,13 +151,7 @@ public class TestPeople extends EnterpriseTestApi assertEquals("myUserName00@"+account1.getId(), p.getId()); assertEquals("Firstname", p.getFirstName()); assertEquals("Lastname", p.getLastName()); - - // TODO: we currently have confusion over cm:description, cm:persondescription and RestApi:description - // PeopleImpl currently removes cm:persondescription and replaces it with {RestApi}description - // We'll keep description as null until we know better. -// assertEquals("my description", p.getDescription()); - assertEquals(null, p.getDescription()); - + assertEquals("my description", p.getDescription()); assertEquals("email@example.com", p.getEmail()); assertEquals("my.skype.id", p.getSkypeId()); assertEquals("google", p.getGoogleId());