Files
alfresco-community-repo/source/java/org/alfresco/repo/rating/RatingCountRollupAlgorithm.java
Raluca Munteanu 8674e2bfc8 Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
      125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-04-26 12:48:49 +00:00

50 lines
1.5 KiB
Java

package org.alfresco.repo.rating;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.rating.Rating;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* An implementation of {@link AbstractRatingRollupAlgorithm} which calculates the count (number) of all
* ratings in a given scheme.
*
* @author Neil McErlean
* @since 3.5
*/
public class RatingCountRollupAlgorithm extends AbstractRatingRollupAlgorithm
{
public static final String ROLLUP_NAME = "Count";
public RatingCountRollupAlgorithm()
{
super(ROLLUP_NAME);
}
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;
}
}