001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Portal/Sources/es/udc/mypersonalizer/portal/model/actions/personalization/ChangeServicePropertyAction.java,v 1.1.1.1 2004/03/25 12:08:40 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:40 $
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.portal.model.actions.personalization;
042:
043: import es.udc.mypersonalizer.kernel.model.actions.AbstractAction;
044: import es.udc.mypersonalizer.kernel.model.repository.interfaces.RepositoryAccessorFactory;
045: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceButtonPermission;
046: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServiceProperty;
047: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServicePropertyAccessor;
048: import es.udc.mypersonalizer.kernel.model.repository.interfaces.ServicePropertyKey;
049: import es.udc.mypersonalizer.kernel.util.exceptions.ActionNotAllowedException;
050: import es.udc.mypersonalizer.kernel.util.exceptions.InstanceNotFoundException;
051: import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
052: import es.udc.mypersonalizer.kernel.util.general.PersonalizationHelper;
053: import es.udc.mypersonalizer.portal.model.permissions.PermissionCheckerSingleton;
054: import es.udc.mypersonalizer.portal.model.types.WizardEvent;
055: import es.udc.mypersonalizer.portal.model.wizards.PropertyUpdater;
056: import es.udc.mypersonalizer.portal.model.wizards.PropertyUpdaterRegistrySingleton;
057: import java.io.Serializable;
058:
059: /**
060: * This action performs a change in the {@link ServiceProperty} object
061: * assigned to a concrete instance of a service in one of the user's
062: * workspaces. The change that will be carried on is determined by
063: * the <tt>propertyUpdaterName</tt> parameter of the {@link WizardEvent}
064: * object it receives. This can be an update in a property structure
065: * (<tt>updateSimpleProperties</tt>), an addition of a new value
066: * (<tt>addPropertyStructure</tt>), a removal (<tt>removePropertyStructure</tt>)
067: * or any other action for which a property updater be registered in
068: * configuration.<p>
069: *
070: * This action first checks that the user have the required permissions
071: * to personalize this service (permissions on the <tt>personalizer</tt>
072: * button.<p>
073: *
074: * It returns the modified ServiceProperty object as a result.
075: *
076: * @author Daniel Fernandez
077: * @since 1.0
078: */
079: public class ChangeServicePropertyAction extends AbstractAction {
080:
081: public Serializable execute(Serializable event)
082: throws InternalErrorException {
083:
084: WizardEvent wizardEvent = (WizardEvent) event;
085:
086: Long propertyIdentifier = wizardEvent.getPropertyIdentifier();
087: String serviceIdentifier = wizardEvent.getServiceIdentifier();
088: ServicePropertyKey servicePropertyKey = new ServicePropertyKey(
089: serviceIdentifier, propertyIdentifier);
090:
091: try {
092:
093: if (!PersonalizationHelper
094: .isPersonalizable(serviceIdentifier)) {
095: throw new InstanceNotFoundException(serviceIdentifier,
096: "ServiceProperty");
097: }
098:
099: /* Accessors */
100: RepositoryAccessorFactory repositoryAccessorFactory = RepositoryAccessorFactory
101: .getInstance();
102:
103: ServicePropertyAccessor servicePropertyAccessor = repositoryAccessorFactory
104: .createServicePropertyAccessor();
105:
106: /* Singletons */
107: PermissionCheckerSingleton permissionCheckerSingleton = PermissionCheckerSingleton
108: .getInstance();
109:
110: PropertyUpdaterRegistrySingleton propertyUpdaterRegistrySingleton = PropertyUpdaterRegistrySingleton
111: .getInstance();
112:
113: /* Service Property to change */
114: ServiceProperty serviceProperty = servicePropertyAccessor
115: .findServiceProperty(servicePropertyKey);
116:
117: if (permissionCheckerSingleton.isServiceButtonAllowed(
118: wizardEvent.getUserCredentials(), serviceProperty
119: .getKey().getServiceIdentifier(),
120: ServiceButtonPermission.PERSONALIZE_BUTTON_NAME)) {
121:
122: PropertyUpdater propertyUpdater = propertyUpdaterRegistrySingleton
123: .getPropertyUpdater(wizardEvent
124: .getPropertyUpdaterName());
125:
126: propertyUpdater.update(serviceProperty.getProperty(),
127: wizardEvent);
128:
129: servicePropertyAccessor
130: .updateServiceProperty(serviceProperty);
131:
132: return serviceProperty;
133:
134: } else {
135: throw new ActionNotAllowedException(
136: "User is not allowed to personalize service "
137: + serviceProperty.getKey()
138: .getServiceIdentifier(),
139: ActionNotAllowedException.PERSONALIZE_SERVICE_ACTION,
140: serviceProperty.getKey().getServiceIdentifier());
141: }
142:
143: } catch (InternalErrorException e) {
144: throw e;
145: } catch (Exception e) {
146: throw new InternalErrorException(e);
147: }
148:
149: }
150:
151: }
|