use of org.alfresco.rest.api.model.Tag in project alfresco-remote-api by Alfresco.
the class TagsImpl method getTags.
public CollectionWithPagingInfo<Tag> getTags(StoreRef storeRef, Parameters params) {
Paging paging = params.getPaging();
PagingResults<Pair<NodeRef, String>> results = taggingService.getTags(storeRef, Util.getPagingRequest(paging));
taggingService.getPagedTags(storeRef, 0, paging.getMaxItems());
Integer totalItems = results.getTotalResultCount().getFirst();
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());
selectedTag.setCount(tagsByCountMap.get(selectedTag.getTag()));
tags.add(selectedTag);
}
return CollectionWithPagingInfo.asPaged(paging, tags, results.hasMoreItems(), (totalItems == null ? null : totalItems.intValue()));
}
use of org.alfresco.rest.api.model.Tag in project alfresco-remote-api by Alfresco.
the class TagsImpl method getTag.
public Tag getTag(StoreRef storeRef, String tagId) {
NodeRef tagNodeRef = validateTag(storeRef, tagId);
String tagValue = taggingService.getTagName(tagNodeRef);
return new Tag(tagNodeRef, tagValue);
}
use of org.alfresco.rest.api.model.Tag in project alfresco-remote-api by Alfresco.
the class TagsImpl method changeTag.
public Tag changeTag(StoreRef storeRef, String tagId, Tag tag) {
try {
NodeRef existingTagNodeRef = validateTag(storeRef, tagId);
String existingTagName = taggingService.getTagName(existingTagNodeRef);
String newTagName = tag.getTag();
NodeRef newTagNodeRef = taggingService.changeTag(storeRef, existingTagName, newTagName);
return new Tag(newTagNodeRef, newTagName);
} catch (NonExistentTagException e) {
throw new NotFoundException(e.getMessage());
} catch (TagExistsException e) {
throw new ConstraintViolatedException(e.getMessage());
} catch (TaggingException e) {
throw new InvalidArgumentException(e.getMessage());
}
}
use of org.alfresco.rest.api.model.Tag in project alfresco-remote-api by Alfresco.
the class TagsImpl method getTags.
public CollectionWithPagingInfo<Tag> getTags(String nodeId, Parameters params) {
NodeRef nodeRef = validateTag(nodeId);
PagingResults<Pair<NodeRef, String>> results = taggingService.getTags(nodeRef, Util.getPagingRequest(params.getPaging()));
Integer totalItems = results.getTotalResultCount().getFirst();
List<Pair<NodeRef, String>> page = results.getPage();
List<Tag> tags = new ArrayList<Tag>(page.size());
for (Pair<NodeRef, String> pair : page) {
tags.add(new Tag(pair.getFirst(), pair.getSecond()));
}
return CollectionWithPagingInfo.asPaged(params.getPaging(), tags, results.hasMoreItems(), (totalItems == null ? null : totalItems.intValue()));
}
use of org.alfresco.rest.api.model.Tag in project alfresco-remote-api by Alfresco.
the class TagsImpl method addTags.
public List<Tag> addTags(String nodeId, final List<Tag> tags) {
NodeRef nodeRef = nodes.validateNode(nodeId);
if (!typeConstraint.matches(nodeRef)) {
throw new UnsupportedResourceOperationException("Cannot tag this node");
}
List<String> tagValues = new AbstractList<String>() {
@Override
public String get(int arg0) {
String tag = tags.get(arg0).getTag();
return tag;
}
@Override
public int size() {
return tags.size();
}
};
try {
List<Pair<String, NodeRef>> tagNodeRefs = taggingService.addTags(nodeRef, tagValues);
List<Tag> ret = new ArrayList<Tag>(tags.size());
for (Pair<String, NodeRef> pair : tagNodeRefs) {
ret.add(new Tag(pair.getSecond(), pair.getFirst()));
}
return ret;
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(e.getMessage());
}
}
Aggregations