Search in sources :

Example 16 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class ChannelListController method getRegistry43.

/*
     * Private methods that support the 4.3 version of the API
     */
/**
 * Gathers and organizes the response based on the specified rootCategory and the permissions of
 * the specified user.
 */
private Map<String, SortedSet<?>> getRegistry43(WebRequest request, IPerson user, PortletCategory rootCategory, boolean includeUncategorized) {
    /*
         * This collection of all the portlets in the portal is for the sake of
         * tracking which ones are uncategorized.  They will be added to the
         * output if includeUncategorized=true.
         */
    Set<IPortletDefinition> portletsNotYetCategorized = includeUncategorized ? new HashSet<IPortletDefinition>(portletDefinitionRegistry.getAllPortletDefinitions()) : new HashSet<// Not necessary to fetch them if we're not
    IPortletDefinition>();
    // tracking them
    // construct a new channel registry
    Map<String, SortedSet<?>> rslt = new TreeMap<String, SortedSet<?>>();
    SortedSet<PortletCategoryBean> categories = new TreeSet<PortletCategoryBean>();
    // add the root category and all its children to the registry
    final Locale locale = getUserLocale(user);
    categories.add(preparePortletCategoryBean(request, rootCategory, portletsNotYetCategorized, user, locale));
    if (includeUncategorized) {
        /*
             * uPortal historically has provided for a convention that portlets not in any category
             * may potentially be viewed by users but may not be subscribed to.
             *
             * As of uPortal 4.2, the logic below now takes any portlets the user has BROWSE access to
             * that have not already been identified as belonging to a category and adds them to a category
             * called Uncategorized.
             */
        EntityIdentifier ei = user.getEntityIdentifier();
        IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
        Set<PortletDefinitionBean> marketplacePortlets = new HashSet<>();
        for (IPortletDefinition portlet : portletsNotYetCategorized) {
            if (authorizationService.canPrincipalBrowse(ap, portlet)) {
                PortletDefinitionBean pdb = preparePortletDefinitionBean(request, portlet, locale);
                marketplacePortlets.add(pdb);
            }
        }
        // construct a new channel category bean for this category
        final String uncName = messageSource.getMessage(UNCATEGORIZED, new Object[] {}, locale);
        final String uncDescription = messageSource.getMessage(UNCATEGORIZED_DESC, new Object[] {}, locale);
        PortletCategory pc = new PortletCategory(// Use of this String for Id matches earlier version of API
        uncName);
        pc.setName(uncName);
        pc.setDescription(uncDescription);
        PortletCategoryBean unc = PortletCategoryBean.fromPortletCategory(pc, null, marketplacePortlets);
        // Add even if no portlets in category
        categories.add(unc);
    }
    rslt.put("categories", categories);
    return rslt;
}
Also used : Locale(java.util.Locale) EntityIdentifier(org.apereo.portal.EntityIdentifier) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) TreeSet(java.util.TreeSet) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 17 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class ChannelListController method getRegistryOriginal.

/*
     * Private methods that support the original (pre-4.3) version of the API
     */
/**
 * Gathers and organizes the response based on the specified rootCategory and the permissions of
 * the specified user.
 */
private Map<String, SortedSet<?>> getRegistryOriginal(WebRequest request, IPerson user) {
    /*
         * This collection of all the portlets in the portal is for the sake of
         * tracking which ones are uncategorized.
         */
    Set<IPortletDefinition> portletsNotYetCategorized = new HashSet<IPortletDefinition>(portletDefinitionRegistry.getAllPortletDefinitions());
    // construct a new channel registry
    Map<String, SortedSet<?>> rslt = new TreeMap<String, SortedSet<?>>();
    SortedSet<ChannelCategoryBean> categories = new TreeSet<ChannelCategoryBean>();
    // add the root category and all its children to the registry
    final PortletCategory rootCategory = portletCategoryRegistry.getTopLevelPortletCategory();
    final Locale locale = getUserLocale(user);
    categories.add(prepareCategoryBean(request, rootCategory, portletsNotYetCategorized, user, locale));
    /*
         * uPortal historically has provided for a convention that portlets not in any category
         * may potentially be viewed by users but may not be subscribed to.
         *
         * As of uPortal 4.2, the logic below now takes any portlets the user has BROWSE access to
         * that have not already been identified as belonging to a category and adds them to a category
         * called Uncategorized.
         */
    EntityIdentifier ei = user.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    // construct a new channel category bean for this category
    String uncategorizedString = messageSource.getMessage(UNCATEGORIZED, new Object[] {}, locale);
    ChannelCategoryBean uncategorizedPortletsBean = new ChannelCategoryBean(new PortletCategory(uncategorizedString));
    uncategorizedPortletsBean.setName(UNCATEGORIZED);
    uncategorizedPortletsBean.setDescription(messageSource.getMessage(UNCATEGORIZED_DESC, new Object[] {}, locale));
    for (IPortletDefinition portlet : portletsNotYetCategorized) {
        if (authorizationService.canPrincipalBrowse(ap, portlet)) {
            // construct a new channel bean from this channel
            ChannelBean channel = getChannel(portlet, request, locale);
            uncategorizedPortletsBean.addChannel(channel);
        }
    }
    // Add even if no portlets in category
    categories.add(uncategorizedPortletsBean);
    rslt.put("categories", categories);
    return rslt;
}
Also used : Locale(java.util.Locale) EntityIdentifier(org.apereo.portal.EntityIdentifier) ChannelBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelBean) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) ChannelCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelCategoryBean) TreeSet(java.util.TreeSet) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 18 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class LayoutRESTController method getRESTController.

