Search in sources :

Example 1 with PortletTabIdResolver

use of org.apereo.portal.layout.PortletTabIdResolver in project uPortal by Jasig.

the class SingleTabUrlNodeSyntaxHelper method getFolderNamesForLayoutNode.

@RequestCache(keyMask = { false, true })
@Override
public List<String> getFolderNamesForLayoutNode(HttpServletRequest request, String layoutNodeId) {
    /*
         * Implementation note:
         * While the API allows one or more folder names, this implementation will only ever return
         * a List with zero or one element.  It's not entirely clear that a List with zero members
         * was allowed by the interface definition, but this implementation will return an empty
         * list if the layoutNodeId cannot be found in the layout.
         */
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayout userLayout = userLayoutManager.getUserLayout();
    final String tabId = userLayout.findNodeId(new PortletTabIdResolver(layoutNodeId));
    if (StringUtils.isEmpty(tabId)) {
        return Collections.emptyList();
    }
    String externalId = stylesheetUserPreferencesService.getLayoutAttribute(request, PreferencesScope.STRUCTURE, tabId, EXTERNAL_ID_ATTR);
    if (externalId != null) {
        final Map<String, String> allNodesAndValuesForAttribute = stylesheetUserPreferencesService.getAllNodesAndValuesForAttribute(request, PreferencesScope.STRUCTURE, EXTERNAL_ID_ATTR);
        boolean appendNodeId = false;
        for (final Entry<String, String> nodeAttributeEntry : allNodesAndValuesForAttribute.entrySet()) {
            final String entryNodeId = nodeAttributeEntry.getKey();
            final String entryValue = nodeAttributeEntry.getValue();
            if (!tabId.equals(entryNodeId) && externalId.equals(entryValue)) {
                appendNodeId = true;
                break;
            }
        }
        if (!FunctionalNameType.isValid(externalId)) {
            logger.warn("ExternalId {} for tab {} is not a valid fname. It will be converted for use in the URL but this results in additional overhead", externalId, tabId);
            externalId = FunctionalNameType.makeValid(externalId);
        }
        if (appendNodeId) {
            externalId = externalId + PORTLET_PATH_ELEMENT_SEPERATOR + layoutNodeId;
        }
        logger.trace("Tab identified by {} resolved to externalId {} " + "so returning that externalId as the sole folder name for node.", layoutNodeId, externalId);
        return Arrays.asList(externalId);
    } else {
        logger.trace("Tab identified by {} had no externalId " + "so returning just {} as the sole folder name for node {}.", layoutNodeId, tabId, layoutNodeId);
        return Arrays.asList(tabId);
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) PortletTabIdResolver(org.apereo.portal.layout.PortletTabIdResolver) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Aggregations

IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1 RequestCache (org.apereo.portal.concurrency.caching.RequestCache)1 IUserLayout (org.apereo.portal.layout.IUserLayout)1 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)1 PortletTabIdResolver (org.apereo.portal.layout.PortletTabIdResolver)1 IUserInstance (org.apereo.portal.user.IUserInstance)1