mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user