/**
 * A REST call to get a json feed of the current users layout. Intent was to provide a layout
 * document without per-tab information for mobile device rendering.
 *
 * @param request The servlet request. Utilized to get the users instance and eventually there
 *     layout
 * @param tab The tab name of which you would like to filter; optional; if not provided, will
 *     return entire layout.
 * @return json feed of the layout
 * @deprecated Use /api/v4-3/dlm/layout.json. It has much more information about portlets and
 *     includes regions and breakout per tab
 */
@Deprecated
@RequestMapping(value = "/layoutDoc", method = RequestMethod.GET)
public ModelAndView getRESTController(HttpServletRequest request, @RequestParam(value = "tab", required = false) String tab) {
    final IPerson person = personManager.getPerson(request);
    List<LayoutPortlet> portlets = new ArrayList<LayoutPortlet>();
    try {
        final IUserInstance ui = userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager upm = ui.getPreferencesManager();
        final IUserProfile profile = upm.getUserProfile();
        final DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, profile);
        Document document = userLayout.getLayout();
        NodeList portletNodes = null;
        if (tab != null) {
            NodeList folders = document.getElementsByTagName("folder");
            for (int i = 0; i < folders.getLength(); i++) {
                Node node = folders.item(i);
                if (tab.equalsIgnoreCase(node.getAttributes().getNamedItem("name").getNodeValue())) {
                    TabListOfNodes tabNodes = new TabListOfNodes();
                    tabNodes.addAllChannels(node.getChildNodes());
                    portletNodes = tabNodes;
                    break;
                }
            }
        } else {
            portletNodes = document.getElementsByTagName("channel");
        }
        for (int i = 0; i < portletNodes.getLength(); i++) {
            try {
                NamedNodeMap attributes = portletNodes.item(i).getAttributes();
                IPortletDefinition def = portletDao.getPortletDefinitionByFname(attributes.getNamedItem("fname").getNodeValue());
                LayoutPortlet portlet = new LayoutPortlet(def);
                portlet.setNodeId(attributes.getNamedItem("ID").getNodeValue());
                // get alt max URL
                String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
                if (alternativeMaximizedLink != null) {
                    portlet.setUrl(alternativeMaximizedLink);
                    portlet.setAltMaxUrl(true);
                } else {
                    // get the maximized URL for this portlet
                    final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
                    final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
                    if (targetPortletWindowId != null) {
                        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
                        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
                    }
                    portlet.setUrl(portalUrlBuilder.getUrlString());
                    portlet.setAltMaxUrl(false);
                }
                portlets.add(portlet);
            } catch (Exception e) {
                log.warn("Exception construction JSON representation of mobile portlet", e);
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("layout", portlets);
        mv.setViewName("json");
        return mv;
    } catch (Exception e) {
        log.error("Error retrieving user layout document", e);
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) TabListOfNodes(org.apereo.portal.rest.layout.TabListOfNodes) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) LayoutPortlet(org.apereo.portal.layout.LayoutPortlet) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition 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 20 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletsRESTController method getRenderedPortlet.

/**
 * Provides a single, fully-rendered portlet. NOTE: Access to this API enpoint requires only
 * <code>IPermission.PORTAL_SUBSCRIBE</code> permission.
 */
@RequestMapping(value = "/v4-3/portlet/{fname}.html", method = RequestMethod.GET)
@ResponseBody
public String getRenderedPortlet(HttpServletRequest req, HttpServletResponse res, @PathVariable String fname) throws Exception {
    // Does the portlet exist in the registry?
    final IPortletDefinition portletDef = portletDefinitionRegistry.getPortletDefinitionByFname(fname);
    if (portletDef == null) {
        res.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return "Portlet not found";
    }
    // Is the user permitted to access it?
    final IAuthorizationPrincipal ap = getAuthorizationPrincipal(req);
    if (!ap.canRender(portletDef.getPortletDefinitionId().getStringId())) {
        res.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return "Access denied";
    }
    // Proceed...
    try {
        final IPortletWindow portletWindow = portletWindowRegistry.getOrCreateDefaultPortletWindow(req, portletDef.getPortletDefinitionId());
        final String rslt = portletExecutionManager.getPortletOutput(portletWindow.getPortletWindowId(), req, res);
        return rslt;
    } catch (Exception e) {
        logger.error("Failed to render the requested portlet '{}'", fname, e);
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "Internal error";
    }
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)109 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)24 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)22 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)17 ArrayList (java.util.ArrayList)16 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)14 HashSet (java.util.HashSet)13 IPerson (org.apereo.portal.security.IPerson)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)9 HashMap (java.util.HashMap)8 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)7 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)7 IUserInstance (org.apereo.portal.user.IUserInstance)7 Locale (java.util.Locale)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)6