Merged mward/5.2.n-custpeopleprops (5.2.1) to 5.2.N (5.2.1)

132754 mward: REPO-1395: add custom properties to people create/get/update.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132871 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Matt Ward
2016-11-17 15:00:17 +00:00
parent 434ca4b824
commit c14aedf7d1
8 changed files with 414 additions and 92 deletions

View File

@@ -25,18 +25,7 @@
*/
package org.alfresco.rest.api;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.rest.api.model.AssocChild;
import org.alfresco.rest.api.model.AssocTarget;
import org.alfresco.rest.api.model.Document;
import org.alfresco.rest.api.model.Folder;
import org.alfresco.rest.api.model.LockInfo;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.model.*;
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
import org.alfresco.rest.framework.resource.content.BinaryResource;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
@@ -46,6 +35,12 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.servlet.FormData;
import java.io.InputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* File Folder (Nodes) API
*
@@ -263,6 +258,49 @@ public interface Nodes
*/
Node unlock(String nodeId, Parameters parameters);
/**
* Convert from node properties (map of QName to Serializable) retrieved from
* the respository to a map of String to Object that can be formatted/expressed
* as required by the API JSON response for get nodes, get person etc.
*
* @param nodeProps
* @param selectParam
* @param mapUserInfo
* @param excludedProps
* @return
*/
Map<String, Object> mapFromNodeProperties(Map<QName, Serializable> nodeProps, List<String> selectParam, Map<String,UserInfo> mapUserInfo, List<QName> excludedProps);
/**
* Map from the JSON API format of properties (String to Object) to
* the typical node properties map used by the repository (QName to Serializable).
*
* @param props
* @return
*/
Map<QName, Serializable> mapToNodeProperties(Map<String, Object> props);
/**
* Map from aspects (Set of QName) retrieved from the repository to a
* map List of String required that can be formatted/expressed as required
* by the API JSON response for get nodes, get person etc.
*
* @param nodeAspects
* @return
*/
List<String> mapFromNodeAspects(Set<QName> nodeAspects);
/**
* Add aspects to the specified NodeRef. Aspects that appear in the exclusions list
* will be ignored.
*
* @param nodeRef
* @param aspectNames
* @param exclusions
*/
void addCustomAspects(NodeRef nodeRef, List<String> aspectNames, List<QName> exclusions);
/**
* API Constants - query parameters, etc
*/

View File

