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: * Sets the transient variable "mostRecentOwner" to the owner of the most
20: * recent step that had an id equal to one of the values in the stepId list. If there is
21: * none found, the variable is unset. This function accepts the following
22: * arguments:
23: *
24: * <ul>
25: * <li>stepId - a comma-seperated list of the most recent steps to look for (required)</li>
26: * </ul>
27: *
28: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
29: * @author <a href="mailto:mischwar@cisco.com">Mike Schwartz</a>
30: * @version $Revision: 1.3 $
31: */
32: public class MostRecentOwner implements FunctionProvider {
33: //~ Methods ////////////////////////////////////////////////////////////////
34:
35: public void execute(Map transientVars, Map args, PropertySet ps)
36: throws WorkflowException {
37: // expects a stepId name/value pair
38: String stepIdString = (String) args.get("stepId");
39: WorkflowEntry entry = (WorkflowEntry) transientVars
40: .get("entry");
41:
42: if (stepIdString == null) {
43: throw new WorkflowException(
44: "This function expects a stepId!");
45: }
46:
47: StringTokenizer st = new StringTokenizer(stepIdString, ",");
48: List stepIds = new LinkedList();
49:
50: while (st.hasMoreTokens()) {
51: stepIds.add(st.nextToken().trim());
52: }
53:
54: WorkflowStore store = (WorkflowStore) transientVars
55: .get("store");
56: List historySteps = store.findHistorySteps(entry.getId());
57:
58: for (Iterator iterator = historySteps.iterator(); iterator
59: .hasNext();) {
60: Step step = (Step) iterator.next();
61:
62: if (stepIds.contains(String.valueOf(step.getStepId()))
63: && TextUtils.stringSet(step.getOwner())) {
64: transientVars.put("mostRecentOwner", step.getOwner());
65:
66: break;
67: }
68: }
69: }
70: }
|