Search in sources :

Example 26 with IPortletWindowId

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

the class PortletDelegationDispatcherImpl method doAction.

@Override
public DelegationActionResponse doAction(ActionRequest actionRequest, ActionResponse actionResponse, DelegationRequest delegationRequest) throws IOException {
    final HttpServletRequest request = this.portalRequestUtils.getPortletHttpRequest(actionRequest);
    final HttpServletResponse response = this.portalRequestUtils.getOriginalPortalResponse(actionRequest);
    // Sanity check that the dispatch is being called by the same user it was created for
    final IPerson person = this.personManager.getPerson(request);
    if (this.userId != person.getID()) {
        throw new IllegalStateException("This dispatcher was created for userId " + this.userId + " but is being executed for userId " + person.getID());
    }
    this.setupDelegateRequestInfo(request, delegationRequest);
    final IPortletWindowId portletWindowId = this.portletWindow.getPortletWindowId();
    try {
        // TODO canRender permission checks!
        this.portletRenderer.doAction(portletWindowId, request, response);
    } catch (RuntimeException e) {
        this.logger.error("Failed to execute action on delegate", e);
        throw e;
    }
    // Get the portal URL builders for this request and check if a redirect was sent
    final IPortalActionUrlBuilder portalActionUrlBuilder = this.portalUrlProvider.getPortalActionUrlBuilder(request);
    final String redirectLocation = portalActionUrlBuilder.getRedirectLocation();
    if (redirectLocation != null) {
        final String renderUrlParamName = portalActionUrlBuilder.getRenderUrlParamName();
        // clear out the redirect from the delegate, leave it up to the parent if the redirect
        // should happen
        portalActionUrlBuilder.setRedirectLocation(null, null);
        return new DelegationActionResponse(this.getDelegateState(), redirectLocation, renderUrlParamName);
    }
    // No redirect so get the portlet's url builder and copy the state-changing data into the
    // delegate response
    final IPortletUrlBuilder portletUrlBuilder = portalActionUrlBuilder.getPortletUrlBuilder(portletWindowId);
    final WindowState windowState = portletUrlBuilder.getWindowState();
    final PortletMode portletMode = portletUrlBuilder.getPortletMode();
    final Map<String, String[]> parameters = portletUrlBuilder.getParameters();
    return new DelegationActionResponse(this.getDelegateState(), portletMode, windowState, parameters);
}
Also used : WindowState(javax.portlet.WindowState) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) HttpServletResponse(javax.servlet.http.HttpServletResponse) IPortalActionUrlBuilder(org.apereo.portal.url.IPortalActionUrlBuilder) DelegationActionResponse(org.apereo.portal.api.portlet.DelegationActionResponse) PortletMode(javax.portlet.PortletMode) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 27 with IPortletWindowId

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

the class UrlSyntaxProviderImplTest method testLegacyPortletUrlParsing.

