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