001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @author <a href="mailto:oliver@wehrens.de">Oliver Wehrens</a>
004: * @version $Id: UserImpl.java 6385 2007-10-25 14:02:26Z wehrens $
005: */
006: package org.gridsphere.services.core.user.impl;
007:
008: import org.gridsphere.services.core.user.User;
009:
010: import java.util.Enumeration;
011: import java.util.HashMap;
012: import java.util.Hashtable;
013: import java.util.Map;
014:
015: /**
016: * The <code>UserImpl</code> implements the <code>User</code> interface
017: * and is an abstract view on the user-specific data.
018: * Apart from a set of pre-defined, fixed set of attributes,
019: * the interface gives access to user profile data.
020: */
021: public class UserImpl implements User {
022:
023: private String oid = null;
024: // store used to maintain user attributes
025: private Map<String, String> attributes = new HashMap<String, String>();
026:
027: private String UserID = "";
028: private String LastName = "";
029: private String FullName = "";
030: private String FirstName = "";
031: private String EmailAddress = "";
032: private String Organization = "";
033: private Long LastLoginTime = null;
034: private Integer numLogins = 0;
035:
036: public String getOid() {
037: return oid;
038: }
039:
040: public void setOid(String oid) {
041: this .oid = oid;
042: }
043:
044: /**
045: * Returns the internal unique user id.
046: *
047: * @return the internal unique id
048: */
049: public String getID() {
050: return getOid();
051: }
052:
053: /**
054: * Sets the internal unique user id.
055: *
056: * @param id the internal unique id
057: */
058: public void setID(String id) {
059: setOid(id);
060: }
061:
062: /**
063: * Returns the user id of the user, or null if the user id is not available.
064: *
065: * @return the user id
066: */
067: public String getUserID() {
068: return UserID;
069: }
070:
071: /**
072: * Sets the user id of the user, or null if the user id is not available.
073: *
074: * @param userID the user id
075: */
076: public void setUserID(String userID) {
077: this .UserID = userID;
078: }
079:
080: /**
081: * This is alias for the getUserID method, which for all intensive
082: * purposes represents the name required for this user to login.
083: *
084: * @return String the user id
085: */
086: public String getUserName() {
087: return this .UserID;
088: }
089:
090: /**
091: * This is an alias for the setUserID method, which for all intensive
092: * purposes represents the name required for this user to login.
093: *
094: * @param name the user id
095: */
096: public void setUserName(String name) {
097: this .UserID = name;
098: }
099:
100: /**
101: * Returns the last name of the user.
102: *
103: * @return the last name
104: */
105: public String getLastName() {
106: return LastName;
107: }
108:
109: /**
110: * Sets the last name of the user.
111: *
112: * @param lastName the last name
113: */
114: public void setLastName(String lastName) {
115: this .LastName = lastName;
116: }
117:
118: /**
119: * Returns the full name of the user, or null if the full name is not available.
120: * The full name contains given names, family names and possibly a title or suffix.
121: * Therefore, the full name may be different from the concatenation of given and family name.
122: *
123: * @return the full name
124: */
125: public String getFullName() {
126: return FullName;
127: }
128:
129: /**
130: * Sets the full name of the user, or null if the full name is not available.
131: * The full name contains given names, family names and possibly a title or suffix.
132: * Therefore, the full name may be different from the concatenation of given and family name.
133: *
134: * @param fullName the full name
135: */
136: public void setFullName(String fullName) {
137: this .FullName = fullName;
138: }
139:
140: /**
141: * Returns the first name of the user
142: *
143: * @return the first name
144: */
145: public String getFirstName() {
146: return FirstName;
147: }
148:
149: /**
150: * Sets the first) name of the user, or if the given name is not available.
151: *
152: * @param firstName the first name
153: */
154: public void setFirstName(String firstName) {
155: this .FirstName = firstName;
156: }
157:
158: /**
159: * Returns the given e-mail of the user or null if none is available.
160: *
161: * @return the email address
162: */
163: public String getEmailAddress() {
164: return EmailAddress;
165: }
166:
167: /**
168: * Sets the given e-mail of the user.
169: *
170: * @param emailAddress the email address
171: */
172: public void setEmailAddress(String emailAddress) {
173: this .EmailAddress = emailAddress;
174: }
175:
176: /**
177: * Gets the organization the user belongs to
178: *
179: * @return organization the organization
180: */
181: public String getOrganization() {
182: return Organization;
183: }
184:
185: /**
186: * Sets the organization the user belongs to
187: *
188: * @param organization the organization name
189: */
190: public void setOrganization(String organization) {
191: this .Organization = organization;
192: }
193:
194: /**
195: * Returns the point of time that this user was last logged in, or
196: * <code>null</code> if this information is not available. The time is
197: * returned in number of milliseconds since January 1, 1970 GMT.
198: *
199: * @return the last login time
200: */
201: public Long getLastLoginTime() {
202: return LastLoginTime;
203: }
204:
205: /**
206: * Sets the point of time that this user was last logged in, or
207: * <code>null</code> if this information is not available.
208: * The time is returned in number of milliseconds since January 1, 1970 GMT.
209: *
210: * @param lastLoginTime the last login time
211: */
212: public void setLastLoginTime(Long lastLoginTime) {
213: this .LastLoginTime = lastLoginTime;
214: }
215:
216: public Map getAttributes() {
217: return attributes;
218: }
219:
220: public void setAttributes(Map<String, String> attributes) {
221: this .attributes = attributes;
222: }
223:
224: /**
225: * Returns the value of the attribute with the given name,s
226: * or null if no attribute with the given name exists.
227: *
228: * @param name the attribute name
229: * @return the attribute value
230: */
231: public Object getAttribute(String name) {
232: return attributes.get(name);
233: }
234:
235: /**
236: * Sets the value of the attribute with the given name,
237: *
238: * @param name the attribute name
239: * @param value the attribute value
240: */
241: public void setAttribute(String name, String value) {
242: attributes.put(name, value);
243: }
244:
245: /**
246: * Returns an enumeration of names of all attributes available to this request.
247: * This method returns an empty enumeration if the request has no attributes available to it.
248: *
249: * @return an enumeration of attribute names
250: */
251: public Enumeration getAttributeNames() {
252: return new Hashtable<String, String>(attributes).keys();
253: }
254:
255: /**
256: * Returns an enumeration of names of all attributes available to this request.
257: * This method returns an empty enumeration if the request has no attributes available to it.
258: *
259: * @return an enumeration of attribute names
260: */
261: public Enumeration getAttributeValues() {
262: return new Hashtable<String, String>(attributes).elements();
263: }
264:
265: /**
266: * Returns the number of login occurences for this user
267: *
268: * @return the number of login occurences
269: */
270: public Integer getNumLogins() {
271: return numLogins;
272: }
273:
274: /**
275: * Sets the number of logins occurences for this user
276: *
277: * @param numLogins the last login time
278: */
279: public void setNumLogins(Integer numLogins) {
280: this .numLogins = numLogins;
281: }
282:
283: /**
284: * Returns a string representaation of the User
285: *
286: * @return User information represented as a String
287: */
288: public String toString() {
289: StringBuffer sb = new StringBuffer();
290: sb.append("Last Name: ").append(LastName).append("\n");
291: sb.append("Full Name: ").append(FullName).append("\n");
292: sb.append("First Name: ").append(FirstName).append("\n");
293: sb.append("Email Address: ").append(EmailAddress).append("\n");
294: sb.append("Id: ").append(getOid()).append("\n");
295: sb.append("UserID: ").append(UserID).append("\n");
296: sb.append("LastLoginTime: ").append(LastLoginTime).append("\n");
297: return sb.toString();
298: }
299:
300: public boolean equals(Object obj) {
301: boolean b = true;
302: if ((obj != null) && (obj.getClass().equals(this .getClass()))) {
303: b = (((UserImpl) obj).EmailAddress == this .EmailAddress);
304: b &= (((UserImpl) obj).LastName == this .LastName);
305: b &= (((UserImpl) obj).FirstName == this .FirstName);
306: b &= (((UserImpl) obj).FullName == this .FullName);
307: b &= (((UserImpl) obj).FullName == this .FullName);
308: b &= (((UserImpl) obj).UserID == this .UserID);
309: b &= (((UserImpl) obj).LastLoginTime == this .LastLoginTime);
310: b &= (((UserImpl) obj).Organization == this .Organization);
311: }
312: return b;
313: }
314:
315: public int hashCode() {
316: return UserID.hashCode();
317: }
318:
319: }
|