01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.util;
06:
07: import com.opensymphony.module.propertyset.PropertySet;
08:
09: import com.opensymphony.util.TextUtils;
10:
11: import com.opensymphony.workflow.*;
12: import com.opensymphony.workflow.spi.Step;
13: import com.opensymphony.workflow.spi.WorkflowEntry;
14: import com.opensymphony.workflow.spi.WorkflowStore;
15:
16: import java.util.*;
17:
18: /**
19: * Simple utility condition that returns true if the current step's status is
20: * the same as the required argument "status". Looks at ALL current steps unless
21: * a stepId is given in the optional argument "stepId".
22: *
23: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
24: */
25: public class StatusCondition implements Condition {
26: //~ Methods ////////////////////////////////////////////////////////////////
27:
28: public boolean passesCondition(Map transientVars, Map args,
29: PropertySet ps) throws StoreException {
30: String status = TextUtils.noNull((String) args.get("status"));
31: int stepId = 0;
32: Object stepIdVal = args.get("stepId");
33:
34: if (stepIdVal != null) {
35: try {
36: stepId = Integer.parseInt(stepIdVal.toString());
37: } catch (Exception ex) {
38: }
39: }
40:
41: WorkflowEntry entry = (WorkflowEntry) transientVars
42: .get("entry");
43: WorkflowStore store = (WorkflowStore) transientVars
44: .get("store");
45: List currentSteps = store.findCurrentSteps(entry.getId());
46:
47: if (stepId == 0) {
48: for (Iterator iterator = currentSteps.iterator(); iterator
49: .hasNext();) {
50: Step step = (Step) iterator.next();
51:
52: if (status.equals(step.getStatus())) {
53: return true;
54: }
55: }
56: } else {
57: for (Iterator iterator = currentSteps.iterator(); iterator
58: .hasNext();) {
59: Step step = (Step) iterator.next();
60:
61: if (stepId == step.getStepId()) {
62: if (status.equals(step.getStatus())) {
63: return true;
64: }
65: }
66: }
67: }
68:
69: return false;
70: }
71: }
|