@Test
public void testLegacyPortletUrlParsing() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/uPortal");
    request.setRequestURI("/render.userLayoutRootNode.uP");
    request.setQueryString("?uP_fname=CourseGuide-Browse-Courses&pltc_type=ACTION&pltc_state=detached&pltc_mode=view&pltp_action=advancedSearch&pltp_subjectChoice=512");
    request.addParameter("uP_fname", "CourseGuide-Browse-Courses");
    request.addParameter("pltc_type", "ACTION");
    request.addParameter("pltc_state", "detached");
    request.addParameter("pltc_mode", "view");
    request.addParameter("pltp_action", "advancedSearch");
    request.addParameter("pltp_subjectChoice", "512");
    final MockPortletWindowId portletWindowId1 = new MockPortletWindowId("16_ctf3_5");
    when(this.portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, "CourseGuide-Browse-Courses")).thenReturn(this.portletWindow1);
    when(this.portletWindow1.getPortletWindowId()).thenReturn(portletWindowId1);
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    assertNotNull(portalRequestInfo);
    assertNull(portalRequestInfo.getTargetedLayoutNodeId());
    assertEquals(portletWindowId1, portalRequestInfo.getTargetedPortletWindowId());
    assertEquals(UrlState.DETACHED, portalRequestInfo.getUrlState());
    assertEquals(UrlType.ACTION, portalRequestInfo.getUrlType());
    final Map<IPortletWindowId, ? extends IPortletRequestInfo> portletRequestInfoMap = portalRequestInfo.getPortletRequestInfoMap();
    assertNotNull(portletRequestInfoMap);
    assertEquals(1, portletRequestInfoMap.size());
    final IPortletRequestInfo portletRequestInfo = portletRequestInfoMap.get(portletWindowId1);
    assertNotNull(portletRequestInfo);
    assertEquals(portletWindowId1, portletRequestInfo.getPortletWindowId());
    assertEquals(ImmutableMap.of("action", Arrays.asList("advancedSearch"), "subjectChoice", Arrays.asList("512")), portletRequestInfo.getPortletParameters());
    assertEquals(IPortletRenderer.DETACHED, portletRequestInfo.getWindowState());
    assertEquals(PortletMode.VIEW, portletRequestInfo.getPortletMode());
    assertNull(portletRequestInfo.getDelegateParentWindowId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Example 28 with IPortletWindowId

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

the class UrlSyntaxProviderImplTest method testSingleFolderPortletDelegationFnameSubscribeIdMinimizedRenderUrlParsingTwo.

@Test
public void testSingleFolderPortletDelegationFnameSubscribeIdMinimizedRenderUrlParsingTwo() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/uPortal");
    request.setRequestURI("/p/portlet-admin.ctf3/max/action.uP");
    request.setQueryString("?pCa=71_dlg-44-ctf3-8_8&pCd_71_dlg-44-ctf3-8_8=44_ctf3_8&pP_71_dlg-44-ctf3-8_8_action=updateKey&pP_execution=e4s4&pP__eventId=configModeAction");
    request.addParameter("pCa", "71_dlg-44-ctf3-8_8");
    request.addParameter("pCd_71_dlg-44-ctf3-8_8", "44_ctf3_8");
    request.addParameter("pP_71_dlg-44-ctf3-8_8_action", "updateKey");
    request.addParameter("pP_execution", "e4s4");
    request.addParameter("pP__eventId", "configModeAction");
    request.addParameter("googleApiKey", "12345");
    final MockPortletWindowId portletWindowId1 = new MockPortletWindowId("44_ctf3_8");
    final MockPortletWindowId portletWindowId2 = new MockPortletWindowId("71_dlg-44-ctf3-8_8");
    when(this.portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request)).thenReturn(urlNodeSyntaxHelper);
    when(this.urlNodeSyntaxHelper.getPortletForFolderName(request, null, "portlet-admin.ctf3")).thenReturn(portletWindowId1);
    when(this.portletWindowRegistry.getPortletWindowId(request, "71_dlg-44-ctf3-8_8")).thenReturn(portletWindowId2);
    when(this.portletWindowRegistry.getPortletWindowId(request, "44_ctf3_8")).thenReturn(portletWindowId1);
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    assertNotNull(portalRequestInfo);
    assertNull(portalRequestInfo.getTargetedLayoutNodeId());
    assertEquals(portletWindowId1, portalRequestInfo.getTargetedPortletWindowId());
    assertEquals(UrlState.MAX, portalRequestInfo.getUrlState());
    assertEquals(UrlType.ACTION, portalRequestInfo.getUrlType());
    final Map<IPortletWindowId, ? extends IPortletRequestInfo> portletRequestInfoMap = portalRequestInfo.getPortletRequestInfoMap();
    assertNotNull(portletRequestInfoMap);
    assertEquals(2, portletRequestInfoMap.size());
    final IPortletRequestInfo portletRequestInfo = portletRequestInfoMap.get(portletWindowId1);
    assertNotNull(portletRequestInfo);
    assertEquals(portletWindowId1, portletRequestInfo.getPortletWindowId());
    assertEquals(ImmutableMap.of("execution", Arrays.asList("e4s4"), "_eventId", Arrays.asList("configModeAction")), portletRequestInfo.getPortletParameters());
    assertEquals(WindowState.MAXIMIZED, portletRequestInfo.getWindowState());
    assertNull(portletRequestInfo.getPortletMode());
    assertNull(portletRequestInfo.getDelegateParentWindowId());
    final IPortletRequestInfo portletRequestInfo2 = portletRequestInfoMap.get(portletWindowId2);
    assertNotNull(portletRequestInfo2);
    assertEquals(portletWindowId2, portletRequestInfo2.getPortletWindowId());
    assertEquals(ImmutableMap.of("action", Arrays.asList("updateKey"), "googleApiKey", Arrays.asList("12345")), portletRequestInfo2.getPortletParameters());
    assertNull(portletRequestInfo2.getWindowState());
    assertNull(portletRequestInfo2.getPortletMode());
    assertEquals(portletWindowId1, portletRequestInfo2.getDelegateParentWindowId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Example 29 with IPortletWindowId

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

the class UrlSyntaxProviderImplTest method testDetachedResourceUrlParsing.

@Test
public void testDetachedResourceUrlParsing() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContextPath("/uPortal");
    request.setRequestURI("/f/u12l1s5/p/news.u12l1n7/detached/calendar.2012-06-01.7.resource.uP");
    request.setQueryString("?pCc=cacheLevelPage");
    request.addParameter("pCc", "cacheLevelPage");
    final MockPortletWindowId portletWindowId = new MockPortletWindowId("s3");
    final MockPortletWindowId detachedPortletWindowId = new MockPortletWindowId("d3");
    when(this.portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
    when(urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request)).thenReturn(urlNodeSyntaxHelper);
    when(this.urlNodeSyntaxHelper.getLayoutNodeForFolderNames(request, Arrays.asList("u12l1s5"))).thenReturn("u12l1s5");
    when(this.urlNodeSyntaxHelper.getPortletForFolderName(request, "u12l1s5", "news.u12l1n7")).thenReturn(portletWindowId);
    when(this.portletWindowRegistry.getOrCreateStatelessPortletWindow(request, portletWindowId)).thenReturn(portletWindow1);
    when(portletWindow1.getPortletWindowId()).thenReturn(detachedPortletWindowId);
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    assertNotNull(portalRequestInfo);
    assertEquals("u12l1s5", portalRequestInfo.getTargetedLayoutNodeId());
    assertEquals(detachedPortletWindowId, portalRequestInfo.getTargetedPortletWindowId());
    assertEquals(UrlState.DETACHED, portalRequestInfo.getUrlState());
    assertEquals(UrlType.RESOURCE, portalRequestInfo.getUrlType());
    final Map<IPortletWindowId, ? extends IPortletRequestInfo> portletRequestInfoMap = portalRequestInfo.getPortletRequestInfoMap();
    assertNotNull(portletRequestInfoMap);
    assertEquals(1, portletRequestInfoMap.size());
    final IPortletRequestInfo portletRequestInfo = portletRequestInfoMap.get(detachedPortletWindowId);
    assertNotNull(portletRequestInfo);
    assertEquals(detachedPortletWindowId, portletRequestInfo.getPortletWindowId());
    assertEquals(Collections.EMPTY_MAP, portletRequestInfo.getPortletParameters());
    assertEquals(IPortletRenderer.DETACHED, portletRequestInfo.getWindowState());
    assertNull(portletRequestInfo.getPortletMode());
    assertEquals(ResourceURL.PAGE, portletRequestInfo.getCacheability());
    assertEquals("calendar.2012-06-01.7", portletRequestInfo.getResourceId());
    final PortalUrlBuilder portalUrlBuilder = new PortalUrlBuilder(urlSyntaxProvider, request, "u12l1s5", detachedPortletWindowId, UrlType.RESOURCE);
    when(this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, detachedPortletWindowId, UrlType.RESOURCE)).thenReturn(portalUrlBuilder);
    when(this.portletWindowRegistry.getPortletWindow(request, detachedPortletWindowId)).thenReturn(portletWindow2);
    when(portletWindow2.getPortletEntity()).thenReturn(portletEntity1);
    when(portletEntity1.getLayoutNodeId()).thenReturn("u12l1s5");
    when(urlNodeSyntaxHelper.getFolderNameForPortlet(request, detachedPortletWindowId)).thenReturn("news.u12l1n7");
    when(urlNodeSyntaxHelper.getFolderNamesForLayoutNode(request, "u12l1s5")).thenReturn(Collections.singletonList("u12l1s5"));
    final String canonicalUrl = this.urlSyntaxProvider.getCanonicalUrl(request);
    assertEquals("/uPortal/f/u12l1s5/p/news.u12l1n7/detached/calendar.2012-06-01.7.resource.uP?pCc=cacheLevelPage", canonicalUrl);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Example 30 with IPortletWindowId

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

