/** * This method can be used to sort RatingSchemes by name. * @since 4.1.5 */ @Override public int compareTo(RatingScheme otherScheme) { return this.name.compareTo(otherScheme.getName()); } }
/** * This method can be used to sort RatingSchemes by name. * @since 4.1.5 */ @Override public int compareTo(RatingScheme otherScheme) { return this.name.compareTo(otherScheme.getName()); } }
/** * Given a ratingScheme, this method returns the aspect name which would * by convention be used to store rating property rollups. * * @param ratingScheme the ratingScheme. * @return the aspect name used to store all property rollups for that scheme. */ public QName getRollupAspectNameFor(RatingScheme ratingScheme) { final String modelPrefix = ratingScheme.getModelPrefix(); final String ratingSchemeName = ratingScheme.getName(); String result = modelPrefix + ":" + ratingSchemeName + "Rollups"; return QName.createQName(result, namespaceService); }
/** * Given a ratingScheme, this method returns the aspect name which would * by convention be used to store rating property rollups. * * @param ratingScheme the ratingScheme. * @return the aspect name used to store all property rollups for that scheme. */ public QName getRollupAspectNameFor(RatingScheme ratingScheme) { final String modelPrefix = ratingScheme.getModelPrefix(); final String ratingSchemeName = ratingScheme.getName(); String result = modelPrefix + ":" + ratingSchemeName + "Rollups"; return QName.createQName(result, namespaceService); }
/** * Given a ratingScheme and a rollup name, this method returns the property name * which would by convention be used to store the given rollup. * * @param ratingScheme the ratingScheme. * @param rollupName the name of the property rollup as given by {@link AbstractRatingRollupAlgorithm#getRollupName()}. * @return the property name used to persist the given rollup in the given scheme. */ public QName getRollupPropertyNameFor(RatingScheme ratingScheme, String rollupName) { final String modelPrefix = ratingScheme.getModelPrefix(); final String ratingSchemeName = ratingScheme.getName(); String result = modelPrefix + ":" + ratingSchemeName + rollupName; return QName.createQName(result, namespaceService); } }
/** * Given a ratingScheme and a rollup name, this method returns the property name * which would by convention be used to store the given rollup. * * @param ratingScheme the ratingScheme. * @param rollupName the name of the property rollup as given by {@link AbstractRatingRollupAlgorithm#getRollupName()}. * @return the property name used to persist the given rollup in the given scheme. */ public QName getRollupPropertyNameFor(RatingScheme ratingScheme, String rollupName) { final String modelPrefix = ratingScheme.getModelPrefix(); final String ratingSchemeName = ratingScheme.getName(); String result = modelPrefix + ":" + ratingSchemeName + rollupName; return QName.createQName(result, namespaceService); } }
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; } }
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; } }
final QName assocQName = ratingNamingConventions.getRatingAssocNameFor(userName, ratingScheme.getName()); List<ChildAssociationRef> myRatingChildren = nodeService.getChildAssocs(targetNode, ContentModel.ASSOC_RATINGS, assocQName); if (myRatingChildren.isEmpty())
final QName assocQName = ratingNamingConventions.getRatingAssocNameFor(userName, ratingScheme.getName()); List<ChildAssociationRef> myRatingChildren = nodeService.getChildAssocs(targetNode, ContentModel.ASSOC_RATINGS, assocQName); if (myRatingChildren.isEmpty())
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; } }
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; } });
/** * This method tests that the expected 'out of the box' rating schemes are available * and correctly initialised. */ @Test public void outOfTheBoxRatingSchemes() throws Exception { Map<String, RatingScheme> schemes = RATING_SERVICE.getRatingSchemes(); assertNotNull("rating scheme collection was null.", schemes); assertTrue("rating scheme collection was empty.", schemes.isEmpty() == false); RatingScheme likesRS = schemes.get(LIKES_SCHEME_NAME); assertNotNull("'likes' rating scheme was missing.", likesRS); assertEquals("'likes' rating scheme had wrong name.", LIKES_SCHEME_NAME, likesRS.getName()); assertEquals("'likes' rating scheme had wrong min.", 1, (int)likesRS.getMinRating()); assertEquals("'likes' rating scheme had wrong max.", 1, (int)likesRS.getMaxRating()); RatingScheme fiveStarRS = schemes.get(FIVE_STAR_SCHEME_NAME); assertNotNull("'5*' rating scheme was missing.", fiveStarRS); assertEquals("'5*' rating scheme had wrong name.", FIVE_STAR_SCHEME_NAME, fiveStarRS.getName()); assertEquals("'5*' rating scheme had wrong min.", 1, (int)fiveStarRS.getMinRating()); assertEquals("'5*' rating scheme had wrong max.", 5, (int)fiveStarRS.getMaxRating()); }