001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Admin/Sources/es/udc/mypersonalizer/admin/model/actions/usergroupmgnt/WizardEventFactory.java,v 1.1.1.1 2004/03/25 12:08:39 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:39 $
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.model.actions.usergroupmgnt;
042:
043: import java.util.Map;
044: import java.util.HashMap;
045: import java.util.Iterator;
046: import java.util.Collection;
047:
048: import es.udc.mypersonalizer.kernel.model.properties.Property;
049: import es.udc.mypersonalizer.kernel.conventions.ServiceConventions;
050: import es.udc.mypersonalizer.kernel.model.repository.interfaces.UserRegistrationInformation;
051: import es.udc.mypersonalizer.kernel.model.properties.PropertyStructure;
052: import es.udc.mypersonalizer.portal.model.types.WizardEvent;
053: import es.udc.mypersonalizer.portal.model.permissions.UserCredentials;
054:
055: public class WizardEventFactory {
056:
057: private WizardEventFactory() {
058: }
059:
060: /**
061: * Converts a <code>UserRegistrtionInformation</code> and a
062: * <code>Collection</code> of user group identifiers to a
063: * <code>WizardEvent</code> object. This class is used to re-use
064: * the already existing model actions for adding and updating a portal
065: * user (See subsystem PORTAL). As the administration application
066: * uses the property editor to update/create a
067: * <code>UserRegistrationInformation</code> and a form to get the
068: * user groups assigned to the new user, it has to convert this
069: * objects to a <code>WizardEvent</code> object because this is the kind
070: * of event that the model actions in the portal subsystem use.
071: * @param userRegistrationInformation the
072: * <code>UserRegistrationInformation</code> to convert.
073: * @param userGroupIdentifiers the identifiers of the groups where
074: * to add the user.
075: * @return the <code>WizardEvent</code> conversion of the
076: * <code>userRegistrationInformation</code> and the
077: * user group identifiers <code>Collection</code> parameters.
078: */
079: public static WizardEvent create(
080: UserRegistrationInformation userRegistrationInformation,
081: Collection userGroupIdentifiers) {
082:
083: PropertyStructure propertyStructureValue = (PropertyStructure) ((userRegistrationInformation
084: .getProperty().getValuesAsObject())[0]);
085:
086: /* Get the UserRegistrationInformation service identifier */
087: String serviceIdentifier = ServiceConventions.USER_REGISTRATION_INFORMATION_SERVICE_IDENTIFIER;
088:
089: /* Get the properties Map */
090: Map properties = propertyStructureValue.getAsMap();
091: Iterator propertyKeys = propertyStructureValue.getAsMap()
092: .keySet().iterator();
093: Map wizardEventProperties = new HashMap();
094:
095: while (propertyKeys.hasNext()) {
096: String propertyKey = (String) propertyKeys.next();
097: Property property = (Property) properties.get(propertyKey);
098: String[] propertyValues = property.getValuesAsString();
099: wizardEventProperties.put(propertyKey, propertyValues);
100: }
101:
102: /* Get the user login name */
103: String loginName = userRegistrationInformation.getLoginName();
104:
105: /* Create the user credentials */
106: UserCredentials userCredentials = new UserCredentials(
107: loginName, userGroupIdentifiers);
108:
109: /* Create the WizardEvent */
110: return (new WizardEvent(userCredentials, wizardEventProperties,
111: serviceIdentifier, "updateSimpleProperties", "0", null));
112: }
113:
114: }
|