001/** 002 * Copyright 2005-2016 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.impl.ui; 017 018import org.kuali.rice.core.api.util.tree.Node; 019import org.kuali.rice.core.api.util.tree.Tree; 020import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 021import org.kuali.rice.krms.impl.repository.ActionBo; 022import org.kuali.rice.krms.impl.repository.AgendaBo; 023import org.kuali.rice.krms.impl.repository.AgendaItemBo; 024import org.kuali.rice.krms.impl.repository.ContextBo; 025 026import java.util.HashMap; 027import java.util.List; 028import java.util.Map; 029 030/** 031 * synthetic (not directly persisted) BO for the KRMS agenda editor 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 * 035 */ 036public class AgendaEditor extends PersistableBusinessObjectBase { 037 038 private static final long serialVersionUID = 1L; 039 040 private ContextBo context; 041 private String namespace; 042 private AgendaBo agenda; 043 private String contextName; 044 private AgendaItemBo agendaItemLine; 045 private ActionBo agendaItemLineRuleAction; 046 private String selectedAgendaItemId; 047 private String cutAgendaItemId; 048 private String selectedPropositionId; 049 private String cutPropositionId; 050 private String copyRuleName; 051 private String oldContextId; 052 private String ruleEditorMessage; 053 private boolean addRuleInProgress = false; 054 private boolean disableButtons = false; 055 private Map<String, String> customAttributesMap = new HashMap<String, String>(); 056 private Map<String, String> customRuleAttributesMap = new HashMap<String, String>(); 057 private Map<String, String> customRuleActionAttributesMap = new HashMap<String, String>(); 058 059 public AgendaEditor() { 060 agenda = new AgendaBo(); 061 // ToDo: Determine proper default values of agenda's typeId 062 agenda.setTypeId(""); 063 agendaItemLine = new AgendaItemBo(); 064 agendaItemLineRuleAction = new ActionBo(); 065 } 066 067 private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) { 068 Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>(); 069 child.setNodeLabel(agendaItem.getRuleText()); 070 child.setNodeType("agendaNode ruleNode"); 071 child.setData(new AgendaTreeRuleNode(agendaItem)); 072 parent.getChildren().add(child); 073 074 // deal with peer nodes: 075 if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways()); 076 077 // deal with child nodes: 078 if (agendaItem.getWhenTrue() != null) { 079 Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>(); 080 whenTrue.setNodeLabel("When TRUE"); 081 whenTrue.setNodeType("agendaNode logicNode whenTrueNode"); 082 whenTrue.setData(new AgendaTreeLogicNode()); 083 child.getChildren().add(whenTrue); 084 085 addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue()); 086 } 087 if (agendaItem.getWhenFalse() != null) { 088 Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>(); 089 whenFalse.setNodeLabel("When FALSE"); 090 whenFalse.setNodeType("agendaNode logicNode whenFalseNode"); 091 whenFalse.setData(new AgendaTreeLogicNode()); 092 child.getChildren().add(whenFalse); 093 094 addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse()); 095 } 096 } 097 098 public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() { 099 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 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 /** 339 * @see org.kuali.rice.krad.bo.BusinessObject#refresh() 340 */ 341 @Override 342 public void refresh() { 343 getPersistenceService().retrieveNonKeyFields(this.getAgenda()); 344 } 345}