From 5cdade38a88f150cd45929405f142733bedcd8b1 Mon Sep 17 00:00:00 2001 From: Nicolas Barithel Date: Tue, 2 Feb 2021 18:36:52 +0100 Subject: [PATCH] Fix MNT-21991 customizable personLookupProperties for REST API (#191) * Fix MNT-21991 custom personLookupProperties * Fix MNT-21991 test case for cm:owner --- .../org/alfresco/rest/api/impl/NodesImpl.java | 26 ++++++++++------ .../api/lookups/PersonPropertyLookup.java | 8 ++--- .../alfresco/public-rest-context.xml | 30 ++++++++++++++----- .../alfresco/rest/api/tests/NodeApiTest.java | 4 ++- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java index ec093897e2..29b7280f50 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -229,10 +229,13 @@ public class NodesImpl implements Nodes private Repository repositoryHelper; private ServiceRegistry sr; private Set defaultIgnoreTypesAndAspects; + private Set defaultPersonLookupProperties; // ignore types/aspects private Set ignoreQNames; + private Set personLookupProperties = new HashSet<>(); + private ConcurrentHashMap ddCache = new ConcurrentHashMap<>(); private Set nonAttachContentTypes = Collections.emptySet(); // pre-configured whitelist, eg. images & pdf @@ -276,6 +279,14 @@ public class NodesImpl implements Nodes ignoreQNames.add(createQName(type)); } } + + if (defaultPersonLookupProperties != null) + { + for (String property : defaultPersonLookupProperties) + { + personLookupProperties.add(createQName(property)); + } + } } public void setServiceRegistry(ServiceRegistry sr) @@ -303,6 +314,10 @@ public class NodesImpl implements Nodes this.defaultIgnoreTypesAndAspects = ignoreTypesAndAspects; } + public void setPersonLookupProperties(Set personLookupProperties) { + this.defaultPersonLookupProperties = personLookupProperties; + } + public void setPoster(ActivityPoster poster) { this.poster = poster; @@ -338,13 +353,6 @@ public class NodesImpl implements Nodes ContentModel.PROP_AUTO_VERSION_PROPS, ContentModel.PROP_AUTO_VERSION); - public static final List PROPS_USERLOOKUP = Arrays.asList( - ContentModel.PROP_CREATOR, - ContentModel.PROP_MODIFIER, - ContentModel.PROP_OWNER, - ContentModel.PROP_LOCK_OWNER, - ContentModel.PROP_WORKING_COPY_OWNER); - public final static Map PARAM_SYNONYMS_QNAME; static { @@ -1222,9 +1230,9 @@ public class NodesImpl implements Nodes Serializable value = nodeProps.get(qName); if (value != null) { - if (PROPS_USERLOOKUP.contains(qName)) + if (personLookupProperties.contains(qName)) { - value = Node.lookupUserInfo((String)value, mapUserInfo, sr.getPersonService()); + value = Node.lookupUserInfo((String) value, mapUserInfo, personService); } // Empty (zero length) string values are considered to be diff --git a/remote-api/src/main/java/org/alfresco/rest/api/lookups/PersonPropertyLookup.java b/remote-api/src/main/java/org/alfresco/rest/api/lookups/PersonPropertyLookup.java index 041d8bb830..779de26bb7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/lookups/PersonPropertyLookup.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/lookups/PersonPropertyLookup.java @@ -25,15 +25,12 @@ */ package org.alfresco.rest.api.lookups; -import org.alfresco.model.ContentModel; import org.alfresco.repo.transaction.TransactionalResourceHelper; -import org.alfresco.rest.api.impl.NodesImpl; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.UserInfo; import org.alfresco.service.ServiceRegistry; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; @@ -63,10 +60,9 @@ public class PersonPropertyLookup implements PropertyLookup return supported; } - public void setSupported(List supported) + public void setSupported(Set supported) { - NodesImpl.PROPS_USERLOOKUP.forEach(entry -> this.supported.add(entry.toString())); - this.supported.addAll(supported); + this.supported = supported; } public void setServiceRegistry(ServiceRegistry serviceRegistry) diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index d92fa719d1..4fc9af0e64 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -518,6 +518,18 @@ + + + + {http://www.alfresco.org/model/content/1.0}creator + {http://www.alfresco.org/model/content/1.0}modifier + {http://www.alfresco.org/model/content/1.0}owner + {http://www.alfresco.org/model/content/1.0}lockOwner + {http://www.alfresco.org/model/content/1.0}workingCopyOwner + + + + @@ -527,6 +539,7 @@ + @@ -835,14 +848,15 @@ - - cm:creator - cm:modifier - cm:owner - creator - modifier - owner - + + + + creator + modifier + owner + + + diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java index 73fa568c32..dde673be98 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -710,6 +710,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest String title = "test title"; Map docProps = new HashMap<>(); docProps.put("cm:title", title); + docProps.put("cm:owner", user2); String contentName = "content " + RUNID + ".txt"; String content1Id = createTextFile(folderB_Id, contentName, "The quick brown fox jumps over the lazy dog.", "UTF-8", docProps).getId(); @@ -743,9 +744,10 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest props.put("cm:title", title); props.put("cm:versionLabel", "1.0"); props.put("cm:versionType", "MAJOR"); + props.put("cm:owner", new UserInfo(user2).toJSON()); d1.setProperties(props); - d1.setAspectNames(Arrays.asList("cm:auditable","cm:titled","cm:versionable","cm:author")); + d1.setAspectNames(Arrays.asList("cm:auditable","cm:titled","cm:versionable","cm:author","cm:ownable")); // Note: Path is not part of the default info d1.expected(documentResp);