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);
}
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);
}
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);
}
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);
}
Aggregations