ACS-4923 Add support for include=count on GET and PUT tag. (#1880)

This commit is contained in:
Tom Page
2023-04-17 10:12:09 +01:00
committed by GitHub
parent 6be773ba18
commit b1466915af
9 changed files with 205 additions and 63 deletions

View File

@@ -27,8 +27,10 @@ package org.alfresco.repo.tagging;
import static java.util.Collections.emptyMap;
import static org.alfresco.model.ContentModel.ASPECT_WORKING_COPY;
import static org.alfresco.model.ContentModel.ASSOC_SUBCATEGORIES;
import static org.alfresco.model.ContentModel.PROP_NAME;
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
import static org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI;
import java.io.BufferedReader;
@@ -333,7 +335,7 @@ public class TaggingServiceImpl implements TaggingService,
public void beforeDeleteNode(NodeRef nodeRef)
{
if (this.nodeService.exists(nodeRef) == true &&
this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == true && !this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY))
this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == true && !this.nodeService.hasAspect(nodeRef, ASPECT_WORKING_COPY))
{
updateAllScopeTags(nodeRef, Boolean.FALSE);
}
@@ -1241,7 +1243,7 @@ public class TaggingServiceImpl implements TaggingService,
// Do the search for nodes
resultSet = this.searchService.query(
storeRef,
SearchService.LANGUAGE_LUCENE,
LANGUAGE_LUCENE,
"+PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"");
List<NodeRef> nodeRefs = resultSet.getNodeRefs();
return nodeRefs;
@@ -1270,7 +1272,7 @@ public class TaggingServiceImpl implements TaggingService,
// Do query
resultSet = this.searchService.query(
storeRef,
SearchService.LANGUAGE_LUCENE,
LANGUAGE_LUCENE,
"+PATH:\"" + pathString + "//*\" +PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"");
List<NodeRef> nodeRefs = resultSet.getNodeRefs();
return nodeRefs;
@@ -1538,7 +1540,7 @@ public class TaggingServiceImpl implements TaggingService,
public void afterCheckOut(NodeRef workingCopy)
{
if (this.nodeService.exists(workingCopy) == true && this.nodeService.hasAspect(workingCopy, ContentModel.ASPECT_TAGGABLE) == true
&& this.nodeService.hasAspect(workingCopy, ContentModel.ASPECT_WORKING_COPY))
&& this.nodeService.hasAspect(workingCopy, ASPECT_WORKING_COPY))
{
updateAllScopeTags(workingCopy, Boolean.FALSE);
}
@@ -1550,10 +1552,10 @@ public class TaggingServiceImpl implements TaggingService,
@Override
public List<Pair<String, Integer>> findTaggedNodesAndCountByTagName(StoreRef storeRef)
{
String queryTaggeble = "ASPECT:\"" + ContentModel.ASPECT_TAGGABLE + "\"" + "-ASPECT:\"" + ContentModel.ASPECT_WORKING_COPY + "\"";
String queryTaggeble = "ASPECT:\"" + ContentModel.ASPECT_TAGGABLE + "\"" + "-ASPECT:\"" + ASPECT_WORKING_COPY + "\"";
SearchParameters sp = new SearchParameters();
sp.setQuery(queryTaggeble);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setLanguage(LANGUAGE_LUCENE);
sp.addStore(storeRef);
sp.addFieldFacet(new FieldFacet("TAG"));
@@ -1573,6 +1575,32 @@ public class TaggingServiceImpl implements TaggingService,
}
}
/** {@inheritDoc} */
@Override
public long findCountByTagName(StoreRef storeRef, String name)
{
String query = "TAG:\"" + name + "\"" + "-ASPECT:\"" + ASPECT_WORKING_COPY + "\"";
SearchParameters sp = new SearchParameters();
sp.setQuery(query);
sp.setLanguage(LANGUAGE_LUCENE);
sp.addStore(storeRef);
ResultSet resultSet = null;
try
{
// Do the search for nodes
resultSet = this.searchService.query(sp);
return resultSet.getNumberFound();
}
finally
{
if (resultSet != null)
{
resultSet.close();
}
}
}
@Experimental
@Override
public List<Pair<String, NodeRef>> createTags(final StoreRef storeRef, final List<String> tagNames)

View File

@@ -338,6 +338,16 @@ public interface TaggingService
@NotAuditable
List<Pair<String, Integer>> findTaggedNodesAndCountByTagName(StoreRef storeRef);
/**
* Get the number of tagged nodes for a given tag.
*
* @param storeRef The store containing the nodes.
* @param name The name of the tag.
* @return The number of nodes tagged with the specified tag.
*/
@NotAuditable
long findCountByTagName(StoreRef storeRef, String name);
/**
* Creates orphan tags. Tag names case will be lowered.
*