01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.test.monitor;
17:
18: import org.apache.commons.lang.StringUtils;
19: import org.kuali.core.document.Document;
20: import org.kuali.core.service.DocumentService;
21:
22: /**
23: * DocumentWorkflowStatusMonitor
24: */
25: public class DocumentWorkflowStatusMonitor extends ChangeMonitor {
26: final DocumentService documentService;
27: final private String docHeaderId;
28: final private String[] desiredWorkflowStates;
29:
30: public DocumentWorkflowStatusMonitor(
31: DocumentService documentService, String docHeaderId,
32: String desiredWorkflowStatus) {
33: this .documentService = documentService;
34: this .docHeaderId = docHeaderId;
35: this .desiredWorkflowStates = new String[] { desiredWorkflowStatus };
36: }
37:
38: public DocumentWorkflowStatusMonitor(
39: DocumentService documentService, String docHeaderId,
40: String[] desiredWorkflowStates) {
41: this .documentService = documentService;
42: this .docHeaderId = docHeaderId;
43: this .desiredWorkflowStates = desiredWorkflowStates;
44: }
45:
46: public boolean valueChanged() throws Exception {
47: Document d = documentService.getByDocumentHeaderId(docHeaderId
48: .toString());
49:
50: String currentStatus = d.getDocumentHeader()
51: .getWorkflowDocument().getRouteHeader()
52: .getDocRouteStatus();
53:
54: for (int i = 0; i < desiredWorkflowStates.length; i++) {
55: if (StringUtils.equals(desiredWorkflowStates[i],
56: currentStatus)) {
57: return true;
58: }
59: }
60: return false;
61: }
62: }
|