mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
[ACS-4636] Added count support for creation of tags to a node
This commit is contained in:
@@ -37,7 +37,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
|
||||
|
||||
public interface Tags
|
||||
{
|
||||
List<Tag> addTags(String nodeId, List<Tag> tags);
|
||||
List<Tag> addTags(String nodeId, List<Tag> tags, Parameters parameters);
|
||||
Tag getTag(StoreRef storeRef, String tagId);
|
||||
void deleteTag(String nodeId, String tagId);
|
||||
CollectionWithPagingInfo<Tag> getTags(StoreRef storeRef, Parameters params);
|
||||
|
@@ -115,7 +115,7 @@ public class TagsImpl implements Tags
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
public List<Tag> addTags(String nodeId, final List<Tag> tags)
|
||||
public List<Tag> addTags(String nodeId, final List<Tag> tags, final Parameters parameters)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
|
||||
if (!typeConstraint.matches(nodeRef))
|
||||
@@ -128,9 +128,15 @@ public class TagsImpl implements Tags
|
||||
{
|
||||
List<Pair<String, NodeRef>> tagNodeRefs = taggingService.addTags(nodeRef, tagValues);
|
||||
List<Tag> ret = new ArrayList<>(tags.size());
|
||||
List<Pair<String, Integer>> tagsCountPairList = taggingService.findTaggedNodesAndCountByTagName(nodeRef.getStoreRef());
|
||||
Map<String, Integer> tagsCountMap = tagsCountPairList.stream().collect(Collectors.toMap(Pair::getFirst,Pair::getSecond));
|
||||
for (Pair<String, NodeRef> 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;
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ public class NodeTagsRelation implements RelationshipResourceAction.Create<Tag>,
|
||||
@WebApiDescription(title="Adds one or more tags to the node with id 'nodeId'.")
|
||||
public List<Tag> create(String nodeId, List<Tag> tagsToCreate, Parameters parameters)
|
||||
{
|
||||
return tags.addTags(nodeId, tagsToCreate);
|
||||
return tags.addTags(nodeId, tagsToCreate, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -429,7 +429,7 @@ public class TagsImplTest
|
||||
List<Tag> tags = tagNames.stream().map(name -> Tag.builder().tag(name).create()).collect(toList());
|
||||
given(taggingServiceMock.addTags(CONTENT_NODE_REF, tagNames)).willReturn(pairs);
|
||||
|
||||
List<Tag> actual = objectUnderTest.addTags(CONTENT_NODE_ID, tags);
|
||||
List<Tag> actual = objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock);
|
||||
|
||||
List<Tag> 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<Tag> 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<Tag> tags = List.of(Tag.builder().tag("tag1").create());
|
||||
|
||||
objectUnderTest.addTags(CONTENT_NODE_ID, tags);
|
||||
objectUnderTest.addTags(CONTENT_NODE_ID, tags, parametersMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user