@@ -888,7 +888,7 @@ public class NodesImpl implements Nodes
if (includeParam.size() > 0)
{
node.setProperties(mapFromNodeProperties(properties, includeParam, mapUserInfo));
node.setProperties(mapFromNodeProperties(properties, includeParam, mapUserInfo, EXCLUDED_PROPS));
}
Set<QName> aspects = null;
@@ -1076,7 +1076,7 @@ public class NodesImpl implements Nodes
return nodeAspects;
}
protected Map<QName, Serializable> mapToNodeProperties(Map<String, Object> props)
public Map<QName, Serializable> mapToNodeProperties(Map<String, Object> props)
{
Map<QName, Serializable> nodeProps = new HashMap<>(props.size());
@@ -1115,8 +1115,8 @@ public class NodesImpl implements Nodes
return nodeProps;
}
protected Map<String, Object> mapFromNodeProperties(Map<QName, Serializable> nodeProps, List<String> selectParam, Map<String,UserInfo> mapUserInfo)
public Map<String, Object> mapFromNodeProperties(Map<QName, Serializable> nodeProps, List<String> selectParam, Map<String,UserInfo> mapUserInfo, List<QName> excludedProps)
{
List<QName> selectedProperties;
@@ -1126,7 +1126,7 @@ public class NodesImpl implements Nodes
selectedProperties = new ArrayList<>(nodeProps.size());
for (QName propQName : nodeProps.keySet())
{
if ((! EXCLUDED_NS.contains(propQName.getNamespaceURI())) && (! EXCLUDED_PROPS.contains(propQName)))
if ((! EXCLUDED_NS.contains(propQName.getNamespaceURI())) && (! excludedProps.contains(propQName)))
{
selectedProperties.add(propQName);
}
@@ -1164,7 +1164,7 @@ public class NodesImpl implements Nodes
return props;
}
protected List<String> mapFromNodeAspects(Set<QName> nodeAspects)
public List<String> mapFromNodeAspects(Set<QName> nodeAspects)
{
List<String> aspectNames = new ArrayList<>(nodeAspects.size());
@@ -1738,22 +1738,8 @@ public class NodesImpl implements Nodes
nodeRef = createNodeImpl(parentNodeRef, nodeName, nodeTypeQName, props, assocTypeQName);
}
List<String> aspectNames = nodeInfo.getAspectNames();
if (aspectNames != null)
{
// node aspects - set any additional aspects
Set<QName> aspectQNames = mapToNodeAspects(aspectNames);
for (QName aspectQName : aspectQNames)
{
if (EXCLUDED_ASPECTS.contains(aspectQName) || aspectQName.equals(ContentModel.ASPECT_AUDITABLE))
{
continue; // ignore
}
addCustomAspects(nodeRef, nodeInfo.getAspectNames(), EXCLUDED_ASPECTS);
nodeService.addAspect(nodeRef, aspectQName, null);
}
}
// eg. to create mandatory assoc(s)
if (nodeInfo.getTargets() != null)
@@ -1775,6 +1761,25 @@ public class NodesImpl implements Nodes
return newNode;
}
public void addCustomAspects(NodeRef nodeRef, List<String> aspectNames, List<QName> exclusions)
{
if (aspectNames == null)
{
return;
}
// node aspects - set any additional aspects
Set<QName> aspectQNames = mapToNodeAspects(aspectNames);
for (QName aspectQName : aspectQNames)
{
if (exclusions.contains(aspectQName) || aspectQName.equals(ContentModel.ASPECT_AUDITABLE))
{
continue; // ignore
}
nodeService.addAspect(nodeRef, aspectQName, null);
}
}
private NodeRef getOrCreatePath(NodeRef parentNodeRef, String relativePath)
{
if (relativePath != null)

View File

@@ -26,12 +26,7 @@
package org.alfresco.rest.api.impl;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingRequest;
@@ -76,6 +71,32 @@ import org.alfresco.util.Pair;
*/
public class PeopleImpl implements People
{
private static final List<QName> EXCLUDED_ASPECTS = Arrays.asList();
private static final List<QName> EXCLUDED_PROPS = Arrays.asList(
ContentModel.PROP_USERNAME,
ContentModel.PROP_FIRSTNAME,
ContentModel.PROP_LASTNAME,
ContentModel.PROP_JOBTITLE,
ContentModel.PROP_LOCATION,
ContentModel.PROP_TELEPHONE,
ContentModel.PROP_MOBILE,
ContentModel.PROP_EMAIL,
ContentModel.PROP_ORGANIZATION,
ContentModel.PROP_COMPANYADDRESS1,
ContentModel.PROP_COMPANYADDRESS2,
ContentModel.PROP_COMPANYADDRESS3,
ContentModel.PROP_COMPANYPOSTCODE,
ContentModel.PROP_COMPANYTELEPHONE,
ContentModel.PROP_COMPANYFAX,
ContentModel.PROP_COMPANYEMAIL,
ContentModel.PROP_SKYPE,
ContentModel.PROP_INSTANTMSG,
ContentModel.PROP_USER_STATUS,
ContentModel.PROP_USER_STATUS_TIME,
ContentModel.PROP_GOOGLEUSERNAME,
ContentModel.PROP_SIZE_QUOTA,
ContentModel.PROP_SIZE_CURRENT,
ContentModel.PROP_EMAIL_FEED_DISABLED);
protected Nodes nodes;
protected Sites sites;
@@ -358,6 +379,18 @@ public class PeopleImpl implements People
});
person = new Person(personNode, nodeProps, enabled);
// Remove the temporary property used to help inline the person description content property.
// It may be accessed from the person object (person.getDescription()).
nodeProps.remove(Person.PROP_PERSON_DESCRIPTION);
// Expose properties
Map<String, Object> custProps = new HashMap<>();
custProps.putAll(nodes.mapFromNodeProperties(nodeProps, new ArrayList<>(), new HashMap<>(), EXCLUDED_PROPS));
person.setProperties(custProps);
// Expose aspect names
Set<QName> aspects = nodeService.getAspects(personNode);
person.setAspectNames(nodes.mapFromNodeAspects(aspects));
// get avatar information
if (hasAvatar(personNode))
{
@@ -405,8 +438,19 @@ public class PeopleImpl implements People
MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService;
mas.createAuthentication(person.getUserName(), person.getPassword().toCharArray());
mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled());
NodeRef nodeRef = personService.createPerson(props);
// Add custom properties
if (person.getProperties() != null)
{
Map<String, Object> customProps = person.getProperties();
props.putAll(nodes.mapToNodeProperties(customProps));
}
NodeRef nodeRef = personService.createPerson(props);
// Add custom aspects
nodes.addCustomAspects(nodeRef, person.getAspectNames(), EXCLUDED_ASPECTS);
// Write the contents of PersonUpdate.getDescription() text to a content file
// and store the content URL in ContentModel.PROP_PERSONDESC
if (person.getDescription() != null)
@@ -417,7 +461,7 @@ public class PeopleImpl implements People
// Return a fresh retrieval
return getPerson(person.getUserName());
}
/**
* Write the description to a content file and store the content URL in
* ContentModel.PROP_PERSONDESC
@@ -483,19 +527,29 @@ public class PeopleImpl implements People
mutableAuthenticationService.setAuthenticationEnabled(personIdToUpdate, person.isEnabled());
}
if (person.getDescription() != null)
{
// Remove person description from saved properties
properties.remove(ContentModel.PROP_PERSONDESC);
// Custom save for person description.
NodeRef personNodeRef = personService.getPerson(personIdToUpdate, false);
NodeRef personNodeRef = personService.getPerson(personIdToUpdate, false);
if (person.getDescription() != null)
{
// Remove person description from saved properties
properties.remove(ContentModel.PROP_PERSONDESC);
// Custom save for person description.
savePersonDescription(person.getDescription(), personNodeRef);
}
// Add custom properties
if (person.getProperties() != null)
{
Map<String, Object> customProps = person.getProperties();
properties.putAll(nodes.mapToNodeProperties(customProps));
}
personService.setPersonProperties(personIdToUpdate, properties, false);
// Add custom aspects
nodes.addCustomAspects(personNodeRef, person.getAspectNames(), EXCLUDED_ASPECTS);
return getPerson(personId);
}

View File

@@ -25,16 +25,17 @@
*/
package org.alfresco.rest.api.model;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.rest.framework.resource.UniqueId;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents a user of the system.
*
@@ -66,6 +67,8 @@ public class Person
protected String description;
protected Company company;
protected String password;
protected Map<String, Object> properties;
protected List<String> aspectNames;
public Person()
{
@@ -352,7 +355,27 @@ public class Person
{
return this.password;
}
public Map<String, Object> getProperties()
{
return properties;
}
public void setProperties(Map<String, Object> properties)
{
this.properties = properties;
}
public List<String> getAspectNames()
{
return aspectNames;
}
public void setAspectNames(List<String> aspectNames)
{
this.aspectNames = aspectNames;
}
@Override
public String toString()
{

View File

@@ -110,26 +110,7 @@ public class PeopleEntityResource implements EntityResourceAction.ReadById<Perso
}
List<Person> result = new ArrayList<>(1);
Person person = new Person();
person.setUserName(p.getUserName());
person.setFirstName(p.getFirstName());
person.setLastName(p.getLastName());
person.setDescription(p.getDescription());
person.setEmail(p.getEmail());
person.setSkypeId(p.getSkypeId());
person.setGoogleId(p.getGoogleId());
person.setInstantMessageId(p.getInstantMessageId());
person.setJobTitle(p.getJobTitle());
person.setLocation(p.getLocation());
person.setCompany(p.getCompany());
person.setMobile(p.getMobile());
person.setTelephone(p.getTelephone());
person.setUserStatus(p.getUserStatus());
person.setEnabled(p.isEnabled());
person.setEmailNotificationsEnabled(p.isEmailNotificationsEnabled());
person.setPassword(p.getPassword());
result.add(people.create(person));
result.add(people.create(p));
return result;
}