1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.imixs.workflow.plugins;
29
30 import java.util.Enumeration;
31 import java.util.List;
32 import java.util.Vector;
33
34 import org.imixs.workflow.ItemCollection;
35 import org.imixs.workflow.Plugin;
36 import org.imixs.workflow.WorkflowContext;
37 import org.imixs.workflow.WorkflowKernel;
38 import org.imixs.workflow.exceptions.PluginException;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public class OwnerPlugin extends AbstractPlugin {
60 ItemCollection documentContext;
61 ItemCollection documentActivity;
62 Vector itemOwnerRollback;
63 WorkflowContext workflowContext;
64
65 public void init(WorkflowContext actx) throws PluginException {
66 workflowContext = actx;
67 }
68
69
70
71
72
73 public int run(ItemCollection adocumentContext,
74 ItemCollection adocumentActivity) throws PluginException {
75 List itemOwner;
76 List vectorAccess;
77
78 documentContext = adocumentContext;
79 documentActivity = adocumentActivity;
80
81
82 validate();
83
84 itemOwner = (Vector) documentContext.getItemValue("namowner");
85
86
87 itemOwnerRollback = (Vector) documentContext
88 .getItemValue("namOwners");
89
90
91 if ("1".equals(documentActivity
92 .getItemValueString("keyOwnershipMode")))
93 vectorAccess = itemOwner;
94 else
95 vectorAccess = new Vector();
96 if (workflowContext.getLogLevel() == WorkflowKernel.LOG_LEVEL_FINE)
97 System.out.println("[OwnerPlugin] AccessMode: '"
98 + documentActivity
99 .getItemValueString("keyOwnershipMode") + "'");
100
101 if (vectorAccess == null)
102 vectorAccess = new Vector();
103
104
105 mergeVectors(vectorAccess,
106 documentActivity.getItemValue("namOwnershipNames"));
107
108
109 mergeMappedFieldValues(documentContext,vectorAccess,
110 documentActivity.getItemValue("keyOwnershipFields"));
111
112
113 vectorAccess = uniqueList(vectorAccess);
114
115
116 documentContext.replaceItemValue("namOwner", vectorAccess);
117 if ((workflowContext.getLogLevel() == WorkflowKernel.LOG_LEVEL_FINE)
118 && (vectorAccess.size() > 0)) {
119 System.out.println("[OwnerPlugin] Owner:");
120 for (int j = 0; j < vectorAccess.size(); j++)
121 System.out.println(" "
122 + (String) vectorAccess.get(j));
123 }
124
125
126
127 return Plugin.PLUGIN_OK;
128 }
129
130 public void close(int status) throws PluginException {
131 try {
132
133
134 if (status == Plugin.PLUGIN_ERROR) {
135 documentContext.replaceItemValue("namOwner", itemOwnerRollback);
136
137 }
138 } catch (Exception e) {
139
140 throw new PluginException("[AccessPlugin] Error close() "
141 + e.toString());
142 }
143 }
144
145
146
147
148
149
150
151
152 private void validate() {
153
154
155 if (!documentActivity.hasItem("keyOwnershipMode"))
156 documentActivity.replaceItemValue("keyOwnershipMode", "");
157
158 if (!documentActivity.hasItem("namOwnershipNames"))
159 documentActivity.replaceItemValue("namOwnershipNames", "");
160
161 if (!documentActivity.hasItem("keyOwnershipFields"))
162 documentActivity.replaceItemValue("keyOwnershipFields", "");
163
164
165 if (!documentContext.hasItem("namOwner"))
166 documentContext.replaceItemValue("namOwner", "");
167
168 }
169
170
171 }