001/**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krms.dto;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.util.tree.Tree;
020import org.kuali.rice.krad.web.form.UifFormBase;
021import org.kuali.rice.krms.api.repository.action.ActionDefinition;
022import org.kuali.rice.krms.api.repository.action.ActionDefinitionContract;
023import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
024import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
025import org.kuali.rice.krms.api.repository.proposition.PropositionType;
026import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
027import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract;
028import org.kuali.rice.krms.tree.node.CompareTreeNode;
029import org.kuali.rice.krms.tree.node.RuleEditorTreeNode;
030import org.kuali.rice.krms.tree.node.TreeNode;
031import org.kuali.rice.krms.util.AlphaIterator;
032
033import java.io.Serializable;
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import java.util.Map;
038
039/**
040 *
041 * @author Kuali Student Team
042 */
043public class RuleEditor extends UifFormBase implements RuleDefinitionContract, Serializable {
044
045    private static final long serialVersionUID = 1L;
046
047    private String key;
048
049    private String id;
050    private String namespace;
051    private String description;
052    private String name;
053    private String typeId;
054    private String propId;
055    private boolean active = true;
056    private Long versionNumber;
057
058    private List<ActionEditor> actions;
059    private Map<String, String> attributes;
060
061    private PropositionEditor proposition;
062
063    private String copyKey;
064    private String selectedKey;
065    private String cutKey;
066    private boolean dummy;
067    private List<String> activeSelections;
068
069    //Edit with Logic
070    private String logicArea;
071
072    // for Rule editor display
073    private Tree<RuleEditorTreeNode, String> editTree;
074
075    // for Rule Preview display
076    private Tree<TreeNode, String> previewTree;
077    private Tree<TreeNode, String> viewTree;
078    private AlphaIterator simpleKeys;
079    private AlphaIterator compoundKeys;
080
081    // for Compare
082    private Tree<CompareTreeNode, String> compareTree;
083
084    //Rule Instruction
085    private RuleTypeInfo ruleTypeInfo;
086    private RuleEditor parent;
087
088    public RuleEditor() {
089        super();
090    }
091
092    public RuleEditor(String key, boolean dummy, RuleTypeInfo ruleTypeInfo) {
093        this.setKey(key);
094        this.setDummy(dummy);
095        this.setTypeId(ruleTypeInfo.getId());
096        this.setRuleTypeInfo(ruleTypeInfo);
097    }
098
099    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     * @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        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;  //To change body of implemented methods use File | Settings | File Templates.
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}