001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.workflow.service.impl;
017:
018: import java.sql.Timestamp;
019: import java.util.ArrayList;
020: import java.util.Iterator;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.kuali.core.bo.user.UniversalUser;
024: import org.kuali.core.workflow.service.KualiWorkflowDocument;
025: import org.kuali.core.workflow.service.KualiWorkflowInfo;
026: import org.kuali.rice.KNSServiceLocator;
027:
028: import edu.iu.uis.eden.EdenConstants;
029: import edu.iu.uis.eden.clientapp.WorkflowDocument;
030: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
031: import edu.iu.uis.eden.clientapp.vo.RouteHeaderVO;
032: import edu.iu.uis.eden.clientapp.vo.UserIdVO;
033: import edu.iu.uis.eden.clientapp.vo.UserVO;
034: import edu.iu.uis.eden.clientapp.vo.WorkflowAttributeDefinitionVO;
035: import edu.iu.uis.eden.clientapp.vo.WorkgroupIdVO;
036: import edu.iu.uis.eden.exception.InvalidActionTakenException;
037: import edu.iu.uis.eden.exception.ResourceUnavailableException;
038: import edu.iu.uis.eden.exception.WorkflowException;
039:
040: public class KualiWorkflowDocumentImpl implements KualiWorkflowDocument {
041:
042: private WorkflowDocument workflowDocument;
043:
044: public KualiWorkflowDocumentImpl(UserIdVO userId,
045: String documentType) throws WorkflowException {
046: workflowDocument = new WorkflowDocument(userId, documentType);
047: }
048:
049: public KualiWorkflowDocumentImpl(UserIdVO userId, Long routeHeaderId)
050: throws WorkflowException {
051: workflowDocument = new WorkflowDocument(userId, routeHeaderId);
052: }
053:
054: // ########################
055: // Document Content methods
056: // ########################
057:
058: /**
059: * Returns the application specific document content.
060: *
061: * For documents routed prior to Workflow 2.0: If the application did NOT use attributes for XML generation, this method will
062: * return the entire document content XML. Otherwise it will return the empty string.
063: */
064: public String getApplicationContent() {
065: return workflowDocument.getApplicationContent();
066: }
067:
068: /**
069: * Sets the application specific document content.
070: */
071: public void setApplicationContent(String applicationContent) {
072: workflowDocument.setApplicationContent(applicationContent);
073: }
074:
075: /**
076: * Clears all attribute document content from the document. Typically, this will be used if it is necessary to update the
077: * attribute doc content on the document. This can be accomplished by clearing the content and then adding the desired attribute
078: * definitions.
079: *
080: * In order for these changes to take effect, an action must be performed on the document (such as "save").
081: */
082: public void clearAttributeContent() {
083: workflowDocument.clearAttributeContent();
084: }
085:
086: /**
087: * Returns the attribute-generated document content.
088: */
089: public String getAttributeContent() {
090: return workflowDocument.getAttributeContent();
091: }
092:
093: /**
094: * Adds an attribute definition which defines creation parameters for a WorkflowAttribute implementation. The created attribute
095: * will be used to generate attribute document content. When the document is sent to the server, this will be appended to the
096: * existing attribute doc content. If it is required to replace the attribute document content, then the clearAttributeContent()
097: * method should be invoked prior to adding attribute definitions.
098: */
099: public void addAttributeDefinition(
100: WorkflowAttributeDefinitionVO attributeDefinition) {
101: workflowDocument.addAttributeDefinition(attributeDefinition);
102: }
103:
104: public void removeAttributeDefinition(
105: WorkflowAttributeDefinitionVO attributeDefinition) {
106: workflowDocument.removeAttributeDefinition(attributeDefinition);
107: }
108:
109: public void clearAttributeDefinitions() {
110: workflowDocument.clearAttributeDefinitions();
111: }
112:
113: public WorkflowAttributeDefinitionVO[] getAttributeDefinitions() {
114: return workflowDocument.getAttributeDefinitions();
115: }
116:
117: /**
118: * Adds a searchable attribute definition which defines creation parameters for a SearchableAttribute implementation. The
119: * created attribute will be used to generate searchable document content. When the document is sent to the server, this will be
120: * appended to the existing searchable doc content. If it is required to replace the searchable document content, then the
121: * clearSearchableContent() method should be invoked prior to adding definitions.
122: */
123: public void addSearchableDefinition(
124: WorkflowAttributeDefinitionVO searchableDefinition) {
125: workflowDocument.addSearchableDefinition(searchableDefinition);
126: }
127:
128: public void removeSearchableDefinition(
129: WorkflowAttributeDefinitionVO searchableDefinition) {
130: workflowDocument
131: .removeSearchableDefinition(searchableDefinition);
132: }
133:
134: public void clearSearchableDefinitions() {
135: workflowDocument.clearSearchableDefinitions();
136: }
137:
138: public WorkflowAttributeDefinitionVO[] getSearchableDefinitions() {
139: return workflowDocument.getSearchableDefinitions();
140: }
141:
142: // ########################
143: // END Document Content methods
144: // ########################
145:
146: public RouteHeaderVO getRouteHeader() {
147: return workflowDocument.getRouteHeader();
148: }
149:
150: public Long getRouteHeaderId() throws WorkflowException {
151: return workflowDocument.getRouteHeaderId();
152: }
153:
154: public void setAppDocId(String appDocId) {
155: workflowDocument.setAppDocId(appDocId);
156: }
157:
158: public String getAppDocId() {
159: return workflowDocument.getAppDocId();
160: }
161:
162: /**
163: * @return
164: */
165: public String getInitiatorNetworkId() {
166: // TODO this was done so conditions in documentControls.tag will work
167: return workflowDocument.getRouteHeader().getInitiator()
168: .getNetworkId();
169: }
170:
171: private String getInitiatorUuId() {
172: return workflowDocument.getRouteHeader().getInitiator()
173: .getUuId();
174: }
175:
176: /**
177: * @return
178: */
179: public String getRoutedByUserNetworkId() {
180: return workflowDocument.getRouteHeader().getRoutedByUser()
181: .getNetworkId();
182: }
183:
184: private String getRoutedByUserUuId() {
185: return workflowDocument.getRouteHeader().getRoutedByUser()
186: .getUuId();
187: }
188:
189: public String getTitle() {
190: return workflowDocument.getTitle();
191: }
192:
193: public void saveDocument(String annotation)
194: throws WorkflowException {
195: workflowDocument.saveDocument(annotation);
196: }
197:
198: public void routeDocument(String annotation)
199: throws WorkflowException {
200: workflowDocument.routeDocument(annotation);
201: }
202:
203: public void disapprove(String annotation) throws WorkflowException {
204: workflowDocument.disapprove(annotation);
205: }
206:
207: public void approve(String annotation) throws WorkflowException {
208: workflowDocument.approve(annotation);
209: }
210:
211: public void super UserApprove(String annotation)
212: throws WorkflowException {
213: workflowDocument.super UserApprove(annotation);
214: }
215:
216: public void super UserActionRequestApprove(Long actionRequestId,
217: String annotation) throws WorkflowException {
218: workflowDocument.super UserActionRequestApprove(actionRequestId,
219: annotation);
220: }
221:
222: public void super UserCancel(String annotation)
223: throws WorkflowException {
224: workflowDocument.super UserCancel(annotation);
225: }
226:
227: public void super UserDisapprove(String annotation)
228: throws WorkflowException {
229: workflowDocument.super UserDisapprove(annotation);
230: }
231:
232: public void cancel(String annotation) throws WorkflowException {
233: workflowDocument.cancel(annotation);
234: }
235:
236: public void blanketApprove(String annotation)
237: throws WorkflowException {
238: workflowDocument.blanketApprove(annotation);
239: }
240:
241: /**
242: *
243: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#blanketApprove(java.lang.String, java.lang.Integer)
244: * @deprecated
245: */
246: @SuppressWarnings("deprecation")
247: public void blanketApprove(String annotation, Integer routeLevel)
248: throws WorkflowException {
249: workflowDocument.blanketApprove(annotation, routeLevel);
250: }
251:
252: public void saveRoutingData() throws WorkflowException {
253: workflowDocument.saveRoutingData();
254: }
255:
256: public void acknowledge(String annotation) throws WorkflowException {
257: workflowDocument.acknowledge(annotation);
258: }
259:
260: public void fyi() throws WorkflowException {
261: workflowDocument.fyi();
262: }
263:
264: public void delete() throws WorkflowException {
265: workflowDocument.delete();
266: }
267:
268: public void refreshContent() throws WorkflowException {
269: workflowDocument.refreshContent();
270: }
271:
272: public void appSpecificRouteDocumentToUser(String actionRequested,
273: String routeTypeName, int priority, String annotation,
274: UserIdVO recipient, String responsibilityDesc,
275: boolean ignorePreviousActions) throws WorkflowException {
276: workflowDocument.appSpecificRouteDocumentToUser(
277: actionRequested, routeTypeName, priority, annotation,
278: recipient, responsibilityDesc, ignorePreviousActions);
279: }
280:
281: public void appSpecificRouteDocumentToWorkgroup(
282: String actionRequested, String routeTypeName, int priority,
283: String annotation, WorkgroupIdVO workgroupId,
284: String responsibilityDesc, boolean ignorePreviousActions)
285: throws WorkflowException {
286: workflowDocument.appSpecificRouteDocumentToWorkgroup(
287: actionRequested, routeTypeName, priority, annotation,
288: workgroupId, responsibilityDesc, ignorePreviousActions);
289: }
290:
291: public void setTitle(String title) throws WorkflowException {
292: workflowDocument.setTitle(title);
293: }
294:
295: public String getDocumentType() {
296: return workflowDocument.getDocumentType();
297: }
298:
299: /**
300: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#isAdHocRequested()
301: */
302: public boolean isAdHocRequested() {
303: boolean isAdHocRequested = false;
304: Long routeHeaderId = null;
305: KualiWorkflowInfo workflowInfo = null;
306: try {
307: routeHeaderId = getRouteHeaderId();
308: workflowInfo = KNSServiceLocator.getWorkflowInfoService();
309: UserVO currentUser = workflowInfo
310: .getWorkflowUser(workflowDocument.getUserId());
311: ActionRequestVO[] actionRequests = workflowInfo
312: .getActionRequests(routeHeaderId);
313: for (int actionRequestIndex = 0; actionRequestIndex < actionRequests.length; actionRequestIndex++) {
314: if (actionRequests[actionRequestIndex].isActivated()
315: && actionRequests[actionRequestIndex]
316: .isAdHocRequest()) {
317: if (actionRequests[actionRequestIndex]
318: .isUserRequest()
319: && currentUser.getWorkflowId().equals(
320: actionRequests[actionRequestIndex]
321: .getUserVO()
322: .getWorkflowId())) {
323: isAdHocRequested = true;
324: } else if (actionRequests[actionRequestIndex]
325: .isWorkgroupRequest()) {
326: for (int workgroupMemberIndex = 0; workgroupMemberIndex < actionRequests[actionRequestIndex]
327: .getWorkgroupVO().getMembers().length; workgroupMemberIndex++) {
328: if (currentUser
329: .getWorkflowId()
330: .equals(
331: actionRequests[actionRequestIndex]
332: .getWorkgroupVO()
333: .getMembers()[workgroupMemberIndex]
334: .getWorkflowId())) {
335: isAdHocRequested = true;
336: }
337: }
338: }
339: }
340: }
341: } catch (WorkflowException e) {
342: throw new RuntimeException(
343: new StringBuffer(getClass().getName())
344: .append(
345: " encountered an exception while attempting to get the actoins requests for routeHeaderId: ")
346: .append(routeHeaderId).toString(), e);
347: }
348: return isAdHocRequested;
349: }
350:
351: /**
352: *
353: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#isAcknowledgeRequested()
354: */
355: public boolean isAcknowledgeRequested() {
356: return workflowDocument.isAcknowledgeRequested();
357: }
358:
359: /**
360: *
361: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#isApprovalRequested()
362: */
363: public boolean isApprovalRequested() {
364: return workflowDocument.isApprovalRequested();
365: }
366:
367: /**
368: *
369: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#isCompletionRequested()
370: */
371: public boolean isCompletionRequested() {
372: return workflowDocument.isCompletionRequested();
373: }
374:
375: /**
376: *
377: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#isFYIRequested()
378: */
379: public boolean isFYIRequested() {
380: return workflowDocument.isFYIRequested();
381: }
382:
383: /**
384: *
385: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#isBlanketApproveCapable()
386: */
387: public boolean isBlanketApproveCapable() {
388: return workflowDocument.isBlanketApproveCapable();
389: }
390:
391: @SuppressWarnings("deprecation")
392: public Integer getDocRouteLevel() {
393: return workflowDocument.getDocRouteLevel();
394: }
395:
396: /**
397: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#getDocRouteLevelName()
398: * @deprecated
399: */
400: // it would probably be easier to just put this info on bean from the server
401: @SuppressWarnings("deprecation")
402: public String getDocRouteLevelName() throws WorkflowException {
403: return workflowDocument.getDocRouteLevelName();
404: }
405:
406: /**
407: *
408: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#getRouteTypeName()
409: * @deprecated
410: */
411: // it would probably be easier to just put this info on bean from the server
412: @SuppressWarnings("deprecation")
413: public String getRouteTypeName() throws WorkflowException {
414: return workflowDocument.getRouteMethodName();
415: }
416:
417: /**
418: * @param annotation
419: * @throws InvalidActionTakenException
420: * @throws ResourceUnavailableException
421: * @throws WorkflowException
422: */
423: public void complete(String annotation) throws WorkflowException {
424: workflowDocument.complete(annotation);
425: }
426:
427: /**
428: * @param annotation
429: * @param destRouteLevel
430: * @throws WorkflowException
431: * @throws InvalidActionTakenException
432: * @throws ResourceUnavailableException
433: * @deprecated
434: */
435: @SuppressWarnings("deprecation")
436: public void returnToPreviousRouteLevel(String annotation,
437: Integer destRouteLevel) throws WorkflowException {
438: workflowDocument.returnToPreviousRouteLevel(annotation,
439: destRouteLevel);
440: }
441:
442: public void logDocumentAction(String annotation)
443: throws WorkflowException {
444: workflowDocument.logDocumentAction(annotation);
445: }
446:
447: /**
448: * Indicates if the document is in the initated state or not.
449: *
450: * @return true if in the specified state
451: */
452: public boolean stateIsInitiated() {
453: return workflowDocument.stateIsInitiated();
454: }
455:
456: /**
457: * Indicates if the document is in the saved state or not.
458: *
459: * @return true if in the specified state
460: */
461: public boolean stateIsSaved() {
462: return workflowDocument.stateIsSaved();
463: }
464:
465: /**
466: * Indicates if the document is in the enroute state or not.
467: *
468: * @return true if in the specified state
469: */
470: public boolean stateIsEnroute() {
471: return workflowDocument.stateIsEnroute();
472: }
473:
474: /**
475: * Indicates if the document is in the final state or not.
476: *
477: * @return true if in the specified state
478: */
479: public boolean stateIsFinal() {
480: return workflowDocument.stateIsFinal();
481: }
482:
483: /**
484: * Indicates if the document is in the exception state or not.
485: *
486: * @return true if in the specified state
487: */
488: public boolean stateIsException() {
489: return workflowDocument.stateIsException();
490: }
491:
492: /**
493: * Indicates if the document is in the canceled state or not.
494: *
495: * @return true if in the specified state
496: */
497: public boolean stateIsCanceled() {
498: return workflowDocument.stateIsCanceled();
499: }
500:
501: /**
502: * Indicates if the document is in the disapproved state or not.
503: *
504: * @return true if in the specified state
505: */
506: public boolean stateIsDisapproved() {
507: return workflowDocument.stateIsDisapproved();
508: }
509:
510: /**
511: * Indicates if the document is in the approved state or not. Will answer true is document is in Processed or Finalized state.
512: *
513: * @return true if in the specified state
514: */
515: public boolean stateIsApproved() {
516: return workflowDocument.stateIsApproved();
517: }
518:
519: /**
520: * Indicates if the document is in the processed state or not.
521: *
522: * @return true if in the specified state
523: */
524: public boolean stateIsProcessed() {
525: return workflowDocument.stateIsProcessed();
526: }
527:
528: public String getStatusDisplayValue() {
529: return workflowDocument.getStatusDisplayValue();
530: }
531:
532: public Timestamp getCreateDate() {
533: return workflowDocument.getDateCreated();
534: }
535:
536: /**
537: *
538: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#userIsInitiator(org.kuali.core.bo.user.KualiUser)
539: */
540: public boolean userIsInitiator(UniversalUser user) {
541: if (user == null) {
542: throw new IllegalArgumentException("invalid (null) user");
543: }
544:
545: return StringUtils.equalsIgnoreCase(getInitiatorUuId(), user
546: .getPersonUniversalIdentifier());
547: }
548:
549: /**
550: *
551: * @see org.kuali.core.workflow.service.KualiWorkflowDocument#userIsRoutedByUser(org.kuali.core.bo.user.KualiUser)
552: */
553: public boolean userIsRoutedByUser(UniversalUser user) {
554: if (user == null) {
555: throw new IllegalArgumentException("invalid (null) user");
556: }
557:
558: return StringUtils.equalsIgnoreCase(getRoutedByUserUuId(), user
559: .getPersonUniversalIdentifier());
560: }
561:
562: public String[] getNodeNames() throws WorkflowException {
563: return workflowDocument.getNodeNames();
564: }
565:
566: public String getCurrentRouteNodeNames() {
567: return workflowDocument.getRouteHeader()
568: .getCurrentRouteNodeNames();
569: }
570:
571: public boolean isStandardSaveAllowed() {
572: return workflowDocument
573: .isActionCodeValidForDocument(EdenConstants.ACTION_TAKEN_SAVED_CD);
574: }
575:
576: /**
577: * @see java.lang.Object#toString()
578: */
579: public String toString() {
580: ArrayList trueFlags = new ArrayList();
581: if (isAcknowledgeRequested()) {
582: trueFlags.add("acknowledgeRequested");
583: }
584: if (isApprovalRequested()) {
585: trueFlags.add("approvalRequested");
586: }
587: if (isBlanketApproveCapable()) {
588: trueFlags.add("blanketApproveCapable");
589: }
590: if (isCompletionRequested()) {
591: trueFlags.add("completionRequested");
592: }
593: if (isFYIRequested()) {
594: trueFlags.add("FYIRequested");
595: }
596:
597: if (stateIsApproved()) {
598: trueFlags.add("stateIsApproved");
599: }
600: if (stateIsCanceled()) {
601: trueFlags.add("stateIsCanceled");
602: }
603: if (stateIsDisapproved()) {
604: trueFlags.add("stateIsDisapproved");
605: }
606: if (stateIsEnroute()) {
607: trueFlags.add("stateIsEnroute");
608: }
609: if (stateIsException()) {
610: trueFlags.add("stateIsException");
611: }
612: if (stateIsFinal()) {
613: trueFlags.add("stateIsFinal");
614: }
615: if (stateIsInitiated()) {
616: trueFlags.add("stateIsInitiated");
617: }
618: if (stateIsProcessed()) {
619: trueFlags.add("stateIsProcessed");
620: }
621: if (stateIsSaved()) {
622: trueFlags.add("stateIsSaved");
623: }
624:
625: StringBuffer b = new StringBuffer("true flags=(");
626: for (Iterator i = trueFlags.iterator(); i.hasNext();) {
627: b.append(i.next());
628: if (i.hasNext()) {
629: b.append(",");
630: }
631: }
632: b.append(")");
633:
634: return b.toString();
635: }
636: }
|