001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Admin/Sources/es/udc/mypersonalizer/admin/model/tasks/DeleteUsersByLoginNameTask.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 Coruņa
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 Coruņa 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: package es.udc.mypersonalizer.admin.model.tasks;
041:
042: import java.util.ArrayList;
043: import java.util.Collection;
044: import java.util.Iterator;
045: import java.util.List;
046:
047: import es.udc.mypersonalizer.kernel.conventions.UserAndGroupConventions;
048: import es.udc.mypersonalizer.kernel.log.Log;
049: import es.udc.mypersonalizer.kernel.log.LogManager;
050: import es.udc.mypersonalizer.kernel.log.LogNamingConventions;
051: import es.udc.mypersonalizer.kernel.model.actions.ActionProcessorSingleton;
052: import es.udc.mypersonalizer.kernel.model.metainfo.MetaProperty;
053: import es.udc.mypersonalizer.kernel.model.metainfo.MetaSimpleProperty;
054: import es.udc.mypersonalizer.kernel.model.properties.SimpleProperty;
055: import es.udc.mypersonalizer.kernel.model.tasks.*;
056: import es.udc.mypersonalizer.kernel.util.exceptions.InternalErrorException;
057: import es.udc.mypersonalizer.kernel.util.exceptions.ModelException;
058:
059: /**
060: * Deletes users given its login name, except for the special users
061: * "mypersonalizer" and "anonymous".
062: * <p>
063: * The given properties must be simple, univalued and of String java type.
064: *
065: * @author Abel Muinho
066: * @since 1.0
067: */
068: public class DeleteUsersByLoginNameTask implements Task {
069: private static final Log log = LogManager
070: .getLog(LogNamingConventions.MYPERSONALIZER);
071:
072: private List messages;
073:
074: /**
075: * Returns <code>true</code> for simple univalued metaproperties with
076: * <code>String</code> java type.
077: * @see Task#isCompatibleWith(MetaProperty)
078: */
079: public boolean isCompatibleWith(MetaProperty metadata) {
080: return (metadata instanceof MetaSimpleProperty)
081: && (metadata.isMultiValued() == false)
082: && (((MetaSimpleProperty) metadata).getJavaType()
083: .equals(String.class));
084: }
085:
086: public void execute(Collection properties)
087: throws InternalErrorException {
088: Iterator propertyIt = properties.iterator();
089: messages = new ArrayList();
090: SimpleProperty loginNameProperty;
091: String loginName;
092: ActionProcessorSingleton processor = ActionProcessorSingleton
093: .getInstance();
094: while (propertyIt.hasNext()) {
095: loginNameProperty = (SimpleProperty) propertyIt.next();
096: loginName = loginNameProperty.getValuesAsString()[0];
097: /* If it is not an special user, try to delete it. */
098: if (!loginName
099: .equals(UserAndGroupConventions.MYPERSONALIZER_LOGIN_NAME)
100: && !loginName
101: .equals(UserAndGroupConventions.ANONYMOUS_LOGIN_NAME)) {
102: try {
103: processor.execute("RemoveUserAction", loginName);
104: } catch (ModelException e) {
105: messages.add("Model error detected: "
106: + e.getMessage());
107: log.write("Ignored model exception:", e,
108: DeleteUsersByLoginNameTask.class);
109: }
110: } else {
111: messages.add("Special user '" + loginName
112: + "' not removed.");
113: }
114: }
115: }
116:
117: public Collection getMessages() {
118: return messages;
119: }
120:
121: }
|