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;
|
package org.alfresco.rest.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import org.alfresco.rest.core.IRestModel;
|
import org.alfresco.rest.core.IRestModel;
|
||||||
@@ -43,6 +45,7 @@ public class RestPersonFavoritesModel extends TestModel implements IRestModel<Re
|
|||||||
|
|
||||||
private String targetGuid;
|
private String targetGuid;
|
||||||
private String createdAt;
|
private String createdAt;
|
||||||
|
private List<String> allowableOperations;
|
||||||
|
|
||||||
private RestTargetModel target;
|
private RestTargetModel target;
|
||||||
|
|
||||||
@@ -86,4 +89,12 @@ public class RestPersonFavoritesModel extends TestModel implements IRestModel<Re
|
|||||||
{
|
{
|
||||||
this.createdAt = createdAt;
|
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 String location;
|
||||||
|
|
||||||
|
private Boolean isFavorite;
|
||||||
|
|
||||||
public Map<String, Object> getAssociation()
|
public Map<String, Object> getAssociation()
|
||||||
{
|
{
|
||||||
return association;
|
return association;
|
||||||
@@ -326,5 +328,12 @@ public class SearchNodeModel extends TestModel implements IRestModel<SearchNodeM
|
|||||||
{
|
{
|
||||||
this.location = location;
|
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
|
public class GetFavoritesTests extends RestTest
|
||||||
{
|
{
|
||||||
|
private static final String ALLOWABLE_OPERATIONS = "allowableOperations";
|
||||||
private UserModel adminUserModel, userModel;
|
private UserModel adminUserModel, userModel;
|
||||||
private SiteModel firstSiteModel;
|
private SiteModel firstSiteModel;
|
||||||
private SiteModel secondSiteModel;
|
private SiteModel secondSiteModel;
|
||||||
@@ -551,4 +552,17 @@ public class GetFavoritesTests extends RestTest
|
|||||||
.field("id").is(thirdSiteModel.getId()).and()
|
.field("id").is(thirdSiteModel.getId()).and()
|
||||||
.field("title").is(thirdSiteModel.getTitle());
|
.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;
|
package org.alfresco.rest.api.impl;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS;
|
||||||
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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 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 Sites sites;
|
||||||
private Nodes nodes;
|
private Nodes nodes;
|
||||||
private FavouritesService favouritesService;
|
private FavouritesService favouritesService;
|
||||||
@@ -175,18 +179,23 @@ public class FavouritesImpl implements Favourites
|
|||||||
fav.setTarget(target);
|
fav.setTarget(target);
|
||||||
|
|
||||||
// REPO-1147 allow retrieving additional properties
|
// 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<>();
|
final List<String> includes = ALLOWED_INCLUDES.stream().filter(a -> paramsInclude.contains(a)).collect(Collectors.toList());
|
||||||
includeProperties.add(PARAM_INCLUDE_PROPERTIES);
|
|
||||||
// get node representation with only properties included
|
// 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
|
// Create a map from node properties excluding properties already in this Favorite
|
||||||
Map<String, Object> filteredNodeProperties = filterProps(node.getProperties(), EXCLUDED_PROPS);
|
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);
|
fav.setProperties(filteredNodeProperties);
|
||||||
}
|
}
|
||||||
|
final List<String> allowableOperations = node.getAllowableOperations();
|
||||||
|
if (CollectionUtils.isNotEmpty(allowableOperations) && paramsInclude.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
|
||||||
|
{
|
||||||
|
fav.setAllowableOperations(allowableOperations);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fav;
|
return fav;
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
package org.alfresco.rest.api.model;
|
package org.alfresco.rest.api.model;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.rest.framework.resource.UniqueId;
|
import org.alfresco.rest.framework.resource.UniqueId;
|
||||||
@@ -42,6 +43,7 @@ public class Favourite
|
|||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
private Target target;
|
private Target target;
|
||||||
private Map<String, Object> properties;
|
private Map<String, Object> properties;
|
||||||
|
private List<String> allowableOperations;
|
||||||
|
|
||||||
public Date getCreatedAt()
|
public Date getCreatedAt()
|
||||||
{
|
{
|
||||||
@@ -84,10 +86,18 @@ public class Favourite
|
|||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getAllowableOperations() {
|
||||||
|
return allowableOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowableOperations(List<String> allowableOperations) {
|
||||||
|
this.allowableOperations = allowableOperations;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "Favourite [targetGuid=" + targetGuid
|
return "Favourite [targetGuid=" + targetGuid
|
||||||
+ ", createdAt=" + createdAt + ", target=" + target + ", properties=" + properties + "]";
|
+ ", createdAt=" + createdAt + ", target=" + target + ", properties=" + properties + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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_ALLOWABLEOPERATIONS;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
|
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_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_ISLINK;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLOCKED;
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLOCKED;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
|
||||||
@@ -96,10 +97,9 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class SearchMapper
|
public class SearchMapper
|
||||||
{
|
{
|
||||||
public static final List<String> PERMITTED_INCLUDES
|
public static final List<String> PERMITTED_INCLUDES = Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
|
||||||
= Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
|
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES, PARAM_INCLUDE_ASSOCIATION,
|
||||||
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES,
|
PARAM_INCLUDE_ISLOCKED, PARAM_INCLUDE_PERMISSIONS, PARAM_INCLUDE_ISFAVORITE);
|
||||||
PARAM_INCLUDE_ASSOCIATION, PARAM_INCLUDE_ISLOCKED, PARAM_INCLUDE_PERMISSIONS);
|
|
||||||
|
|
||||||
public static final String CMIS = "cmis";
|
public static final String CMIS = "cmis";
|
||||||
public static final String LUCENE = "lucene";
|
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_ALLOWABLEOPERATIONS;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
|
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_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_ISLINK;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLOCKED;
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLOCKED;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
|
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,
|
searchMapper.validateInclude(Arrays.asList(PARAM_INCLUDE_ALLOWABLEOPERATIONS,PARAM_INCLUDE_ASPECTNAMES,
|
||||||
PARAM_INCLUDE_ISLINK, PARAM_INCLUDE_PATH, PARAM_INCLUDE_PROPERTIES,
|
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