@Override public NodeRef execute() throws Throwable { RATING_SERVICE.applyRating(testDoc_UserOne, 11.0F, spinalTapScheme); return null; } });
/** * Gets the average (mean) rating by all users on the specified node in the specified scheme. * @param node ScriptNode * @param ratingSchemeName * @param ratingSchemeName String * @return float */ public float getAverageRating(ScriptNode node, String ratingSchemeName) { return ratingService.getAverageRating(node.getNodeRef(), ratingSchemeName); } }
/** * Gets the maximum allowed rating for the specified rating scheme. * * @param ratingSchemeName String * @return float */ public float getMax(String ratingSchemeName) { return ratingService.getRatingScheme(ratingSchemeName).getMaxRating(); }
public Void execute() throws Throwable { RATING_SERVICE.applyRating(testDoc_Admin, 1.0f, FIVE_STAR_SCHEME_NAME); // A new score in the same rating scheme by the same user should replace the previous score. RATING_SERVICE.applyRating(testDoc_Admin, 2.0f, FIVE_STAR_SCHEME_NAME); float meanRating = RATING_SERVICE.getAverageRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong mean rating.", 2, (int)meanRating); float totalRating = RATING_SERVICE.getTotalRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong total rating.", 2, (int)totalRating); int ratingsCount = RATING_SERVICE.getRatingsCount(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong ratings count.", 1, ratingsCount); // There should only be one rating child node under the rated node. assertEquals("Wrong number of child nodes", 1 , NODE_SERVICE.getChildAssocs(testDoc_Admin).size()); return null; } });
public Void execute() throws Throwable Rating nullRating = RATING_SERVICE.getRatingByCurrentUser(testDoc_Admin, LIKES_SCHEME_NAME); assertNull("Expected a null rating,", nullRating); assertNull("Expected a null remove result.", RATING_SERVICE.removeRatingByCurrentUser(testDoc_Admin, LIKES_SCHEME_NAME)); RATING_SERVICE.applyRating(testDoc_Admin, fiveStarScore, FIVE_STAR_SCHEME_NAME); assertModifierIs(testDoc_Admin, AuthenticationUtil.getAdminUserName()); Rating fiveStarRating = RATING_SERVICE.getRatingByCurrentUser(testDoc_Admin, FIVE_STAR_SCHEME_NAME); RATING_SERVICE.applyRating(testDoc_Admin, updatedFiveStarScore, FIVE_STAR_SCHEME_NAME); assertModifierIs(testDoc_Admin, AuthenticationUtil.getAdminUserName()); Rating updatedFiveStarRating = RATING_SERVICE.getRatingByCurrentUser(testDoc_Admin, FIVE_STAR_SCHEME_NAME); Rating deletedStarRating = RATING_SERVICE.removeRatingByCurrentUser(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertModifierIs(testDoc_Admin, AuthenticationUtil.getAdminUserName()); assertNull("5* rating not null.", RATING_SERVICE.getRatingByCurrentUser(testDoc_Admin, FIVE_STAR_SCHEME_NAME));
RATING_SERVICE.applyRating(testDoc_UserTwo, 2.0f, FIVE_STAR_SCHEME_NAME); RATING_SERVICE.applyRating(testDoc_UserTwo, 1.0f, LIKES_SCHEME_NAME); List<Rating> ratings = RATING_SERVICE.getRatingsByCurrentUser(testDoc_UserTwo); assertEquals(2, ratings.size()); assertEquals(FIVE_STAR_SCHEME_NAME, ratings.get(0).getScheme().getName()); List<Rating> copiedRatings = RATING_SERVICE.getRatingsByCurrentUser(testDocCopy); assertEquals(0, copiedRatings.size()); final int likesRatingCount = RATING_SERVICE.getRatingsCount(testDocCopy, LIKES_SCHEME_NAME); final int fiveStarRatingCount = RATING_SERVICE.getRatingsCount(testDocCopy, FIVE_STAR_SCHEME_NAME);
@Override public NodeRef execute() throws Throwable { // Create a new folder to copy the rated node to. NodeRef testFolder = testNodes.createNode(COMPANY_HOME, "copyTarget", ContentModel.TYPE_FOLDER, AuthenticationUtil.getAdminUserName()); // Ensure the test document is not rated initially. assertNull(RATING_SERVICE.getRatingByCurrentUser(testDoc_Admin, LIKES_SCHEME_NAME)); // Apply a rating to the test document. RATING_SERVICE.applyRating(testDoc_Admin, 1, LIKES_SCHEME_NAME); return testFolder; } });
public Void execute() throws Throwable { RATING_SERVICE.applyRating(testDoc_UserTwo, 2.0f, FIVE_STAR_SCHEME_NAME); // A new score in a different rating scheme by the same user should not fail. RATING_SERVICE.applyRating(testDoc_UserTwo, 1.0f, LIKES_SCHEME_NAME); // There should be two rating child nodes under the rated node. assertEquals("Wrong number of child nodes", 2 , NODE_SERVICE.getChildAssocs(testDoc_UserTwo).size()); List<Rating> ratings = RATING_SERVICE.getRatingsByCurrentUser(testDoc_UserTwo); assertEquals(2, ratings.size()); assertEquals(FIVE_STAR_SCHEME_NAME, ratings.get(0).getScheme().getName()); assertEquals(LIKES_SCHEME_NAME, ratings.get(1).getScheme().getName()); return null; } });
/** * 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 names for rating schemes currently in the system. * @return String[] */ public String[] getRatingSchemeNames() { Set<String> schemeNames = ratingService.getRatingSchemes().keySet(); String[] result = new String[0]; result = schemeNames.toArray(result); return result; }
/** * Gets the total (sum) rating by all users on the specified node in the specified scheme. * @param node ScriptNode * @param ratingSchemeName String * @return float */ public float getTotalRating(ScriptNode node, String ratingSchemeName) { return ratingService.getTotalRating(node.getNodeRef(), ratingSchemeName); }
/** * Gets the number of ratings applied to the specified node by all users in the specified * scheme. * @param node ScriptNode * @param ratingSchemeName String * @return int */ public int getRatingsCount(ScriptNode node, String ratingSchemeName) { return ratingService.getRatingsCount(node.getNodeRef(), ratingSchemeName); }
/** * Removes any rating by the current user in the specified scheme from the specified * noderef. * @param node ScriptNode * @param ratingSchemeName String */ public void removeRating(ScriptNode node, String ratingSchemeName) { ratingService.removeRatingByCurrentUser(node.getNodeRef(), ratingSchemeName); }
@Override public NodeRef execute() throws Throwable { List<Rating> ratings = RATING_SERVICE.getRatingsByCurrentUser(copiedDoc); assertTrue("Expected there to be no ratings on the copied test doc.", ratings.isEmpty()); assertFalse("Unexpected cm:rateable aspect.", NODE_SERVICE.hasAspect(copiedDoc, ContentModel.ASPECT_RATEABLE)); assertFalse("Unexpected cm:likesRatingSchemeRollups aspect.", NODE_SERVICE.hasAspect(copiedDoc, ContentModel.ASPECT_LIKES_RATING_SCHEME_ROLLUPS)); assertFalse("Unexpected cm:fiveStarRatingSchemeRollups aspect.", NODE_SERVICE.hasAspect(copiedDoc, ContentModel.ASPECT_FIVESTAR_RATING_SCHEME_ROLLUPS)); return null; } });
RATING_SERVICE.applyRating(testDoc_Admin, 4.0f, FIVE_STAR_SCHEME_NAME); assertModifierIs(testDoc_Admin, AuthenticationUtil.getAdminUserName()); RATING_SERVICE.applyRating(testDoc_Admin, 2.0f, FIVE_STAR_SCHEME_NAME); assertModifierIs(testDoc_Admin, AuthenticationUtil.getAdminUserName()); float meanRating = RATING_SERVICE.getAverageRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong mean rating.", 3, (int)meanRating); float totalRating = RATING_SERVICE.getTotalRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong total rating.", 6, (int)totalRating); int ratingsCount = RATING_SERVICE.getRatingsCount(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong ratings count.", 2, ratingsCount); RATING_SERVICE.removeRatingByCurrentUser(testDoc_Admin, FIVE_STAR_SCHEME_NAME); meanRating = RATING_SERVICE.getAverageRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong mean rating.", 4, (int)meanRating); totalRating = RATING_SERVICE.getTotalRating(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong total rating.", 4, (int)totalRating); ratingsCount = RATING_SERVICE.getRatingsCount(testDoc_Admin, FIVE_STAR_SCHEME_NAME); assertEquals("Document had wrong ratings count.", 1, ratingsCount);
/** * Gets the rating applied date for the specified node in the specified scheme by * the currently authenticated user. * @param node ScriptNode * @param ratingSchemeName String * @return rating applied date if there is one, else <code>null</code> */ public Date getRatingAppliedAt(ScriptNode node, String ratingSchemeName) { final Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(node.getNodeRef(), ratingSchemeName); return ratingByCurrentUser == null ? null : ratingByCurrentUser.getAppliedAt(); }
/** * Gets the names for rating schemes currently in the system. * @return String[] */ public String[] getRatingSchemeNames() { Set<String> schemeNames = ratingService.getRatingSchemes().keySet(); String[] result = new String[0]; result = schemeNames.toArray(result); return result; }
/** * Gets the total (sum) rating by all users on the specified node in the specified scheme. * @param node ScriptNode * @param ratingSchemeName String * @return float */ public float getTotalRating(ScriptNode node, String ratingSchemeName) { return ratingService.getTotalRating(node.getNodeRef(), ratingSchemeName); }
/** * Gets the number of ratings applied to the specified node by all users in the specified * scheme. * @param node ScriptNode * @param ratingSchemeName String * @return int */ public int getRatingsCount(ScriptNode node, String ratingSchemeName) { return ratingService.getRatingsCount(node.getNodeRef(), ratingSchemeName); }
/** * Removes any rating by the current user in the specified scheme from the specified * noderef. * @param node ScriptNode * @param ratingSchemeName String */ public void removeRating(ScriptNode node, String ratingSchemeName) { ratingService.removeRatingByCurrentUser(node.getNodeRef(), ratingSchemeName); }