Search in sources :

Example 1 with MarketplaceEntry

use of org.apereo.portal.rest.layout.MarketplaceEntry 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 MarketplaceEntry

use of org.apereo.portal.rest.layout.MarketplaceEntry in project uPortal by Jasig.

the class MarketplaceService method loadMarketplaceEntriesFor.

/**
     * Load the list of marketplace entries for a user. Will load entries async. This method is
     * primarily intended for seeding data. Most impls should call browseableMarketplaceEntriesFor()
     * instead.
     *
     * <p>Note: Set is immutable since it is potentially shared between threads. If the set needs
     * mutability, be sure to consider the thread safety implications. No protections have been
     * provided against modifying the MarketplaceEntry itself, so be careful when modifying the
     * entities contained in the list.
     *
     * @param user The non-null user
     * @param categories Restricts the output to entries within the specified categories if
     *     non-empty
     * @return a Future that will resolve to a set of MarketplaceEntry objects the requested user
     *     has browse access to.
     * @throws java.lang.IllegalArgumentException if user is null
     * @since 4.2
     */
@Async
public Future<ImmutableSet<MarketplaceEntry>> loadMarketplaceEntriesFor(final IPerson user, final Set<PortletCategory> categories) {
    final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
    List<IPortletDefinition> allDisplayablePortletDefinitions = this.portletDefinitionRegistry.getAllPortletDefinitions();
    if (!categories.isEmpty()) {
        // Indicates we plan to restrict portlets displayed in the Portlet
        // Marketplace to those that belong to one or more specified groups.
        Element portletDefinitionsElement = marketplaceCategoryCache.get(categories);
        if (portletDefinitionsElement == null) {
            /*
                 * Collection not in cache -- need to recreate it
                 */
            // Gather the complete collection of allowable categories (specified categories & their descendants)
            final Set<PortletCategory> allSpecifiedAndDecendantCategories = new HashSet<>();
            for (PortletCategory pc : categories) {
                collectSpecifiedAndDescendantCategories(pc, allSpecifiedAndDecendantCategories);
            }
            // Filter portlets that match the criteria
            Set<IPortletDefinition> filteredPortletDefinitions = new HashSet<>();
            for (final IPortletDefinition portletDefinition : allDisplayablePortletDefinitions) {
                final Set<PortletCategory> parents = portletCategoryRegistry.getParentCategories(portletDefinition);
                for (final PortletCategory parent : parents) {
                    if (allSpecifiedAndDecendantCategories.contains(parent)) {
                        filteredPortletDefinitions.add(portletDefinition);
                        break;
                    }
                }
            }
            portletDefinitionsElement = new Element(categories, new ArrayList<>(filteredPortletDefinitions));
            marketplaceCategoryCache.put(portletDefinitionsElement);
        }
        allDisplayablePortletDefinitions = (List<IPortletDefinition>) portletDefinitionsElement.getObjectValue();
    }
    final Set<MarketplaceEntry> visiblePortletDefinitions = new HashSet<>();
    for (final IPortletDefinition portletDefinition : allDisplayablePortletDefinitions) {
        if (mayBrowsePortlet(principal, portletDefinition)) {
            final MarketplacePortletDefinition marketplacePortletDefinition = getOrCreateMarketplacePortletDefinition(portletDefinition);
            final MarketplaceEntry entry = new MarketplaceEntry(marketplacePortletDefinition, user);
            // flag whether this use can add the portlet...
            boolean canAdd = mayAddPortlet(user, portletDefinition);
            entry.setCanAdd(canAdd);
            visiblePortletDefinitions.add(entry);
        }
    }
    logger.trace("These portlet definitions {} are browseable by {}.", visiblePortletDefinitions, user);
    Future<ImmutableSet<MarketplaceEntry>> result = new AsyncResult<>(ImmutableSet.copyOf(visiblePortletDefinitions));
    Element cacheElement = new Element(user.getUserName(), result);
    marketplaceUserPortletDefinitionCache.put(cacheElement);
    return result;
}
Also used : Element(net.sf.ehcache.Element) ArrayList(java.util.ArrayList) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) ImmutableSet(com.google.common.collect.ImmutableSet) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) Async(org.springframework.scheduling.annotation.Async)

Example 3 with MarketplaceEntry

use of org.apereo.portal.rest.layout.MarketplaceEntry in project uPortal by Jasig.

the class MarketplaceRESTController method marketplaceEntriesFeed.

