REPO-892: correctly store and retrieve cm:persondescription as a cm:content blob.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131902 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2016-10-31 15:58:22 +00:00
parent c70a9f960e
commit 4d8673f058
3 changed files with 26 additions and 18 deletions

View File

@@ -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<QName, Serializable> nodeProps)
protected void processPersonProperties(final Map<QName, Serializable> 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<QName, Serializable> 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<Boolean>()
@@ -298,9 +296,28 @@ public class PeopleImpl implements People
}
Map<QName, Serializable> 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<Void>()
{
@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);

View File

@@ -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());

View File

@@ -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());