Search in sources :

Example 1 with ActionMapping

use of org.springframework.web.portlet.bind.annotation.ActionMapping 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 2 with ActionMapping

use of org.springframework.web.portlet.bind.annotation.ActionMapping in project uPortal by Jasig.

the class DirectoryPortletController method submitSearch.

@ActionMapping
public void submitSearch(ActionRequest request, ActionResponse response, @RequestParam(value = "query", required = false) String query) {
    // Should we request to maximize?
    PortletPreferences prefs = request.getPreferences();
    boolean maximize = Boolean.parseBoolean(// default is true
    prefs.getValue(MAXIMIZE_ON_SEARCH_PREFERENCE, "true"));
    if (maximize) {
        try {
            response.setWindowState(WindowState.MAXIMIZED);
        } catch (WindowStateException e) {
            log.warn("Failed to set the window state to MAXIMIZED", e);
        }
    }
    // Forward the query parameter...
    if (query != null) {
        response.setRenderParameter("query", query);
    }
}
Also used : WindowStateException(javax.portlet.WindowStateException) PortletPreferences(javax.portlet.PortletPreferences) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 3 with ActionMapping

use of org.springframework.web.portlet.bind.annotation.ActionMapping in project uPortal by Jasig.

the class FavoritesEditController method unFavoriteNode.

/**
     * Un-favorite a favorite node (portlet or collection) identified by node ID. Routed by the
     * action=delete parameter. If no favorites remain after un-favoriting, switches portlet mode to
     * VIEW.
     *
     * <p>Sets render parameters: successMessageCode: message code of success message if applicable
     * errorMessageCode: message code of error message if applicable nameOfFavoriteActedUpon:
     * user-facing name of favorite acted upon. action: will be set to "list" to facilitate not
     * repeatedly attempting delete.
     *
     * <p>Exactly one of [successMessageCode|errorMessageCode] render parameters will be set.
     * nameOfFavoriteActedUpon and action will always be set.
     *
     * @param nodeId identifier of target node
     * @param response ActionResponse onto which render parameters will, mode may, be set
     */
@ActionMapping(params = { "action=delete" })
public void unFavoriteNode(@RequestParam("nodeId") String nodeId, ActionResponse response) {
    try {
        // ferret out the layout manager
        HttpServletRequest servletRequest = this.portalRequestUtils.getCurrentPortalRequest();
        IUserInstance userInstance = this.userInstanceManager.getUserInstance(servletRequest);
        IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
        IUserLayoutManager layoutManager = preferencesManager.getUserLayoutManager();
        IUserLayoutNodeDescription nodeDescription = layoutManager.getNode(nodeId);
        String userFacingNodeName = nodeDescription.getName();
        response.setRenderParameter("nameOfFavoriteActedUpon", userFacingNodeName);
        if (nodeDescription.isDeleteAllowed()) {
            boolean nodeSuccessfullyDeleted = layoutManager.deleteNode(nodeId);
            if (nodeSuccessfullyDeleted) {
                layoutManager.saveUserLayout();
                response.setRenderParameter("successMessageCode", "favorites.unfavorite.success.parameterized");
                IUserLayout updatedLayout = layoutManager.getUserLayout();
                // if removed last favorite, return to VIEW mode
                if (!FavoritesUtils.hasAnyFavorites(updatedLayout)) {
                    response.setPortletMode(PortletMode.VIEW);
                }
                logger.debug("Successfully unfavorited [{}]", nodeDescription);
            } else {
                logger.error("Failed to delete node [{}] on unfavorite request, but this should have succeeded?", nodeDescription);
                response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.parameterized");
            }
        } else {
            logger.warn("Attempt to unfavorite [{}] failed because user lacks permission to delete that layout node.", nodeDescription);
            response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.lack.permission.parameterized");
        }
    } catch (Exception e) {
        // TODO: this log message is kind of useless without the username to put the node in context
        logger.error("Something went wrong unfavoriting nodeId [{}].", nodeId);
        // may have failed to load node description, so fall back on describing by id
        final String fallbackUserFacingNodeName = "node with id " + nodeId;
        response.setRenderParameter("errorMessageCode", "favorites.unfavorite.fail.parameterized");
        response.setRenderParameter("nameOfFavoriteActedUpon", fallbackUserFacingNodeName);
    }
    response.setRenderParameter("action", "list");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayout(org.apereo.portal.layout.IUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 4 with ActionMapping

use of org.springframework.web.portlet.bind.annotation.ActionMapping in project uPortal by Jasig.

the class TenantManagerController method doAddTenant.

@ActionMapping(params = "action=doAddTenant")
public void doAddTenant(ActionRequest req, ActionResponse res, final PortletSession session, @RequestParam("name") String name) {
    final Map<String, String> attributes = gatherAttributesFromPortletRequest(req);
    final String fname = calculateFnameFromName(name);
    // Validation
    final Set<String> invalidFields = detectInvalidFields(name, fname, attributes);
    if (!invalidFields.isEmpty()) {
        /*
             * Something wasn't valid;  return the user to the addTenant screen.
             */
        this.returnToInvalidForm(req, res, name, attributes, invalidFields, "showAddTenant");
        return;
    }
    // Honor the user's choices as far as optional listeners
    final List<String> selectedListenerFnames = (req.getParameterValues(OPTIONAL_LISTENER_PARAMETER) != null) ? Arrays.asList(req.getParameterValues(OPTIONAL_LISTENER_PARAMETER)) : // None were selected
    new ArrayList<String>(0);
    final Set<String> skipListenerFnames = new HashSet<>();
    for (ITenantOperationsListener listener : tenantService.getOptionalOperationsListeners()) {
        if (!selectedListenerFnames.contains(listener.getFname())) {
            skipListenerFnames.add(listener.getFname());
        }
    }
    final List<TenantOperationResponse> responses = new ArrayList<>();
    tenantService.createTenant(name, fname, attributes, skipListenerFnames, responses);
    forwardToReportScreen(req, res, "tenant.manager.add", responses);
}
Also used : TenantOperationResponse(org.apereo.portal.tenants.TenantOperationResponse) ArrayList(java.util.ArrayList) ITenantOperationsListener(org.apereo.portal.tenants.ITenantOperationsListener) HashSet(java.util.HashSet) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 5 with ActionMapping

use of org.springframework.web.portlet.bind.annotation.ActionMapping 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)

Aggregations

ActionMapping (org.springframework.web.portlet.bind.annotation.ActionMapping)6 TenantOperationResponse (org.apereo.portal.tenants.TenantOperationResponse)3 ArrayList (java.util.ArrayList)2 ITenant (org.apereo.portal.tenants.ITenant)2 HashSet (java.util.HashSet)1 PortletPreferences (javax.portlet.PortletPreferences)1 PortletSession (javax.portlet.PortletSession)1 WindowStateException (javax.portlet.WindowStateException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)1 IUserLayout (org.apereo.portal.layout.IUserLayout)1 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)1 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)1 SearchRequest (org.apereo.portal.search.SearchRequest)1 ITenantManagementAction (org.apereo.portal.tenants.ITenantManagementAction)1 ITenantOperationsListener (org.apereo.portal.tenants.ITenantOperationsListener)1 IUserInstance (org.apereo.portal.user.IUserInstance)1