the class UrlSyntaxProviderImplTest method testParsePortletWindowIdSuffix.

@Test
public void testParsePortletWindowIdSuffix() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final Set<String> ids = ImmutableSet.of("pw2");
    final MockPortletWindowId expectedPortletWindowId = new MockPortletWindowId("pw2");
    when(this.portletWindowRegistry.getPortletWindowId(request, "pw2")).thenReturn(expectedPortletWindowId);
    IPortletWindowId portletWindowId = this.urlSyntaxProvider.parsePortletWindowIdSuffix(request, UrlSyntaxProviderImpl.PARAM_WINDOW_STATE, ids, UrlSyntaxProviderImpl.PARAM_WINDOW_STATE + UrlSyntaxProviderImpl.SEPARATOR + "pw2");
    assertEquals(expectedPortletWindowId, portletWindowId);
    portletWindowId = this.urlSyntaxProvider.parsePortletWindowIdSuffix(request, UrlSyntaxProviderImpl.PARAM_WINDOW_STATE, ids, UrlSyntaxProviderImpl.PARAM_WINDOW_STATE + UrlSyntaxProviderImpl.SEPARATOR + UrlSyntaxProviderImpl.SEPARATOR + "pw2");
    assertNull(portletWindowId);
    portletWindowId = this.urlSyntaxProvider.parsePortletWindowIdSuffix(request, UrlSyntaxProviderImpl.PARAM_WINDOW_STATE, ids, UrlSyntaxProviderImpl.PARAM_WINDOW_STATE);
    assertNull(portletWindowId);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

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 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)8 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPortletRenderExecutionWorker (org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker)7 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)7 LinkedHashMap (java.util.LinkedHashMap)6 IPerson (org.apereo.portal.security.IPerson)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 IOException (java.io.IOException)5 List (java.util.List)5 IUserInstance (org.apereo.portal.user.IUserInstance)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5