Search in sources :

Example 31 with IUserLayoutNodeDescription

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

the class SingleTabUrlNodeSyntaxHelper method getLayoutNodeForFolderNames.

@Override
public String getLayoutNodeForFolderNames(HttpServletRequest request, List<String> folderNames) {
    if (folderNames == null || folderNames.isEmpty()) {
        logger.warn("Asked to get layout node for an empty or null folderNames ({}).", folderNames);
        return null;
    }
    // Check if the folder name is compound and parse it if it is
    String folderName = folderNames.get(0);
    String layoutNodeId = null;
    final int seperatorIndex = folderName.indexOf(PORTLET_PATH_ELEMENT_SEPERATOR);
    if (seperatorIndex > 0 && seperatorIndex < folderName.length() - 1) {
        layoutNodeId = folderName.substring(seperatorIndex + 1);
        folderName = folderName.substring(0, seperatorIndex);
    }
    if (folderNames.size() > 1) {
        logger.warn("Asked to consider multiple folder names {}, " + "but ignoring all but the first which has been parsed as {}.", folderNames, folderName);
    }
    // Search the users layout attributes for a layout node with a matching externalId value
    String firstMatchingNodeId = null;
    final Map<String, String> allNodesAndValuesForAttribute = stylesheetUserPreferencesService.getAllNodesAndValuesForAttribute(request, PreferencesScope.STRUCTURE, EXTERNAL_ID_ATTR);
    for (final Entry<String, String> entry : allNodesAndValuesForAttribute.entrySet()) {
        final String value = entry.getValue();
        // could have already been translated
        if (value.equals(folderName) || FunctionalNameType.makeValid(value).equals(folderName)) {
            final String nodeId = entry.getKey();
            if (nodeId.equals(layoutNodeId)) {
                // ExternalId matched as well as the layoutNodeId, clear the firstMatchingNodeId
                // since we found the nodeId here
                logger.trace("Parsed folder names {} to nodeId {}.", folderNames, nodeId);
                return nodeId;
            } else if (firstMatchingNodeId == null) {
                firstMatchingNodeId = nodeId;
            }
        }
    }
    // use that match
    if (firstMatchingNodeId != null) {
        layoutNodeId = firstMatchingNodeId;
    } else // In this case the folderName must not have been an externalId, assume it is a layout node
    if (layoutNodeId == null) {
        layoutNodeId = folderName;
    }
    // Verify the parsed layoutNodeId matches a node in the user's layout
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayoutNodeDescription node;
    try {
        node = userLayoutManager.getNode(layoutNodeId);
    } catch (PortalException e) {
        logger.warn("Parsed requested folder names {} to layoutNodeId {} " + "but did not match a node in the user layout.", folderNames, layoutNodeId, e);
        return null;
    }
    if (node == null) {
        logger.warn("Parsed requested folder names to layoutNodeId {} " + "but did not match a node in the user layout.", folderNames, layoutNodeId);
        return null;
    }
    String nodeId = node.getId();
    logger.trace("Resolved node id {} for folder names {}.", nodeId, folderNames);
    return nodeId;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 32 with IUserLayoutNodeDescription

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

the class PortalUrlProviderImpl method getLayoutNodeType.

/**
 * Verify the requested node exists in the user's layout. Also if the node exists see if it is a
 * portlet node and if it is return the {@link IPortletWindowId} of the corresponding portlet.
 */
protected LayoutNodeType getLayoutNodeType(HttpServletRequest request, String folderNodeId) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayoutNodeDescription node = userLayoutManager.getNode(folderNodeId);
    if (node == null) {
        return null;
    }
    return node.getType();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Aggregations

IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)32 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)15 PortalException (org.apereo.portal.PortalException)14 IUserInstance (org.apereo.portal.user.IUserInstance)13 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)12 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)9 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)9 Element (org.w3c.dom.Element)7 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 Node (org.w3c.dom.Node)6 ArrayList (java.util.ArrayList)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 Document (org.w3c.dom.Document)5 Enumeration (java.util.Enumeration)4 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 IUserLayout (org.apereo.portal.layout.IUserLayout)4 UserLayoutChannelDescription (org.apereo.portal.layout.node.UserLayoutChannelDescription)4