Map<Long,Rating> ratings = new HashMap<Long,Rating>(); ratings.put(product.getId(),new Rating(1,"I think it's really bad..")); session.setAttribute("ratings",ratings);
/** * 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; }
/** * 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; }
Table<User, Item, Rating> table = new Table<>(); table.addEmptyCol(new Item("Television")); table.addEmptyCol(new Item("Sofa")); User user = new User("Anakin"); Item item = new Item("Light Sabre"); table.put(user, item, new Rating(5)); Item item1 = new Item("Helmet"); table.put(user, item1, new Rating(7)); Rating rating = table.get(user, item); rating.setRating(rating.getRating() + 10); User user1 = new User("Obi-Wan"); table.put(user1, item, new Rating(8)); table.put(user1, new Item("Television"), new Rating(0));
/** * 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; }
Map<String, Object> map = jp.readValueAs(Map.class); Rating rating = new Rating(); rating.setId(getInt(map, "id")); rating.setRated(getRated(map));
/** * 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; }
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; // If the rating is for the specified scheme delete it. // 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; }
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; // If the rating is for the specified scheme delete it. // 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; }
rating = new Rating(5);