Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Fix MNT-21991 customizable personLookupProperties for REST API #866

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/main/java/org/alfresco/rest/api/impl/NodesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ private enum Activity_Type
private Repository repositoryHelper;
private ServiceRegistry sr;
private Set<String> defaultIgnoreTypesAndAspects;
private Set<String> defaultPersonLookupProperties;

// ignore types/aspects
private Set<QName> ignoreQNames;

private Set<QName> personLookupProperties = new HashSet<>();

private ConcurrentHashMap<String,NodeRef> ddCache = new ConcurrentHashMap<>();

private Set<String> nonAttachContentTypes = Collections.emptySet(); // pre-configured whitelist, eg. images & pdf
Expand Down Expand Up @@ -276,6 +279,14 @@ public void init()
ignoreQNames.add(createQName(type));
}
}

if (defaultPersonLookupProperties != null)
{
for (String property : defaultPersonLookupProperties)
{
personLookupProperties.add(createQName(property));
}
}
}

public void setServiceRegistry(ServiceRegistry sr)
Expand Down Expand Up @@ -303,6 +314,10 @@ public void setIgnoreTypes(Set<String> ignoreTypesAndAspects)
this.defaultIgnoreTypesAndAspects = ignoreTypesAndAspects;
}

public void setPersonLookupProperties(Set<String> personLookupProperties) {
this.defaultPersonLookupProperties = personLookupProperties;
}

public void setPoster(ActivityPoster poster)
{
this.poster = poster;
Expand Down Expand Up @@ -338,13 +353,6 @@ public void setNodeDefinitionMapper(NodeDefinitionMapper nodeDefinitionMapper)
ContentModel.PROP_AUTO_VERSION_PROPS,
ContentModel.PROP_AUTO_VERSION);

public static final List<QName> 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<String,QName> PARAM_SYNONYMS_QNAME;
static
{
Expand Down Expand Up @@ -1222,9 +1230,9 @@ public Map<String, Object> mapFromNodeProperties(Map<QName, Serializable> nodePr
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -63,10 +60,9 @@ public Set<String> supports()
return supported;
}

public void setSupported(List<String> supported)
public void setSupported(Set<String> supported)
{
NodesImpl.PROPS_USERLOOKUP.forEach(entry -> this.supported.add(entry.toString()));
this.supported.addAll(supported);
this.supported = supported;
}

public void setServiceRegistry(ServiceRegistry serviceRegistry)
Expand Down
30 changes: 22 additions & 8 deletions src/main/resources/alfresco/public-rest-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,18 @@
</property>
</bean>

<bean id="nodes.personLookupProperties" class="org.springframework.beans.factory.config.SetFactoryBean">
<property name="sourceSet">
<set>
<value>{http://www.alfresco.org/model/content/1.0}creator</value>
<value>{http://www.alfresco.org/model/content/1.0}modifier</value>
<value>{http://www.alfresco.org/model/content/1.0}owner</value>
<value>{http://www.alfresco.org/model/content/1.0}lockOwner</value>
<value>{http://www.alfresco.org/model/content/1.0}workingCopyOwner</value>
</set>
</property>
</bean>

<bean id="nodeDefinitionMapper" class="org.alfresco.rest.api.impl.NodeDefinitionMapperImpl"/>

<bean id="nodes" class="org.alfresco.rest.api.impl.NodesImpl" init-method="init">
Expand All @@ -527,6 +539,7 @@
<property name="behaviourFilter" ref="policyBehaviourFilter"/>
<property name="ignoreTypes" ref="nodes.ignoreTypes"/>
<property name="nonAttachContentTypes" ref="nodes.nonAttachContentTypes"/>
<property name="personLookupProperties" ref="nodes.personLookupProperties"/>
<property name="poster" ref="activitiesPoster" />
<property name="smartStore" ref="smartStore"/>
<property name="nodeDefinitionMapper" ref="nodeDefinitionMapper" />
Expand Down Expand Up @@ -835,14 +848,15 @@
<bean id="publicapi.personPropertyLookup" class="org.alfresco.rest.api.lookups.PersonPropertyLookup">
<property name="serviceRegistry" ref="ServiceRegistry"/>
<property name="supported">
<list>
<value>cm:creator</value>
<value>cm:modifier</value>
<value>cm:owner</value>
<value>creator</value>
<value>modifier</value>
<value>owner</value>
</list>
<bean parent="nodes.personLookupProperties" class="org.springframework.beans.factory.config.SetFactoryBean">
<property name="sourceSet">
<set merge="true">
<value>creator</value>
<value>modifier</value>
<value>owner</value>
</set>
</property>
</bean>
</property>
</bean>

Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/alfresco/rest/api/tests/NodeApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ public void testGetNodeInfo() throws Exception
String title = "test title";
Map<String,String> 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();

Expand Down Expand Up @@ -742,9 +743,10 @@ public void testGetNodeInfo() throws Exception
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);
Expand Down