Search in sources :

Example 1 with IPortletEntity

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

the class SingleTabUrlNodeSyntaxHelper method getPortletForFolderName.

@Override
public IPortletWindowId getPortletForFolderName(HttpServletRequest request, String targetedLayoutNodeId, String folderName) {
    //Basic parsing of the
    final String fname;
    String subscribeId = null;
    final int seperatorIndex = folderName.indexOf(PORTLET_PATH_ELEMENT_SEPERATOR);
    if (seperatorIndex <= 0 || seperatorIndex + 1 == folderName.length()) {
        fname = folderName;
    } else {
        fname = folderName.substring(0, seperatorIndex);
        subscribeId = folderName.substring(seperatorIndex + 1);
    }
    //If a subscribeId was provided validate that it matches up with the fname
    if (subscribeId != null) {
        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
        final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, subscribeId);
        if (portletEntity == null || !fname.equals(portletEntity.getPortletDefinition().getFName())) {
            //If no entity found or the fname doesn't match ignore the provided subscribeId by setting it to null
            subscribeId = null;
        } else {
            //subscribeId matches fname, lookup the window for the entity and return the windowId
            final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
            final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindow(request, portletEntityId);
            if (portletWindow == null) {
                return null;
            }
            return portletWindow.getPortletWindowId();
        }
    }
    //If a layout node is targeted then look for a matching subscribeId under that targeted node
    if (targetedLayoutNodeId != null) {
        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
        final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
        //First look for the layout node only under the specified folder
        subscribeId = userLayoutManager.getSubscribeId(targetedLayoutNodeId, fname);
    }
    //Find a subscribeId based on the fname
    final IPortletWindow portletWindow;
    if (subscribeId == null) {
        portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname);
    } else {
        portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, subscribeId);
    }
    if (portletWindow == null) {
        return null;
    }
    return portletWindow.getPortletWindowId();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 2 with IPortletEntity

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

the class UrlSyntaxProviderImpl method generateUrl.

@Override
public String generateUrl(HttpServletRequest request, IPortalUrlBuilder portalUrlBuilder) {
    Validate.notNull(request, "HttpServletRequest was null");
    Validate.notNull(portalUrlBuilder, "IPortalPortletUrl was null");
    //Convert the callback request to the portal request
    request = this.portalRequestUtils.getOriginalPortalRequest(request);
    final IUrlNodeSyntaxHelper urlNodeSyntaxHelper = this.urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request);
    //Get the encoding and create a new URL string builder
    final String encoding = this.getEncoding(request);
    //Add the portal's context path
    final String contextPath = this.getCleanedContextPath(request);
    final UrlStringBuilder url = new UrlStringBuilder(encoding, contextPath.length() > 0 ? contextPath : null);
    final Map<IPortletWindowId, IPortletUrlBuilder> portletUrlBuilders = portalUrlBuilder.getPortletUrlBuilders();
    //Build folder path based on targeted portlet or targeted folder
    final IPortletWindowId targetedPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
    final UrlType urlType = portalUrlBuilder.getUrlType();
    final UrlState urlState;
    final String resourceId;
    if (targetedPortletWindowId != null) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetedPortletWindowId);
        final IPortletEntity portletEntity = portletWindow.getPortletEntity();
        //Add folder information if available: /f/tabId
        final String channelSubscribeId = portletEntity.getLayoutNodeId();
        final List<String> folderNames = urlNodeSyntaxHelper.getFolderNamesForLayoutNode(request, channelSubscribeId);
        if (!folderNames.isEmpty()) {
            url.addPath(FOLDER_PATH_PREFIX);
            for (final String folderName : folderNames) {
                url.addPath(folderName);
            }
        }
        final IPortletUrlBuilder targetedPortletUrlBuilder = portletUrlBuilders.get(targetedPortletWindowId);
        //Determine the resourceId for resource requests
        if (urlType == UrlType.RESOURCE && targetedPortletUrlBuilder != null) {
            resourceId = targetedPortletUrlBuilder.getResourceId();
        } else {
            resourceId = null;
        }
        //Resource requests will never have a requested window state
        urlState = this.determineUrlState(portletWindow, targetedPortletUrlBuilder);
        final String targetedPortletString = urlNodeSyntaxHelper.getFolderNameForPortlet(request, targetedPortletWindowId);
        //If a non-normal render url or an action/resource url stick the portlet info in the path
        if ((urlType == UrlType.RENDER && urlState != UrlState.NORMAL) || urlType == UrlType.ACTION || urlType == UrlType.RESOURCE) {
            url.addPath(PORTLET_PATH_PREFIX);
            url.addPath(targetedPortletString);
        } else //For normal render requests (generally multiple portlets on a page) add the targeted portlet as a parameter
        {
            url.addParameter(PARAM_TARGET_PORTLET, targetedPortletString);
        }
    } else {
        final String targetFolderId = portalUrlBuilder.getTargetFolderId();
        final List<String> folderNames = urlNodeSyntaxHelper.getFolderNamesForLayoutNode(request, targetFolderId);
        if (folderNames != null && !folderNames.isEmpty()) {
            url.addPath(FOLDER_PATH_PREFIX);
            for (final String folderName : folderNames) {
                url.addPath(folderName);
            }
        }
        urlState = UrlState.NORMAL;
        resourceId = null;
    }
    //Add the state of the URL
    url.addPath(urlState.toLowercaseString());
    //File part specifying the type of URL, resource URLs include the resourceId
    if (urlType == UrlType.RESOURCE && resourceId != null) {
        url.addPath(resourceId + "." + urlType.toLowercaseString() + REQUEST_TYPE_SUFFIX);
    } else {
        url.addPath(urlType.toLowercaseString() + REQUEST_TYPE_SUFFIX);
    }
    //Add all portal parameters
    final Map<String, String[]> portalParameters = portalUrlBuilder.getParameters();
    url.addParametersArray(PORTAL_PARAM_PREFIX, portalParameters);
    //Is this URL stateless
    final boolean statelessUrl = statelessUrlStates.contains(urlState);
    //Add parameters for every portlet URL
    for (final IPortletUrlBuilder portletUrlBuilder : portletUrlBuilders.values()) {
        this.addPortletUrlData(request, url, urlType, portletUrlBuilder, targetedPortletWindowId, statelessUrl);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Generated '" + url + "' from '" + portalUrlBuilder);
    }
    return url.toString();
}
Also used : IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 3 with IPortletEntity

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

