Search in sources :

Example 11 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class PortletMarketplaceController method getPermittedCategories.

private Set<PortletCategory> getPermittedCategories(PortletRequest req) {
    // default
    Set<PortletCategory> rslt = Collections.emptySet();
    final PortletPreferences prefs = req.getPreferences();
    final String[] permittedCategories = prefs.getValues(PERMITTED_CATEGORIES_PREFERENCE, new String[0]);
    if (permittedCategories.length != 0) {
        // Expensive to create, use cache for this collection...
        Set<String> cacheKey = new HashSet<>(Arrays.asList(permittedCategories));
        net.sf.ehcache.Element cacheElement = marketplaceCategoryCache.get(cacheKey);
        if (cacheElement == null) {
            // Nothing in cache currently;  need to populate cache
            HashSet<PortletCategory> portletCategories = new HashSet<>();
            for (final String categoryName : permittedCategories) {
                EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.IS, IPortletDefinition.class);
                if (cats != null && cats.length > 0) {
                    PortletCategory pc = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
                    if (pc != null) {
                        portletCategories.add(pc);
                    } else {
                        logger.warn("No PortletCategory found in portletCategoryRegistry for id '{}'", cats[0].getKey());
                    }
                } else {
                    logger.warn("No category found in GroupService for name '{}'", categoryName);
                }
            }
            /*
                 * Sanity Check:  Since at least 1 category name was specified, we
                 * need to make certain there's at least 1 PortletCategory in the
                 * set;  otherwise, a restricted Marketplace portlet would become
                 * an unrestricted one.
                 */
            if (portletCategories.isEmpty()) {
                throw new IllegalStateException("None of the specified category " + "names could be resolved to a PortletCategory:  " + Arrays.asList(permittedCategories));
            }
            cacheElement = new net.sf.ehcache.Element(cacheKey, portletCategories);
            this.marketplaceCategoryCache.put(cacheElement);
        }
        rslt = (Set<PortletCategory>) cacheElement.getObjectValue();
    }
    return rslt;
}
Also used : EntityIdentifier(org.apereo.portal.EntityIdentifier) PortletPreferences(javax.portlet.PortletPreferences) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) HashSet(java.util.HashSet)

Example 12 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class GroupListHelperImpl method search.

/*
     * (non-Javadoc)
     * @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#search(java.lang.String, java.lang.String)
     */
@SuppressWarnings("unchecked")
public Set<JsonEntityBean> search(String entityType, String searchTerm) {
    Set<JsonEntityBean> results = new HashSet<JsonEntityBean>();
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    EntityIdentifier[] identifiers;
    Class identifierType;
    // to locate it
    if (entityEnum.isGroup()) {
        identifiers = GroupService.searchForGroups(searchTerm, GroupService.CONTAINS, entityEnum.getClazz());
        identifierType = IEntityGroup.class;
    } else // otherwise use the getGroupMember method
    {
        identifiers = GroupService.searchForEntities(searchTerm, GroupService.CONTAINS, entityEnum.getClazz());
        identifierType = entityEnum.getClazz();
    }
    for (int i = 0; i < identifiers.length; i++) {
        if (identifiers[i].getType().equals(identifierType)) {
            IGroupMember entity = GroupService.getGroupMember(identifiers[i]);
            if (entity != null) {
                JsonEntityBean jsonBean = getEntity(entity);
                results.add(jsonBean);
            } else {
                log.warn("Grouper member entity of " + identifiers[i].getKey() + " is null.");
            }
        }
    }
    return results;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 13 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier 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 = AuthorizationService.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) HashSet(java.util.HashSet) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 14 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class ChannelListController method prepareCategoryBean.

private ChannelCategoryBean prepareCategoryBean(WebRequest request, PortletCategory category, Set<IPortletDefinition> portletsNotYetCategorized, IPerson user, Locale locale) {
    // construct a new channel category bean for this category
    ChannelCategoryBean categoryBean = new ChannelCategoryBean(category);
    categoryBean.setName(messageSource.getMessage(category.getName(), new Object[] {}, locale));
    // 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());
    for (IPortletDefinition portlet : portlets) {
        if (authorizationService.canPrincipalBrowse(ap, portlet)) {
            // construct a new channel bean from this channel
            ChannelBean channel = getChannel(portlet, request, locale);
            categoryBean.addChannel(channel);
        }
        /*
             * Remove the portlet from the uncategorized collection;
             * note -- this approach will not prevent portlets from
             * appearing in multiple categories (as appropriate).
             */
        portletsNotYetCategorized.remove(portlet);
    }
    /* Now add child categories. */
    for (PortletCategory childCategory : this.portletCategoryRegistry.getChildCategories(category)) {
        ChannelCategoryBean childCategoryBean = prepareCategoryBean(request, childCategory, portletsNotYetCategorized, user, locale);
        categoryBean.addCategory(childCategoryBean);
    }
    return categoryBean;
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier) ChannelBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelBean) ChannelCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelCategoryBean) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 15 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier 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)

Aggregations

EntityIdentifier (org.apereo.portal.EntityIdentifier)79 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)31 HashSet (java.util.HashSet)20 IPerson (org.apereo.portal.security.IPerson)17 ArrayList (java.util.ArrayList)15 IEntityGroup (org.apereo.portal.groups.IEntityGroup)13 IGroupMember (org.apereo.portal.groups.IGroupMember)12 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)12 Set (java.util.Set)9 GroupsException (org.apereo.portal.groups.GroupsException)9 Iterator (java.util.Iterator)7 Element (net.sf.ehcache.Element)6 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)6 HashMap (java.util.HashMap)4 List (java.util.List)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedList (java.util.LinkedList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 SortedSet (java.util.SortedSet)2