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 List<String> activeSelections;
68
69
70 private String logicArea;
71
72
73 private Tree<RuleEditorTreeNode, String> editTree;
74
75
76 private Tree<TreeNode, String> previewTree;
77 private Tree<TreeNode, String> viewTree;
78 private AlphaIterator simpleKeys;
79 private AlphaIterator compoundKeys;
80
81
82 private Tree<CompareTreeNode, String> compareTree;
83
84
85 private RuleTypeInfo ruleTypeInfo;
86 private RuleEditor parent;
87
88 public RuleEditor() {
89 super();
90 }
91
92 public RuleEditor(String key, boolean dummy, RuleTypeInfo ruleTypeInfo) {
93 this.setKey(key);
94 this.setDummy(dummy);
95 this.setTypeId(ruleTypeInfo.getId());
96 this.setRuleTypeInfo(ruleTypeInfo);
97 }
98
99 public RuleEditor(RuleDefinitionContract definition) {
100 this.id = definition.getId();
101 this.namespace = definition.getNamespace();
102 this.name = definition.getName();
103 this.description = definition.getDescription();
104 this.typeId = definition.getTypeId();
105 this.propId = definition.getPropId();
106 this.active = definition.isActive();
107 if(definition.getProposition()!=null){
108 this.proposition = createPropositionEditor(definition.getProposition());
109 }
110 this.versionNumber = definition.getVersionNumber();
111
112 if(definition.getActions()!=null){
113 this.actions = new ArrayList<ActionEditor>();
114 for(ActionDefinitionContract action : definition.getActions()){
115 this.actions.add(new ActionEditor(action));
116 }
117 } else {
118 this.actions = null;
119 }
120
121 this.attributes = definition.getAttributes();
122
123 }
124
125 public String getKey() {
126 return key;
127 }
128
129 public void setKey(String key) {
130 this.key = key;
131 }
132
133 public void setId(String id) {
134 this.id = id;
135 }
136
137 public void setDescription(String description) {
138 this.description = description;
139 }
140
141 public PropositionEditor getPropositionEditor(){
142 return proposition;
143 }
144
145 public void setProposition(PropositionEditor proposition) {
146 this.proposition = proposition;
147 }
148
149 public void setPropId(String propId) {
150 this.propId = propId;
151 }
152
153 public void setTypeId(String typeId) {
154 this.typeId = typeId;
155 }
156
157 public void setActive(boolean active) {
158 this.active = active;
159 }
160
161 public void setName(String name) {
162 this.name = name;
163 }
164
165 public void setNamespace(String namespace) {
166 this.namespace = namespace;
167 }
168
169 public List<String> getActiveSelections() {
170 return activeSelections;
171 }
172
173 public void setActiveSelections(List<String> activeSelections) {
174 this.activeSelections = activeSelections;
175 }
176
177 public AlphaIterator getSimpleKeys() {
178 if (simpleKeys == null){
179 simpleKeys = new AlphaIterator(StringUtils.EMPTY);
180 }
181 return simpleKeys;
182 }
183
184 public void setSimpleKeys(AlphaIterator simpleKeys) {
185 this.simpleKeys = simpleKeys;
186 }
187
188 public AlphaIterator getCompoundKeys() {
189 if (compoundKeys == null){
190 compoundKeys = new AlphaIterator(PropositionType.COMPOUND.getCode() + "-");
191 }
192 return compoundKeys;
193 }
194
195 public void setCompoundKeys(AlphaIterator compoundKeys) {
196 this.compoundKeys = compoundKeys;
197 }
198
199
200
201
202 public String getSelectedKey() {
203 return this.selectedKey;
204 }
205
206
207
208
209 public void setSelectedKey(String selectedKey) {
210 this.selectedKey = selectedKey;
211 }
212
213
214
215
216 public String getCutKey() {
217 return cutKey;
218 }
219
220 public void setCutKey(String cutKey) {
221 this.cutKey = cutKey;
222 }
223
224 public boolean isDummy() {
225 return dummy;
226 }
227
228 public void setDummy(boolean dummy) {
229 this.dummy = dummy;
230 }
231
232
233
234
235 public String getCopyKey() {
236 return copyKey;
237 }
238
239
240
241
242 public void setCopyKey(String copyKey) {
243 this.copyKey = copyKey;
244 }
245
246 public String getLogicArea() {
247 return logicArea;
248 }
249
250 public void setLogicArea(String logicArea) {
251 this.logicArea = logicArea;
252 }
253
254 @Override
255 public String getName() {
256 return this.name;
257 }
258
259 @Override
260 public String getDescription() {
261 return this.description;
262 }
263
264 @Override
265 public String getNamespace() {
266 return this.namespace;
267 }
268
269 @Override
270 public String getTypeId() {
271 return this.typeId;
272 }
273
274 @Override
275 public String getPropId() {
276 return this.propId;
277 }
278
279 @Override
280 public PropositionDefinitionContract getProposition() {
281 return proposition;
282 }
283
284 @Override
285 public List<? extends ActionDefinitionContract> getActions() {
286 if(this.actions==null){
287 this.actions = new ArrayList<ActionEditor>();
288 }
289 return actions;
290 }
291
292 public List<ActionEditor> getActionEditors() {
293 if(this.actions==null){
294 this.actions = new ArrayList<ActionEditor>();
295 }
296 return actions;
297 }
298
299 @Override
300 public Map<String, String> getAttributes() {
301 return null;
302 }
303
304 @Override
305 public String getId() {
306 return this.id;
307 }
308
309 @Override
310 public boolean isActive() {
311 return this.active;
312 }
313
314 public Tree<RuleEditorTreeNode, String> getEditTree() {
315 return editTree;
316 }
317
318 public void setEditTree(Tree<RuleEditorTreeNode, String> editTree) {
319 this.editTree = editTree;
320 }
321
322 public Tree<TreeNode, String> getPreviewTree() {
323 return previewTree;
324 }
325
326 public void setPreviewTree(Tree<TreeNode, String> previewTree) {
327 this.previewTree = previewTree;
328 }
329
330
331 public Tree<TreeNode, String> getViewTree() {
332 return viewTree;
333 }
334
335 public void setViewTree(Tree<TreeNode, String> viewTree) {
336 this.viewTree = viewTree;
337 }
338
339
340 public Tree<CompareTreeNode, String> getCompareTree() {
341 return compareTree;
342 }
343
344 public void setCompareTree(Tree<CompareTreeNode, String> compareTree) {
345 this.compareTree = compareTree;
346 }
347
348 public void setVersionNumber(Long versionNumber) {
349 this.versionNumber = versionNumber;
350 }
351
352 @Override
353 public Long getVersionNumber() {
354 return versionNumber;
355 }
356
357 protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition){
358 return new PropositionEditor(definition);
359 }
360
361 public RuleTypeInfo getRuleTypeInfo() {
362 return ruleTypeInfo;
363 }
364
365 public void setRuleTypeInfo(RuleTypeInfo ruleTypeInfo) {
366 this.ruleTypeInfo = ruleTypeInfo;
367 }
368
369 public RuleEditor getParent() {
370 return parent;
371 }
372
373 public void setParent(RuleEditor parent) {
374 this.parent = parent;
375 }
376
377 public void reset(){
378 this.getEditTree().setRootElement(null);
379 this.setPropId(null);
380 this.setProposition(null);
381 this.setSimpleKeys(null);
382 this.setCompoundKeys(null);
383 this.setSelectedKey(StringUtils.EMPTY);
384 }
385 }