Search in sources :

Example 1 with PortletCategoryBean

use of org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean 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 2 with PortletCategoryBean

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

the class ChannelListController method filterCategoryFavoritesOnly.

/**
 * Returns the filtered category, or <code>null</code> if there is no content remaining in the
 * category.
 */
private PortletCategoryBean filterCategoryFavoritesOnly(PortletCategoryBean category) {
    // Subcategories
    final Set<PortletCategoryBean> subcategories = new HashSet<>();
    category.getSubcategories().forEach(sub -> {
        final PortletCategoryBean filteredBean = filterCategoryFavoritesOnly(sub);
        if (filteredBean != null) {
            subcategories.add(filteredBean);
        }
    });
    // Portlets
    final Set<PortletDefinitionBean> portlets = new HashSet<>();
    category.getPortlets().forEach(child -> {
        if (child.getFavorite()) {
            log.debug("Including portlet '{}' because it is a favorite:  {}", child.getFname());
            portlets.add(child);
        } else {
            log.debug("Skipping portlet '{}' because it IS NOT a favorite:  {}", child.getFname());
        }
    });
    return !subcategories.isEmpty() || !portlets.isEmpty() ? PortletCategoryBean.create(category.getId(), category.getName(), category.getDescription(), subcategories, portlets) : null;
}
Also used : PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) HashSet(java.util.HashSet)

Example 3 with PortletCategoryBean

use of org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean 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<PortletCategoryBean>> getRegistry43(WebRequest request, IPerson user, PortletCategory rootCategory, boolean includeUncategorized, Set<IPortletDefinition> favorites) {
    /*
         * 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<>(portletDefinitionRegistry.getAllPortletDefinitions()) : // Not necessary to fetch them if we're not
    new HashSet<>();
    // tracking them
    // construct a new channel registry
    Map<String, SortedSet<PortletCategoryBean>> rslt = new TreeMap<>();
    SortedSet<PortletCategoryBean> categories = new TreeSet<>();
    // add the root category and all its children to the registry
    final Locale locale = getUserLocale(user);
    categories.add(preparePortletCategoryBean(request, rootCategory, portletsNotYetCategorized, user, locale, favorites));
    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, favorites.contains(portlet));
                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_MAP_KEY, 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 4 with PortletCategoryBean

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

the class PortletCategoryBeanTest method testEqualsNull.

@Test
public void testEqualsNull() {
    PortletCategoryBean pcb1 = buildTestPortletCategoryBean("id1", "name1", "desc");
    assertFalse(pcb1.equals(null));
}
Also used : PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) Test(org.junit.Test)

Example 5 with PortletCategoryBean

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

the class PortletCategoryBeanTest method testEqualsSameID.

@Test
public void testEqualsSameID() {
    String id1 = "id1";
    PortletCategoryBean pcb1 = buildTestPortletCategoryBean(id1, "name1", "desc");
    PortletCategoryBean pcb2 = buildTestPortletCategoryBean(id1, "name2", "desc");
    assertTrue(pcb1.equals(pcb2));
}
Also used : PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) Test(org.junit.Test)

Aggregations

PortletCategoryBean (org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean)16 Test (org.junit.Test)10 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)5 HashSet (java.util.HashSet)4 TreeSet (java.util.TreeSet)4 PortletDefinitionBean (org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean)4 SortedSet (java.util.SortedSet)3 TreeMap (java.util.TreeMap)3 EntityIdentifier (org.apereo.portal.EntityIdentifier)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)3 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)3 Locale (java.util.Locale)2