001 /** 002 * Copyright 2005-2013 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 */ 016 package org.kuali.rice.krms.impl.ui; 017 018 import org.kuali.rice.core.api.util.tree.Node; 019 import org.kuali.rice.core.api.util.tree.Tree; 020 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 021 import org.kuali.rice.krms.impl.repository.ActionBo; 022 import org.kuali.rice.krms.impl.repository.AgendaBo; 023 import org.kuali.rice.krms.impl.repository.AgendaItemBo; 024 import org.kuali.rice.krms.impl.repository.ContextBo; 025 026 import java.util.HashMap; 027 import java.util.List; 028 import 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 */ 036 public 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 Map<String, String> customAttributesMap = new HashMap<String, String>(); 055 private Map<String, String> customRuleAttributesMap = new HashMap<String, String>(); 056 private Map<String, String> customRuleActionAttributesMap = new HashMap<String, String>(); 057 058 public AgendaEditor() { 059 agenda = new AgendaBo(); 060 // ToDo: Determine proper default values of agenda's typeId 061 agenda.setTypeId(""); 062 agendaItemLine = new AgendaItemBo(); 063 agendaItemLineRuleAction = new ActionBo(); 064 } 065 066 private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) { 067 Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>(); 068 child.setNodeLabel(agendaItem.getRuleText()); 069 child.setNodeType("agendaNode ruleNode"); 070 child.setData(new AgendaTreeRuleNode(agendaItem)); 071 parent.getChildren().add(child); 072 073 // deal with peer nodes: 074 if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways()); 075 076 // deal with child nodes: 077 if (agendaItem.getWhenTrue() != null) { 078 Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>(); 079 whenTrue.setNodeLabel("When TRUE"); 080 whenTrue.setNodeType("agendaNode logicNode whenTrueNode"); 081 whenTrue.setData(new AgendaTreeLogicNode()); 082 child.getChildren().add(whenTrue); 083 084 addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue()); 085 } 086 if (agendaItem.getWhenFalse() != null) { 087 Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>(); 088 whenFalse.setNodeLabel("When FALSE"); 089 whenFalse.setNodeType("agendaNode logicNode whenFalseNode"); 090 whenFalse.setData(new AgendaTreeLogicNode()); 091 child.getChildren().add(whenFalse); 092 093 addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse()); 094 } 095 } 096 097 public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() { 098 Tree<AgendaTreeNode, String> agendaTree = new Tree<AgendaTreeNode, String>(); 099 100 Node<AgendaTreeNode, String> rootNode = new Node<AgendaTreeNode, String>(); 101 agendaTree.setRootElement(rootNode); 102 103 if (agenda != null) { 104 String firstItemId = agenda.getFirstItemId(); 105 List<AgendaItemBo> items = agenda.getItems(); 106 AgendaItemBo firstItem = null; 107 108 if (items != null && firstItemId != null) { 109 for (AgendaItemBo item : items) { 110 if (firstItemId.equals(item.getId())) { 111 firstItem = item; 112 break; 113 } 114 } 115 } 116 117 if (firstItem != null) addAgendaItemAndChildren(rootNode, firstItem); 118 } 119 120 return agendaTree; 121 } 122 123 /** 124 * @return the agendaItemLine 125 */ 126 public AgendaItemBo getAgendaItemLine() { 127 return this.agendaItemLine; 128 } 129 130 /** 131 * @param agendaItemLine the agendaItemLine to set 132 */ 133 public void setAgendaItemLine(AgendaItemBo agendaItemLine) { 134 this.agendaItemLine = agendaItemLine; 135 } 136 137 public ActionBo getAgendaItemLineRuleAction() { 138 return agendaItemLineRuleAction; 139 } 140 141 public void setAgendaItemLineRuleAction(ActionBo actionBo) { 142 this.agendaItemLineRuleAction = actionBo; 143 } 144 145 /** 146 * @return the selectedAgendaItemId 147 */ 148 public String getSelectedAgendaItemId() { 149 return this.selectedAgendaItemId; 150 } 151 152 /** 153 * @param selectedAgendaItemId the selectedAgendaItemId to set 154 */ 155 public void setSelectedAgendaItemId(String selectedAgendaItemId) { 156 this.selectedAgendaItemId = selectedAgendaItemId; 157 } 158 159 /** 160 * @return the cutAgendaItemId 161 */ 162 public String getCutAgendaItemId() { 163 return this.cutAgendaItemId; 164 } 165 166 /** 167 * @param cutAgendaItemId the cutAgendaItemId to set 168 */ 169 public void setCutAgendaItemId(String cutAgendaItemId) { 170 this.cutAgendaItemId = cutAgendaItemId; 171 } 172 173 /** 174 * @return the context 175 */ 176 public ContextBo getContext() { 177 return this.context; 178 } 179 180 /** 181 * @param context the context to set 182 */ 183 public void setContext(ContextBo context) { 184 this.context = context; 185 } 186 187 /** 188 * @return the agenda 189 */ 190 public AgendaBo getAgenda() { 191 return this.agenda; 192 } 193 194 /** 195 * @param agenda the agenda to set 196 */ 197 public void setAgenda(AgendaBo agenda) { 198 this.agenda = agenda; 199 } 200 201 public Map<String, String> getCustomAttributesMap() { 202 return customAttributesMap; 203 } 204 205 public void setCustomAttributesMap(Map<String, String> customAttributesMap) { 206 this.customAttributesMap = customAttributesMap; 207 } 208 209 public Map<String, String> getCustomRuleAttributesMap() { 210 return customRuleAttributesMap; 211 } 212 213 public void setCustomRuleAttributesMap(Map<String, String> customRuleAttributesMap) { 214 this.customRuleAttributesMap = customRuleAttributesMap; 215 } 216 217 public Map<String, String> getCustomRuleActionAttributesMap() { 218 return customRuleActionAttributesMap; 219 } 220 221 public void setCustomRuleActionAttributesMap(Map<String, String> customRuleActionAttributesMap) { 222 this.customRuleActionAttributesMap = customRuleActionAttributesMap; 223 } 224 225 /** 226 * @param copyRuleName the rule name from which to copy 227 */ 228 public void setCopyRuleName(String copyRuleName) { 229 this.copyRuleName = copyRuleName; 230 } 231 232 /** 233 * @return the rule name from which to copy 234 */ 235 public String getCopyRuleName() { 236 return copyRuleName; 237 } 238 239 /** 240 * @param oldContextId the contextId that the agenda currently has (i.e. before the next context change) 241 */ 242 public void setOldContextId(String oldContextId) { 243 this.oldContextId = oldContextId; 244 } 245 246 /** 247 * @return the contextId that the agenda had before the context change 248 */ 249 public String getOldContextId() { 250 return oldContextId; 251 } 252 253 /** 254 * @return the selectedPropositionId 255 */ 256 public String getSelectedPropositionId() { 257 return this.selectedPropositionId; 258 } 259 260 /** 261 * @param selectedPropositionId the selectedPropositionId to set 262 */ 263 public void setSelectedPropositionId(String selectedPropositionId) { 264 this.selectedPropositionId = selectedPropositionId; 265 } 266 267 268 /** 269 * @return the cutPropositionId 270 */ 271 public String getCutPropositionId() { 272 return cutPropositionId; 273 } 274 275 public String getContextName() { 276 return contextName; 277 } 278 279 public void setContextName(String contextName) { 280 this.contextName = contextName; 281 } 282 283 public String getNamespace() { 284 return namespace; 285 } 286 287 public void setNamespace(String namespace) { 288 this.namespace = namespace; 289 } 290 291 public String getRuleEditorMessage() { 292 return this.ruleEditorMessage; 293 } 294 295 public void setRuleEditorMessage(String message) { 296 this.ruleEditorMessage = message; 297 } 298 299 public boolean isAddRuleInProgress() { 300 return addRuleInProgress; 301 } 302 303 public void setAddRuleInProgress(boolean addRuleInProgress) { 304 this.addRuleInProgress = addRuleInProgress; 305 } 306 307 /** 308 * @param cutPropositionId the cutPropositionId to set 309 */ 310 public void setCutPropositionId(String cutPropositionId) { 311 this.cutPropositionId = cutPropositionId; 312 } 313 314 // Need to override this method since the actual persistable BO is wrapped inside dataObject. 315 @Override 316 public void refreshNonUpdateableReferences() { 317 getPersistenceService().refreshAllNonUpdatingReferences(this.getAgenda()); 318 } 319 320 }