use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.
the class RatingServiceImpl method convertNodeRefToRating.
/**
* This method converts a NodeRef (which must be an instance of a cm:rating node)
* into a {@link Rating} object.
* @param user String
* @param ratingNode NodeRef
* @return Rating
*/
private Rating convertNodeRefToRating(String user, NodeRef ratingNode) {
Map<QName, Serializable> properties = nodeService.getProperties(ratingNode);
String existingRatingScheme = (String) properties.get(ContentModel.PROP_RATING_SCHEME);
Float existingRatingScore = (Float) properties.get(ContentModel.PROP_RATING_SCORE);
Date existingRatingDate = (Date) properties.get(ContentModel.PROP_RATED_AT);
Rating result = new Rating(getRatingScheme(existingRatingScheme), existingRatingScore, user, existingRatingDate);
return result;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.
the class RatingServiceImpl method getRatingFrom.
/**
* This method returns a {@link Rating} object for the specified cm:rating node.
* @param ratingNode NodeRef
* @return Rating
*/
Rating getRatingFrom(NodeRef ratingNode) {
// The appliedBy is encoded in the parent assoc qname.
// It will be the same user for all ratings in this node.
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(ratingNode);
String appliedBy = parentAssoc.getQName().getLocalName();
Map<QName, Serializable> properties = nodeService.getProperties(ratingNode);
final String schemeName = (String) properties.get(ContentModel.PROP_RATING_SCHEME);
final Float score = (Float) properties.get(ContentModel.PROP_RATING_SCORE);
final Date ratedAt = (Date) properties.get(ContentModel.PROP_RATED_AT);
RatingScheme scheme = getRatingScheme(schemeName);
Rating result = new Rating(scheme, score, appliedBy, ratedAt);
return result;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.
the class RatingServiceImpl method getRatingsByCurrentUser.
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.rating.RatingService#getRatingsByCurrentUser(org.alfresco.service.cmr.repository.NodeRef)
*/
@Extend(traitAPI = RatingServiceTrait.class, extensionAPI = RatingServiceExtension.class)
public List<Rating> getRatingsByCurrentUser(NodeRef targetNode) {
final String fullyAuthenticatedUser = AuthenticationUtil.getFullyAuthenticatedUser();
List<ChildAssociationRef> children = getRatingNodeChildren(targetNode, null, fullyAuthenticatedUser);
List<Rating> result = new ArrayList<Rating>(children.size());
for (ChildAssociationRef child : children) {
result.add(convertNodeRefToRating(fullyAuthenticatedUser, child.getChildRef()));
}
return result;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.
the class RatingServiceImpl method removeRating.
private Rating removeRating(NodeRef targetNode, String ratingSchemeName, final String user) {
List<ChildAssociationRef> ratingChildren = getRatingNodeChildren(targetNode, ratingSchemeName, user);
if (ratingChildren.isEmpty()) {
return null;
}
ChildAssociationRef child = ratingChildren.get(0);
Map<QName, Serializable> properties = nodeService.getProperties(child.getChildRef());
Rating result = null;
// Get the scheme name and check it.
if (ratingSchemeName.equals(properties.get(ContentModel.PROP_RATING_SCHEME))) {
Float score = (Float) properties.get(ContentModel.PROP_RATING_SCORE);
Date date = (Date) properties.get(ContentModel.PROP_RATED_AT);
nodeService.deleteNode(child.getChildRef());
recalculateRatingRollups(targetNode, getRatingScheme(ratingSchemeName));
result = new Rating(getRatingScheme(ratingSchemeName), score, user, date);
}
return result;
}
use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.
the class RatingTotalRollupAlgorithm method recalculate.
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;
}
Aggregations