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.workflow.Condition;
10: import com.opensymphony.workflow.StoreException;
11: import com.opensymphony.workflow.WorkflowContext;
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: * <p>
20: * A simple utility condition that returns true if the the current user (caller)
21: * is the step owner.
22: * </p>
23: *
24: * <p>
25: * This condition may be used to deny the owner of the step by negating the
26: * condition in the workflow descriptor with <code>negate='true'</code>.
27: * <p>
28: *
29: * <p>
30: * Looks at ALL current steps unless a step id is given in the optional argument
31: * "stepId".
32: * </p>
33: *
34: * <p>
35: * The implementation was originally contained in AllowOwnerOfStepCondition by
36: * Pat Lightbody.
37: * </p>
38: *
39: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody </a> (original
40: * implementation)
41: * @author <a href="mailto:adam@southtech.co.uk">Adam Southall </a> (refactored
42: * owner conditions to use this generic class.
43: */
44: public class IsUserOwnerCondition implements Condition {
45: //~ Methods ////////////////////////////////////////////////////////////////
46:
47: // ////////////////////////////////////////////////////////////////
48: public boolean passesCondition(Map transientVars, Map args,
49: PropertySet ps) throws StoreException {
50: int stepId = 0;
51: String stepIdVal = (String) args.get("stepId");
52:
53: if (stepIdVal != null) {
54: try {
55: stepId = Integer.parseInt(stepIdVal);
56: } catch (Exception ex) {
57: }
58: }
59:
60: WorkflowContext context = (WorkflowContext) transientVars
61: .get("context");
62: WorkflowEntry entry = (WorkflowEntry) transientVars
63: .get("entry");
64: WorkflowStore store = (WorkflowStore) transientVars
65: .get("store");
66: List currentSteps = store.findCurrentSteps(entry.getId());
67:
68: if (stepId == 0) {
69: for (Iterator iterator = currentSteps.iterator(); iterator
70: .hasNext();) {
71: Step step = (Step) iterator.next();
72:
73: if ((step.getOwner() != null)
74: && context.getCaller().equals(step.getOwner())) {
75: return true;
76: }
77: }
78: } else {
79: for (Iterator iterator = currentSteps.iterator(); iterator
80: .hasNext();) {
81: Step step = (Step) iterator.next();
82:
83: if (stepId == step.getStepId()) {
84: if ((step.getOwner() != null)
85: && context.getCaller().equals(
86: step.getOwner())) {
87: return true;
88: }
89: }
90: }
91: }
92:
93: return false;
94: }
95: }
|