001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: *
005: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
006: * General Public License as published by the Free Software Foundation; either version 2 of the License,
007: * or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License along with this program; if not,
014: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
015: */
016:
017: package wilos.model.misc.wilosuser;
018:
019: import java.util.Random;
020:
021: import org.apache.commons.lang.builder.EqualsBuilder;
022: import org.apache.commons.lang.builder.HashCodeBuilder;
023:
024: /**
025: * This class represents a user of Wilos.
026: *
027: */
028: public abstract class WilosUser implements Cloneable {
029:
030: private String id;
031:
032: private String name;
033:
034: private String firstname;
035:
036: private String emailAddress;
037:
038: private String login;
039:
040: private String password;
041:
042: /**
043: * Default constructor.
044: *
045: */
046: public WilosUser() {
047: // None.
048: }
049:
050: /**
051: * Constructor.
052: *
053: * @param _name the user name
054: * @param _fName the user first name
055: * @param _email the user email address
056: * @param _login the user login
057: * @param _password the user password
058: */
059: public WilosUser(String _name, String _fName, String _email,
060: String _login, String _password) {
061: this .name = "";
062: this .firstname = "";
063: this .emailAddress = "";
064: this .login = "";
065: this .password = "";
066: }
067:
068: /**
069: * create random password and encrypt it in the participant password
070: *
071: * @return : new password not encrypted
072: */
073: public String generateNewPassword() {
074: String notCryptedPassword = "";
075: String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
076: Random rand = new Random();
077: for (int i = 0; i < 8; i++) {
078: // add one alphabet element to the string (here 8 elements)
079: notCryptedPassword += alphabet.charAt(rand.nextInt(alphabet
080: .length()));
081: }
082: return notCryptedPassword;
083: }
084:
085: /**
086: * Getter of emailAddress.
087: *
088: * @return the emailAddress.
089: */
090: public String getEmailAddress() {
091: return this .emailAddress;
092: }
093:
094: /**
095: * Setter of emailAddress.
096: *
097: * @param _emailAddress
098: * The emailAddress to set.
099: */
100: public void setEmailAddress(String _emailAddress) {
101: this .emailAddress = _emailAddress;
102: }
103:
104: /**
105: * Getter of firstname.
106: *
107: * @return the firstname.
108: */
109: public String getFirstname() {
110: return this .firstname;
111: }
112:
113: /**
114: * Setter of firstname.
115: *
116: * @param _firstname
117: * The firstname to set.
118: */
119: public void setFirstname(String _firstname) {
120: this .firstname = _firstname;
121: }
122:
123: /**
124: * Getter of login.
125: *
126: * @return the login.
127: */
128: public String getLogin() {
129: return this .login;
130: }
131:
132: /**
133: * Setter of login.
134: *
135: * @param _login
136: * The login to set.
137: */
138: public void setLogin(String _login) {
139: this .login = _login;
140: }
141:
142: /**
143: * Getter of name.
144: *
145: * @return the name.
146: */
147: public String getName() {
148: return this .name;
149: }
150:
151: /**
152: * Setter of name.
153: *
154: * @param _name
155: * The name to set.
156: */
157: public void setName(String _name) {
158: this .name = _name;
159: }
160:
161: /**
162: * Getter of password.
163: *
164: * @return the password.
165: */
166: public String getPassword() {
167: return this .password;
168: }
169:
170: /**
171: * Setter of password.
172: *
173: * @param _password
174: * The password to set.
175: */
176: public void setPassword(String _password) {
177: this .password = _password;
178: }
179:
180: /**
181: * Copy the object.
182: *
183: * @param _element
184: * The element to copy.
185: */
186: protected void copy(final WilosUser _wilosUser) {
187: this .name = _wilosUser.name;
188: this .firstname = _wilosUser.firstname;
189: this .emailAddress = _wilosUser.emailAddress;
190: this .login = _wilosUser.login;
191: this .password = _wilosUser.password;
192: }
193:
194: /**
195: * Defines if the specified Object is the same or has the same values as the
196: * current instance of the class.
197: *
198: * @param _obj
199: * the Object to be compare to the WilosUser
200: * @return true if the specified Object is the same, false otherwise
201: */
202: public boolean equals(Object obj) {
203: if (obj instanceof WilosUser == false) {
204: return false;
205: }
206: if (this == obj) {
207: return true;
208: }
209: WilosUser wilosUser = (WilosUser) obj;
210: return new EqualsBuilder().append(this .name, wilosUser.name)
211: .append(this .firstname, wilosUser.firstname).append(
212: this .emailAddress, wilosUser.emailAddress)
213: .append(this .login, wilosUser.login).append(
214: this .password, wilosUser.password).isEquals();
215: }
216:
217: /**
218: * Returns a hash code value for the object. This method is supported for
219: * the benefit of hash tables.
220: *
221: * @return the hash code of the current instance of WilosUser
222: */
223: public int hashCode() {
224: return new HashCodeBuilder(17, 37).append(this .name).append(
225: this .firstname).append(this .emailAddress).append(
226: this .login).append(this .password).toHashCode();
227: }
228:
229: /**
230: * Getter of the WilosUser identifier.
231: *
232: * @return the WilosUser identifier.
233: */
234: public String getId() {
235: return this .id;
236: }
237:
238: /**
239: * Setter of the WilosUser identifier.
240: *
241: * @param the WilosUser identifier to set
242: */
243: public void setId(String _id) {
244: this.id = _id;
245: }
246:
247: }
|