Search in sources :

Example 31 with IUserLayoutManager

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

the class UserInstanceManagerImpl method getUserInstance.

/**
 * Returns the UserInstance object that is associated with the given request.
 *
 * @param request Incoming HttpServletRequest
 * @return UserInstance object associated with the given request
 */
@Override
public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
    try {
        request = this.portalRequestUtils.getOriginalPortalRequest(request);
    } catch (IllegalArgumentException iae) {
    // ignore, just means that this isn't a wrapped request
    }
    // Use request attributes first for the fastest possible retrieval
    IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
    if (userInstance != null) {
        return userInstance;
    }
    final IPerson person;
    try {
        // Retrieve the person object that is associated with the request
        person = this.personManager.getPerson(request);
    } catch (Exception e) {
        logger.error("Exception while retrieving IPerson!", e);
        throw new PortalSecurityException("Could not retrieve IPerson", e);
    }
    if (person == null) {
        throw new PortalSecurityException("PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
    }
    final HttpSession session = request.getSession();
    if (session == null) {
        throw new IllegalStateException("HttpServletRequest.getSession() returned a null session for request: " + request);
    }
    // Return the UserInstance object if it's in the session
    UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
    if (userInstanceHolder != null) {
        userInstance = userInstanceHolder.getUserInstance();
        if (userInstance != null) {
            return userInstance;
        }
    }
    // Create either a UserInstance or a GuestUserInstance
    final LocaleManager localeManager = this.getLocaleManager(request, person);
    final String userAgent = this.getUserAgent(request);
    final IUserProfile userProfile = this.getUserProfile(request, person, localeManager, userAgent);
    // Create the user layout manager and user instance object
    IUserLayoutManager userLayoutManager = userLayoutManagerFactory.getUserLayoutManager(person, userProfile);
    final UserPreferencesManager userPreferencesManager = new UserPreferencesManager(person, userProfile, userLayoutManager);
    userInstance = new UserInstance(person, userPreferencesManager, localeManager);
    // Ensure the newly created UserInstance is cached in the session
    if (userInstanceHolder == null) {
        userInstanceHolder = new UserInstanceHolder();
    }
    userInstanceHolder.setUserInstance(userInstance);
    session.setAttribute(KEY, userInstanceHolder);
    request.setAttribute(KEY, userInstance);
    // Return the new UserInstance
    return userInstance;
}
Also used : HttpSession(javax.servlet.http.HttpSession) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) PortalException(org.apereo.portal.PortalException) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) LocaleManager(org.apereo.portal.i18n.LocaleManager) UserInstance(org.apereo.portal.UserInstance) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 32 with IUserLayoutManager

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

the class FavoritesEditController method initializeView.

/**
 * Handles all Favorites portlet EDIT mode renders. Populates model with user's favorites and
 * selects a view to display those favorites.
 *
 * <p>View selection:
 *
 * <p>Returns "jsp/Favorites/edit" in the normal case where the user has at least one favorited
 * portlet or favorited collection.
 *
 * <p>Returns "jsp/Favorites/edit_zero" in the edge case where the user has zero favorited
 * portlets AND zero favorited collections.
 *
 * <p>Model: marketPlaceFname --> String functional name of Marketplace portlet, or null if not
 * available. collections --> List of favorited collections (IUserLayoutNodeDescription s)
 * favorites --> List of favorited individual portlets (IUserLayoutNodeDescription s)
 * successMessageCode --> String success message bundle key, or null if none errorMessageCode
 * --> String error message bundle key, or null if none nameOfFavoriteActedUpon --> Name of
 * favorite acted upon, intended as parameter to success or error message
 *
 * @param model . Spring model. This method adds five model attributes.
 * @return jsp/Favorites/edit[_zero]
 */
