View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @author Kuali Student Team
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<ActionDefinitionContract> 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      //Edit with Logic
70      private String logicArea;
71  
72      // for Rule editor display
73      private Tree<RuleEditorTreeNode, String> editTree;
74  
75      // for Rule Preview display
76      private Tree<TreeNode, String> previewTree;
77      private Tree<TreeNode, String> viewTree;
78      private AlphaIterator simpleKeys;
79      private AlphaIterator compoundKeys;
80  
81      // for Compare
82      private Tree<CompareTreeNode, String> compareTree;
83  
84      //Rule Instruction
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<ActionDefinitionContract>();
114             for(ActionDefinitionContract action : definition.getActions()){
115                 this.actions.add(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      * @return the selectedKey
201      */
202     public String getSelectedKey() {
203         return this.selectedKey;
204     }
205 
206     /**
207      * @param selectedKey the selectedKey to set
208      */
209     public void setSelectedKey(String selectedKey) {
210         this.selectedKey = selectedKey;
211     }
212 
213     /**
214      * @return the cutKey
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      * @return the copyKey
234      */
235     public String getCopyKey() {
236         return copyKey;
237     }
238 
239     /**
240      * @param copyKey the copyKey to set
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         return null;  //To change body of implemented methods use File | Settings | File Templates.
287     }
288 
289     @Override
290     public Map<String, String> getAttributes() {
291         return null;  //To change body of implemented methods use File | Settings | File Templates.
292     }
293 
294     @Override
295     public String getId() {
296         return this.id;
297     }
298 
299     @Override
300     public boolean isActive() {
301         return this.active;
302     }
303 
304     public Tree<RuleEditorTreeNode, String> getEditTree() {
305         return editTree;
306     }
307 
308     public void setEditTree(Tree<RuleEditorTreeNode, String> editTree) {
309         this.editTree = editTree;
310     }
311 
312     public Tree<TreeNode, String> getPreviewTree() {
313         return previewTree;
314     }
315 
316     public void setPreviewTree(Tree<TreeNode, String> previewTree) {
317         this.previewTree = previewTree;
318     }
319 
320 
321     public Tree<TreeNode, String> getViewTree() {
322         return viewTree;
323     }
324 
325     public void setViewTree(Tree<TreeNode, String> viewTree) {
326         this.viewTree = viewTree;
327     }
328 
329 
330     public Tree<CompareTreeNode, String> getCompareTree() {
331         return compareTree;
332     }
333 
334     public void setCompareTree(Tree<CompareTreeNode, String> compareTree) {
335         this.compareTree = compareTree;
336     }
337 
338     public void setVersionNumber(Long versionNumber) {
339         this.versionNumber = versionNumber;
340     }
341 
342     @Override
343     public Long getVersionNumber() {
344         return versionNumber;
345     }
346 
347     protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition){
348         return new PropositionEditor(definition);
349     }
350 
351     public RuleTypeInfo getRuleTypeInfo() {
352         return ruleTypeInfo;
353     }
354 
355     public void setRuleTypeInfo(RuleTypeInfo ruleTypeInfo) {
356         this.ruleTypeInfo = ruleTypeInfo;
357     }
358 
359     public RuleEditor getParent() {
360         return parent;
361     }
362 
363     public void setParent(RuleEditor parent) {
364         this.parent = parent;
365     }
366 
367     public void reset(){
368         this.getEditTree().setRootElement(null);
369         this.setPropId(null);
370         this.setProposition(null);
371         this.setSimpleKeys(null);
372         this.setCompoundKeys(null);
373         this.setSelectedKey(StringUtils.EMPTY);
374     }
375 }