1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.dto;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.tree.Tree;
20 import org.kuali.rice.krad.web.form.UifFormBase;
21 import org.kuali.rice.krms.api.repository.action.ActionDefinition;
22 import org.kuali.rice.krms.api.repository.action.ActionDefinitionContract;
23 import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
24 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
25 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
26 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
27 import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract;
28 import org.kuali.rice.krms.tree.node.CompareTreeNode;
29 import org.kuali.rice.krms.tree.node.RuleEditorTreeNode;
30 import org.kuali.rice.krms.tree.node.TreeNode;
31 import org.kuali.rice.krms.util.AlphaIterator;
32
33 import java.io.Serializable;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.List;
37 import java.util.Map;
38
39
40
41
42
43 public class RuleEditor extends UifFormBase implements RuleDefinitionContract, Serializable {
44
45 private static final long serialVersionUID = 1L;
46
47 private String key;
48
49 private String id;
50 private String namespace;
51 private String description;
52 private String name;
53 private String typeId;
54 private String propId;
55 private boolean active = true;
56 private Long versionNumber;
57
58 private List<ActionEditor> actions;
59 private Map<String, String> attributes;
60
61 private PropositionEditor proposition;
62
63 private String copyKey;
64 private String selectedKey;
65 private String cutKey;
66 private boolean dummy;
67 private boolean initialized;
68 private List<String> activeSelections;
69
70
71 private String logicArea;
72
73
74 private Tree<RuleEditorTreeNode, String> editTree;
75
76
77 private Tree<TreeNode, String> previewTree;
78 private Tree<TreeNode, String> viewTree;
79 private AlphaIterator simpleKeys;
80 private AlphaIterator compoundKeys;
81
82
83 private Tree<CompareTreeNode, String> compareTree;
84
85
86 private RuleTypeInfo ruleTypeInfo;
87 private RuleEditor parent;
88
89 public RuleEditor() {
90 super();
91 }
92
93 public RuleEditor(String key, boolean dummy, RuleTypeInfo ruleTypeInfo) {
94 this.setKey(key);
95 this.setDummy(dummy);
96 this.setTypeId(ruleTypeInfo.getId());
97 this.setRuleTypeInfo(ruleTypeInfo);
98 }
99
100 public RuleEditor(RuleDefinitionContract definition) {
101 this.id = definition.getId();
102 this.namespace = definition.getNamespace();
103 this.name = definition.getName();
104 this.description = definition.getDescription();
105 this.typeId = definition.getTypeId();
106 this.propId = definition.getPropId();
107 this.active = definition.isActive();
108 if(definition.getProposition()!=null){
109 this.proposition = createPropositionEditor(definition.getProposition());
110 }
111 this.versionNumber = definition.getVersionNumber();
112
113 if(definition.getActions()!=null){
114 this.actions = new ArrayList<ActionEditor>();
115 for(ActionDefinitionContract action : definition.getActions()){
116 this.actions.add(new ActionEditor(action));
117 }
118 } else {
119 this.actions = null;
120 }
121
122 this.attributes = definition.getAttributes();
123
124 }
125
126 public String getKey() {
127 return key;
128 }
129
130 public void setKey(String key) {
131 this.key = key;
132 }
133
134 public void setId(String id) {
135 this.id = id;
136 }
137
138 public void setDescription(String description) {
139 this.description = description;
140 }
141
142 public PropositionEditor getPropositionEditor(){
143 return proposition;
144 }
145
146 public void setProposition(PropositionEditor proposition) {
147 this.proposition = proposition;
148 }
149
150 public void setPropId(String propId) {
151 this.propId = propId;
152 }
153
154 public void setTypeId(String typeId) {
155 this.typeId = typeId;
156 }
157
158 public void setActive(boolean active) {
159 this.active = active;
160 }
161
162 public void setName(String name) {
163 this.name = name;
164 }
165
166 public void setNamespace(String namespace) {
167 this.namespace = namespace;
168 }
169
170 public List<String> getActiveSelections() {
171 return activeSelections;
172 }
173
174 public void setActiveSelections(List<String> activeSelections) {
175 this.activeSelections = activeSelections;
176 }
177
178 public AlphaIterator getSimpleKeys() {
179 if (simpleKeys == null){
180 simpleKeys = new AlphaIterator(StringUtils.EMPTY);
181 }
182 return simpleKeys;
183 }
184
185 public void setSimpleKeys(AlphaIterator simpleKeys) {
186 this.simpleKeys = simpleKeys;
187 }
188
189 public AlphaIterator getCompoundKeys() {
190 if (compoundKeys == null){
191 compoundKeys = new AlphaIterator(PropositionType.COMPOUND.getCode() + "-");
192 }
193 return compoundKeys;
194 }
195
196 public void setCompoundKeys(AlphaIterator compoundKeys) {
197 this.compoundKeys = compoundKeys;
198 }
199
200
201
202
203 public String getSelectedKey() {
204 return this.selectedKey;
205 }
206
207
208
209
210 public void setSelectedKey(String selectedKey) {
211 this.selectedKey = selectedKey;
212 }
213
214
215
216
217 public String getCutKey() {
218 return cutKey;
219 }
220
221 public void setCutKey(String cutKey) {
222 this.cutKey = cutKey;
223 }
224
225 public boolean isDummy() {
226 return dummy;
227 }
228
229 public void setDummy(boolean dummy) {
230 this.dummy = dummy;
231 }
232
233 public boolean isInitialized() {
234 return initialized;
235 }
236
237 public void setInitialized(boolean initialized) {
238 this.initialized = initialized;
239 }
240
241
242
243
244 public String getCopyKey() {
245 return copyKey;
246 }
247
248
249
250
251 public void setCopyKey(String copyKey) {
252 this.copyKey = copyKey;
253 }
254
255 public String getLogicArea() {
256 return logicArea;
257 }
258
259 public void setLogicArea(String logicArea) {
260 this.logicArea = logicArea;
261 }
262
263 @Override
264 public String getName() {
265 return this.name;
266 }
267
268 @Override
269 public String getDescription() {
270 return this.description;
271 }
272
273 @Override
274 public String getNamespace() {
275 return this.namespace;
276 }
277
278 @Override
279 public String getTypeId() {
280 return this.typeId;
281 }
282
283 @Override
284 public String getPropId() {
285 return this.propId;
286 }
287
288 @Override
289 public PropositionDefinitionContract getProposition() {
290 return proposition;
291 }
292
293 @Override
294 public List<? extends ActionDefinitionContract> getActions() {
295 if(this.actions==null){
296 this.actions = new ArrayList<ActionEditor>();
297 }
298 return actions;
299 }
300
301 public List<ActionEditor> getActionEditors() {
302 if(this.actions==null){
303 this.actions = new ArrayList<ActionEditor>();
304 }
305 return actions;
306 }
307
308 @Override
309 public Map<String, String> getAttributes() {
310 return null;
311 }
312
313 @Override
314 public String getId() {
315 return this.id;
316 }
317
318 @Override
319 public boolean isActive() {
320 return this.active;
321 }
322
323 public Tree<RuleEditorTreeNode, String> getEditTree() {
324 return editTree;
325 }
326
327 public void setEditTree(Tree<RuleEditorTreeNode, String> editTree) {
328 this.editTree = editTree;
329 }
330
331 public Tree<TreeNode, String> getPreviewTree() {
332 return previewTree;
333 }
334
335 public void setPreviewTree(Tree<TreeNode, String> previewTree) {
336 this.previewTree = previewTree;
337 }
338
339
340 public Tree<TreeNode, String> getViewTree() {
341 return viewTree;
342 }
343
344 public void setViewTree(Tree<TreeNode, String> viewTree) {
345 this.viewTree = viewTree;
346 }
347
348
349 public Tree<CompareTreeNode, String> getCompareTree() {
350 return compareTree;
351 }
352
353 public void setCompareTree(Tree<CompareTreeNode, String> compareTree) {
354 this.compareTree = compareTree;
355 }
356
357 public void setVersionNumber(Long versionNumber) {
358 this.versionNumber = versionNumber;
359 }
360
361 @Override
362 public Long getVersionNumber() {
363 return versionNumber;
364 }
365
366 protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition){
367 return new PropositionEditor(definition);
368 }
369
370 public RuleTypeInfo getRuleTypeInfo() {
371 return ruleTypeInfo;
372 }
373
374 public void setRuleTypeInfo(RuleTypeInfo ruleTypeInfo) {
375 this.ruleTypeInfo = ruleTypeInfo;
376 }
377
378 public RuleEditor getParent() {
379 return parent;
380 }
381
382 public void setParent(RuleEditor parent) {
383 this.parent = parent;
384 }
385
386 public void reset(){
387 this.getEditTree().setRootElement(null);
388 this.setPropId(null);
389 this.setProposition(null);
390 this.setSimpleKeys(null);
391 this.setCompoundKeys(null);
392 this.setSelectedKey(StringUtils.EMPTY);
393 }
394 }