Search in sources :

Example 1 with Tag

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()));
}
Also used : HashMap(java.util.HashMap) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Tag(org.alfresco.rest.api.model.Tag) Pair(org.alfresco.util.Pair)

Example 2 with Tag

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Tag(org.alfresco.rest.api.model.Tag)

Example 3 with Tag

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());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) TagExistsException(org.alfresco.repo.tagging.TagExistsException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) TaggingException(org.alfresco.repo.tagging.TaggingException) Tag(org.alfresco.rest.api.model.Tag) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) NonExistentTagException(org.alfresco.repo.tagging.NonExistentTagException)

Example 4 with Tag

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()));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArrayList(java.util.ArrayList) Tag(org.alfresco.rest.api.model.Tag) Pair(org.alfresco.util.Pair)

Example 5 with Tag

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());
    }
}
Also used : AbstractList(java.util.AbstractList) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Tag(org.alfresco.rest.api.model.Tag) Pair(org.alfresco.util.Pair)

Aggregations

Tag (org.alfresco.rest.api.model.Tag)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 ArrayList (java.util.ArrayList)3 Pair (org.alfresco.util.Pair)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 AbstractList (java.util.AbstractList)1 HashMap (java.util.HashMap)1 NonExistentTagException (org.alfresco.repo.tagging.NonExistentTagException)1 TagExistsException (org.alfresco.repo.tagging.TagExistsException)1 TaggingException (org.alfresco.repo.tagging.TaggingException)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)1 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1