Search in sources :

Example 1 with ChannelBean

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

use of org.apereo.portal.layout.dlm.remoting.registry.ChannelBean 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 3 with ChannelBean

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

the class ChannelListController method listChannels.

/**
     * Original, pre-4.3 version of this API. Always returns the entire contents of the Portlet
     * Registry, including uncategorized portlets, to which the user has access. Access is based on
     * the SUBSCRIBE permission.
     */
@RequestMapping(value = "/portletList", method = RequestMethod.GET)
public ModelAndView listChannels(WebRequest webRequest, HttpServletRequest request, @RequestParam(value = "type", required = false) String type) {
    if (type != null && TYPE_MANAGE.equals(type)) {
        throw new UnsupportedOperationException("Moved to PortletRESTController under /api/portlets.json");
    }
    final IPerson user = personManager.getPerson(request);
    final Map<String, SortedSet<?>> registry = getRegistryOriginal(webRequest, user);
    // Since type=manage was deprecated channels is always empty but retained for backwards compatibility
    registry.put("channels", new TreeSet<ChannelBean>());
    return new ModelAndView("jsonView", "registry", registry);
}
Also used : IPerson(org.apereo.portal.security.IPerson) ModelAndView(org.springframework.web.servlet.ModelAndView) ChannelBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelBean) SortedSet(java.util.SortedSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ChannelBean

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

the class ChannelListController method getChannel.

private ChannelBean getChannel(IPortletDefinition definition, WebRequest request, Locale locale) {
    ChannelBean channel = new ChannelBean();
    channel.setId(definition.getPortletDefinitionId().getStringId());
    channel.setDescription(definition.getDescription(locale.toString()));
    channel.setFname(definition.getFName());
    channel.setName(definition.getName(locale.toString()));
    channel.setState(definition.getLifecycleState().toString());
    channel.setTitle(definition.getTitle(locale.toString()));
    channel.setTypeId(definition.getType().getId());
    // See api docs for postProcessIconUrlParameter() below
    IPortletDefinitionParameter iconParameter = definition.getParameter(ICON_URL_PARAMETER_NAME);
    if (iconParameter != null) {
        IPortletDefinitionParameter evaluated = postProcessIconUrlParameter(iconParameter, request);
        channel.setIconUrl(evaluated.getValue());
    }
    return channel;
}
Also used : IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ChannelBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelBean)

Aggregations

ChannelBean (org.apereo.portal.layout.dlm.remoting.registry.ChannelBean)4 SortedSet (java.util.SortedSet)2 EntityIdentifier (org.apereo.portal.EntityIdentifier)2 ChannelCategoryBean (org.apereo.portal.layout.dlm.remoting.registry.ChannelCategoryBean)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)1 IPerson (org.apereo.portal.security.IPerson)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1