001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.user;
018:
019: import java.sql.Timestamp;
020:
021: import org.springframework.beans.factory.BeanNameAware;
022:
023: /**
024: * A simple user implementation which can be used as the base for other
025: * user implementations of {@link WorkflowUser}.
026: *
027: * @see WorkflowUser
028: *
029: * @author Aaron Hamid (arh14 at cornell dot edu)
030: */
031: public class BaseWorkflowUser implements WorkflowUser, BeanNameAware {
032:
033: private static final long serialVersionUID = -1498627602071447775L;
034:
035: private String workflowUserId;
036: private String authenticationUserId;
037: private String uuId;
038: private String emplId;
039:
040: private String givenName;
041: private String lastName;
042: private String displayName;
043: private String emailAddress;
044:
045: private Timestamp createDate;
046: private Timestamp lastUpdateDate;
047: private boolean defaulted;
048:
049: private Integer lockVerNbr = new Integer(0);
050:
051: public BaseWorkflowUser() {
052: }
053:
054: public BaseWorkflowUser(String defaultId) {
055: setDefaultId(defaultId);
056: }
057:
058: /**
059: * Convenience setter which initializes all fields
060: * based on Spring bean name
061: * @param name the Spring bean name
062: */
063: public void setBeanName(String name) {
064: if (!defaulted)
065: setDefaultId(name);
066: }
067:
068: /**
069: * Convenience setter which initializes all fields
070: * based on a default id
071: * @param name the user name
072: */
073: public void setDefaultId(String name) {
074: setDisplayName(name);
075: setGivenName(name);
076: setLastName(name + "-lastname");
077: setEmailAddress(name + "@localhost");
078: setAuthenticationUserId(new AuthenticationUserId(name));
079: setWorkflowUserId(new WorkflowUserId(name));
080: setEmplId(new EmplId(name));
081: setUuId(new UuId(name));
082: defaulted = true;
083: }
084:
085: public String getDisplayName() {
086: return displayName;
087: }
088:
089: public void setDisplayName(String displayName) {
090: this .displayName = displayName;
091: }
092:
093: public String getGivenName() {
094: return givenName;
095: }
096:
097: public void setGivenName(String givenName) {
098: this .givenName = givenName;
099: }
100:
101: public String getLastName() {
102: return lastName;
103: }
104:
105: public void setLastName(String lastName) {
106: this .lastName = lastName;
107: }
108:
109: public String getEmailAddress() {
110: return emailAddress;
111: }
112:
113: public void setEmailAddress(String emailAddress) {
114: this .emailAddress = emailAddress;
115: }
116:
117: public AuthenticationUserId getAuthenticationUserId() {
118: return new AuthenticationUserId(authenticationUserId);
119: }
120:
121: public void setAuthenticationUserId(
122: AuthenticationUserId authenticationUserId) {
123: this .authenticationUserId = (authenticationUserId == null ? null
124: : authenticationUserId.getAuthenticationId());
125: }
126:
127: public WorkflowUserId getWorkflowUserId() {
128: return new WorkflowUserId(workflowUserId);
129: }
130:
131: public void setWorkflowUserId(WorkflowUserId workflowUserId) {
132: this .workflowUserId = (workflowUserId == null ? null
133: : workflowUserId.getWorkflowId());
134: }
135:
136: public EmplId getEmplId() {
137: return new EmplId(emplId);
138: }
139:
140: public void setEmplId(EmplId emplId) {
141: this .emplId = (emplId == null ? null : emplId.getEmplId());
142: }
143:
144: public UuId getUuId() {
145: return new UuId(uuId);
146: }
147:
148: public void setUuId(UuId uuId) {
149: this .uuId = (uuId == null ? null : uuId.getUuId());
150: }
151:
152: /**
153: * Utility to determine whether a UserId is missing or empty
154: * @param userId the userId
155: * @return whether a UserId is missing or empty
156: */
157: private static final boolean idIsEmpty(UserId userId) {
158: return userId == null || userId.isEmpty();
159: }
160:
161: public boolean hasId() {
162: boolean noId = idIsEmpty(getAuthenticationUserId())
163: && idIsEmpty(getEmplId()) && idIsEmpty(getUuId())
164: && idIsEmpty(getWorkflowUserId());
165: return !noId;
166: }
167:
168: public String getTransposedName() {
169: return this .getLastName() + ", " + this .getGivenName();
170: }
171:
172: // FIXME: -- extra properties for Struts forms w/ beanutils
173: public void setWorkflowId(String id) {
174: setWorkflowUserId(new WorkflowUserId(id));
175: }
176:
177: public String getWorkflowId() {
178: return (getWorkflowUserId() == null ? null
179: : getWorkflowUserId().getWorkflowId());
180: }
181:
182: public Integer getLockVerNbr() {
183: return lockVerNbr;
184: }
185:
186: public void setLockVerNbr(Integer lockVerNbr) {
187: this .lockVerNbr = lockVerNbr;
188: }
189:
190: public Timestamp getCreateDate() {
191: return createDate;
192: }
193:
194: public void setCreateDate(Timestamp createDate) {
195: this .createDate = createDate;
196: }
197:
198: public Timestamp getLastUpdateDate() {
199: return lastUpdateDate;
200: }
201:
202: public void setLastUpdateDate(Timestamp lastUpdateDate) {
203: this .lastUpdateDate = lastUpdateDate;
204: }
205:
206: public String toString() {
207: return "[SimpleWorkflowUser: " + ", displayName=" + displayName
208: + ", givenName=" + givenName + ", lastName=" + lastName
209: + ", emailAddress=" + emailAddress + ", emplId="
210: + emplId + ", uuId=" + uuId + ", authenticationId="
211: + authenticationUserId + ", workflowId="
212: + workflowUserId + "]";
213: }
214: }
|