Search in sources :

Example 1 with MarketplaceEntryRating

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);
}
Also used : IPerson(org.apereo.portal.security.IPerson) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) MarketplaceEntryRating(org.apereo.portal.rest.layout.MarketplaceEntryRating) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MarketplaceEntryRating

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));
}
Also used : MarketplaceEntryRating(org.apereo.portal.rest.layout.MarketplaceEntryRating) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MarketplaceEntryRating

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);
}
Also used : IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) MarketplaceEntryRating(org.apereo.portal.rest.layout.MarketplaceEntryRating) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MarketplaceEntryRating (org.apereo.portal.rest.layout.MarketplaceEntryRating)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 IMarketplaceRating (org.apereo.portal.portlet.marketplace.IMarketplaceRating)2 ArrayList (java.util.ArrayList)1 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)1 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)1 IPerson (org.apereo.portal.security.IPerson)1