Search in sources :

Example 6 with IPortletWindow

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

the class RequestPropertiesManagerBrokerTest method testGetProperties.

public void testGetProperties() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final IPortletWindow portletWindow = EasyMock.createMock(IPortletWindow.class);
    EasyMock.replay(portletWindow);
    final MockRequestPropertiesManager delegateManager1 = new MockRequestPropertiesManager();
    delegateManager1.setOrder(Ordered.HIGHEST_PRECEDENCE);
    final MockRequestPropertiesManager delegateManager2 = new MockRequestPropertiesManager();
    delegateManager2.setOrder(Ordered.LOWEST_PRECEDENCE);
    this.requestPropertiesManagerBroker.setPropertiesManagers(ImmutableList.of(delegateManager1, delegateManager2));
    delegateManager1.setResponseProperty(request, portletWindow, "prop.A", "prop.A.1");
    delegateManager1.setResponseProperty(request, portletWindow, "prop.B", "prop.B.1");
    delegateManager2.setResponseProperty(request, portletWindow, "prop.C", "prop.C.1");
    MultivaluedMapPopulator<String, String> multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    this.requestPropertiesManagerBroker.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    final Map<String, List<String>> expected1 = ImmutableMap.<String, List<String>>of("prop.A", ImmutableList.of("prop.A.1"), "prop.B", ImmutableList.of("prop.B.1"), "prop.C", ImmutableList.of("prop.C.1"));
    assertEquals(expected1, multivaluedMapPopulator.getMap());
    delegateManager2.setResponseProperty(request, portletWindow, "prop.A", "prop.A.2");
    multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    this.requestPropertiesManagerBroker.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    final Map<String, List<String>> expected2 = ImmutableMap.<String, List<String>>of("prop.A", ImmutableList.of("prop.A.1", "prop.A.2"), "prop.B", ImmutableList.of("prop.B.1"), "prop.C", ImmutableList.of("prop.C.1"));
    assertEquals(expected2, multivaluedMapPopulator.getMap());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) MultivaluedMapPopulator(org.apereo.portal.utils.MultivaluedMapPopulator)

Example 7 with IPortletWindow

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

the class RequestPropertiesManagerBrokerTest method testSetProperties.

public void testSetProperties() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final IPortletWindow portletWindow = EasyMock.createMock(IPortletWindow.class);
    EasyMock.replay(portletWindow);
    final MockRequestPropertiesManager delegateManager1 = new MockRequestPropertiesManager();
    delegateManager1.setOrder(Ordered.HIGHEST_PRECEDENCE);
    final MockRequestPropertiesManager delegateManager2 = new MockRequestPropertiesManager();
    delegateManager2.setOrder(Ordered.LOWEST_PRECEDENCE);
    this.requestPropertiesManagerBroker.setPropertiesManagers(ImmutableList.of(delegateManager1, delegateManager2));
    this.requestPropertiesManagerBroker.setResponseProperty(request, portletWindow, "prop.A", "prop.A.1");
    final Map<String, List<String>> expected1 = Collections.singletonMap("prop.A", Collections.singletonList("prop.A.1"));
    MultivaluedMapPopulator<String, String> multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    this.requestPropertiesManagerBroker.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    assertEquals(expected1, multivaluedMapPopulator.getMap());
    multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    delegateManager1.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    assertEquals(expected1, multivaluedMapPopulator.getMap());
    multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    delegateManager2.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    assertEquals(Collections.EMPTY_MAP, multivaluedMapPopulator.getMap());
    this.requestPropertiesManagerBroker.setResponseProperty(request, portletWindow, "prop.A", "prop.A.2");
    final Map<String, List<String>> expected2 = Collections.<String, List<String>>singletonMap("prop.A", ImmutableList.of("prop.A.2"));
    multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    this.requestPropertiesManagerBroker.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    assertEquals(expected2, multivaluedMapPopulator.getMap());
    multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    delegateManager1.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    assertEquals(expected2, multivaluedMapPopulator.getMap());
    multivaluedMapPopulator = new MultivaluedMapPopulator<String, String>();
    delegateManager2.populateRequestProperties(request, portletWindow, multivaluedMapPopulator);
    assertEquals(Collections.EMPTY_MAP, multivaluedMapPopulator.getMap());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) MultivaluedMapPopulator(org.apereo.portal.utils.MultivaluedMapPopulator)

