private float getFiveStarRating() { float rating = random.nextFloat() * (fiveStarRatingScheme.getMaxRating() - fiveStarRatingScheme.getMinRating()) + fiveStarRatingScheme.getMinRating(); assertTrue("Five star rating is out of range: " + rating, (rating >= fiveStarRatingScheme.getMinRating() && rating <= fiveStarRatingScheme.getMaxRating())); return rating; }
/** * 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); }
/** * This method checks whether self-rating is allowed for the specified rating scheme. * If self-rating is allowed in the specified scheme, then the cm:creator of a node can apply a rating, * otherwise they cannot. * * @param ratingSchemeName the rating scheme bean name. * @return <code>true</code> if users can rate their own content, else <code>false</code>. */ public boolean isSelfRatingAllowed(String ratingSchemeName) { return ratingService.getRatingScheme(ratingSchemeName).isSelfRatingAllowed(); }
if (rating < ratingScheme.getMinRating() || rating > ratingScheme.getMaxRating()) final QName assocQName = ratingNamingConventions.getRatingAssocNameFor(userName, ratingScheme.getName()); List<ChildAssociationRef> myRatingChildren = nodeService.getChildAssocs(targetNode, ContentModel.ASSOC_RATINGS, assocQName); if (myRatingChildren.isEmpty())
/** * 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()); } }
/** * 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(); }
/** * Gets the minimum allowed rating for the specified rating scheme. * * @param ratingSchemeName String * @return float */ public float getMin(String ratingSchemeName) { return ratingService.getRatingScheme(ratingSchemeName).getMinRating(); }
/** * Initialise method */ public void init() { // Prevent the ratebale aspect from being copied bindNoCopyBehaviour(ContentModel.ASPECT_RATEABLE); // Prevent the roll up aspects from being copied for (RatingScheme ratingScheme : ratingSchemeRegistry.getRatingSchemes().values()) { if (ratingScheme.getPropertyRollups() != null && ratingScheme.getPropertyRollups().size() > 0) { QName rollupAspectName = ratingNamingConventions.getRollupAspectNameFor(ratingScheme); bindNoCopyBehaviour(rollupAspectName); } } }
if (rating < ratingScheme.getMinRating() || rating > ratingScheme.getMaxRating()) final QName assocQName = ratingNamingConventions.getRatingAssocNameFor(userName, ratingScheme.getName()); List<ChildAssociationRef> myRatingChildren = nodeService.getChildAssocs(targetNode, ContentModel.ASSOC_RATINGS, assocQName); if (myRatingChildren.isEmpty())
/** * 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()); } }
/** * 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(); }
/** * Gets the minimum allowed rating for the specified rating scheme. * * @param ratingSchemeName String * @return float */ public float getMin(String ratingSchemeName) { return ratingService.getRatingScheme(ratingSchemeName).getMinRating(); }
/** * Initialise method */ public void init() { // Prevent the ratebale aspect from being copied bindNoCopyBehaviour(ContentModel.ASPECT_RATEABLE); // Prevent the roll up aspects from being copied for (RatingScheme ratingScheme : ratingSchemeRegistry.getRatingSchemes().values()) { if (ratingScheme.getPropertyRollups() != null && ratingScheme.getPropertyRollups().size() > 0) { QName rollupAspectName = ratingNamingConventions.getRollupAspectNameFor(ratingScheme); bindNoCopyBehaviour(rollupAspectName); } } }
/** * 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()); }
/** * 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); }
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; } }
assertEquals(11.0f, spinalTap.getMaxRating(), 0.0001f);
/** * This method checks whether self-rating is allowed for the specified rating scheme. * If self-rating is allowed in the specified scheme, then the cm:creator of a node can apply a rating, * otherwise they cannot. * * @param ratingSchemeName the rating scheme bean name. * @return <code>true</code> if users can rate their own content, else <code>false</code>. */ public boolean isSelfRatingAllowed(String ratingSchemeName) { return ratingService.getRatingScheme(ratingSchemeName).isSelfRatingAllowed(); }
try for (AbstractRatingRollupAlgorithm rollupAlgorithm : ratingScheme.getPropertyRollups())
/** * 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); } }