ACS-4032 create category (multiple categories pagination fix) (#1610)

* ACS-4032: Some fixes and refactors after verification. Fixing pagination info on POST multiple entities response.

* ACS-4032: Some fixes and refactors after verification. Fixing pagination info on POST multiple entities response.

* Fixing a test STEP description

Co-authored-by: Tom Page <tpage-alfresco@users.noreply.github.com>

Co-authored-by: Tom Page <tpage-alfresco@users.noreply.github.com>
This commit is contained in:
Maciej Pichura
2022-12-08 17:40:56 +01:00
committed by GitHub
parent f96b3012c4
commit f511436823
5 changed files with 116 additions and 3 deletions

View File

@@ -49,12 +49,14 @@ import org.alfresco.service.cmr.search.CategoryService;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@Experimental
public class CategoriesImpl implements Categories
{
static final String NOT_A_VALID_CATEGORY = "Node id does not refer to a valid category";
static final String NO_PERMISSION_TO_CREATE_A_CATEGORY = "Current user does not have permission to create a category";
private static final String NOT_NULL_OR_EMPTY = "Category name must not be null or empty";
private final AuthorityService authorityService;
private final CategoryService categoryService;
@@ -97,13 +99,21 @@ public class CategoriesImpl implements Categories
throw new InvalidArgumentException(NOT_A_VALID_CATEGORY, new String[]{parentCategoryId});
}
final List<NodeRef> categoryNodeRefs = categories.stream()
.map(c -> categoryService.createCategory(parentNodeRef, c.getName()))
.map(c -> createCategoryNodeRef(parentNodeRef, c))
.collect(Collectors.toList());
return categoryNodeRefs.stream()
.map(this::mapToCategory)
.collect(Collectors.toList());
}
private NodeRef createCategoryNodeRef(NodeRef parentNodeRef, Category c)
{
if (StringUtils.isEmpty(c.getName())) {
throw new InvalidArgumentException(NOT_NULL_OR_EMPTY);
}
return categoryService.createCategory(parentNodeRef, c.getName());
}
private boolean isNotACategory(NodeRef nodeRef)
{
return !nodes.isSubClass(nodeRef, ContentModel.TYPE_CATEGORY, false);

View File

@@ -44,6 +44,7 @@ import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResource
import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartRelationshipResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Paging;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams;
import org.alfresco.rest.framework.tools.RecognizedParamsExtractor;
@@ -377,7 +378,8 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
{
if (created !=null && created.size() > 1)
{
return CollectionWithPagingInfo.asPagedCollection(created.toArray());
final Paging pagingAll = Paging.valueOf(0, created.size());
return CollectionWithPagingInfo.asPaged(pagingAll, created);
}
else
{