Example 8 with IPortletWindow

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

the class XsltPortalUrlProvider method getPortletUrlBuilder.

/**
     * Get the portlet URL builder for the specified fname or layoutId (fname takes precedence)
     *
     * @param request
     * @param portalUrlBuilder
     * @param fname - can be empty string
     * @param layoutId - can by empty string
     * @param state - can be empty string
     * @param mode - can be empty string
     * @param copyCurrentRenderParameters
     * @param resourceId - can be empty string
     * @return IPortletUrlBuilder
     * @since 4.1
     */
public IPortletUrlBuilder getPortletUrlBuilder(HttpServletRequest request, IPortalUrlBuilder portalUrlBuilder, String fname, String layoutId, String state, String mode, String copyCurrentRenderParameters, String resourceId) {
    final IPortletUrlBuilder portletUrlBuilder;
    if (StringUtils.isNotEmpty(fname)) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname);
        final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
        portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
    } else if (StringUtils.isNotEmpty(layoutId)) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, layoutId);
        final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
        portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
    } else {
        final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
        if (targetPortletWindowId == null) {
            if (this.logger.isDebugEnabled()) {
                this.logger.warn("Can only target the default portlet if the root portal-url targets a portlet.", new Throwable());
            } else {
                this.logger.warn("Can only target the default portlet if the root portal-url targets a portlet. Enable debug for stack trace.");
            }
            return new FailSafePortletUrlBuilder(null, portalUrlBuilder);
        }
        portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    }
    portletUrlBuilder.setCopyCurrentRenderParameters(Boolean.parseBoolean(copyCurrentRenderParameters));
    if (StringUtils.isNotEmpty(state)) {
        portletUrlBuilder.setWindowState(PortletUtils.getWindowState(state));
    }
    if (StringUtils.isNotEmpty(mode)) {
        portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(mode));
    }
    if (StringUtils.isNotEmpty(resourceId) && portletUrlBuilder.getPortalUrlBuilder().getUrlType() == UrlType.RESOURCE) {
        portletUrlBuilder.setResourceId(resourceId);
    }
    return portletUrlBuilder;
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 9 with IPortletWindow

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

the class PortletWindowAttributeSource method getCacheKey.

@Override
public final CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response) {
    final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllLayoutPortletWindows(request);
    final CacheKeyBuilder cacheKeyBuilder = CacheKey.builder(this.name);
    for (final IPortletWindow portletWindow : portletWindows) {
        if (portletWindow != null) {
            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
            final WindowState windowState = portletWindow.getWindowState();
            final PortletMode portletMode = portletWindow.getPortletMode();
            cacheKeyBuilder.addAll(portletWindowId, windowState.toString(), portletMode.toString());
        } else {
            this.logger.warn("portletWindowRegistry#getAllLayoutPortletWindows() returned a null portletWindow");
        }
    }
    return cacheKeyBuilder.build();
}
Also used : WindowState(javax.portlet.WindowState) CacheKeyBuilder(org.apereo.portal.utils.cache.CacheKey.CacheKeyBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) PortletMode(javax.portlet.PortletMode)

Example 10 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow 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)

Aggregations

IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)88 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)32 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)32 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)12 IUserInstance (org.apereo.portal.user.IUserInstance)12 List (java.util.List)10 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)10 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 IOException (java.io.IOException)8 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)7 WindowState (javax.portlet.WindowState)6 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 LinkedHashMap (java.util.LinkedHashMap)5 Locale (java.util.Locale)5 PortletException (javax.portlet.PortletException)5 PortletMode (javax.portlet.PortletMode)5