Search in sources :

Example 71 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class UrlSyntaxProviderImpl method getPortalRequestInfo.

/* (non-Javadoc)
     * @see org.apereo.portal.url.IPortalUrlProvider#getPortalRequestInfo(javax.servlet.http.HttpServletRequest)
     */
@Override
public IPortalRequestInfo getPortalRequestInfo(HttpServletRequest request) {
    request = this.portalRequestUtils.getOriginalPortalRequest(request);
    final IPortalRequestInfo cachedPortalRequestInfo = (IPortalRequestInfo) request.getAttribute(PORTAL_REQUEST_INFO_ATTR);
    if (cachedPortalRequestInfo != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("short-circuit: found portalRequestInfo within request attributes");
        }
        return cachedPortalRequestInfo;
    }
    synchronized (PortalWebUtils.getRequestAttributeMutex(request)) {
        // set a flag to say this request is currently being parsed
        final Boolean inProgressAttr = (Boolean) request.getAttribute(PORTAL_REQUEST_PARSING_IN_PROGRESS_ATTR);
        if (inProgressAttr != null && inProgressAttr) {
            if (logger.isDebugEnabled()) {
                logger.warn("Portal request info parsing already in progress, returning null");
            }
            return null;
        }
        request.setAttribute(PORTAL_REQUEST_PARSING_IN_PROGRESS_ATTR, Boolean.TRUE);
    }
    try {
        // Clone the parameter map so data can be removed from it as it is parsed to help
        // determine
        // what to do with non-namespaced parameters
        final Map<String, String[]> parameterMap = new ParameterMap(request.getParameterMap());
        final String requestPath = this.urlPathHelper.getPathWithinApplication(request);
        if (LEGACY_URL_PATHS.contains(requestPath)) {
            return parseLegacyPortalUrl(request, parameterMap);
        }
        final IUrlNodeSyntaxHelper urlNodeSyntaxHelper = this.urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request);
        final PortalRequestInfoImpl portalRequestInfo = new PortalRequestInfoImpl();
        IPortletWindowId targetedPortletWindowId = null;
        PortletRequestInfoImpl targetedPortletRequestInfo = null;
        final String[] requestPathParts = SLASH_PATTERN.split(requestPath);
        UrlState requestedUrlState = null;
        ParseStep parseStep = ParseStep.FOLDER;
        for (int pathPartIndex = 0; pathPartIndex < requestPathParts.length; pathPartIndex++) {
            String pathPart = requestPathParts[pathPartIndex];
            logger.trace("In parseStep {} considering pathPart [{}].", parseStep, pathPart);
            if (StringUtils.isEmpty(pathPart)) {
                continue;
            }
            switch(parseStep) {
                case FOLDER:
                    {
                        parseStep = ParseStep.PORTLET;
                        if (FOLDER_PATH_PREFIX.equals(pathPart)) {
                            logger.trace("Skipping adding {} to the folders deque " + "because it is simply the folder path prefix.", pathPart);
                            pathPartIndex++;
                            final LinkedList<String> folders = new LinkedList<String>();
                            for (; pathPartIndex < requestPathParts.length; pathPartIndex++) {
                                pathPart = requestPathParts[pathPartIndex];
                                if (PORTLET_PATH_PREFIX.equals(pathPart)) {
                                    logger.trace("Found the portlet part of the path " + "demarked by portlet path prefix [{}]; " + "stepping back one path part to finish folder processing", pathPart);
                                    pathPartIndex--;
                                    break;
                                } else {
                                    if (pathPart.endsWith(REQUEST_TYPE_SUFFIX)) {
                                        logger.trace("Found the end of the folder path with pathPart [{}];" + " stepping back one, checking for state, " + "and finishing folder parsing", pathPart);
                                        pathPartIndex--;
                                        pathPart = requestPathParts[pathPartIndex];
                                        // other code can handle it
                                        if (UrlState.valueOfIngoreCase(pathPart, null) != null) {
                                            logger.trace("A state was added to the end of folder list {};" + " removing it.", folders);
                                            folders.removeLast();
                                            pathPartIndex--;
                                        }
                                        break;
                                    }
                                }
                                logger.trace("Adding pathPart [{}] to folders.", pathPart);
                                folders.add(pathPart);
                            }
                            logger.trace("Folders is [{}]", folders);
                            if (folders.size() > 0) {
                                final String targetedLayoutNodeId = urlNodeSyntaxHelper.getLayoutNodeForFolderNames(request, folders);
                                portalRequestInfo.setTargetedLayoutNodeId(targetedLayoutNodeId);
                            }
                            break;
                        }
                    }
                // fall through
                case PORTLET:
                    {
                        parseStep = ParseStep.STATE;
                        final String targetedLayoutNodeId = portalRequestInfo.getTargetedLayoutNodeId();
                        if (PORTLET_PATH_PREFIX.equals(pathPart)) {
                            if (++pathPartIndex < requestPathParts.length) {
                                pathPart = requestPathParts[pathPartIndex];
                                targetedPortletWindowId = urlNodeSyntaxHelper.getPortletForFolderName(request, targetedLayoutNodeId, pathPart);
                            }
                            break;
                        }
                        // See if a portlet was targeted by parameter
                        final String[] targetedPortletIds = parameterMap.remove(PARAM_TARGET_PORTLET);
                        if (targetedPortletIds != null && targetedPortletIds.length > 0) {
                            final String targetedPortletString = targetedPortletIds[0];
                            targetedPortletWindowId = urlNodeSyntaxHelper.getPortletForFolderName(request, targetedLayoutNodeId, targetedPortletString);
                        }
                    }
                // fall through
                case STATE:
                    {
                        parseStep = ParseStep.TYPE;
                        // targeted
                        if (targetedPortletWindowId == null) {
                            break;
                        }
                        requestedUrlState = UrlState.valueOfIngoreCase(pathPart, null);
                        // Set the URL state
                        if (requestedUrlState != null) {
                            portalRequestInfo.setUrlState(requestedUrlState);
                            // If the request is stateless
                            if (statelessUrlStates.contains(requestedUrlState)) {
                                final IPortletWindow statelessPortletWindow = this.portletWindowRegistry.getOrCreateStatelessPortletWindow(request, targetedPortletWindowId);
                                targetedPortletWindowId = statelessPortletWindow.getPortletWindowId();
                            }
                            // Create the portlet request info
                            targetedPortletRequestInfo = portalRequestInfo.getPortletRequestInfo(targetedPortletWindowId);
                            portalRequestInfo.setTargetedPortletWindowId(targetedPortletWindowId);
                            // window state parameter
                            switch(requestedUrlState) {
                                case MAX:
                                    {
                                        targetedPortletRequestInfo.setWindowState(WindowState.MAXIMIZED);
                                    }
                                    break;
                                case DETACHED:
                                    {
                                        targetedPortletRequestInfo.setWindowState(IPortletRenderer.DETACHED);
                                    }
                                    break;
                                case EXCLUSIVE:
                                    {
                                        targetedPortletRequestInfo.setWindowState(IPortletRenderer.EXCLUSIVE);
                                    }
                                    break;
                                default:
                            }
                            break;
                        }
                    }
                // fall through
                case TYPE:
                    {
                        parseStep = ParseStep.COMPLETE;
                        if (pathPartIndex == requestPathParts.length - 1 && pathPart.endsWith(REQUEST_TYPE_SUFFIX) && pathPart.length() > REQUEST_TYPE_SUFFIX.length()) {
                            final String urlTypePart = pathPart.substring(0, pathPart.length() - REQUEST_TYPE_SUFFIX.length());
                            final UrlType urlType;
                            // Handle inline resourceIds, look for a . in the request type
                            // string and use the suffix as the urlType
                            final int lastPeriod = urlTypePart.lastIndexOf('.');
                            if (lastPeriod >= 0 && lastPeriod < urlTypePart.length()) {
                                final String urlTypePartSuffix = urlTypePart.substring(lastPeriod + 1);
                                urlType = UrlType.valueOfIngoreCase(urlTypePartSuffix, null);
                                if (urlType == UrlType.RESOURCE && targetedPortletRequestInfo != null) {
                                    final String resourceId = urlTypePart.substring(0, lastPeriod);
                                    targetedPortletRequestInfo.setResourceId(resourceId);
                                }
                            } else {
                                urlType = UrlType.valueOfIngoreCase(urlTypePart, null);
                            }
                            if (urlType != null) {
                                portalRequestInfo.setUrlType(urlType);
                                break;
                            }
                        }
                    }
                // fall through
                default:
            }
        }
        // been retrieved yet, set it up
        if (targetedPortletWindowId != null && targetedPortletRequestInfo == null) {
            targetedPortletRequestInfo = portalRequestInfo.getPortletRequestInfo(targetedPortletWindowId);
            portalRequestInfo.setTargetedPortletWindowId(targetedPortletWindowId);
        }
        // Get the set of portlet window ids that also have parameters on the url
        final String[] additionalPortletIdArray = parameterMap.remove(PARAM_ADDITIONAL_PORTLET);
        final Set<String> additionalPortletIds = Sets.newHashSet(additionalPortletIdArray != null ? additionalPortletIdArray : new String[0]);
        // Used if there is delegation to capture form-submit and other non-prefixed parameters
        // Map of parent id to delegate id
        final Map<IPortletWindowId, IPortletWindowId> delegateIdMappings = new LinkedHashMap<IPortletWindowId, IPortletWindowId>(0);
        // Parse all remaining parameters from the request
        final Set<Entry<String, String[]>> parameterEntrySet = parameterMap.entrySet();
        for (final Iterator<Entry<String, String[]>> parameterEntryItr = parameterEntrySet.iterator(); parameterEntryItr.hasNext(); ) {
            final Entry<String, String[]> parameterEntry = parameterEntryItr.next();
            final String name = parameterEntry.getKey();
            final List<String> values = Arrays.asList(parameterEntry.getValue());
            // Portal Parameters, just need to remove the prefix
            if (name.startsWith(PORTAL_PARAM_PREFIX)) {
                final Map<String, List<String>> portalParameters = portalRequestInfo.getPortalParameters();
                portalParameters.put(this.safeSubstringAfter(PORTAL_PARAM_PREFIX, name), values);
                parameterEntryItr.remove();
                continue;
            }
            // portlet windowId between the prefix and parameter name
            if (name.startsWith(PORTLET_PARAM_PREFIX)) {
                final Tuple<String, IPortletWindowId> portletParameterParts = this.parsePortletParameterName(request, name, additionalPortletIds);
                final IPortletWindowId portletWindowId = portletParameterParts.second;
                final String paramName = portletParameterParts.first;
                // Get the portlet parameter map to add the parameter to
                final Map<String, List<String>> portletParameters;
                if (portletWindowId == null) {
                    if (targetedPortletRequestInfo == null) {
                        this.logger.warn("Parameter " + name + " is for the targeted portlet but no portlet is targeted by the request. The parameter will be ignored. Value: " + values);
                        parameterEntryItr.remove();
                        break;
                    }
                    portletParameters = targetedPortletRequestInfo.getPortletParameters();
                } else {
                    final PortletRequestInfoImpl portletRequestInfoImpl = portalRequestInfo.getPortletRequestInfo(portletWindowId);
                    portletParameters = portletRequestInfoImpl.getPortletParameters();
                }
                portletParameters.put(paramName, values);
                parameterEntryItr.remove();
                continue;
            }
            // SuffixedPortletParameter to simplify their parsing
            for (final SuffixedPortletParameter suffixedPortletParameter : SuffixedPortletParameter.values()) {
                final String parameterPrefix = suffixedPortletParameter.getParameterPrefix();
                // Skip to the next parameter prefix if the current doesn't match
                if (!name.startsWith(parameterPrefix)) {
                    continue;
                }
                // All of these parameters require at least one value
                if (values.isEmpty()) {
                    this.logger.warn("Ignoring parameter {} as it must have a value. Value: {}", name, values);
                    break;
                }
                // Verify the parameter is being used on the correct type of URL
                final Set<UrlType> validUrlTypes = suffixedPortletParameter.getValidUrlTypes();
                if (!validUrlTypes.contains(portalRequestInfo.getUrlType())) {
                    this.logger.warn("Ignoring parameter {} as it is only valid for {} requests and this is a " + "{} request. Value: {}", name, validUrlTypes, portalRequestInfo.getUrlType(), values);
                    break;
                }
                // Determine the portlet window and request info the parameter targets
                final IPortletWindowId portletWindowId = this.parsePortletWindowIdSuffix(request, parameterPrefix, additionalPortletIds, name);
                final PortletRequestInfoImpl portletRequestInfo = getTargetedPortletRequestInfo(portalRequestInfo, targetedPortletRequestInfo, portletWindowId);
                if (portletRequestInfo == null) {
                    this.logger.warn("Parameter {} is for the targeted portlet but no portlet is targeted" + " by the request. The parameter will be ignored. Value: {}", name, values);
                    break;
                }
                parameterEntryItr.remove();
                // Use the enum helper to store the parameter values on the request info
                suffixedPortletParameter.updateRequestInfo(request, portletWindowRegistry, portletRequestInfo, values, delegateIdMappings);
                break;
            }
        }
        // Any non-namespaced parameters still need processing?
        if (!parameterMap.isEmpty()) {
            // If the parameter was not ignored by a previous parser add it to whatever was
            // targeted (portlet or portal)
            final Map<String, List<String>> parameters;
            if (!delegateIdMappings.isEmpty()) {
                // Resolve the last portlet window in the chain of delegation
                PortletRequestInfoImpl delegatePortletRequestInfo = null;
                for (final IPortletWindowId delegatePortletWindowId : delegateIdMappings.values()) {
                    if (!delegateIdMappings.containsKey(delegatePortletWindowId)) {
                        delegatePortletRequestInfo = portalRequestInfo.getPortletRequestInfo(delegatePortletWindowId);
                        break;
                    }
                }
                if (delegatePortletRequestInfo != null) {
                    parameters = delegatePortletRequestInfo.getPortletParameters();
                } else {
                    this.logger.warn("No root delegate portlet could be resolved, non-namespaced parameters" + " will be sent to the targeted portlet. THIS SHOULD NEVER HAPPEN. Delegate" + " parent/child mapping: {}", delegateIdMappings);
                    if (targetedPortletRequestInfo != null) {
                        parameters = targetedPortletRequestInfo.getPortletParameters();
                    } else {
                        parameters = portalRequestInfo.getPortalParameters();
                    }
                }
            } else if (targetedPortletRequestInfo != null) {
                parameters = targetedPortletRequestInfo.getPortletParameters();
            } else {
                parameters = portalRequestInfo.getPortalParameters();
            }
            ParameterMap.putAllList(parameters, parameterMap);
        }
        // If a portlet is targeted but no layout node is targeted must be maximized
        if (targetedPortletRequestInfo != null && portalRequestInfo.getTargetedLayoutNodeId() == null && (requestedUrlState == null || requestedUrlState == UrlState.NORMAL)) {
            portalRequestInfo.setUrlState(UrlState.MAX);
            targetedPortletRequestInfo.setWindowState(WindowState.MAXIMIZED);
        }
        // Make the request info object read-only, once parsed the request info should be static
        portalRequestInfo.makeReadOnly();
        request.setAttribute(PORTAL_REQUEST_INFO_ATTR, portalRequestInfo);
        logger.debug("Finished building requestInfo: {}", portalRequestInfo);
        return portalRequestInfo;
    } finally {
        request.removeAttribute(PORTAL_REQUEST_PARSING_IN_PROGRESS_ATTR);
    }
}
Also used : IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 72 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class PortletDelegationDispatcherImpl method setupDelegateRequestInfo.

