KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > AllowOwnerOfStepCondition


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.util;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8
9 import com.opensymphony.workflow.*;
10 import com.opensymphony.workflow.spi.Step;
11 import com.opensymphony.workflow.spi.WorkflowEntry;
12 import com.opensymphony.workflow.spi.WorkflowStore;
13
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17
18
19 /**
20  * Checks owner of "stepId" in args and compares to current user
21  *
22  * @author Travis reeder
23  * Date: Feb 18, 2003
24  * Time: 4:47:00 PM
25  * @version 0.1
26  */

27 public class AllowOwnerOfStepCondition implements Condition {
28     //~ Methods ////////////////////////////////////////////////////////////////
29

30     public boolean passesCondition(Map JavaDoc transientVars, Map JavaDoc args, PropertySet ps) throws WorkflowException {
31         String JavaDoc stepIdString = (String JavaDoc) args.get("stepId");
32         WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
33         WorkflowContext context = (WorkflowContext) transientVars.get("context");
34
35         if (stepIdString == null) {
36             throw new WorkflowException("This condition expects a stepId!");
37         }
38
39         int stepId = 0;
40
41         if (stepIdString != null) {
42             try {
43                 stepId = Integer.parseInt(stepIdString);
44             } catch (Exception JavaDoc ex) {
45                 throw new WorkflowException("This condition expects a stepId > 0!");
46             }
47         }
48
49         WorkflowStore store = (WorkflowStore) transientVars.get("store");
50         List JavaDoc historySteps = store.findHistorySteps(entry.getId());
51
52         for (Iterator JavaDoc iterator = historySteps.iterator(); iterator.hasNext();) {
53             Step step = (Step) iterator.next();
54
55             if (stepId == (step.getStepId())) {
56                 // check to see if owner same as caller
57
if (((step.getOwner() != null) && (context.getCaller() != null)) && context.getCaller().equals(step.getOwner())) {
58                     return true;
59                 }
60             }
61         }
62
63         return false;
64     }
65 }
66
Popular Tags