View Javadoc

1   /**
2    * Copyright 2005-2011 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 Map<String, String> customAttributesMap = new HashMap<String, String>();
53      private Map<String, String> customRuleAttributesMap = new HashMap<String, String>();
54      private Map<String, String> customRuleActionAttributesMap = new HashMap<String, String>();
55  
56      public AgendaEditor() {
57          agenda = new AgendaBo();
58          // ToDo: Determine proper default values of agenda's typeId
59          agenda.setTypeId("");
60          agendaItemLine = new AgendaItemBo();
61          agendaItemLineRuleAction = new ActionBo();
62      }
63  
64  	private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) {
65  	    Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>();
66  	    child.setNodeLabel(agendaItem.getRuleText());
67  	    child.setNodeType("agendaNode ruleNode");
68  	    child.setData(new AgendaTreeRuleNode(agendaItem));
69  	    parent.getChildren().add(child);
70  	    
71  	    // deal with peer nodes:
72  	    if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways());
73  	    
74  	    // deal with child nodes:
75  	    if (agendaItem.getWhenTrue() != null) {
76  	        Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>();
77  	        whenTrue.setNodeLabel("When TRUE");
78  	        whenTrue.setNodeType("agendaNode logicNode whenTrueNode");
79  	        whenTrue.setData(new AgendaTreeLogicNode());
80  	        child.getChildren().add(whenTrue);
81  	        
82  	        addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue());
83  	    }
84          if (agendaItem.getWhenFalse() != null) {
85              Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>();
86              whenFalse.setNodeLabel("When FALSE");
87              whenFalse.setNodeType("agendaNode logicNode whenFalseNode");
88              whenFalse.setData(new AgendaTreeLogicNode());
89              child.getChildren().add(whenFalse);
90              
91              addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse());
92          }
93  	}
94  	
95      public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() {
96          Tree<AgendaTreeNode, String> agendaTree = new Tree<AgendaTreeNode, String>();
97  
98          Node<AgendaTreeNode, String> rootNode = new Node<AgendaTreeNode, String>();
99          agendaTree.setRootElement(rootNode);
100         
101         if (agenda != null) {
102             String firstItemId = agenda.getFirstItemId();
103             List<AgendaItemBo> items = agenda.getItems();
104             AgendaItemBo firstItem = null;
105 
106             if (items != null && firstItemId != null) {
107                 for (AgendaItemBo item : items) {
108                     if (firstItemId.equals(item.getId())) {
109                         firstItem = item;
110                         break;
111                     }
112                 }
113             }
114 
115             if (firstItem != null) addAgendaItemAndChildren(rootNode, firstItem);
116         } 
117         
118         return agendaTree;
119     }	
120 	
121 	/**
122      * @return the agendaItemLine
123      */
124     public AgendaItemBo getAgendaItemLine() {
125         return this.agendaItemLine;
126     }
127 
128     /**
129      * @param agendaItemLine the agendaItemLine to set
130      */
131     public void setAgendaItemLine(AgendaItemBo agendaItemLine) {
132         this.agendaItemLine = agendaItemLine;
133     }
134 
135     public ActionBo getAgendaItemLineRuleAction() {
136         return agendaItemLineRuleAction;
137     }
138 
139     public void setAgendaItemLineRuleAction(ActionBo actionBo) {
140         this.agendaItemLineRuleAction = actionBo;
141     }
142 
143     /**
144      * @return the selectedAgendaItemId
145      */
146     public String getSelectedAgendaItemId() {
147         return this.selectedAgendaItemId;
148     }
149 
150     /**
151      * @param selectedAgendaItemId the selectedAgendaItemId to set
152      */
153     public void setSelectedAgendaItemId(String selectedAgendaItemId) {
154         this.selectedAgendaItemId = selectedAgendaItemId;
155     }
156 
157     /**
158      * @return the cutAgendaItemId
159      */
160     public String getCutAgendaItemId() {
161         return this.cutAgendaItemId;
162     }
163 
164     /**
165      * @param cutAgendaItemId the cutAgendaItemId to set
166      */
167     public void setCutAgendaItemId(String cutAgendaItemId) {
168         this.cutAgendaItemId = cutAgendaItemId;
169     }
170 
171     /**
172 	 * @return the context
173 	 */
174 	public ContextBo getContext() {
175 		return this.context;
176 	}
177 
178 	/**
179 	 * @param context the context to set
180 	 */
181 	public void setContext(ContextBo context) {
182 		this.context = context;
183 	}
184 
185 	/**
186 	 * @return the agenda
187 	 */
188 	public AgendaBo getAgenda() {
189 		return this.agenda;
190 	}
191 
192 	/**
193 	 * @param agenda the agenda to set
194 	 */
195 	public void setAgenda(AgendaBo agenda) {
196 		this.agenda = agenda;
197 	}
198 
199     public Map<String, String> getCustomAttributesMap() {
200         return customAttributesMap;
201     }
202 
203     public void setCustomAttributesMap(Map<String, String> customAttributesMap) {
204         this.customAttributesMap = customAttributesMap;
205     }
206 
207     public Map<String, String> getCustomRuleAttributesMap() {
208         return customRuleAttributesMap;
209     }
210 
211     public void setCustomRuleAttributesMap(Map<String, String> customRuleAttributesMap) {
212         this.customRuleAttributesMap = customRuleAttributesMap;
213     }
214 
215     public Map<String, String> getCustomRuleActionAttributesMap() {
216         return customRuleActionAttributesMap;
217     }
218 
219     public void setCustomRuleActionAttributesMap(Map<String, String> customRuleActionAttributesMap) {
220         this.customRuleActionAttributesMap = customRuleActionAttributesMap;
221     }
222 
223     /**
224      * @param copyRuleName the rule name from which to copy
225      */
226     public void setCopyRuleName(String copyRuleName) {
227         this.copyRuleName = copyRuleName;
228     }
229 
230     /**
231      * @return the rule name from which to copy
232      */
233     public String getCopyRuleName() {
234         return copyRuleName;
235     }
236 
237     /**
238      * @param oldContextId the contextId that the agenda currently has (i.e. before the next context change)
239      */
240     public void setOldContextId(String oldContextId) {
241         this.oldContextId = oldContextId;
242     }
243 
244     /**
245      * @return the contextId that the agenda had before the context change
246      */
247     public String getOldContextId() {
248         return oldContextId;
249     }
250 
251     /**
252      * @return the selectedPropositionId
253      */
254     public String getSelectedPropositionId() {
255         return this.selectedPropositionId;
256     }
257 
258     /**
259      * @param selectedPropositionId the selectedPropositionId to set
260      */
261     public void setSelectedPropositionId(String selectedPropositionId) {
262         this.selectedPropositionId = selectedPropositionId;
263     }
264 
265 
266     /**
267      * @return the cutPropositionId
268      */
269     public String getCutPropositionId() {
270         return cutPropositionId;
271     }
272 
273     public String getContextName() {
274         return contextName;
275     }
276 
277     public void setContextName(String contextName) {
278         this.contextName = contextName;
279     }
280 
281     public String getNamespace() {
282         return namespace;
283     }
284 
285     public void setNamespace(String namespace) {
286         this.namespace = namespace;
287     }
288 
289     /**
290      * @param cutPropositionId the cutPropositionId to set
291      */
292     public void setCutPropositionId(String cutPropositionId) {
293         this.cutPropositionId = cutPropositionId;
294     }
295 
296     // Need to override this method since the actual persistable BO is wrapped inside dataObject.
297     @Override
298     public void refreshNonUpdateableReferences() {
299         getPersistenceService().refreshAllNonUpdatingReferences(this.getAgenda());
300     }
301 
302 }