mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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:
@@ -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);
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user