Search in sources :

Example 6 with IMarketplaceRating

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

Example 7 with IMarketplaceRating

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

the class JpaMarketplaceRatingDao method getRatingsByFname.

/**
 * @since 5.0
 * @param marketplaceRatingPK the primary key of the entity you want
 * @return Set of ratings per portlet definition
 */
@PortalTransactionalReadOnly
@OpenEntityManager(unitName = PERSISTENCE_UNIT_NAME)
public Set<IMarketplaceRating> getRatingsByFname(String fname) {
    // Build criteria to fetch MarketplaceRatingImpl based on the incoming portlet name.
    final EntityManager entityManager = this.getEntityManager();
    final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    final CriteriaQuery<IMarketplaceRating> getByPortlet = cb.createQuery(IMarketplaceRating.class);
    final Root<MarketplaceRatingImpl> imr = getByPortlet.from(MarketplaceRatingImpl.class);
    getByPortlet.select(imr);
    // Define the path to the portlet fName
    final Path<MarketplaceRatingPK> mrPK = imr.get("marketplaceRatingPK");
    final Path<PortletDefinitionImpl> mrIPD = mrPK.get("portletDefinition");
    final ParameterExpression<String> portletFName = cb.parameter(String.class, "portletFName");
    getByPortlet.where(cb.equal(mrIPD.get("fname"), portletFName));
    TypedQuery<IMarketplaceRating> tq = entityManager.createQuery(getByPortlet);
    tq.setParameter("portletFName", fname);
    List<IMarketplaceRating> resultList = tq.getResultList();
    Set<IMarketplaceRating> resultSet = new HashSet<IMarketplaceRating>(resultList);
    return resultSet;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) HashSet(java.util.HashSet) OpenEntityManager(org.apereo.portal.jpa.OpenEntityManager)

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