protected void setupDelegateRequestInfo(HttpServletRequest request, DelegationRequest delegationRequest) {
    if (delegationRequest == null) {
        return;
    }
    final DelegateState delegateState = delegationRequest.getDelegateState();
    if (delegateState != null) {
        final PortletMode portletMode = delegateState.getPortletMode();
        if (portletMode != null) {
            this.portletWindow.setPortletMode(portletMode);
        }
        final WindowState windowState = delegateState.getWindowState();
        if (windowState != null) {
            this.portletWindow.setWindowState(windowState);
        }
    }
    final IPortletWindowId portletWindowId = this.portletWindow.getPortletWindowId();
    // Store the DelegationRequest so it can be accessed elsewhere
    this.portletDelegationManager.setDelegationRequest(request, portletWindowId, delegationRequest);
}
Also used : WindowState(javax.portlet.WindowState) DelegateState(org.apereo.portal.api.portlet.DelegateState) PortletMode(javax.portlet.PortletMode) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 73 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class RenderPortletTag method doEndTag.

@Override
public int doEndTag() throws JspException {
    // From portlet:defineObjects
    final RenderRequest renderRequest = (RenderRequest) this.pageContext.getAttribute("renderRequest");
    final RenderResponse renderResponse = (RenderResponse) this.pageContext.getAttribute("renderResponse");
    final PortletDelegationLocator portletDelegationLocator = (PortletDelegationLocator) renderRequest.getAttribute(PortletDelegationLocator.PORTLET_DELECATION_LOCATOR_ATTR);
    final String sessionKey = this.sessionKeyPrefix + this.fname;
    final PortletSession portletSession = renderRequest.getPortletSession();
    IPortletWindowId portletWindowId = (IPortletWindowId) portletSession.getAttribute(sessionKey);
    final PortletDelegationDispatcher portletDelegationDispatcher;
    final DelegateState delegateState;
    // No id in session, create a new dispatcher
    if (portletWindowId == null) {
        portletDelegationDispatcher = portletDelegationLocator.createRequestDispatcher(renderRequest, this.fname);
        portletWindowId = portletDelegationDispatcher.getPortletWindowId();
        portletSession.setAttribute(sessionKey, portletWindowId);
        final PortletMode portletMode = PortletUtils.getPortletMode(this.portletMode);
        final WindowState windowState = PortletUtils.getWindowState(this.windowState);
        delegateState = new DelegateState(portletMode, windowState);
    } else // id in session, get the old dispatcher
    {
        portletDelegationDispatcher = portletDelegationLocator.getRequestDispatcher(renderRequest, portletWindowId);
        delegateState = null;
    }
    final DelegationRequest delegationRequest = new DelegationRequest();
    delegationRequest.setDelegateState(delegateState);
    // Setup base for portlet URLs
    delegationRequest.setParentPortletMode(this.parentUrlMode);
    delegationRequest.setParentWindowState(this.parentUrlState);
    delegationRequest.setParentParameters(this.parentUrlParameters);
    final JspWriter out = this.pageContext.getOut();
    try {
        portletDelegationDispatcher.doRender(renderRequest, renderResponse, delegationRequest, new JspWriterPortletOutputHandler(out, renderResponse));
    } catch (IOException e) {
        throw new JspException("Failed to execute delegate render on portlet '" + this.fname + "'", e);
    }
    return Tag.EVAL_PAGE;
}
Also used : WindowState(javax.portlet.WindowState) RenderRequest(javax.portlet.RenderRequest) DelegateState(org.apereo.portal.api.portlet.DelegateState) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) PortletMode(javax.portlet.PortletMode) JspException(javax.servlet.jsp.JspException) PortletSession(javax.portlet.PortletSession) PortletDelegationDispatcher(org.apereo.portal.api.portlet.PortletDelegationDispatcher) RenderResponse(javax.portlet.RenderResponse) PortletDelegationLocator(org.apereo.portal.api.portlet.PortletDelegationLocator) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) DelegationRequest(org.apereo.portal.api.portlet.DelegationRequest)

