Search in sources :

Example 1 with ITenant

use of org.apereo.portal.tenants.ITenant in project uPortal by Jasig.

the class TenantManagerController method showTenantDetails.

/** @since 4.3 */
@RenderMapping(params = "action=showTenantDetails")
public ModelAndView showTenantDetails(final RenderRequest req, final PortletSession session) {
    // Should the user chose to perform an action on the details screen, we
    // will need to know which tenant upon which to invoke it.  Not crazy
    // about storing this object in the PortletSession, but taking it as a
    // @RequestParameter could increase the challenges of URL-hacking
    // diligence down the road.  Every pass through this method will re-set
    // the tenancy under the microscope.
    ITenant tenant = null;
    // There are two possibilities that work...
    final String fnameParameter = req.getParameter("fname");
    if (!StringUtils.isBlank(fnameParameter)) {
        // An fname came in the request;  this possibility trumps others
        tenant = tenantService.getTenantByFName(fnameParameter);
        session.setAttribute(CURRENT_TENANT_SESSION_ATTRIBUTE, tenant);
    } else if (session.getAttributeMap().containsKey(CURRENT_TENANT_SESSION_ATTRIBUTE)) {
        // A tenant was previously identified;  we are most likely
        // re-playing the tenant details after failed validation
        tenant = (ITenant) session.getAttribute(CURRENT_TENANT_SESSION_ATTRIBUTE);
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("tenant", tenant);
    model.put("tenantManagerAttributes", Collections.unmodifiableMap(tenantManagerAttributes));
    model.put(OPERATIONS_LINTENER_AVAILABLE_ACTIONS, tenantService.getAllAvaialableActions());
    /*
         * The following 2 items are empty the first time you visit the screen,
         * but may contain data if you attempted to create a tenant but your
         * inputs failed validation.
         */
    // default
    Map<String, String> previousResponses = Collections.emptyMap();
    if (session.getAttributeMap().containsKey(PREVIOUS_RESPONSES)) {
        previousResponses = (Map<String, String>) session.getAttribute(PREVIOUS_RESPONSES);
    }
    model.put(PREVIOUS_RESPONSES, previousResponses);
    // default
    Map<String, Object> invalidFields = Collections.emptyMap();
    if (session.getAttributeMap().containsKey(INVALID_FIELDS)) {
        invalidFields = (Map<String, Object>) session.getAttribute(INVALID_FIELDS);
    }
    model.put(INVALID_FIELDS, invalidFields);
    return new ModelAndView(TENANT_DETAILS_VIEW_NAME, model);
}
Also used : ITenant(org.apereo.portal.tenants.ITenant) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 2 with ITenant

use of org.apereo.portal.tenants.ITenant in project uPortal by Jasig.

the class TenantManagerController method doListenerAction.

/** @since 4.3 */
@ActionMapping(params = "action=doListenerAction")
public void doListenerAction(ActionRequest req, ActionResponse res, @RequestParam("fname") String fname, final PortletSession session) {
    final ITenantManagementAction action = tenantService.getAction(fname);
    final ITenant tenant = (ITenant) session.getAttribute(CURRENT_TENANT_SESSION_ATTRIBUTE);
    if (tenant == null) {
        throw new IllegalStateException("No current tenant");
    }
    TenantOperationResponse response = action.invoke(tenant);
    forwardToReportScreen(req, res, action.getMessageCode(), Collections.singletonList(response));
}
Also used : ITenant(org.apereo.portal.tenants.ITenant) TenantOperationResponse(org.apereo.portal.tenants.TenantOperationResponse) ITenantManagementAction(org.apereo.portal.tenants.ITenantManagementAction) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 3 with ITenant

use of org.apereo.portal.tenants.ITenant in project uPortal by Jasig.

the class TenantManagerController method doUpdateTenant.

@ActionMapping(params = "action=doUpdateTenant")
public void doUpdateTenant(final ActionRequest req, final ActionResponse res, final PortletSession session) {
    final ITenant tenant = (ITenant) session.getAttribute(CURRENT_TENANT_SESSION_ATTRIBUTE);
    if (tenant == null) {
        throw new IllegalStateException("No current tenant");
    }
    final Map<String, String> attributes = gatherAttributesFromPortletRequest(req);
    // Validation
    final Set<String> invalidFields = detectInvalidFields(tenant.getName(), tenant.getFname(), attributes);
    if (!invalidFields.isEmpty()) {
        /*
             * Something wasn't valid;  return the user to the addTenant screen.
             */
        this.returnToInvalidForm(req, res, tenant.getName(), attributes, invalidFields, "showTenantDetails");
        return;
    }
    final List<TenantOperationResponse> responses = new ArrayList<>();
    tenantService.updateTenant(tenant, attributes, responses);
    forwardToReportScreen(req, res, "tenant.manager.update.attributes", responses);
}
Also used : ITenant(org.apereo.portal.tenants.ITenant) TenantOperationResponse(org.apereo.portal.tenants.TenantOperationResponse) ArrayList(java.util.ArrayList) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 4 with ITenant

use of org.apereo.portal.tenants.ITenant in project uPortal by Jasig.

the class JacksonPortalEventTest method verifyOutputFormat.

@Test
public void verifyOutputFormat() throws Exception {
    final String sessionId = "1234567890123_system_AAAAAAAAAAA";
    final PortalEvent.PortalEventBuilder eventBuilder = new PortalEvent.PortalEventBuilder(this, "example.com", sessionId, SystemPerson.INSTANCE, null);
    final PortletExecutionEvent.PortletExecutionEventBuilder portletExecutionEventBuilder = new PortletExecutionEvent.PortletExecutionEventBuilder(eventBuilder, new MockPortletWindowId("pw1"), "fname", 12345, Collections.EMPTY_MAP, WindowState.NORMAL, PortletMode.VIEW);
    PortalEvent event;
    //TODO: Will uncomment once we add in attribute swapper event processing.
    /*event = new AttributeSwapEvent(eventBuilder, Collections.EMPTY_MAP);
        assertEventJsonEquals("{\"@c\":\".AttributeSwapEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"swappedAttributes\":{}}", event);

        event = new AttributeSwapResetEvent(eventBuilder);
        assertEventJsonEquals("{\"@c\":\".AttributeSwapResetEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);

        event = new IdentitySwapStartEvent(eventBuilder, "originalUserName", "originalEventSessionId");
        assertEventJsonEquals("{\"@c\":\".IdentitySwapStartEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"originalUserName\":\"originalUserName\",\"originalEventSessionId\":\"originalEventSessionId\"}", event);

        event = new IdentitySwapStopEvent(eventBuilder, "targetUserName");
        assertEventJsonEquals("{\"@c\":\".IdentitySwapStopEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"targetUserName\":\"targetUserName\"}", event);
        */
    event = new FolderAddedToLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "newFolderId");
    assertEventJsonEquals("{\"@c\":\".FolderAddedToLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"newFolderId\":\"newFolderId\"}", event);
    event = new FolderDeletedFromLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "deletedFolderId", "deletedFolderName");
    assertEventJsonEquals("{\"@c\":\".FolderDeletedFromLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"oldParentFolderId\":\"oldParentFolderId\",\"deletedFolderId\":\"deletedFolderId\",\"deletedFolderName\":\"deletedFolderName\"}", event);
    event = new FolderMovedInLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "movedFolderId");
    assertEventJsonEquals("{\"@c\":\".FolderMovedInLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"oldParentFolderId\":\"oldParentFolderId\",\"movedFolderId\":\"movedFolderId\"}", event);
    event = new PortletAddedToLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "parentFolderId", "fname");
    assertEventJsonEquals("{\"@c\":\".PortletAddedToLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"parentFolderId\":\"parentFolderId\"}", event);
    event = new PortletDeletedFromLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "fname");
    assertEventJsonEquals("{\"@c\":\".PortletDeletedFromLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"oldParentFolderId\":\"oldParentFolderId\"}", event);
    event = new PortletMovedInLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "newParentFolderId", "fname");
    assertEventJsonEquals("{\"@c\":\".PortletMovedInLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"oldParentFolderId\":\"oldParentFolderId\",\"newParentFolderId\":\"newParentFolderId\"}", event);
    event = new LoginEvent(eventBuilder, Collections.EMPTY_SET, Collections.EMPTY_MAP);
    assertEventJsonEquals("{\"@c\":\".LoginEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"groups\":[],\"attributes\":{}}", event);
    event = new LogoutEvent(eventBuilder);
    assertEventJsonEquals("{\"@c\":\".LogoutEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
    event = new PortalRenderEvent(eventBuilder, "requestPathInfo", 12345, UrlState.NORMAL, UrlType.RENDER, Collections.EMPTY_MAP, "targetedLayoutNodeId");
    assertEventJsonEquals("{\"@c\":\".PortalRenderEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"requestPathInfo\":\"requestPathInfo\",\"urlState\":\"NORMAL\",\"urlType\":\"RENDER\",\"parameters\":{},\"targetedLayoutNodeId\":\"targetedLayoutNodeId\",\"executionTimeNano\":12345}", event);
    event = new PortletActionExecutionEvent(portletExecutionEventBuilder);
    assertEventJsonEquals("{\"@c\":\".PortletActionExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{}}", event);
    event = new PortletEventExecutionEvent(portletExecutionEventBuilder, new QName("http://example.com/uri", "EventName"));
    assertEventJsonEquals("{\"@c\":\".PortletEventExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"eventName\":\"{http://example.com/uri}EventName\"}", event);
    event = new PortletRenderExecutionEvent(portletExecutionEventBuilder, true, false);
    assertEventJsonEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"targeted\":true,\"usedPortalCache\":false}", event);
    event = new PortletRenderHeaderExecutionEvent(portletExecutionEventBuilder, true, false);
    assertEventJsonEquals("{\"@c\":\".PortletRenderHeaderExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"targeted\":true,\"cached\":false}", event);
    event = new PortletResourceExecutionEvent(portletExecutionEventBuilder, "resourceId", false, false);
    assertEventJsonEquals("{\"@c\":\".PortletResourceExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"resourceId\":\"resourceId\",\"usedBrowserCache\":false,\"usedPortalCache\":false}", event);
    final IPortletExecutionWorker hungWorker = mock(IPortletExecutionWorker.class);
    when(hungWorker.getPortletFname()).thenReturn("fname");
    event = new PortletHungCompleteEvent(eventBuilder, hungWorker);
    assertEventJsonEquals("{\"@c\":\".PortletHungCompleteEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\"}", event);
    event = new PortletHungEvent(eventBuilder, hungWorker);
    assertEventJsonEquals("{\"@c\":\".PortletHungEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\"}", event);
    final ITenant tenant = new ITenant() {

        private static final long serialVersionUID = 1L;

        @Override
        public int compareTo(ITenant o) {
            return 0;
        }

        @Override
        public long getId() {
            return 1L;
        }

        @Override
        public String getName() {
            return "Mordor";
        }

        @Override
        public void setName(String name) {
        }

        @Override
        public String getFname() {
            return "mordor";
        }

        @Override
        public void setFname(String fname) {
        }

        @Override
        public String getAttribute(String name) {
            return null;
        }

        @Override
        public void setAttribute(String name, String value) {
        }

        @Override
        public Map<String, String> getAttributesMap() {
            return Collections.emptyMap();
        }
    };
    event = new TenantCreatedTenantEvent(eventBuilder, tenant);
    assertEventJsonEquals("{\"@c\":\".TenantCreatedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
    event = new TenantUpdatedTenantEvent(eventBuilder, tenant);
    assertEventJsonEquals("{\"@c\":\".TenantUpdatedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
    event = new TenantRemovedTenantEvent(eventBuilder, tenant);
    assertEventJsonEquals("{\"@c\":\".TenantRemovedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
}
Also used : ITenant(org.apereo.portal.tenants.ITenant) IPortletExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker) QName(javax.xml.namespace.QName) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) Test(org.junit.Test)

Aggregations

ITenant (org.apereo.portal.tenants.ITenant)4 TenantOperationResponse (org.apereo.portal.tenants.TenantOperationResponse)2 ActionMapping (org.springframework.web.portlet.bind.annotation.ActionMapping)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)1 IPortletExecutionWorker (org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker)1 ITenantManagementAction (org.apereo.portal.tenants.ITenantManagementAction)1 Test (org.junit.Test)1 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1