use of org.alfresco.service.cmr.rating.Rating 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.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.
the class RepoService method getNodeRatings.
public List<NodeRating> getNodeRatings(String personId, String networkId, final NodeRef nodeRef) {
List<NodeRating> ratings = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<NodeRating>>() {
@Override
public List<NodeRating> doWork() throws Exception {
List<NodeRating> ratings = new ArrayList<NodeRating>();
{
Rating likesRating = ratingService.getRatingByCurrentUser(nodeRef, "likesRatingScheme");
Object myRating = null;
String ratedAt = null;
if (likesRating != null) {
myRating = likesRating.getScore() == 1.0f ? Boolean.TRUE : Boolean.FALSE;
Date rateTime = likesRating.getAppliedAt();
ratedAt = PublicApiDateFormat.getDateFormat().format(rateTime);
}
int ratingsCount = ratingService.getRatingsCount(nodeRef, "likesRatingScheme");
Aggregate aggregate = new Aggregate(ratingsCount, null);
ratings.add(new NodeRating(nodeRef.getId(), "likes", ratedAt, myRating, aggregate));
}
{
Rating fiveStarRating = ratingService.getRatingByCurrentUser(nodeRef, "fiveStarRatingScheme");
Object myRating = null;
String ratedAt = null;
if (fiveStarRating != null) {
myRating = fiveStarRating.getScore();
Date rateTime = fiveStarRating.getAppliedAt();
ratedAt = PublicApiDateFormat.getDateFormat().format(rateTime);
}
int ratingsCount = ratingService.getRatingsCount(nodeRef, "fiveStarRatingScheme");
float averageRating = ratingService.getAverageRating(nodeRef, "fiveStarRatingScheme");
Aggregate aggregate = new Aggregate(ratingsCount, averageRating == -1 ? null : averageRating);
ratings.add(new NodeRating(nodeRef.getId(), "fiveStar", ratedAt, myRating, aggregate));
}
return ratings;
}
}, personId, networkId);
Collections.sort(ratings);
return ratings;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.
the class RatingsGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req);
// These are the data for the current user's ratings of this node, if any.
List<Rating> myRatings = new ArrayList<Rating>();
// These maps hold the average rating, accumulated total of all ratings and
// the number of ratings applied for this node as a function of rating scheme.
Map<String, Float> averageRatings = new HashMap<String, Float>();
Map<String, Float> ratingsTotals = new HashMap<String, Float>();
Map<String, Integer> ratingsCounts = new HashMap<String, Integer>();
for (String schemeName : ratingService.getRatingSchemes().keySet()) {
final Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(nodeRef, schemeName);
if (ratingByCurrentUser != null) {
myRatings.add(ratingByCurrentUser);
}
averageRatings.put(schemeName, ratingService.getAverageRating(nodeRef, schemeName));
ratingsTotals.put(schemeName, ratingService.getTotalRating(nodeRef, schemeName));
ratingsCounts.put(schemeName, ratingService.getRatingsCount(nodeRef, schemeName));
}
model.put(NODE_REF, nodeRef.toString());
model.put(RATINGS, myRatings);
model.put(AVERAGE_RATINGS, averageRatings);
model.put(RATINGS_TOTALS, ratingsTotals);
model.put(RATINGS_COUNTS, ratingsCounts);
return model;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.
the class RatingDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req);
String ratingSchemeName = parseRequestForScheme(req);
Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName);
if (deletedRating == null) {
// There was no rating in the specified scheme to delete.
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: " + ratingSchemeName + " from " + nodeRef.toString());
}
model.put(NODE_REF, nodeRef.toString());
model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName));
model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName));
model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName));
return model;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.
the class RatingCountRollupAlgorithm method recalculate.
public Integer recalculate(NodeRef ratedNode) {
int result = 0;
// If the node is not rateable, then it has no ratings in any scheme.
if (nodeService.hasAspect(ratedNode, ContentModel.ASPECT_RATEABLE)) {
List<ChildAssociationRef> ratingsNodes = ratingServiceImpl.getRatingNodeChildren(ratedNode, ratingSchemeName, null);
// Filter by scheme
for (ChildAssociationRef chAssRef : ratingsNodes) {
NodeRef nextRatingNode = chAssRef.getChildRef();
Rating rating = ratingServiceImpl.getRatingFrom(nextRatingNode);
if (ratingSchemeName.equals(rating.getScheme().getName())) {
result++;
}
}
}
return result;
}
Aggregations