@RenderMapping
public String initializeView(Model model, RenderRequest renderRequest) {
    IUserInstance ui = userInstanceManager.getUserInstance(portalRequestUtils.getCurrentPortalRequest());
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    IUserLayout userLayout = ulm.getUserLayout();
    // TODO: the portlet could predicate including a non-null marketplace portlet fname
    // on the accessing user having permission to render the portlet referenced by that fname
    // so that portlet would gracefully degrade when configured with bad marketplace portlet
    // fname
    // and also gracefully degrade when the accessing user doesn't have permission to access an
    // otherwise
    // viable configured marketplace.  This complexity may not be worth it.  Anyway it is not
    // yet implemented.
    model.addAttribute("marketplaceFname", this.marketplaceFName);
    List<IUserLayoutNodeDescription> collections = FavoritesUtils.getFavoriteCollections(userLayout);
    model.addAttribute("collections", collections);
    List<IUserLayoutNodeDescription> favorites = FavoritesUtils.getFavoritePortlets(userLayout);
    model.addAttribute("favorites", favorites);
    model.addAttribute("successMessageCode", renderRequest.getParameter("successMessageCode"));
    model.addAttribute("errorMessageCode", renderRequest.getParameter("errorMessageCode"));
    model.addAttribute("nameOfFavoriteActedUpon", renderRequest.getParameter("nameOfFavoriteActedUpon"));
    // default to the regular old edit view
    String viewName = "jsp/Favorites/edit";
    if (collections.isEmpty() && favorites.isEmpty()) {
        // use the special case view
        viewName = "jsp/Favorites/edit_zero";
    }
    logger.trace("Favorites Portlet EDIT mode built model [{}] and selected view {}.", model, viewName);
    return viewName;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 33 with IUserLayoutManager

use of org.apereo.portal.layout.IUserLayoutManager 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 34 with IUserLayoutManager

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

the class SingleTabUrlNodeSyntaxHelper method getDefaultLayoutNodeId.

@Override
public String getDefaultLayoutNodeId(HttpServletRequest httpServletRequest) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(httpServletRequest);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IUserLayout userLayout = userLayoutManager.getUserLayout();
    // This logic is specific to tab/column layouts
    final String defaultTabIndex = this.getDefaultTabIndex(httpServletRequest);
    if (defaultTabIndex != null) {
        final String defaultTabId = this.getTabId(userLayout, defaultTabIndex);
        if (StringUtils.isNotEmpty(defaultTabId)) {
            return defaultTabId;
        }
    }
    this.logger.warn("Failed to find default tab id for '" + userInstance.getPerson().getUserName() + "' with default tab index " + defaultTabIndex + ". Index 1 will be tried as a fall-back.");
    final String firstTabId = getTabId(userLayout, "1");
    if (StringUtils.isNotEmpty(firstTabId)) {
        return firstTabId;
    }
    this.logger.warn("Failed to find default tab id for '" + userInstance.getPerson().getUserName() + "' with default tab index 1. The user has no tabs.");
    return userLayout.getRootId();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 35 with IUserLayoutManager

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

the class TransientPortletEntityDao method wrapEntity.

/**
 * Adds a TransientPortletEntity wrapper to the portletEntity if it is needed. If the specified
 * entity is transient but no transient subscribe id has been registered for it yet in the
 * transientIdMap null is returned. If no wrapping is needed the original entity is returned.
 */
protected IPortletEntity wrapEntity(IPortletEntity portletEntity) {
    if (portletEntity == null) {
        return null;
    }
    final String persistentLayoutNodeId = portletEntity.getLayoutNodeId();
    if (persistentLayoutNodeId.startsWith(TransientUserLayoutManagerWrapper.SUBSCRIBE_PREFIX)) {
        final IUserLayoutManager userLayoutManager = this.getUserLayoutManager();
        if (userLayoutManager == null) {
            this.logger.warn("Could not find IUserLayoutManager when trying to wrap transient portlet entity: " + portletEntity);
            return portletEntity;
        }
        final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
        final String fname = portletDefinition.getFName();
        final String layoutNodeId = userLayoutManager.getSubscribeId(fname);
        return new TransientPortletEntity(portletEntity, layoutNodeId);
    }
    return portletEntity;
}
Also used : IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)38 IUserInstance (org.apereo.portal.user.IUserInstance)28 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)17 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)16 PortalException (org.apereo.portal.PortalException)16 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 IPerson (org.apereo.portal.security.IPerson)10 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)9 IUserLayout (org.apereo.portal.layout.IUserLayout)7 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)7 HashMap (java.util.HashMap)6 Locale (java.util.Locale)6 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)5 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)5 UserLayoutFolderDescription (org.apereo.portal.layout.node.UserLayoutFolderDescription)4 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)4 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)4