Search in sources :

Example 21 with IUserPreferencesManager

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

Example 22 with IUserPreferencesManager

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

the class TransientPortletEntityDao method getUserLayoutManager.

protected IUserLayoutManager getUserLayoutManager() {
    final HttpServletRequest portalRequest = this.portalRequestUtils.getCurrentPortalRequest();
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(portalRequest);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    return preferencesManager.getUserLayoutManager();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 23 with IUserPreferencesManager

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

the class UserLocaleHelper method getCurrentUserLocale.

/**
 * Return the current user's locale.
 *
 * @param request The current {@link PortletRequest}
 * @return
 */
public Locale getCurrentUserLocale(PortletRequest request) {
    final HttpServletRequest originalPortalRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    IUserInstance ui = userInstanceManager.getUserInstance(originalPortalRequest);
    IUserPreferencesManager upm = ui.getPreferencesManager();
    final IUserProfile userProfile = upm.getUserProfile();
    LocaleManager localeManager = userProfile.getLocaleManager();
    // first check the session locales
    List<Locale> sessionLocales = localeManager.getSessionLocales();
    if (sessionLocales != null && sessionLocales.size() > 0) {
        return sessionLocales.get(0);
    }
    // if no session locales were found, check the user locales
    List<Locale> userLocales = localeManager.getUserLocales();
    if (userLocales != null && userLocales.size() > 0) {
        return userLocales.get(0);
    }
    // just return null
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Example 24 with IUserPreferencesManager

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

the class LocaleManagerLocaleResolver method setLocale.

@Override
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final LocaleManager localeManager = userInstance.getLocaleManager();
    localeManager.setSessionLocales(Collections.singletonList(locale));
    // if the current user is logged in, also update the persisted user locale
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final IPerson person = ui.getPerson();
    if (!person.isGuest()) {
        try {
            localeManager.setUserLocales(Collections.singletonList(locale));
            localeStore.updateUserLocales(person, new Locale[] { locale });
            final IUserPreferencesManager upm = ui.getPreferencesManager();
            upm.getUserLayoutManager().loadUserLayout();
        } catch (Exception e) {
            throw new PortalException(e);
        }
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 25 with IUserPreferencesManager

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

the class UserLayoutParameterProcessor method processParameters.

@Override
@SuppressWarnings("FallThrough")
public boolean processParameters(HttpServletRequest request, HttpServletResponse response) {
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final String tabId = portalRequestInfo.getTargetedLayoutNodeId();
    if (tabId != null) {
        this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "focusedTabID", tabId);
    }
    // on a portlet, it will get overwritten with the new value below.
    if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
        final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
        transientUserLayoutManagerWrapper.setFocusedId(null);
    }
    final UrlState urlState = portalRequestInfo.getUrlState();
    switch(urlState) {
        case DETACHED:
            this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "detached", Boolean.TRUE.toString());
        case MAX:
            {
                final IPortletRequestInfo portletRequestInfo = portalRequestInfo.getTargetedPortletRequestInfo();
                if (portletRequestInfo != null) {
                    final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
                    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetWindowId);
                    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
                    final String channelSubscribeId = portletEntity.getLayoutNodeId();
                    this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", channelSubscribeId);
                    if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
                        // get wrapper implementation for focusing
                        final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
                        // .. and now set it as the focused id
                        transientUserLayoutManagerWrapper.setFocusedId(channelSubscribeId);
                    }
                    // If portletRequestInfo was null just fall through to NORMAL state
                    break;
                }
            }
        case NORMAL:
        default:
            {
                this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", IUserLayout.ROOT_NODE_NAME);
                break;
            }
    }
    return true;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) TransientUserLayoutManagerWrapper(org.apereo.portal.layout.TransientUserLayoutManagerWrapper) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IPortletRequestInfo(org.apereo.portal.url.IPortletRequestInfo) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) UrlState(org.apereo.portal.url.UrlState)

Aggregations

IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)29 IUserInstance (org.apereo.portal.user.IUserInstance)27 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)15 IUserProfile (org.apereo.portal.IUserProfile)9 IPerson (org.apereo.portal.security.IPerson)8 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)5 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IUserLayout (org.apereo.portal.layout.IUserLayout)4 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)4 PortalException (org.apereo.portal.PortalException)3 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Locale (java.util.Locale)2 RequestCache (org.apereo.portal.concurrency.caching.RequestCache)2 LocaleManager (org.apereo.portal.i18n.LocaleManager)2