Merged HEAD (5.2) to 5.2.N (5.2.1)

126359 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      119631 jvonka: RA-639: FileFolder API - update node info (metadata) - add &/or remove aspects
      - TODO add tests (across the board)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126705 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 10:47:50 +00:00
parent 78a2510b8d
commit 2997aa5bfe
2 changed files with 56 additions and 2 deletions

View File

@@ -884,7 +884,6 @@ public class NodesImpl implements Nodes
public Node updateNode(String nodeId, Node nodeInfo, Parameters parameters) public Node updateNode(String nodeId, Node nodeInfo, Parameters parameters)
{ {
final NodeRef nodeRef = validateNode(nodeId); final NodeRef nodeRef = validateNode(nodeId);
final Set<QName> fileOrFolder = new HashSet<>(Arrays.asList(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)); final Set<QName> fileOrFolder = new HashSet<>(Arrays.asList(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT));
@@ -911,6 +910,61 @@ public class NodesImpl implements Nodes
props.put(ContentModel.PROP_NAME, name); props.put(ContentModel.PROP_NAME, name);
} }
List<String> aspectNames = nodeInfo.getAspectNames();
if (aspectNames != null)
{
// note: can be empty (eg. to remove existing aspects (+ aspect properties) ... apart from cm:auditable, sys:referencable, sys:localized)
Set<QName> aspectQNames = new HashSet<>(aspectNames.size());
for (String aspectName : aspectNames)
{
QName aspectQName = QName.createQName(aspectName, namespaceService);
aspectQNames.add(aspectQName);
}
Set<QName> existingAspects = nodeService.getAspects(nodeRef);
Set<QName> aspectsToAdd = new HashSet<>(3);
Set<QName> aspectsToRemove = new HashSet<>(3);
for (QName aspectQName : aspectQNames)
{
if (EXCLUDED_ASPECTS.contains(aspectQName) || aspectQName.equals(ContentModel.ASPECT_AUDITABLE))
{
continue; // ignore
}
if (! existingAspects.contains(aspectQName))
{
aspectsToAdd.add(aspectQName);
}
}
for (QName existingAspect : existingAspects)
{
if (EXCLUDED_ASPECTS.contains(existingAspect) || existingAspect.equals(ContentModel.ASPECT_AUDITABLE))
{
continue; // ignore
}
if (! aspectQNames.contains(existingAspect))
{
aspectsToRemove.add(existingAspect);
}
}
// Note: for now, if aspectNames are sent then all that are required should be sent (to avoid properties from other existing aspects being removed)
// TODO: optional PATCH mechanism to add one new new aspect (with some related aspect properties) without affecting existing aspects/properties
for (QName aQName : aspectsToRemove)
{
nodeService.removeAspect(nodeRef, aQName);
}
for (QName aQName : aspectsToAdd)
{
nodeService.addAspect(nodeRef, aQName, null);
}
}
if (props.size() > 0) if (props.size() > 0)
{ {
nodeService.addProperties(nodeRef, props); nodeService.addProperties(nodeRef, props);

View File

@@ -114,7 +114,7 @@ public class Node implements Comparable<Node>
public static UserInfo lookupUserInfo(String userName, Map<String, UserInfo> mapUserInfo, PersonService personService) { public static UserInfo lookupUserInfo(String userName, Map<String, UserInfo> mapUserInfo, PersonService personService) {
UserInfo userInfo = mapUserInfo.get(userName); UserInfo userInfo = mapUserInfo.get(userName);
if (userInfo == null) if ((userInfo == null) && (userName != null))
{ {
String sysUserName = AuthenticationUtil.getSystemUserName(); String sysUserName = AuthenticationUtil.getSystemUserName();
if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled() && userName.startsWith(sysUserName + "@"))) if (userName.equals(sysUserName) || (AuthenticationUtil.isMtEnabled() && userName.startsWith(sysUserName + "@")))