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.actiontaken;
018:
019: import java.sql.Timestamp;
020: import java.util.ArrayList;
021: import java.util.Collection;
022:
023: import org.apache.commons.beanutils.BeanUtils;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.WorkflowPersistable;
028: import edu.iu.uis.eden.actionrequests.ActionRequestService;
029: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
030: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
031: import edu.iu.uis.eden.user.Recipient;
032: import edu.iu.uis.eden.user.UserService;
033: import edu.iu.uis.eden.user.WorkflowUser;
034: import edu.iu.uis.eden.user.WorkflowUserId;
035: import edu.iu.uis.eden.util.CodeTranslator;
036: import edu.iu.uis.eden.workgroup.WorkflowGroupId;
037: import edu.iu.uis.eden.workgroup.Workgroup;
038: import edu.iu.uis.eden.workgroup.WorkgroupService;
039:
040: /**
041: * Model object mapped to ojb for representing actions taken on documents by
042: * users.
043: *
044: * @author rkirkend
045: * @author ewestfal
046: */
047: public class ActionTakenValue implements WorkflowPersistable {
048:
049: /**
050: *
051: */
052: private static final long serialVersionUID = -81505450567067594L;
053: private Long actionTakenId;
054: private Long routeHeaderId;
055: private String actionTaken;
056: private Timestamp actionDate;
057: private String annotation = "";
058: private Integer docVersion;
059: private Integer lockVerNbr;
060: private String workflowId;
061: private String delegatorWorkflowId;
062: private Long delegatorWorkgroupId;
063: private DocumentRouteHeaderValue routeHeader;
064: private Collection actionRequests;
065: private Boolean currentIndicator = new Boolean(true);
066: private String actionDateString;
067:
068: public WorkflowUser getWorkflowUser()
069: throws EdenUserNotFoundException {
070: return getWorkflowUserForWorkflowId(workflowId);
071: }
072:
073: public WorkflowUser getDelegatorUser()
074: throws EdenUserNotFoundException {
075: return getWorkflowUserForWorkflowId(delegatorWorkflowId);
076: }
077:
078: public Workgroup getDelegatorWorkgroup() {
079: return getWorkgroupService().getWorkgroup(
080: new WorkflowGroupId(delegatorWorkgroupId));
081: }
082:
083: public void setDelegator(Recipient recipient) {
084: if (recipient instanceof WorkflowUser) {
085: setDelegatorWorkflowId(((WorkflowUser) recipient)
086: .getWorkflowUserId().getWorkflowId());
087: } else if (recipient instanceof Workgroup) {
088: setDelegatorWorkgroupId(((Workgroup) recipient)
089: .getWorkflowGroupId().getGroupId());
090: } else {
091: setDelegatorWorkflowId(null);
092: setDelegatorWorkgroupId(null);
093: }
094: }
095:
096: public boolean isForDelegator() {
097: return getDelegatorWorkflowId() != null
098: || getDelegatorWorkgroupId() != null;
099: }
100:
101: public String getDelegatorDisplayName()
102: throws EdenUserNotFoundException {
103: if (!isForDelegator()) {
104: return "";
105: }
106: if (getDelegatorWorkflowId() != null) {
107: return getDelegatorUser().getDisplayName();
108: } else {
109: return getDelegatorWorkgroup().getGroupNameId().getNameId();
110: }
111: }
112:
113: private WorkflowUser getWorkflowUserForWorkflowId(String id)
114: throws EdenUserNotFoundException {
115: WorkflowUser w = null;
116:
117: if ((id != null) && (id.trim().length() > 0)) {
118: w = getUserService()
119: .getWorkflowUser(new WorkflowUserId(id));
120: }
121:
122: return w;
123: }
124:
125: public String getActionTakenLabel() {
126: return CodeTranslator.getActionTakenLabel(actionTaken);
127: }
128:
129: public Collection getActionRequests() {
130: if (actionRequests == null) {
131: setActionRequests(new ArrayList());
132: }
133: return actionRequests;
134: }
135:
136: public void setActionRequests(Collection actionRequests) {
137: this .actionRequests = actionRequests;
138: }
139:
140: public DocumentRouteHeaderValue getRouteHeader() {
141: return routeHeader;
142: }
143:
144: public void setRouteHeader(DocumentRouteHeaderValue routeHeader) {
145: this .routeHeader = routeHeader;
146: }
147:
148: public Timestamp getActionDate() {
149: return actionDate;
150: }
151:
152: public void setActionDate(Timestamp actionDate) {
153: this .actionDate = actionDate;
154: }
155:
156: public String getActionTaken() {
157: return actionTaken;
158: }
159:
160: public void setActionTaken(String actionTaken) {
161: this .actionTaken = actionTaken;
162: }
163:
164: public Long getActionTakenId() {
165: return actionTakenId;
166: }
167:
168: public void setActionTakenId(Long actionTakenId) {
169: this .actionTakenId = actionTakenId;
170: }
171:
172: public String getAnnotation() {
173: return annotation;
174: }
175:
176: public void setAnnotation(String annotation) {
177: this .annotation = annotation;
178: }
179:
180: public String getDelegatorWorkflowId() {
181: return delegatorWorkflowId;
182: }
183:
184: public void setDelegatorWorkflowId(String delegatorWorkflowId) {
185: this .delegatorWorkflowId = delegatorWorkflowId;
186: }
187:
188: public Long getDelegatorWorkgroupId() {
189: return delegatorWorkgroupId;
190: }
191:
192: public void setDelegatorWorkgroupId(Long delegatorWorkgroupId) {
193: this .delegatorWorkgroupId = delegatorWorkgroupId;
194: }
195:
196: public Integer getDocVersion() {
197: return docVersion;
198: }
199:
200: public void setDocVersion(Integer docVersion) {
201: this .docVersion = docVersion;
202: }
203:
204: public Integer getLockVerNbr() {
205: return lockVerNbr;
206: }
207:
208: public void setLockVerNbr(Integer lockVerNbr) {
209: this .lockVerNbr = lockVerNbr;
210: }
211:
212: public Long getRouteHeaderId() {
213: return routeHeaderId;
214: }
215:
216: public void setRouteHeaderId(Long routeHeaderId) {
217: this .routeHeaderId = routeHeaderId;
218: }
219:
220: public String getWorkflowId() {
221: return workflowId;
222: }
223:
224: public void setWorkflowId(String workflowId) {
225: this .workflowId = workflowId;
226: }
227:
228: public Boolean getCurrentIndicator() {
229: return currentIndicator;
230: }
231:
232: public void setCurrentIndicator(Boolean currentIndicator) {
233: this .currentIndicator = currentIndicator;
234: }
235:
236: public Collection getRootActionRequests() {
237: return getActionRequestService().getRootRequests(
238: getActionRequests());
239: }
240:
241: public Object copy(boolean preserveKeys) {
242: ActionTakenValue clone = new ActionTakenValue();
243: try {
244: BeanUtils.copyProperties(clone, this );
245: } catch (Exception e) {
246: throw new RuntimeException(e);
247: }
248:
249: if (!preserveKeys) {
250: clone.setActionTakenId(null);
251: }
252: return clone;
253: }
254:
255: private UserService getUserService() {
256: return (UserService) KEWServiceLocator
257: .getService(KEWServiceLocator.USER_SERVICE);
258: }
259:
260: private WorkgroupService getWorkgroupService() {
261: return (WorkgroupService) KEWServiceLocator
262: .getService(KEWServiceLocator.WORKGROUP_SRV);
263: }
264:
265: private ActionRequestService getActionRequestService() {
266: return (ActionRequestService) KEWServiceLocator
267: .getService(KEWServiceLocator.ACTION_REQUEST_SRV);
268: }
269:
270: public String getActionDateString() {
271: if (actionDateString == null
272: || actionDateString.trim().equals("")) {
273: return EdenConstants.getDefaultDateFormat().format(
274: getActionDate());
275: } else {
276: return actionDateString;
277: }
278: }
279:
280: public void setActionDateString(String actionDateString) {
281: this .actionDateString = actionDateString;
282: }
283:
284: public boolean isApproval() {
285: return EdenConstants.ACTION_TAKEN_APPROVED_CD
286: .equals(getActionTaken());
287: }
288:
289: public boolean isCompletion() {
290: return EdenConstants.ACTION_TAKEN_COMPLETED_CD
291: .equals(getActionTaken());
292: }
293: }
|