Search in sources :

Example 1 with IMarketplaceRating

use of org.apereo.portal.portlet.marketplace.IMarketplaceRating in project uPortal by Jasig.

the class PortletMarketplaceController method entryView.

@RenderMapping(params = "action=view")
public String entryView(RenderRequest renderRequest, RenderResponse renderResponse, WebRequest webRequest, PortletRequest portletRequest, Model model) {
    IPortletDefinition result = this.portletDefinitionRegistry.getPortletDefinitionByFname(portletRequest.getParameter("fName"));
    if (result == null) {
        this.setUpInitialView(webRequest, portletRequest, model, null);
        return "jsp/Marketplace/portlet/view";
    }
    final HttpServletRequest servletRequest = this.portalRequestUtils.getPortletHttpRequest(portletRequest);
    final IPerson user = personManager.getPerson(servletRequest);
    final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
    if (!this.marketplaceService.mayBrowsePortlet(principal, result)) {
        // TODO: provide an error experience
        // currently at least blocks rendering the entry for the portlet the user is not authorized to see.
        this.setUpInitialView(webRequest, portletRequest, model, null);
        return "jsp/Marketplace/portlet/view";
    }
    MarketplacePortletDefinition mpDefinition = marketplaceService.getOrCreateMarketplacePortletDefinition(result);
    IMarketplaceRating tempRatingImpl = marketplaceRatingDAO.getRating(portletRequest.getRemoteUser(), portletDefinitionDao.getPortletDefinitionByFname(result.getFName()));
    final MarketplaceEntry marketplaceEntry = new MarketplaceEntry(mpDefinition, user);
    model.addAttribute("marketplaceRating", tempRatingImpl);
    model.addAttribute("reviewMaxLength", IMarketplaceRating.REVIEW_MAX_LENGTH);
    model.addAttribute("marketplaceEntry", marketplaceEntry);
    model.addAttribute("shortURL", mpDefinition.getShortURL());
    // User allowed to favorite this portlet?
    final String targetString = PermissionHelper.permissionTargetIdForPortletDefinition(mpDefinition);
    final boolean canFavorite = principal.hasPermission(IPermission.PORTAL_SYSTEM, IPermission.PORTLET_FAVORITE_ACTIVITY, targetString);
    model.addAttribute("canFavorite", canFavorite);
    // Reviews feature enabled?
    final PortletPreferences prefs = renderRequest.getPreferences();
    final String enableReviewsPreferenceValue = prefs.getValue(ENABLE_REVIEWS_PREFERENCE, ENABLE_REVIEWS_DEFAULT);
    model.addAttribute("enableReviews", Boolean.valueOf(enableReviewsPreferenceValue));
    return "jsp/Marketplace/portlet/entry";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortletPreferences(javax.portlet.PortletPreferences) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 2 with IMarketplaceRating

use of org.apereo.portal.portlet.marketplace.IMarketplaceRating in project uPortal by Jasig.

the class JpaMarketplaceRatingDao method createOrUpdateRating.

/**
     * This method will either create a new rating or update an existing rating
     *
     * @param Must not be null
     * @return the attached entity
     */
@Override
@PortalTransactional
public IMarketplaceRating createOrUpdateRating(IMarketplaceRating marketplaceRatingImplementation) {
    Validate.notNull(marketplaceRatingImplementation, "MarketplaceRatingImpl must not be null");
    final EntityManager entityManager = this.getEntityManager();
    IMarketplaceRating temp = this.getRating(marketplaceRatingImplementation.getMarketplaceRatingPK());
    if (!entityManager.contains(marketplaceRatingImplementation) && temp != null) {
        //Entity is not managed and there is a rating for this portlet/user - update needed
        temp = entityManager.merge(marketplaceRatingImplementation);
    } else {
        //Entity is either already managed or doesn't exist - create needed
        temp = marketplaceRatingImplementation;
    }
    entityManager.persist(temp);
    return temp;
}
Also used : EntityManager(javax.persistence.EntityManager) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating)

Example 3 with IMarketplaceRating

use of org.apereo.portal.portlet.marketplace.IMarketplaceRating in project uPortal by Jasig.

the class JpaMarketplaceRatingDao method deleteRating.

/** @param entity to delete - can not be null */
@Override
@PortalTransactional
public void deleteRating(IMarketplaceRating marketplaceRatingImplementation) {
    Validate.notNull(marketplaceRatingImplementation, "marketplaceRatingImplementation can not be null");
    final IMarketplaceRating persistantMarketplaceRatingImpl;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(marketplaceRatingImplementation)) {
        persistantMarketplaceRatingImpl = marketplaceRatingImplementation;
    } else {
        persistantMarketplaceRatingImpl = entityManager.merge(marketplaceRatingImplementation);
    }
    entityManager.remove(persistantMarketplaceRatingImpl);
}
Also used : EntityManager(javax.persistence.EntityManager) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating)

Example 4 with IMarketplaceRating

use of org.apereo.portal.portlet.marketplace.IMarketplaceRating in project uPortal by Jasig.

the class PortletMarketplaceController method getRating.

/**
     * @param request
     * @param response
     * @param portletRequest
     * @return 'rating' as a JSON object. Can be null if rating doesn't exist.
     */
@ResourceMapping("getRating")
public String getRating(ResourceRequest request, ResourceResponse response, @RequestParam String portletFName, PortletRequest portletRequest, Model model) {
    Validate.notNull(portletFName, "Please supply a portlet to get rating for - should not be null");
    IMarketplaceRating tempRating = marketplaceRatingDAO.getRating(portletRequest.getRemoteUser(), portletDefinitionDao.getPortletDefinitionByFname(portletFName));
    model.addAttribute("rating", tempRating == null ? null : tempRating.getRating());
    return "json";
}
Also used : IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Example 5 with IMarketplaceRating

use of org.apereo.portal.portlet.marketplace.IMarketplaceRating 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)

Aggregations

IMarketplaceRating (org.apereo.portal.portlet.marketplace.IMarketplaceRating)7 EntityManager (javax.persistence.EntityManager)3 OpenEntityManager (org.apereo.portal.jpa.OpenEntityManager)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 MarketplaceEntryRating (org.apereo.portal.rest.layout.MarketplaceEntryRating)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 IPerson (org.apereo.portal.security.IPerson)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 PortletPreferences (javax.portlet.PortletPreferences)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 MarketplacePortletDefinition (org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition)1 MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)1 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)1 ResourceMapping (org.springframework.web.portlet.bind.annotation.ResourceMapping)1