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 */ 016package org.kuali.rice.krms.dto; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.util.tree.Tree; 020import org.kuali.rice.krad.web.form.UifFormBase; 021import org.kuali.rice.krms.api.repository.action.ActionDefinition; 022import org.kuali.rice.krms.api.repository.action.ActionDefinitionContract; 023import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition; 024import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract; 025import org.kuali.rice.krms.api.repository.proposition.PropositionType; 026import org.kuali.rice.krms.api.repository.rule.RuleDefinition; 027import org.kuali.rice.krms.api.repository.rule.RuleDefinitionContract; 028import org.kuali.rice.krms.tree.node.CompareTreeNode; 029import org.kuali.rice.krms.tree.node.RuleEditorTreeNode; 030import org.kuali.rice.krms.tree.node.TreeNode; 031import org.kuali.rice.krms.util.AlphaIterator; 032 033import java.io.Serializable; 034import java.util.ArrayList; 035import java.util.Date; 036import java.util.List; 037import java.util.Map; 038 039/** 040 * 041 * @author Kuali Student Team 042 */ 043public class RuleEditor extends UifFormBase implements RuleDefinitionContract, Serializable { 044 045 private static final long serialVersionUID = 1L; 046 047 private String key; 048 049 private String id; 050 private String namespace; 051 private String description; 052 private String name; 053 private String typeId; 054 private String propId; 055 private boolean active = true; 056 private Long versionNumber; 057 058 private List<ActionEditor> actions; 059 private Map<String, String> attributes; 060 061 private PropositionEditor proposition; 062 063 private String copyKey; 064 private String selectedKey; 065 private String cutKey; 066 private boolean dummy; 067 private boolean initialized; 068 private List<String> activeSelections; 069 070 //Edit with Logic 071 private String logicArea; 072 073 // for Rule editor display 074 private Tree<RuleEditorTreeNode, String> editTree; 075 076 // for Rule Preview display 077 private Tree<TreeNode, String> previewTree; 078 private Tree<TreeNode, String> viewTree; 079 private AlphaIterator simpleKeys; 080 private AlphaIterator compoundKeys; 081 082 // for Compare 083 private Tree<CompareTreeNode, String> compareTree; 084 085 //Rule Instruction 086 private RuleTypeInfo ruleTypeInfo; 087 private RuleEditor parent; 088 089 public RuleEditor() { 090 super(); 091 } 092 093 public RuleEditor(String key, boolean dummy, RuleTypeInfo ruleTypeInfo) { 094 this.setKey(key); 095 this.setDummy(dummy); 096 this.setTypeId(ruleTypeInfo.getId()); 097 this.setRuleTypeInfo(ruleTypeInfo); 098 } 099 100 public RuleEditor(RuleDefinitionContract definition) { 101 this.id = definition.getId(); 102 this.namespace = definition.getNamespace(); 103 this.name = definition.getName(); 104 this.description = definition.getDescription(); 105 this.typeId = definition.getTypeId(); 106 this.propId = definition.getPropId(); 107 this.active = definition.isActive(); 108 if(definition.getProposition()!=null){ 109 this.proposition = createPropositionEditor(definition.getProposition()); 110 } 111 this.versionNumber = definition.getVersionNumber(); 112 113 if(definition.getActions()!=null){ 114 this.actions = new ArrayList<ActionEditor>(); 115 for(ActionDefinitionContract action : definition.getActions()){ 116 this.actions.add(new ActionEditor(action)); 117 } 118 } else { 119 this.actions = null; 120 } 121 122 this.attributes = definition.getAttributes(); 123 124 } 125 126 public String getKey() { 127 return key; 128 } 129 130 public void setKey(String key) { 131 this.key = key; 132 } 133 134 public void setId(String id) { 135 this.id = id; 136 } 137 138 public void setDescription(String description) { 139 this.description = description; 140 } 141 142 public PropositionEditor getPropositionEditor(){ 143 return proposition; 144 } 145 146 public void setProposition(PropositionEditor proposition) { 147 this.proposition = proposition; 148 } 149 150 public void setPropId(String propId) { 151 this.propId = propId; 152 } 153 154 public void setTypeId(String typeId) { 155 this.typeId = typeId; 156 } 157 158 public void setActive(boolean active) { 159 this.active = active; 160 } 161 162 public void setName(String name) { 163 this.name = name; 164 } 165 166 public void setNamespace(String namespace) { 167 this.namespace = namespace; 168 } 169 170 public List<String> getActiveSelections() { 171 return activeSelections; 172 } 173 174 public void setActiveSelections(List<String> activeSelections) { 175 this.activeSelections = activeSelections; 176 } 177 178 public AlphaIterator getSimpleKeys() { 179 if (simpleKeys == null){ 180 simpleKeys = new AlphaIterator(StringUtils.EMPTY); 181 } 182 return simpleKeys; 183 } 184 185 public void setSimpleKeys(AlphaIterator simpleKeys) { 186 this.simpleKeys = simpleKeys; 187 } 188 189 public AlphaIterator getCompoundKeys() { 190 if (compoundKeys == null){ 191 compoundKeys = new AlphaIterator(PropositionType.COMPOUND.getCode() + "-"); 192 } 193 return compoundKeys; 194 } 195 196 public void setCompoundKeys(AlphaIterator compoundKeys) { 197 this.compoundKeys = compoundKeys; 198 } 199 200 /** 201 * @return the selectedKey 202 */ 203 public String getSelectedKey() { 204 return this.selectedKey; 205 } 206 207 /** 208 * @param selectedKey the selectedKey to set 209 */ 210 public void setSelectedKey(String selectedKey) { 211 this.selectedKey = selectedKey; 212 } 213 214 /** 215 * @return the cutKey 216 */ 217 public String getCutKey() { 218 return cutKey; 219 } 220 221 public void setCutKey(String cutKey) { 222 this.cutKey = cutKey; 223 } 224 225 public boolean isDummy() { 226 return dummy; 227 } 228 229 public void setDummy(boolean dummy) { 230 this.dummy = dummy; 231 } 232 233 public boolean isInitialized() { 234 return initialized; 235 } 236 237 public void setInitialized(boolean initialized) { 238 this.initialized = initialized; 239 } 240 241 /** 242 * @return the copyKey 243 */ 244 public String getCopyKey() { 245 return copyKey; 246 } 247 248 /** 249 * @param copyKey the copyKey to set 250 */ 251 public void setCopyKey(String copyKey) { 252 this.copyKey = copyKey; 253 } 254 255 public String getLogicArea() { 256 return logicArea; 257 } 258 259 public void setLogicArea(String logicArea) { 260 this.logicArea = logicArea; 261 } 262 263 @Override 264 public String getName() { 265 return this.name; 266 } 267 268 @Override 269 public String getDescription() { 270 return this.description; 271 } 272 273 @Override 274 public String getNamespace() { 275 return this.namespace; 276 } 277 278 @Override 279 public String getTypeId() { 280 return this.typeId; 281 } 282 283 @Override 284 public String getPropId() { 285 return this.propId; 286 } 287 288 @Override 289 public PropositionDefinitionContract getProposition() { 290 return proposition; 291 } 292 293 @Override 294 public List<? extends ActionDefinitionContract> getActions() { 295 if(this.actions==null){ 296 this.actions = new ArrayList<ActionEditor>(); 297 } 298 return actions; 299 } 300 301 public List<ActionEditor> getActionEditors() { 302 if(this.actions==null){ 303 this.actions = new ArrayList<ActionEditor>(); 304 } 305 return actions; 306 } 307 308 @Override 309 public Map<String, String> getAttributes() { 310 return null; //To change body of implemented methods use File | Settings | File Templates. 311 } 312 313 @Override 314 public String getId() { 315 return this.id; 316 } 317 318 @Override 319 public boolean isActive() { 320 return this.active; 321 } 322 323 public Tree<RuleEditorTreeNode, String> getEditTree() { 324 return editTree; 325 } 326 327 public void setEditTree(Tree<RuleEditorTreeNode, String> editTree) { 328 this.editTree = editTree; 329 } 330 331 public Tree<TreeNode, String> getPreviewTree() { 332 return previewTree; 333 } 334 335 public void setPreviewTree(Tree<TreeNode, String> previewTree) { 336 this.previewTree = previewTree; 337 } 338 339 340 public Tree<TreeNode, String> getViewTree() { 341 return viewTree; 342 } 343 344 public void setViewTree(Tree<TreeNode, String> viewTree) { 345 this.viewTree = viewTree; 346 } 347 348 349 public Tree<CompareTreeNode, String> getCompareTree() { 350 return compareTree; 351 } 352 353 public void setCompareTree(Tree<CompareTreeNode, String> compareTree) { 354 this.compareTree = compareTree; 355 } 356 357 public void setVersionNumber(Long versionNumber) { 358 this.versionNumber = versionNumber; 359 } 360 361 @Override 362 public Long getVersionNumber() { 363 return versionNumber; 364 } 365 366 protected PropositionEditor createPropositionEditor(PropositionDefinitionContract definition){ 367 return new PropositionEditor(definition); 368 } 369 370 public RuleTypeInfo getRuleTypeInfo() { 371 return ruleTypeInfo; 372 } 373 374 public void setRuleTypeInfo(RuleTypeInfo ruleTypeInfo) { 375 this.ruleTypeInfo = ruleTypeInfo; 376 } 377 378 public RuleEditor getParent() { 379 return parent; 380 } 381 382 public void setParent(RuleEditor parent) { 383 this.parent = parent; 384 } 385 386 public void reset(){ 387 this.getEditTree().setRootElement(null); 388 this.setPropId(null); 389 this.setProposition(null); 390 this.setSimpleKeys(null); 391 this.setCompoundKeys(null); 392 this.setSelectedKey(StringUtils.EMPTY); 393 } 394}