REPO-Tags: GET tags endpoint should provide aggregation info

This commit is contained in:
Andreea Nechifor
2018-03-06 08:30:08 +02:00
parent 05c8b6c968
commit c68f98d889

View File

@@ -27,7 +27,9 @@ package org.alfresco.rest.api.impl;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.tagging.NonExistentTagException;
@@ -135,25 +137,23 @@ public class TagsImpl implements Tags
List<Pair<NodeRef, String>> page = results.getPage();
List<Tag> tags = new ArrayList<Tag>(page.size());
List<Pair<String, Integer>> tagsByCount = null;
Map<String, Integer> tagsByCountMap = new HashMap<String, Integer>();
if (params.getInclude().contains(PARAM_INCLUDE_COUNT))
{
tagsByCount = taggingService.findTaggedNodesAndCountByTagName(storeRef);
if (tagsByCount != null)
{
for (Pair<String, Integer> tagByCountElem : tagsByCount)
{
tagsByCountMap.put(tagByCountElem.getFirst(), tagByCountElem.getSecond());
}
}
}
for (Pair<NodeRef, String> pair : page)
{
Tag selectedTag = new Tag(pair.getFirst(), pair.getSecond());
if (tagsByCount != null)
{
for (Pair<String, Integer> tagByCount : tagsByCount)
{
if (tagByCount.getFirst().equals(selectedTag.getTag()))
{
selectedTag.setCount(tagByCount.getSecond());
break;
}
}
}
selectedTag.setCount(tagsByCountMap.get(selectedTag.getTag()));
tags.add(selectedTag);
}