Feature/ACS-5624 Search and Favorites API enhancements (#2076)

* ACS-5624: Seacrh and Favorites API enhancements.

* ACS-5624: Reverting unwanted test change.

* ACS-5624: Adding isFavorite to SearchNodeModel.
This commit is contained in:
Maciej Pichura
2023-07-20 10:39:17 +02:00
committed by GitHub
parent 114cec4987
commit b423a7ae96
7 changed files with 68 additions and 14 deletions

View File

@@ -25,13 +25,14 @@
*/
package org.alfresco.rest.api.impl;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -76,6 +77,7 @@ import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -89,7 +91,9 @@ public class FavouritesImpl implements Favourites
{
private static final Log logger = LogFactory.getLog(FavouritesImpl.class);
private People people;
private static final List<String> ALLOWED_INCLUDES = List.of(PARAM_INCLUDE_PROPERTIES, PARAM_INCLUDE_ALLOWABLEOPERATIONS);
private People people;
private Sites sites;
private Nodes nodes;
private FavouritesService favouritesService;
@@ -175,18 +179,23 @@ public class FavouritesImpl implements Favourites
fav.setTarget(target);
// REPO-1147 allow retrieving additional properties
if (parameters.getInclude().contains(PARAM_INCLUDE_PROPERTIES))
final List<String> paramsInclude = parameters.getInclude();
if (!Collections.disjoint(paramsInclude, ALLOWED_INCLUDES))
{
List<String> includeProperties = new LinkedList<>();
includeProperties.add(PARAM_INCLUDE_PROPERTIES);
final List<String> includes = ALLOWED_INCLUDES.stream().filter(a -> paramsInclude.contains(a)).collect(Collectors.toList());
// get node representation with only properties included
Node node = nodes.getFolderOrDocument(personFavourite.getNodeRef(), null, null, includeProperties, null);
Node node = nodes.getFolderOrDocument(personFavourite.getNodeRef(), null, null, includes, null);
// Create a map from node properties excluding properties already in this Favorite
Map<String, Object> filteredNodeProperties = filterProps(node.getProperties(), EXCLUDED_PROPS);
if(filteredNodeProperties.size() > 0)
if(filteredNodeProperties.size() > 0 && paramsInclude.contains(PARAM_INCLUDE_PROPERTIES))
{
fav.setProperties(filteredNodeProperties);
}
final List<String> allowableOperations = node.getAllowableOperations();
if (CollectionUtils.isNotEmpty(allowableOperations) && paramsInclude.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
{
fav.setAllowableOperations(allowableOperations);
}
}
return fav;

View File

@@ -26,6 +26,7 @@
package org.alfresco.rest.api.model;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.alfresco.rest.framework.resource.UniqueId;
@@ -42,6 +43,7 @@ public class Favourite
private Date createdAt;
private Target target;
private Map<String, Object> properties;
private List<String> allowableOperations;
public Date getCreatedAt()
{
@@ -84,10 +86,18 @@ public class Favourite
this.properties = properties;
}
public List<String> getAllowableOperations() {
return allowableOperations;
}
public void setAllowableOperations(List<String> allowableOperations) {
this.allowableOperations = allowableOperations;
}
@Override
public String toString()
{
return "Favourite [targetGuid=" + targetGuid
+ ", createdAt=" + createdAt + ", target=" + target + ", properties=" + properties + "]";
}
}
}

View File

@@ -31,6 +31,7 @@ import static java.util.stream.Collectors.toList;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASSOCIATION;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISFAVORITE;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLINK;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLOCKED;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
@@ -96,10 +97,9 @@ import java.util.stream.Collectors;
*/
public class SearchMapper
{
public static final List<String> PERMITTED_INCLUDES
= Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES,
PARAM_INCLUDE_ASSOCIATION, PARAM_INCLUDE_ISLOCKED, PARAM_INCLUDE_PERMISSIONS);
public static final List<String> PERMITTED_INCLUDES = Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES, PARAM_INCLUDE_ASSOCIATION,
PARAM_INCLUDE_ISLOCKED, PARAM_INCLUDE_PERMISSIONS, PARAM_INCLUDE_ISFAVORITE);
public static final String CMIS = "cmis";
public static final String LUCENE = "lucene";

View File

@@ -32,6 +32,7 @@ import static junit.framework.TestCase.fail;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASSOCIATION;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISFAVORITE;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLINK;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLOCKED;
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
@@ -300,7 +301,7 @@ public class SearchMapperTests
{
searchMapper.validateInclude(Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES,
PARAM_INCLUDE_ASSOCIATION, PARAM_INCLUDE_ISLOCKED, PARAM_INCLUDE_PERMISSIONS));
PARAM_INCLUDE_ASSOCIATION, PARAM_INCLUDE_ISLOCKED, PARAM_INCLUDE_PERMISSIONS, PARAM_INCLUDE_ISFAVORITE));
}