View Javadoc
1   /**
2    * Copyright 2005-2016 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.impl.ui;
17  
18  import org.kuali.rice.core.api.util.tree.Node;
19  import org.kuali.rice.core.api.util.tree.Tree;
20  import org.kuali.rice.krms.impl.repository.ActionBo;
21  import org.kuali.rice.krms.impl.repository.AgendaBo;
22  import org.kuali.rice.krms.impl.repository.AgendaItemBo;
23  import org.kuali.rice.krms.impl.repository.ContextBo;
24  
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  /**
32   * synthetic (not directly persisted) BO for the KRMS agenda editor
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  public class AgendaEditor implements Serializable {
38  	
39  	private static final long serialVersionUID = 1L;
40  	
41  	private ContextBo context;
42      private String namespace;
43  	private AgendaBo agenda;
44      private String contextName;
45  	private AgendaItemBo agendaItemLine;
46      private ActionBo agendaItemLineRuleAction;
47      private String selectedAgendaItemId;
48      private String cutAgendaItemId;
49      private String selectedPropositionId;
50      private String cutPropositionId;
51      private List<String> deletedPropositionIdsFromRule = new ArrayList<>();
52      private List<String> deletedPropositionIds = new ArrayList<>();
53      private String copyRuleName;
54      private String oldContextId;
55      private String ruleEditorMessage;
56      private boolean addRuleInProgress = false;
57      private boolean disableButtons = false;
58      private Map<String, String> customAttributesMap = new HashMap<String, String>();
59      private Map<String, String> customRuleAttributesMap = new HashMap<String, String>();
60      private Map<String, String> customRuleActionAttributesMap = new HashMap<String, String>();
61  
62      public AgendaEditor() {
63          agenda = new AgendaBo();
64          // ToDo: Determine proper default values of agenda's typeId
65          agenda.setTypeId("");
66          agendaItemLine = new AgendaItemBo();
67          agendaItemLineRuleAction = new ActionBo();
68      }
69  
70  	private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) {
71  	    Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>();
72  	    child.setNodeLabel(agendaItem.getRuleText());
73  	    child.setNodeType("agendaNode ruleNode");
74  	    child.setData(new AgendaTreeRuleNode(agendaItem));
75  	    parent.getChildren().add(child);
76  	    
77  	    // deal with peer nodes:
78  	    if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways());
79  	    
80  	    // deal with child nodes:
81  	    if (agendaItem.getWhenTrue() != null) {
82  	        Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>();
83  	        whenTrue.setNodeLabel("When TRUE");
84  	        whenTrue.setNodeType("agendaNode logicNode whenTrueNode");
85  	        whenTrue.setData(new AgendaTreeLogicNode());
86  	        child.getChildren().add(whenTrue);
87  	        
88  	        addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue());
89  	    }
90          if (agendaItem.getWhenFalse() != null) {
91              Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>();
92              whenFalse.setNodeLabel("When FALSE");
93              whenFalse.setNodeType("agendaNode logicNode whenFalseNode");
94              whenFalse.setData(new AgendaTreeLogicNode());
95              child.getChildren().add(whenFalse);
96              
97              addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse());
98          }
99  	}
100 	
101     public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() {
102         Tree<AgendaTreeNode, String> agendaTree = new Tree<AgendaTreeNode, String>();
103 
104         Node<AgendaTreeNode, String> rootNode = new Node<AgendaTreeNode, String>();
105         agendaTree.setRootElement(rootNode);
106         
107         if (agenda != null) {
108             String firstItemId = agenda.getFirstItemId();
109             List<AgendaItemBo> items = agenda.getItems();
110             AgendaItemBo firstItem = null;
111 
112             if (items != null && firstItemId != null) {
113                 for (AgendaItemBo item : items) {
114                     if (firstItemId.equals(item.getId())) {
115                         firstItem = item;
116                         break;
117                     }
118                 }
119             }
120 
121             if (firstItem != null) addAgendaItemAndChildren(rootNode, firstItem);
122         } 
123         
124         return agendaTree;
125     }	
126 	
127 	/**
128      * @return the agendaItemLine
129      */
130     public AgendaItemBo getAgendaItemLine() {
131         return this.agendaItemLine;
132     }
133 
134     /**
135      * @param agendaItemLine the agendaItemLine to set
136      */
137     public void setAgendaItemLine(AgendaItemBo agendaItemLine) {
138         this.agendaItemLine = agendaItemLine;
139     }
140 
141     public ActionBo getAgendaItemLineRuleAction() {
142         return agendaItemLineRuleAction;
143     }
144 
145     public void setAgendaItemLineRuleAction(ActionBo actionBo) {
146         this.agendaItemLineRuleAction = actionBo;
147     }
148 
149     /**
150      * @return the selectedAgendaItemId
151      */
152     public String getSelectedAgendaItemId() {
153         return this.selectedAgendaItemId;
154     }
155 
156     /**
157      * @param selectedAgendaItemId the selectedAgendaItemId to set
158      */
159     public void setSelectedAgendaItemId(String selectedAgendaItemId) {
160         this.selectedAgendaItemId = selectedAgendaItemId;
161     }
162 
163     /**
164      * @return the cutAgendaItemId
165      */
166     public String getCutAgendaItemId() {
167         return this.cutAgendaItemId;
168     }
169 
170     /**
171      * @param cutAgendaItemId the cutAgendaItemId to set
172      */
173     public void setCutAgendaItemId(String cutAgendaItemId) {
174         this.cutAgendaItemId = cutAgendaItemId;
175     }
176 
177     /**
178 	 * @return the context
179 	 */
180 	public ContextBo getContext() {
181 		return this.context;
182 	}
183 
184 	/**
185 	 * @param context the context to set
186 	 */
187 	public void setContext(ContextBo context) {
188 		this.context = context;
189 	}
190 
191 	/**
192 	 * @return the agenda
193 	 */
194 	public AgendaBo getAgenda() {
195 		return this.agenda;
196 	}
197 
198 	/**
199 	 * @param agenda the agenda to set
200 	 */
201 	public void setAgenda(AgendaBo agenda) {
202 		this.agenda = agenda;
203 	}
204 
205     public Map<String, String> getCustomAttributesMap() {
206         return customAttributesMap;
207     }
208 
209     public void setCustomAttributesMap(Map<String, String> customAttributesMap) {
210         this.customAttributesMap = customAttributesMap;
211     }
212 
213     public Map<String, String> getCustomRuleAttributesMap() {
214         return customRuleAttributesMap;
215     }
216 
217     public void setCustomRuleAttributesMap(Map<String, String> customRuleAttributesMap) {
218         this.customRuleAttributesMap = customRuleAttributesMap;
219     }
220 
221     public Map<String, String> getCustomRuleActionAttributesMap() {
222         return customRuleActionAttributesMap;
223     }
224 
225     public void setCustomRuleActionAttributesMap(Map<String, String> customRuleActionAttributesMap) {
226         this.customRuleActionAttributesMap = customRuleActionAttributesMap;
227     }
228 
229     /**
230      * @param copyRuleName the rule name from which to copy
231      */
232     public void setCopyRuleName(String copyRuleName) {
233         this.copyRuleName = copyRuleName;
234     }
235 
236     /**
237      * @return the rule name from which to copy
238      */
239     public String getCopyRuleName() {
240         return copyRuleName;
241     }
242 
243     /**
244      * @param oldContextId the contextId that the agenda currently has (i.e. before the next context change)
245      */
246     public void setOldContextId(String oldContextId) {
247         this.oldContextId = oldContextId;
248     }
249 
250     /**
251      * @return the contextId that the agenda had before the context change
252      */
253     public String getOldContextId() {
254         return oldContextId;
255     }
256 
257     /**
258      * @return the selectedPropositionId
259      */
260     public String getSelectedPropositionId() {
261         return this.selectedPropositionId;
262     }
263 
264     /**
265      * @param selectedPropositionId the selectedPropositionId to set
266      */
267     public void setSelectedPropositionId(String selectedPropositionId) {
268         this.selectedPropositionId = selectedPropositionId;
269     }
270 
271 
272     /**
273      * @return the cutPropositionId
274      */
275     public String getCutPropositionId() {
276         return cutPropositionId;
277     }
278 
279     /**
280      * A list of the IDs for the propositions that have been deleted from this rule.
281      *
282      * @return the deleted proposition IDs
283      */
284     public List<String> getDeletedPropositionIdsFromRule() {
285         return deletedPropositionIdsFromRule;
286     }
287 
288     /**
289      * Set the list of the IDs for the propositions that have been deleted from this rule.
290      *
291      * @param deletedPropositionIdsFromRule the proposition IDs to set
292      */
293     public void setDeletedPropositionIdsFromRule(List<String> deletedPropositionIdsFromRule) {
294         this.deletedPropositionIdsFromRule = deletedPropositionIdsFromRule;
295     }
296 
297     /**
298      * Get the list of the IDs for propositions that have been deleted from this agenda.
299      *
300      * @return the deleted proposition IDs
301      */
302     public List<String> getDeletedPropositionIds() {
303         return deletedPropositionIds;
304     }
305 
306     /**
307      * Set the list of the IDs for propositions that have been deleted from this agenda.
308      *
309      * @param deletedPropositionIds the proposition IDs to set
310      */
311     public void setDeletedPropositionIds(List<String> deletedPropositionIds) {
312         this.deletedPropositionIds = deletedPropositionIds;
313     }
314 
315     public void addDeletedPropositionIdFromRule(String propId) {
316         getDeletedPropositionIdsFromRule().add(propId);
317     }
318 
319     /**
320      * Removes all of the proposition ID that have been tracked as deleted from this rule.
321      *
322      * <p>This is something to do when the user abandons the changes that have been made to
323      * the current edited rule.</p>
324      */
325     public void clearDeletedPropositionIdsFromRule() {
326         getDeletedPropositionIdsFromRule().clear();
327     }
328 
329     /**
330      * Moves all of the proposition IDs that have been tracked as deleted from this rule to
331      * the list on the agenda.
332      *
333      * <p>This essentially commits to the deletions that have been made in the rule.</p>
334      */
335     public void applyDeletedPropositionIdsFromRule() {
336         getDeletedPropositionIds().addAll(getDeletedPropositionIdsFromRule());
337         clearDeletedPropositionIdsFromRule();
338     }
339 
340     public String getContextName() {
341         return contextName;
342     }
343 
344     public void setContextName(String contextName) {
345         this.contextName = contextName;
346     }
347 
348     public String getNamespace() {
349         return namespace;
350     }
351 
352     public void setNamespace(String namespace) {
353         this.namespace = namespace;
354     }
355 
356     public String getRuleEditorMessage() {
357         return this.ruleEditorMessage;
358     }
359 
360     public void setRuleEditorMessage(String message) {
361         this.ruleEditorMessage = message;
362     }
363 
364     public boolean isAddRuleInProgress() {
365         return addRuleInProgress;
366     }
367 
368     public void setAddRuleInProgress(boolean addRuleInProgress) {
369         this.addRuleInProgress = addRuleInProgress;
370     }
371 
372     /**
373      *
374      * @return if the tree buttons should be disabled
375      */
376     public boolean isDisableButtons() {
377         return disableButtons;
378     }
379 
380     /**
381      * Setter for disableButtons. Set to true when the Agenda is submitted
382      *
383      * @param disableButtons
384      */
385     public void setDisableButtons(boolean disableButtons) {
386         this.disableButtons = disableButtons;
387     }
388 
389     /**
390      * @param cutPropositionId the cutPropositionId to set
391      */
392     public void setCutPropositionId(String cutPropositionId) {
393         this.cutPropositionId = cutPropositionId;
394     }
395 }