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