Search in sources :

Example 1 with RatingScheme

use of org.alfresco.rest.api.impl.node.ratings.RatingScheme in project alfresco-remote-api by Alfresco.

the class NodeRatingsImpl method getNodeRating.

// TODO deal with fractional ratings - InvalidArgumentException
public NodeRating getNodeRating(String nodeId, String ratingSchemeId) {
    NodeRef nodeRef = nodes.validateNode(nodeId);
    RatingScheme ratingScheme = validateRatingScheme(ratingSchemeId);
    return ratingScheme.getNodeRating(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RatingScheme(org.alfresco.rest.api.impl.node.ratings.RatingScheme)

Example 2 with RatingScheme

use of org.alfresco.rest.api.impl.node.ratings.RatingScheme in project alfresco-remote-api by Alfresco.

the class NodeRatingsImpl method addRating.

public void addRating(String nodeId, String ratingSchemeId, Object rating) {
    NodeRef nodeRef = nodes.validateNode(nodeId);
    RatingScheme ratingScheme = validateRatingScheme(ratingSchemeId);
    if (!typeConstraint.matches(nodeRef)) {
        throw new UnsupportedResourceOperationException("Cannot rate this node");
    }
    ratingScheme.applyRating(nodeRef, rating);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RatingScheme(org.alfresco.rest.api.impl.node.ratings.RatingScheme) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)

Example 3 with RatingScheme

use of org.alfresco.rest.api.impl.node.ratings.RatingScheme in project alfresco-remote-api by Alfresco.

the class NodeRatingsImpl method removeRating.

public void removeRating(String nodeId, String ratingSchemeId) {
    RatingScheme ratingScheme = validateRatingScheme(ratingSchemeId);
    NodeRef nodeRef = nodes.validateNode(nodeId);
    ratingScheme.removeRating(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RatingScheme(org.alfresco.rest.api.impl.node.ratings.RatingScheme)

Example 4 with RatingScheme

use of org.alfresco.rest.api.impl.node.ratings.RatingScheme in project alfresco-remote-api by Alfresco.

the class NodeRatingsImpl method getNodeRatings.

public CollectionWithPagingInfo<NodeRating> getNodeRatings(String nodeId, Paging paging) {
    NodeRef nodeRef = nodes.validateNode(nodeId);
    Set<String> schemes = new TreeSet<String>(ratingService.getRatingSchemes().keySet());
    Iterator<String> it = schemes.iterator();
    int skipCount = paging.getSkipCount();
    int maxItems = paging.getMaxItems();
    int totalSize = schemes.size();
    int count = 0;
    int end = skipCount + maxItems;
    if (end < 0) {
        // overflow
        end = Integer.MAX_VALUE;
    }
    List<NodeRating> ratings = new ArrayList<NodeRating>(totalSize);
    for (int i = 0; i < end && it.hasNext(); i++) {
        String schemeName = it.next();
        if (i < skipCount) {
            continue;
        }
        count++;
        RatingScheme ratingScheme = validateRatingScheme(schemeName);
        NodeRating nodeRating = ratingScheme.getNodeRating(nodeRef);
        ratings.add(nodeRating);
    }
    boolean hasMoreItems = (skipCount + count < totalSize);
    return CollectionWithPagingInfo.asPaged(paging, ratings, hasMoreItems, totalSize);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RatingScheme(org.alfresco.rest.api.impl.node.ratings.RatingScheme) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) NodeRating(org.alfresco.rest.api.model.NodeRating) TypeConstraint(org.alfresco.util.TypeConstraint)

Aggregations

RatingScheme (org.alfresco.rest.api.impl.node.ratings.RatingScheme)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 NodeRating (org.alfresco.rest.api.model.NodeRating)1 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)1 TypeConstraint (org.alfresco.util.TypeConstraint)1