/** * Gets the rating applied to the specified node in the specified scheme by * the currently authenticated user. * @param node ScriptNode * @param ratingSchemeName String * @return rating if there is one, else -1. * TODO -1 could be a valid rating. */ public float getRating(ScriptNode node, String ratingSchemeName) { final Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(node.getNodeRef(), ratingSchemeName); return ratingByCurrentUser == null ? -1f : ratingByCurrentUser.getScore(); }
/** * Gets the rating applied to the specified node in the specified scheme by * the currently authenticated user. * @param node ScriptNode * @param ratingSchemeName String * @return rating if there is one, else -1. * TODO -1 could be a valid rating. */ public float getRating(ScriptNode node, String ratingSchemeName) { final Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(node.getNodeRef(), ratingSchemeName); return ratingByCurrentUser == null ? -1f : ratingByCurrentUser.getScore(); }
public Float recalculate(NodeRef ratedNode) { float 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 += rating.getScore(); } } } return result; } }
public Float recalculate(NodeRef ratedNode) { float 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 += rating.getScore(); } } } return result; } }
assertEquals("Wrong score for rating", fiveStarScore, (int)fiveStarRating.getScore()); assertEquals("Wrong user for rating", AuthenticationUtil.getFullyAuthenticatedUser(), fiveStarRating.getAppliedBy()); final Date fiveStarRatingAppliedAt = fiveStarRating.getAppliedAt(); assertEquals("Wrong score for rating", updatedFiveStarScore, (int)updatedFiveStarRating.getScore()); assertEquals("Wrong user for rating", AuthenticationUtil.getFullyAuthenticatedUser(), updatedFiveStarRating.getAppliedBy()); assertTrue("five star rating date was unchanged.", fiveStarRatingAppliedAt.equals(updatedFiveStarRating.getAppliedAt()) == false); assertEquals("Wrong score for rating", updatedFiveStarScore, (int)deletedStarRating.getScore()); assertEquals("Wrong user for rating", AuthenticationUtil.getFullyAuthenticatedUser(), deletedStarRating.getAppliedBy()); assertEquals("Wrong date for rating", updatedFiveStarRating.getAppliedAt(), deletedStarRating.getAppliedAt());