From 626e5b34efa31f770073c5b334f7c6c638fbd120 Mon Sep 17 00:00:00 2001 From: "suneet.gupta" Date: Thu, 23 Mar 2023 18:35:12 +0530 Subject: [PATCH] [ACS-4636] Added count support for creation of tags to a node --- .../main/java/org/alfresco/rest/api/Tags.java | 2 +- .../org/alfresco/rest/api/impl/TagsImpl.java | 12 +++-- .../rest/api/nodes/NodeTagsRelation.java | 52 +++++++++---------- .../alfresco/rest/api/impl/TagsImplTest.java | 6 +-- 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/Tags.java b/remote-api/src/main/java/org/alfresco/rest/api/Tags.java index ec64b5b8de..e75c1ef8ca 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/Tags.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/Tags.java @@ -37,7 +37,7 @@ import org.alfresco.service.cmr.repository.StoreRef; public interface Tags { - List addTags(String nodeId, List tags); + List addTags(String nodeId, List tags, Parameters parameters); Tag getTag(StoreRef storeRef, String tagId); void deleteTag(String nodeId, String tagId); CollectionWithPagingInfo getTags(StoreRef storeRef, Parameters params); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java index d703b86262..53c81c31a5 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/TagsImpl.java @@ -96,7 +96,7 @@ public class TagsImpl implements Tags this.typeConstraint = typeConstraint; } - public void setNodes(Nodes nodes) + public void setNodes(Nodes nodes) { this.nodes = nodes; } @@ -115,7 +115,7 @@ public class TagsImpl implements Tags this.authorityService = authorityService; } - public List addTags(String nodeId, final List tags) + public List addTags(String nodeId, final List tags, final Parameters parameters) { NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null); if (!typeConstraint.matches(nodeRef)) @@ -128,9 +128,15 @@ public class TagsImpl implements Tags { List> tagNodeRefs = taggingService.addTags(nodeRef, tagValues); List ret = new ArrayList<>(tags.size()); + List> tagsCountPairList = taggingService.findTaggedNodesAndCountByTagName(nodeRef.getStoreRef()); + Map tagsCountMap = tagsCountPairList.stream().collect(Collectors.toMap(Pair::getFirst,Pair::getSecond)); for (Pair pair : tagNodeRefs) { - ret.add(new Tag(pair.getSecond(), pair.getFirst())); + Tag createdTag = new Tag(pair.getSecond(), pair.getFirst()); + if (parameters.getInclude().contains(PARAM_INCLUDE_COUNT)) { + createdTag.setCount(Optional.ofNullable(tagsCountMap.get(createdTag.getTag())).orElse(0) + 1); + } + ret.add(createdTag); } return ret; } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeTagsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeTagsRelation.java index 9e9d9ea3c6..4e836718be 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeTagsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeTagsRelation.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.rest.api.nodes; import java.util.List; @@ -61,7 +61,7 @@ public class NodeTagsRelation implements RelationshipResourceAction.Create, @WebApiDescription(title="Adds one or more tags to the node with id 'nodeId'.") public List create(String nodeId, List tagsToCreate, Parameters parameters) { - return tags.addTags(nodeId, tagsToCreate); + return tags.addTags(nodeId, tagsToCreate, parameters); } @Override diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java index f874db09e2..90360d46fb 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/TagsImplTest.java @@ -429,7 +429,7 @@ public class TagsImplTest List tags = tagNames.stream().map(name -> Tag.builder().tag(name).create()).collect(toList()); given(taggingServiceMock.addTags(CONTENT_NODE_REF, tagNames)).willReturn(pairs); - List actual = objectUnderTest.addTags(CONTENT_NODE_ID, tags); + List actual = objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock); List expected = pairs.stream().map(pair -> new Tag(pair.getSecond(), pair.getFirst())).collect(toList()); assertEquals("Unexpected tags returned.", expected, actual); @@ -441,7 +441,7 @@ public class TagsImplTest given(nodesMock.validateOrLookupNode(CONTENT_NODE_ID, null)).willThrow(new InvalidArgumentException()); List tags = List.of(Tag.builder().tag("tag1").create()); - objectUnderTest.addTags(CONTENT_NODE_ID, tags); + objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock); } @Test(expected = UnsupportedResourceOperationException.class) @@ -452,7 +452,7 @@ public class TagsImplTest List tags = List.of(Tag.builder().tag("tag1").create()); - objectUnderTest.addTags(CONTENT_NODE_ID, tags); + objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock); } @Test