Search in sources :

Example 1 with NodeRating

use of org.alfresco.rest.api.model.NodeRating in project alfresco-remote-api by Alfresco.

the class AbstractRatingScheme method getNodeRating.

public NodeRating getNodeRating(NodeRef nodeRef) {
    Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(nodeRef, ratingSchemeName);
    Float rating = null;
    Date appliedAt = null;
    if (ratingByCurrentUser != null) {
        rating = ratingByCurrentUser.getScore();
        appliedAt = ratingByCurrentUser.getAppliedAt();
    }
    Object myRating = null;
    if (rating != null) {
        validateRating(rating);
        myRating = getApiRating(rating);
    }
    DocumentRatingSummary documentRatingSummary = getDocumentRatingSummary(nodeRef);
    NodeRating nodeRating = new NodeRating(ratingSchemeId, myRating, appliedAt, documentRatingSummary);
    return nodeRating;
}
Also used : DocumentRatingSummary(org.alfresco.rest.api.model.DocumentRatingSummary) Rating(org.alfresco.service.cmr.rating.Rating) NodeRating(org.alfresco.rest.api.model.NodeRating) JSONObject(org.json.simple.JSONObject) NodeRating(org.alfresco.rest.api.model.NodeRating) Date(java.util.Date)

Example 2 with NodeRating

use of org.alfresco.rest.api.model.NodeRating 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)

Example 3 with NodeRating

use of org.alfresco.rest.api.model.NodeRating in project alfresco-remote-api by Alfresco.

the class NodeRatingsRelation method create.

/**
 * Create a rating for the node with id 'nodeId'.
 */
@Override
@WebApiDescription(title = "Rate a node for 'nodeId'.")
@WebApiParam(name = "ratingEntity", title = "A single rating", description = "A single node rating, multiple ratings are not supported.", kind = ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple = false, required = true)
public List<NodeRating> create(String nodeId, List<NodeRating> ratingEntity, Parameters parameters) {
    // There will always be 1 value because allowMultiple=false
    NodeRating rating = ratingEntity.get(0);
    String ratingSchemeId = rating.getScheme();
    nodeRatings.addRating(nodeId, ratingSchemeId, rating.getMyRating());
    return Collections.singletonList(nodeRatings.getNodeRating(nodeId, ratingSchemeId));
}
Also used : NodeRating(org.alfresco.rest.api.model.NodeRating) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Aggregations

NodeRating (org.alfresco.rest.api.model.NodeRating)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeSet (java.util.TreeSet)1 RatingScheme (org.alfresco.rest.api.impl.node.ratings.RatingScheme)1 DocumentRatingSummary (org.alfresco.rest.api.model.DocumentRatingSummary)1 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)1 WebApiParam (org.alfresco.rest.framework.WebApiParam)1 Rating (org.alfresco.service.cmr.rating.Rating)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 TypeConstraint (org.alfresco.util.TypeConstraint)1 JSONObject (org.json.simple.JSONObject)1