Search in sources :

Example 6 with Rating

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;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Rating(org.alfresco.service.cmr.rating.Rating) Date(java.util.Date)

Example 7 with Rating

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;
}
Also used : Serializable(java.io.Serializable) RatingScheme(org.alfresco.service.cmr.rating.RatingScheme) QName(org.alfresco.service.namespace.QName) Rating(org.alfresco.service.cmr.rating.Rating) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date)

Example 8 with Rating

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;
}
Also used : Rating(org.alfresco.service.cmr.rating.Rating) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Extend(org.alfresco.traitextender.Extend)

Example 9 with Rating

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;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Rating(org.alfresco.service.cmr.rating.Rating) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date)

Example 10 with Rating

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Rating(org.alfresco.service.cmr.rating.Rating) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

Rating (org.alfresco.service.cmr.rating.Rating)10 Date (java.util.Date)5 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 QName (org.alfresco.service.namespace.QName)3 HashMap (java.util.HashMap)2 JSONObject (org.json.simple.JSONObject)2 SQLException (java.sql.SQLException)1 List (java.util.List)1 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)1 SiteDoesNotExistException (org.alfresco.repo.site.SiteDoesNotExistException)1 DocumentRatingSummary (org.alfresco.rest.api.model.DocumentRatingSummary)1 NodeRating (org.alfresco.rest.api.model.NodeRating)1 NodeRating (org.alfresco.rest.api.tests.client.data.NodeRating)1 Aggregate (org.alfresco.rest.api.tests.client.data.NodeRating.Aggregate)1 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 RatingScheme (org.alfresco.service.cmr.rating.RatingScheme)1