Search in sources :

Example 26 with IUserPreferencesManager

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

the class ThemeNameRequestPropertiesManager method populateRequestProperties.

@Override
public <P extends Populator<String, String>> void populateRequestProperties(HttpServletRequest portletRequest, IPortletWindow portletWindow, P propertiesPopulator) {
    // get the current user profile
    IUserInstance ui = userInstanceManager.getUserInstance(portletRequest);
    IUserPreferencesManager upm = ui.getPreferencesManager();
    IUserProfile profile = upm.getUserProfile();
    // get the theme for this profile
    long themeId = profile.getThemeStylesheetId();
    IStylesheetDescriptor theme = stylesheetDao.getStylesheetDescriptor(themeId);
    // set the theme name as a portlet response property
    final String themeName = theme.getName();
    propertiesPopulator.put(IPortletRenderer.THEME_NAME_PROPERTY, themeName);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserProfile(org.apereo.portal.IUserProfile) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 27 with IUserPreferencesManager

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

the class UserLayoutParameterProcessor method processParameters.

@Override
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)

Example 28 with IUserPreferencesManager

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

the class PortletEventCoordinatationService method resolvePortletEvents.

@Override
public void resolvePortletEvents(HttpServletRequest request, PortletEventQueue portletEventQueue) {
    final Queue<QueuedEvent> events = portletEventQueue.getUnresolvedEvents();
    //Skip all processing if there are no new events.
    if (events.isEmpty()) {
        return;
    }
    //Get all the portlets the user is subscribed to
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    //Make a local copy so we can remove data from it
    final Set<String> allLayoutNodeIds = new LinkedHashSet<String>(userLayoutManager.getAllSubscribedChannels());
    final Map<String, IPortletEntity> portletEntityCache = new LinkedHashMap<String, IPortletEntity>();
    while (!events.isEmpty()) {
        final QueuedEvent queuedEvent = events.poll();
        if (queuedEvent == null) {
            //no more queued events, done resolving
            return;
        }
        final IPortletWindowId sourceWindowId = queuedEvent.getPortletWindowId();
        final Event event = queuedEvent.getEvent();
        final boolean globalEvent = isGlobalEvent(request, sourceWindowId, event);
        final Set<IPortletDefinition> portletDefinitions = new LinkedHashSet<IPortletDefinition>();
        if (globalEvent) {
            portletDefinitions.addAll(this.portletDefinitionRegistry.getAllPortletDefinitions());
        }
        //Check each subscription to see what events it is registered to see
        for (final Iterator<String> layoutNodeIdItr = allLayoutNodeIds.iterator(); layoutNodeIdItr.hasNext(); ) {
            final String layoutNodeId = layoutNodeIdItr.next();
            IPortletEntity portletEntity = portletEntityCache.get(layoutNodeId);
            if (portletEntity == null) {
                portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, layoutNodeId);
                // if portlet entity registry returned null, then portlet has been deleted - remove it (see UP-3378)
                if (portletEntity == null) {
                    layoutNodeIdItr.remove();
                    continue;
                }
                final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
                final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
                if (portletDescriptor == null) {
                    //Missconfigured portlet, remove it from the list so we don't check again and ignore it
                    layoutNodeIdItr.remove();
                    continue;
                }
                final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
                //Skip portlets that don't handle any events and remove them from the set so they are not checked again
                if (supportedProcessingEvents == null || supportedProcessingEvents.size() == 0) {
                    layoutNodeIdItr.remove();
                    continue;
                }
                portletEntityCache.put(layoutNodeId, portletEntity);
            }
            final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
            final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
            if (this.supportsEvent(event, portletDefinitionId)) {
                this.logger.debug("{} supports event {}", portletDefinition, event);
                //If this is the default portlet entity remove the definition from the all defs set to avoid duplicate processing
                final IPortletEntity defaultPortletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
                if (defaultPortletEntity.equals(portletEntity)) {
                    portletDefinitions.remove(portletDefinition);
                }
                // Is this portlet permitted to receive events?  (Or is it disablePortletEvents=true?)
                IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
                if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
                    logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
                    continue;
                }
                final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
                final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
                for (final IPortletWindow portletWindow : portletWindows) {
                    this.logger.debug("{} resolved target {}", event, portletWindow);
                    final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                    final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
                    portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
                }
            } else {
                portletDefinitions.remove(portletDefinition);
            }
        }
        if (!portletDefinitions.isEmpty()) {
            final IPerson user = userInstance.getPerson();
            final EntityIdentifier ei = user.getEntityIdentifier();
            final IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
            //If the event is global there might still be portlet definitions that need targeting
            for (final IPortletDefinition portletDefinition : portletDefinitions) {
                // Is this portlet permitted to receive events?  (Or is it disablePortletEvents=true?)
                IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
                if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
                    logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
                    continue;
                }
                final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
                //Check if the user can render the portlet definition before doing event tests
                if (ap.canRender(portletDefinitionId.getStringId())) {
                    if (this.supportsEvent(event, portletDefinitionId)) {
                        this.logger.debug("{} supports event {}", portletDefinition, event);
                        final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
                        final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
                        final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
                        for (final IPortletWindow portletWindow : portletWindows) {
                            this.logger.debug("{} resolved target {}", event, portletWindow);
                            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                            final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
                            portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
                        }
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) LinkedHashMap(java.util.LinkedHashMap) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) Event(javax.portlet.Event) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 29 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)

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