the class RequestRenderingPipelineUtilsImpl method getPortletDefinitionFromServletRequest.

@Override
public IPortletDefinition getPortletDefinitionFromServletRequest(HttpServletRequest request) {
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    if (portalRequestInfo != null && portalRequestInfo.getTargetedPortletWindowId() != null) {
        IPortletWindowId targetedPortletWindowId = portalRequestInfo.getTargetedPortletWindowId();
        IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetedPortletWindowId);
        if (portletWindow != null && portletWindow.getPortletEntity() != null) {
            final IPortletEntity portletEntity = portletWindow.getPortletEntity();
            IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
            return portletDefinition;
        }
    }
    return null;
}
Also used : IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 4 with IPortletEntity

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

the class PortletWindowRegistryImpl method getOrCreateDefaultPortletWindowByLayoutNodeId.

@Override
public IPortletWindow getOrCreateDefaultPortletWindowByLayoutNodeId(HttpServletRequest request, String subscribeId) {
    Validate.notNull(request, "HttpServletRequest cannot be null");
    Validate.notNull(subscribeId, "subscribeId cannot be null");
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, subscribeId);
    if (portletEntity == null) {
        logger.debug("No portlet entity found for id {}, no IPortletWindow will be returned.", subscribeId);
        return null;
    }
    logger.trace("Found portlet entity {} for id {}", portletEntity, subscribeId);
    final IPortletWindow portletWindow = this.getOrCreateDefaultPortletWindow(request, portletEntity.getPortletEntityId());
    logger.trace("Found portlet window {} for layout node {}", portletWindow, subscribeId);
    return portletWindow;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 5 with IPortletEntity

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

the class PortletWindowRegistryImpl method getOrCreateStatelessPortletWindow.

@Override
public IPortletWindow getOrCreateStatelessPortletWindow(HttpServletRequest request, IPortletWindowId basePortletWindowId) {
    //Need the basePortletWindowId to be an instance of PortletWindowIdImpl so that we can extract the entity ID
    if (!(basePortletWindowId instanceof PortletWindowIdImpl)) {
        final String basePortletWindowIdStr = basePortletWindowId.getStringId();
        basePortletWindowId = this.getPortletWindowId(request, basePortletWindowIdStr);
    }
    //Get the entity ID for the portlet window
    final IPortletEntityId portletEntityId = ((PortletWindowIdImpl) basePortletWindowId).getPortletEntityId();
    //Create the stateless ID
    final PortletWindowIdImpl statelessPortletWindowId = this.createPortletWindowId(STATELESS_PORTLET_WINDOW_ID, portletEntityId);
    //See if there is already a request cached stateless window
    IPortletWindow statelessPortletWindow = this.getPortletWindow(request, statelessPortletWindowId);
    if (statelessPortletWindow != null) {
        return statelessPortletWindow;
    }
    //Lookup the base portlet window to clone the stateless from
    final IPortletWindow basePortletWindow = this.getPortletWindow(request, basePortletWindowId);
    final PortletWindowCache<PortletWindowData> statelessPortletWindowDataMap = this.getStatelessPortletWindowDataMap(request, true);
    //If no base to clone from lookup the entity and pluto definition data
    if (basePortletWindow == null) {
        final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
        if (portletEntity == null) {
            throw new IllegalArgumentException("No IPortletEntity could be found for " + portletEntity + " while creating stateless portlet window for " + basePortletWindowId);
        }
        final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
        final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
        final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
        final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
        statelessPortletWindowDataMap.storeWindow(portletWindowData);
        statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    } else //Clone the existing base window
    {
        final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
        portletWindowData.setExpirationCache(basePortletWindow.getExpirationCache());
        portletWindowData.setPortletMode(basePortletWindow.getPortletMode());
        portletWindowData.setWindowState(basePortletWindow.getWindowState());
        portletWindowData.setPublicRenderParameters(basePortletWindow.getPublicRenderParameters());
        portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters());
        statelessPortletWindowDataMap.storeWindow(portletWindowData);
        final IPortletEntity portletEntity = basePortletWindow.getPortletEntity();
        final PortletDefinition portletDescriptor = basePortletWindow.getPlutoPortletWindow().getPortletDefinition();
        statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    }
    //Cache the stateless window in the request
    final PortletWindowCache<IPortletWindow> portletWindowMap = this.getPortletWindowMap(request);
    portletWindowMap.storeWindow(statelessPortletWindow);
    return statelessPortletWindow;
}
Also used : IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Aggregations

IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)63 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)32 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)25 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)24 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)19 IUserInstance (org.apereo.portal.user.IUserInstance)12 Test (org.junit.Test)11 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)10 List (java.util.List)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 PortletPreferenceImpl (org.apereo.portal.portlet.dao.jpa.PortletPreferenceImpl)9 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)9 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)9 IPerson (org.apereo.portal.security.IPerson)7 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)5 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)5 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)5 ArrayList (java.util.ArrayList)4 Callable (java.util.concurrent.Callable)4