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";
}
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;
}
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);
}
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";
}
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);
}
Aggregations