View Javadoc

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