use of org.apereo.portal.rest.layout.MarketplaceEntryRating in project uPortal by Jasig.
the class MarketplaceRESTController method getPortletRatings.
/** @since 5.0 */
@RequestMapping(value = "/v5-0/marketplace/{fname}/ratings", method = RequestMethod.GET)
public ModelAndView getPortletRatings(HttpServletRequest request, @PathVariable String fname) {
// TODO: This method should send 404 or 403 in appropriate circumstances
Validate.notNull(fname, "Please supply a portlet to get rating for - should not be null");
IPortletDefinition marketplacePortletDefinition = (IPortletDefinition) marketplaceService.getOrCreateMarketplacePortletDefinitionIfTheFnameExists(fname);
final IPerson user = personManager.getPerson(request);
final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
if (principal.canManage(marketplacePortletDefinition.getPortletDefinitionId().getStringId())) {
Set<IMarketplaceRating> portletRatings = marketplaceRatingDAO.getRatingsByFname(fname);
if (portletRatings != null) {
List<MarketplaceEntryRating> ratingResults = new ArrayList<>();
for (IMarketplaceRating imr : portletRatings) {
ratingResults.add(new MarketplaceEntryRating(imr.getRating(), imr.getReview()));
}
return new ModelAndView("json", "ratings", ratingResults);
}
}
return new ModelAndView("json", "ratings", null);
}
use of org.apereo.portal.rest.layout.MarketplaceEntryRating in project uPortal by Jasig.
the class MarketplaceRESTController method saveUserRating.
@RequestMapping(value = "/marketplace/{fname}/rating/{rating}", method = RequestMethod.POST)
public ModelAndView saveUserRating(HttpServletRequest request, @PathVariable String fname, @PathVariable String rating, @RequestParam(required = false) String review) {
Validate.notNull(rating, "Please supply a rating - should not be null");
Validate.notNull(fname, "Please supply a portlet to rate - should not be null");
marketplaceRatingDAO.createOrUpdateRating(Integer.parseInt(rating), request.getRemoteUser(), review, marketplaceService.getOrCreateMarketplacePortletDefinitionIfTheFnameExists(fname));
return new ModelAndView("json", "rating", new MarketplaceEntryRating(Integer.parseInt(rating), review));
}
use of org.apereo.portal.rest.layout.MarketplaceEntryRating in project uPortal by Jasig.
the class MarketplaceRESTController method getUserRating.
@RequestMapping(value = "/marketplace/{fname}/getRating", method = RequestMethod.GET)
public ModelAndView getUserRating(HttpServletRequest request, @PathVariable String fname) {
Validate.notNull(fname, "Please supply a portlet to get rating for - should not be null");
IMarketplaceRating tempRating = marketplaceRatingDAO.getRating(request.getRemoteUser(), marketplaceService.getOrCreateMarketplacePortletDefinitionIfTheFnameExists(fname));
if (tempRating != null) {
return new ModelAndView("json", "rating", new MarketplaceEntryRating(tempRating.getRating(), tempRating.getReview()));
}
return new ModelAndView("json", "rating", null);
}
Aggregations