mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package org.alfresco.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.alfresco.rest.core.IRestModel;
|
||||
@@ -43,6 +45,7 @@ public class RestPersonFavoritesModel extends TestModel implements IRestModel<Re
|
||||
|
||||
private String targetGuid;
|
||||
private String createdAt;
|
||||
private List<String> allowableOperations;
|
||||
|
||||
private RestTargetModel target;
|
||||
|
||||
@@ -86,4 +89,12 @@ public class RestPersonFavoritesModel extends TestModel implements IRestModel<Re
|
||||
{
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public List<String> getAllowableOperations() {
|
||||
return allowableOperations;
|
||||
}
|
||||
|
||||
public void setAllowableOperations(List<String> allowableOperations) {
|
||||
this.allowableOperations = allowableOperations;
|
||||
}
|
||||
}
|
||||
|
@@ -101,6 +101,8 @@ public class SearchNodeModel extends TestModel implements IRestModel<SearchNodeM
|
||||
|
||||
private String location;
|
||||
|
||||
private Boolean isFavorite;
|
||||
|
||||
public Map<String, Object> getAssociation()
|
||||
{
|
||||
return association;
|
||||
@@ -327,4 +329,11 @@ public class SearchNodeModel extends TestModel implements IRestModel<SearchNodeM
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Boolean isFavorite() {
|
||||
return isFavorite;
|
||||
}
|
||||
|
||||
public void setIsFavorite(Boolean favorite) {
|
||||
isFavorite = favorite;
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ import org.testng.annotations.Test;
|
||||
|
||||
public class GetFavoritesTests extends RestTest
|
||||
{
|
||||
private static final String ALLOWABLE_OPERATIONS = "allowableOperations";
|
||||
private UserModel adminUserModel, userModel;
|
||||
private SiteModel firstSiteModel;
|
||||
private SiteModel secondSiteModel;
|
||||
@@ -551,4 +552,17 @@ public class GetFavoritesTests extends RestTest
|
||||
.field("id").is(thirdSiteModel.getId()).and()
|
||||
.field("title").is(thirdSiteModel.getTitle());
|
||||
}
|
||||
|
||||
@Test(groups = { TestGroup.REST_API, TestGroup.FAVORITES, TestGroup.REGRESSION })
|
||||
@TestRail(section = { TestGroup.REST_API, TestGroup.FAVORITES }, executionType = ExecutionType.REGRESSION, description = "Verify if get favorites response returns allowableOperations object when requested")
|
||||
public void checkResponseForGetFavoritesWithAllowableOperations()
|
||||
{
|
||||
RestPersonFavoritesModelsCollection adminFavorites =
|
||||
restClient.authenticateUser(adminUserModel).withCoreAPI().usingAuthUser().include(ALLOWABLE_OPERATIONS).getFavorites();
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
|
||||
adminFavorites.getEntries().stream()
|
||||
.map(RestPersonFavoritesModel::onModel)
|
||||
.forEach(m -> m.assertThat().field(ALLOWABLE_OPERATIONS).isNotEmpty());
|
||||
}
|
||||
}
|
||||
|
@@ -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,6 +91,8 @@ public class FavouritesImpl implements Favourites
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(FavouritesImpl.class);
|
||||
|
||||
private static final List<String> ALLOWED_INCLUDES = List.of(PARAM_INCLUDE_PROPERTIES, PARAM_INCLUDE_ALLOWABLEOPERATIONS);
|
||||
|
||||
private People people;
|
||||
private Sites sites;
|
||||
private Nodes nodes;
|
||||
@@ -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;
|
||||
|
@@ -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,6 +86,14 @@ 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()
|
||||
{
|
||||
|
@@ -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";
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user