001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Admin/Sources/es/udc/mypersonalizer/admin/http/controller/actions/serviceperms/ProcessUpdateServicePermissionsAction.java,v 1.1.1.1 2004/03/25 12:08:38 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:38 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.admin.http.controller.actions.serviceperms;
042:
043: import java.util.Collection;
044: import java.util.Iterator;
045: import java.util.ArrayList;
046: import java.util.Arrays;
047: import java.util.Map;
048: import java.util.HashMap;
049:
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052:
053: import org.apache.struts.action.ActionMapping;
054: import org.apache.struts.action.ActionForm;
055: import org.apache.struts.action.ActionForward;
056:
057: import es.udc.mypersonalizer.kernel.controller.actions.DefaultAction;
058: import es.udc.mypersonalizer.kernel.model.actions.ActionProcessorSingleton;
059: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServicePermissions;
060: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceButtonPermission;
061: import es.udc.mypersonalizer.portal.config.PortalConfigManager;
062:
063: import es.udc.mypersonalizer.admin.http.view.actionforms.serviceperms.UpdateServicePermissionsForm;
064:
065: /**
066: * This action checks that the given permissions for a service, obtained
067: * using {@link UpdateServicePermissionsForm} are correct, this is,
068: * permissions for a service button are a subset of the service availability
069: * if so, this action updates the permissions for the service and redirects
070: * to <code>ServicePermissionsMain</code>, else forwards back to the frm
071: * with an error message. The check can't be done in an
072: * <code>ActionForm</code> because service buttons are dynamic and an
073: * <code>ActionForm</code> is not prepared for this kind of
074: * tasks.
075: *
076: * @author Abel Iago Toral Quiroga
077: * @since 1.0
078: */
079: public class ProcessUpdateServicePermissionsAction extends
080: DefaultAction {
081:
082: protected ActionForward doExecute(ActionMapping mapping,
083: ActionForm form, HttpServletRequest request,
084: HttpServletResponse response) throws Exception {
085:
086: /* Get parameters */
087: UpdateServicePermissionsForm frm = (UpdateServicePermissionsForm) form;
088:
089: /* 1.- Service identifier */
090: String serviceIdentifier = frm.getServiceIdentifier();
091:
092: /* 2.- Service availability */
093: Long[] availableToAsLong = frm.getAvailableTo();
094: Collection availableTo = Arrays.asList(availableToAsLong);
095:
096: /* 3.- Buttons availability */
097: boolean parameterError = false;
098: Map buttonsAvailability = new HashMap();
099:
100: Iterator buttonTypes = PortalConfigManager.getConfig()
101: .getPortalModelConfig().getServiceButtonsConfig()
102: .getServiceButtonNames().iterator();
103:
104: while (buttonTypes.hasNext() && !parameterError) {
105: String buttonType = (String) buttonTypes.next();
106: String[] buttonAvailableToAsString = (String[]) request
107: .getParameterValues(buttonType);
108:
109: Collection buttonAvailableTo = new ArrayList();
110: if (buttonAvailableToAsString != null) {
111: for (int i = 0; i < buttonAvailableToAsString.length; i++) {
112: buttonAvailableTo.add(new Long(
113: buttonAvailableToAsString[i]));
114: }
115: }
116:
117: /* 4.- Check that button permissions are a subset of service
118: * permissions */
119: if (!availableTo.containsAll(buttonAvailableTo)) {
120: parameterError = true;
121: } else {
122: ServiceButtonPermission this ButtonPermissions = new ServiceButtonPermission(
123: buttonType, buttonAvailableTo);
124: buttonsAvailability.put(buttonType,
125: this ButtonPermissions);
126: }
127: }
128:
129: /* Do update service permissions */
130: if (!parameterError) {
131: /* 1.- Create the ServicePermissions object */
132: ServicePermissions newServicePermissions = new ServicePermissions(
133: serviceIdentifier, availableTo, buttonsAvailability);
134:
135: /* 2.- Call the ActionProcessor */
136: ActionProcessorSingleton.getInstance().execute(
137: "UpdateServicePermissionsAction",
138: newServicePermissions);
139:
140: /* Do forward*/
141: return mapping.findForward("ServicePermissionsMain");
142:
143: } else {
144: /* Return to previous frm with an error message */
145: request.setAttribute("notASubSetError", "true");
146: return new ActionForward(mapping.getInput());
147: }
148: }
149: }
|