mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125781 rmunteanu: 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/HEAD/root@127808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
50 lines
1.5 KiB
Java
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 total (sum) of all
|
|
* ratings in a given scheme.
|
|
*
|
|
* @author Neil McErlean
|
|
* @since 3.5
|
|
*/
|
|
public class RatingTotalRollupAlgorithm extends AbstractRatingRollupAlgorithm
|
|
{
|
|
public static final String ROLLUP_NAME = "Total";
|
|
|
|
public RatingTotalRollupAlgorithm()
|
|
{
|
|
super(ROLLUP_NAME);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|