Example 74 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId in project uPortal by Jasig.

the class MarketplaceSearchService method getSearchResults.

/**
 * Returns a list of search results that pertain to the marketplace query is the query to search
 * will search name, title, description, fname, and captions
 */
@Override
public SearchResults getSearchResults(PortletRequest request, SearchRequest query) {
    final String queryString = query.getSearchTerms().toLowerCase();
    final List<IPortletDefinition> portlets = portletDefinitionRegistry.getAllPortletDefinitions();
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final SearchResults results = new SearchResults();
    for (IPortletDefinition portlet : portlets) {
        if (this.matches(queryString, new MarketplacePortletDefinition(portlet, this.marketplaceService, this.portletCategoryRegistry))) {
            final SearchResult result = new SearchResult();
            result.setTitle(portlet.getTitle());
            result.setSummary(portlet.getDescription());
            result.getType().add("marketplace");
            final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(httpServletRequest, portlet.getFName());
            // If user does not have browse permission, exclude the portlet.
            if (portletWindow != null && authorizationService.canPrincipalBrowse(authorizationService.newPrincipal(request.getRemoteUser(), EntityEnum.PERSON.getClazz()), portlet)) {
                final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletFName(httpServletRequest, portlet.getFName(), UrlType.RENDER);
                final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
                portletUrlBuilder.setWindowState(PortletUtils.getWindowState("maximized"));
                result.setExternalUrl(portalUrlBuilder.getUrlString());
                PortletUrl url = new PortletUrl();
                url.setType(PortletUrlType.RENDER);
                url.setPortletMode("VIEW");
                url.setWindowState("maximized");
                PortletUrlParameter actionParam = new PortletUrlParameter();
                actionParam.setName("action");
                actionParam.getValue().add("view");
                url.getParam().add(actionParam);
                PortletUrlParameter fNameParam = new PortletUrlParameter();
                fNameParam.setName("fName");
                fNameParam.getValue().add(portlet.getFName());
                url.getParam().add(fNameParam);
                result.setPortletUrl(url);
                // Add the result to list to return
                results.getSearchResult().add(result);
            }
        }
    }
    return results;
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) SearchResult(org.apereo.portal.search.SearchResult) SearchResults(org.apereo.portal.search.SearchResults) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrl(org.apereo.portal.search.PortletUrl) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 75 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId 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);
                // 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();
                // 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 = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
            // 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)

Aggregations

IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)85 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)31 Test (org.junit.Test)19 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)15 WindowState (javax.portlet.WindowState)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)9 PortletMode (javax.portlet.PortletMode)8 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)8 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)8 IPortletRenderExecutionWorker (org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker)7 IPerson (org.apereo.portal.security.IPerson)7 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)7 LinkedHashMap (java.util.LinkedHashMap)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 IUserInstance (org.apereo.portal.user.IUserInstance)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 IOException (java.io.IOException)5 List (java.util.List)5