@RequestMapping(value = "/marketplace/entries.json", method = RequestMethod.GET)
public ModelAndView marketplaceEntriesFeed(HttpServletRequest request) {
    final IPerson user = personManager.getPerson(request);
    final Set<PortletCategory> empty = // Produces an complete/unfiltered collection
    Collections.emptySet();
    final Set<MarketplaceEntry> marketplaceEntries = marketplaceService.browseableMarketplaceEntriesFor(user, empty);
    return new ModelAndView("json", "portlets", marketplaceEntries);
}
Also used : IPerson(org.apereo.portal.security.IPerson) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) ModelAndView(org.springframework.web.servlet.ModelAndView) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MarketplaceEntry

use of org.apereo.portal.rest.layout.MarketplaceEntry in project uPortal by Jasig.

the class MarketplaceRESTController method marketplaceEntryFeed.

@RequestMapping(value = "/marketplace/entry/{fname}.json")
public ModelAndView marketplaceEntryFeed(HttpServletRequest request, HttpServletResponse response, @PathVariable String fname) {
    final IPerson user = personManager.getPerson(request);
    final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
    final MarketplacePortletDefinition marketplacePortletDefinition = marketplaceService.getOrCreateMarketplacePortletDefinitionIfTheFnameExists(fname);
    if (marketplacePortletDefinition != null && marketplaceService.mayBrowsePortlet(principal, marketplacePortletDefinition)) {
        MarketplaceEntry entry = new MarketplaceEntry(marketplacePortletDefinition, true, user);
        entry.setCanAdd(marketplaceService.mayAddPortlet(user, marketplacePortletDefinition));
        return new ModelAndView("json", "entry", entry);
    }
    response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    return null;
}
Also used : IPerson(org.apereo.portal.security.IPerson) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MarketplaceEntry

use of org.apereo.portal.rest.layout.MarketplaceEntry in project uPortal by Jasig.

the class PortletMarketplaceController method setUpInitialView.

private void setUpInitialView(WebRequest webRequest, PortletRequest portletRequest, Model model, String initialFilter) {
    // We'll track and potentially log the time it takes to perform this initialization
    final long timestamp = System.currentTimeMillis();
    final HttpServletRequest servletRequest = this.portalRequestUtils.getPortletHttpRequest(portletRequest);
    final PortletPreferences preferences = portletRequest.getPreferences();
    final boolean isLogLevelDebug = logger.isDebugEnabled();
    final IPerson user = personManager.getPerson(servletRequest);
    final Map<String, Set<?>> registry = getRegistry(user, portletRequest);
    @SuppressWarnings("unchecked") final Set<MarketplaceEntry> marketplaceEntries = (Set<MarketplaceEntry>) registry.get("portlets");
    model.addAttribute("marketplaceEntries", marketplaceEntries);
    @SuppressWarnings("unchecked") Set<PortletCategory> categoryList = (Set<PortletCategory>) registry.get("categories");
    @SuppressWarnings("unchecked") final Set<MarketplaceEntry> featuredPortlets = (Set<MarketplaceEntry>) registry.get("featured");
    model.addAttribute("featuredEntries", featuredPortlets);
    //Determine if the marketplace is going to show the root category
    String showRootCategoryPreferenceValue = preferences.getValue(SHOW_ROOT_CATEGORY_PREFERENCE, "false");
    boolean showRootCategory = Boolean.parseBoolean(showRootCategoryPreferenceValue);
    if (isLogLevelDebug) {
        logger.debug("Going to show Root Category?: {}", Boolean.toString(showRootCategory));
    }
    if (showRootCategory == false) {
        categoryList.remove(this.portletCategoryRegistry.getTopLevelPortletCategory());
    }
    model.addAttribute("categoryList", categoryList);
    model.addAttribute("initialFilter", initialFilter);
    logger.debug("Marketplace took {}ms in setUpInitialView for user '{}'", System.currentTimeMillis() - timestamp, user.getUserName());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) PortletPreferences(javax.portlet.PortletPreferences) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Aggregations

MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)7 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)5 HashSet (java.util.HashSet)4 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)4 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)4 IPerson (org.apereo.portal.security.IPerson)4 PortletPreferences (javax.portlet.PortletPreferences)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MarketplacePortletDefinition (org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Element (net.sf.ehcache.Element)1 IMarketplaceRating (org.apereo.portal.portlet.marketplace.IMarketplaceRating)1 Async (org.springframework.scheduling.annotation.Async)1 AsyncResult (org.springframework.scheduling.annotation.AsyncResult)1 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)1