Search in sources :

Example 1 with Rating

use of org.alfresco.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.

the class AbstractRatingScheme method getNodeRating.

public NodeRating getNodeRating(NodeRef nodeRef) {
    Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(nodeRef, ratingSchemeName);
    Float rating = null;
    Date appliedAt = null;
    if (ratingByCurrentUser != null) {
        rating = ratingByCurrentUser.getScore();
        appliedAt = ratingByCurrentUser.getAppliedAt();
    }
    Object myRating = null;
    if (rating != null) {
        validateRating(rating);
        myRating = getApiRating(rating);
    }
    DocumentRatingSummary documentRatingSummary = getDocumentRatingSummary(nodeRef);
    NodeRating nodeRating = new NodeRating(ratingSchemeId, myRating, appliedAt, documentRatingSummary);
    return nodeRating;
}
Also used : DocumentRatingSummary(org.alfresco.rest.api.model.DocumentRatingSummary) Rating(org.alfresco.service.cmr.rating.Rating) NodeRating(org.alfresco.rest.api.model.NodeRating) JSONObject(org.json.simple.JSONObject) NodeRating(org.alfresco.rest.api.model.NodeRating) Date(java.util.Date)

Example 2 with Rating

use of org.alfresco.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.

the class RepoService method getNodeRatings.

public List<NodeRating> getNodeRatings(String personId, String networkId, final NodeRef nodeRef) {
    List<NodeRating> ratings = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<NodeRating>>() {

        @Override
        public List<NodeRating> doWork() throws Exception {
            List<NodeRating> ratings = new ArrayList<NodeRating>();
            {
                Rating likesRating = ratingService.getRatingByCurrentUser(nodeRef, "likesRatingScheme");
                Object myRating = null;
                String ratedAt = null;
                if (likesRating != null) {
                    myRating = likesRating.getScore() == 1.0f ? Boolean.TRUE : Boolean.FALSE;
                    Date rateTime = likesRating.getAppliedAt();
                    ratedAt = PublicApiDateFormat.getDateFormat().format(rateTime);
                }
                int ratingsCount = ratingService.getRatingsCount(nodeRef, "likesRatingScheme");
                Aggregate aggregate = new Aggregate(ratingsCount, null);
                ratings.add(new NodeRating(nodeRef.getId(), "likes", ratedAt, myRating, aggregate));
            }
            {
                Rating fiveStarRating = ratingService.getRatingByCurrentUser(nodeRef, "fiveStarRatingScheme");
                Object myRating = null;
                String ratedAt = null;
                if (fiveStarRating != null) {
                    myRating = fiveStarRating.getScore();
                    Date rateTime = fiveStarRating.getAppliedAt();
                    ratedAt = PublicApiDateFormat.getDateFormat().format(rateTime);
                }
                int ratingsCount = ratingService.getRatingsCount(nodeRef, "fiveStarRatingScheme");
                float averageRating = ratingService.getAverageRating(nodeRef, "fiveStarRatingScheme");
                Aggregate aggregate = new Aggregate(ratingsCount, averageRating == -1 ? null : averageRating);
                ratings.add(new NodeRating(nodeRef.getId(), "fiveStar", ratedAt, myRating, aggregate));
            }
            return ratings;
        }
    }, personId, networkId);
    Collections.sort(ratings);
    return ratings;
}
Also used : NodeRating(org.alfresco.rest.api.tests.client.data.NodeRating) Rating(org.alfresco.service.cmr.rating.Rating) NodeRating(org.alfresco.rest.api.tests.client.data.NodeRating) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) JSONException(org.json.JSONException) SQLException(java.sql.SQLException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) JobExecutionException(org.quartz.JobExecutionException) SiteDoesNotExistException(org.alfresco.repo.site.SiteDoesNotExistException) Date(java.util.Date) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(org.json.simple.JSONObject) Aggregate(org.alfresco.rest.api.tests.client.data.NodeRating.Aggregate)

Example 3 with Rating

use of org.alfresco.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.

the class RatingsGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    NodeRef nodeRef = parseRequestForNodeRef(req);
    // These are the data for the current user's ratings of this node, if any.
    List<Rating> myRatings = new ArrayList<Rating>();
    // These maps hold the average rating, accumulated total of all ratings and
    // the number of ratings applied for this node as a function of rating scheme.
    Map<String, Float> averageRatings = new HashMap<String, Float>();
    Map<String, Float> ratingsTotals = new HashMap<String, Float>();
    Map<String, Integer> ratingsCounts = new HashMap<String, Integer>();
    for (String schemeName : ratingService.getRatingSchemes().keySet()) {
        final Rating ratingByCurrentUser = ratingService.getRatingByCurrentUser(nodeRef, schemeName);
        if (ratingByCurrentUser != null) {
            myRatings.add(ratingByCurrentUser);
        }
        averageRatings.put(schemeName, ratingService.getAverageRating(nodeRef, schemeName));
        ratingsTotals.put(schemeName, ratingService.getTotalRating(nodeRef, schemeName));
        ratingsCounts.put(schemeName, ratingService.getRatingsCount(nodeRef, schemeName));
    }
    model.put(NODE_REF, nodeRef.toString());
    model.put(RATINGS, myRatings);
    model.put(AVERAGE_RATINGS, averageRatings);
    model.put(RATINGS_TOTALS, ratingsTotals);
    model.put(RATINGS_COUNTS, ratingsCounts);
    return model;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Rating(org.alfresco.service.cmr.rating.Rating) ArrayList(java.util.ArrayList)

Example 4 with Rating

use of org.alfresco.service.cmr.rating.Rating in project alfresco-remote-api by Alfresco.

the class RatingDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    NodeRef nodeRef = parseRequestForNodeRef(req);
    String ratingSchemeName = parseRequestForScheme(req);
    Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName);
    if (deletedRating == null) {
        // There was no rating in the specified scheme to delete.
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: " + ratingSchemeName + " from " + nodeRef.toString());
    }
    model.put(NODE_REF, nodeRef.toString());
    model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName));
    model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName));
    model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName));
    return model;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Rating(org.alfresco.service.cmr.rating.Rating)

Example 5 with Rating

use of org.alfresco.service.cmr.rating.Rating in project alfresco-repository by Alfresco.

the class RatingCountRollupAlgorithm method recalculate.

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;
}
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