1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.engine.node.service.impl; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.apache.log4j.Logger; |
21 | |
import org.kuali.rice.kew.engine.node.Branch; |
22 | |
import org.kuali.rice.kew.engine.node.BranchState; |
23 | |
import org.kuali.rice.kew.engine.node.dao.BranchDAO; |
24 | |
import org.kuali.rice.kew.engine.node.service.BranchService; |
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class BranchServiceImpl implements BranchService { |
29 | 0 | private static final Logger LOG = Logger.getLogger(BranchServiceImpl.class); |
30 | |
|
31 | |
private BranchDAO branchDAO; |
32 | |
|
33 | |
public void save(Branch branch){ |
34 | 0 | getBranchDAO().save(branch); |
35 | 0 | } |
36 | |
|
37 | |
public BranchDAO getBranchDAO() { |
38 | 0 | return branchDAO; |
39 | |
} |
40 | |
public void setBranchDAO(BranchDAO branchDAO) { |
41 | 0 | this.branchDAO = branchDAO; |
42 | 0 | } |
43 | |
|
44 | |
public void deleteBranchStates(List statesToBeDeleted){ |
45 | 0 | getBranchDAO().deleteBranchStates(statesToBeDeleted); |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private BranchState resolveScopedVariable(Branch branch, String name) { |
55 | 0 | Branch b = branch; |
56 | 0 | while (b != null) { |
57 | 0 | for (BranchState bs: b.getBranchState()) { |
58 | 0 | LOG.debug(bs); |
59 | |
} |
60 | 0 | LOG.debug("Resolving variable: '" + name + "' in scope (branch): '" + branch.getName() + "' (" + branch.getBranchId() + ")"); |
61 | 0 | BranchState bs = b.getBranchState(name); |
62 | 0 | if (bs != null) { |
63 | 0 | return bs; |
64 | |
} |
65 | 0 | b = b.getParentBranch(); |
66 | 0 | } |
67 | 0 | return null; |
68 | |
} |
69 | |
|
70 | |
public String getScopedVariableValue(Branch branch, String name) { |
71 | 0 | BranchState bs = resolveScopedVariable(branch, name); |
72 | 0 | if (bs != null) return bs.getValue(); |
73 | 0 | return null; |
74 | |
} |
75 | |
|
76 | |
public String setScopedVariableValue(Branch branch, String name, String value) { |
77 | 0 | LOG.debug("Setting scoped variable value: " + name + " " + value); |
78 | 0 | BranchState bs = resolveScopedVariable(branch, name); |
79 | 0 | String oldValue = null; |
80 | 0 | if (bs == null) { |
81 | 0 | LOG.debug("Defining new variable named '" + name + "' at scope '" + branch + "'"); |
82 | |
|
83 | 0 | bs = new BranchState(); |
84 | 0 | bs.setKey(name); |
85 | 0 | bs.setValue(value); |
86 | 0 | bs.setBranch(branch); |
87 | 0 | branch.addBranchState(bs); |
88 | |
} else { |
89 | 0 | oldValue = bs.getValue(); |
90 | 0 | LOG.debug("Replacing old value of variable '" + name + "' (" + oldValue + ") at scope '" + branch + "' with new value: " + value); |
91 | 0 | bs.setValue(value); |
92 | |
} |
93 | |
|
94 | 0 | save(bs.getBranch()); |
95 | 0 | return oldValue; |
96 | |
} |
97 | |
|
98 | |
} |