Search in sources :

Example 1 with PortletDefinitionBean

use of org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean 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 tracking them
    IPortletDefinition>();
    // 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 = AuthorizationService.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 2 with PortletDefinitionBean

use of org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean in project uPortal by Jasig.

the class ChannelListController method preparePortletCategoryBean.

private PortletCategoryBean preparePortletCategoryBean(WebRequest req, PortletCategory category, Set<IPortletDefinition> portletsNotYetCategorized, IPerson user, Locale locale) {
    /* Prepare child categories. */
    Set<PortletCategoryBean> subcategories = new HashSet<>();
    for (PortletCategory childCategory : this.portletCategoryRegistry.getChildCategories(category)) {
        PortletCategoryBean childBean = preparePortletCategoryBean(req, childCategory, portletsNotYetCategorized, user, locale);
        subcategories.add(childBean);
    }
    // add the direct child channels for this category
    Set<IPortletDefinition> portlets = portletCategoryRegistry.getChildPortlets(category);
    EntityIdentifier ei = user.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
    Set<PortletDefinitionBean> marketplacePortlets = new HashSet<>();
    for (IPortletDefinition portlet : portlets) {
        if (authorizationService.canPrincipalBrowse(ap, portlet)) {
            PortletDefinitionBean pdb = preparePortletDefinitionBean(req, portlet, locale);
            marketplacePortlets.add(pdb);
        }
        /*
             * Remove the portlet from the uncategorized collection;
             * note -- this approach will not prevent portlets from
             * appearing in multiple categories (as appropriate).
             */
        portletsNotYetCategorized.remove(portlet);
    }
    // construct a new portlet category bean for this category
    PortletCategoryBean categoryBean = PortletCategoryBean.fromPortletCategory(category, subcategories, marketplacePortlets);
    categoryBean.setName(messageSource.getMessage(category.getName(), new Object[] {}, locale));
    return categoryBean;
}
Also used : PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 3 with PortletDefinitionBean

use of org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean in project uPortal by Jasig.

the class ChannelListController method preparePortletDefinitionBean.

private PortletDefinitionBean preparePortletDefinitionBean(WebRequest req, IPortletDefinition portlet, Locale locale) {
    MarketplacePortletDefinition mktpd = marketplaceService.getOrCreateMarketplacePortletDefinition(portlet);
    PortletDefinitionBean rslt = PortletDefinitionBean.fromMarketplacePortletDefinition(mktpd, locale);
    // See api docs for postProcessIconUrlParameter() below
    IPortletDefinitionParameter iconParameter = rslt.getParameters().get(ICON_URL_PARAMETER_NAME);
    if (iconParameter != null) {
        IPortletDefinitionParameter evaluated = postProcessIconUrlParameter(iconParameter, req);
        rslt.putParameter(evaluated);
    }
    return rslt;
}
Also used : MarketplacePortletDefinition(org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean)

Aggregations

PortletDefinitionBean (org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean)3 HashSet (java.util.HashSet)2 EntityIdentifier (org.apereo.portal.EntityIdentifier)2 PortletCategoryBean (org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 Locale (java.util.Locale)1 SortedSet (java.util.SortedSet)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 MarketplacePortletDefinition (org.apereo.portal.portlet.marketplace.MarketplacePortletDefinition)1 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)1