Coverage Report - org.kuali.rice.krms.impl.ui.EditorDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
EditorDocument
0%
0/82
0%
0/18
2.125
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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 java.util.List;
 19  
 
 20  
 import org.kuali.rice.core.util.Node;
 21  
 import org.kuali.rice.core.util.Tree;
 22  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
 23  
 import org.kuali.rice.krms.impl.repository.AgendaBo;
 24  
 import org.kuali.rice.krms.impl.repository.AgendaItemBo;
 25  
 import org.kuali.rice.krms.impl.repository.ContextBo;
 26  
 
 27  
 /**
 28  
  * BO for the KRMS agenda editor
 29  
  * 
 30  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 31  
  *
 32  
  */
 33  
 // TODO: this is not a document, rename?
 34  0
 public class EditorDocument extends PersistableBusinessObjectBase {
 35  
         
 36  
         private static final long serialVersionUID = 1L;
 37  
         
 38  
         private ContextBo context;
 39  
         private AgendaBo agenda;
 40  
         private AgendaItemBo agendaItemAddLine;
 41  
         
 42  
         private void addAgendaItemAndChildren(Node<AgendaTreeNode, String> parent, AgendaItemBo agendaItem) {
 43  0
             Node<AgendaTreeNode, String> child = new Node<AgendaTreeNode, String>();
 44  0
             child.setNodeLabel(agendaItem.getRuleText());
 45  0
             child.setNodeType("agendaNode ruleNode");
 46  0
             child.setData(new AgendaTreeRuleNode(agendaItem));
 47  0
             parent.getChildren().add(child);
 48  
             
 49  
             // deal with peer nodes:
 50  0
             if (agendaItem.getAlways() != null) addAgendaItemAndChildren(parent, agendaItem.getAlways());
 51  
             
 52  
             // deal with child nodes:
 53  0
             if (agendaItem.getWhenTrue() != null) {
 54  0
                 Node<AgendaTreeNode, String> whenTrue = new Node<AgendaTreeNode, String>();
 55  0
                 whenTrue.setNodeLabel("When TRUE");
 56  0
                 whenTrue.setNodeType("agendaNode logicNode whenTrueNode");
 57  0
                 whenTrue.setData(new AgendaTreeLogicNode());
 58  0
                 child.getChildren().add(whenTrue);
 59  
                 
 60  0
                 addAgendaItemAndChildren(whenTrue, agendaItem.getWhenTrue());
 61  
             }
 62  0
         if (agendaItem.getWhenFalse() != null) {
 63  0
             Node<AgendaTreeNode, String> whenFalse = new Node<AgendaTreeNode, String>();
 64  0
             whenFalse.setNodeLabel("When FALSE");
 65  0
             whenFalse.setNodeType("agendaNode logicNode whenFalseNode");
 66  0
             whenFalse.setData(new AgendaTreeLogicNode());
 67  0
             child.getChildren().add(whenFalse);
 68  
             
 69  0
             addAgendaItemAndChildren(whenFalse, agendaItem.getWhenFalse());
 70  
         }
 71  0
         }
 72  
         
 73  
     public Tree<? extends AgendaTreeNode, String> getAgendaRuleTree() {
 74  0
         Tree<AgendaTreeNode, String> agendaTree = new Tree<AgendaTreeNode, String>();
 75  
 
 76  0
         Node<AgendaTreeNode, String> rootNode = new Node<AgendaTreeNode, String>();
 77  0
         agendaTree.setRootElement(rootNode);
 78  
         
 79  0
         if (agenda != null) {
 80  0
             String firstItemId = agenda.getFirstItemId();
 81  0
             List<AgendaItemBo> items = agenda.getItems();
 82  0
             AgendaItemBo firstItem = null;
 83  
 
 84  0
             if (items != null && firstItemId != null) {
 85  0
                 for (AgendaItemBo item : items) {
 86  0
                     if (firstItemId.equals(item.getId())) {
 87  0
                         firstItem = item;
 88  0
                         break;
 89  
                     }
 90  
                 }
 91  
             }
 92  
 
 93  0
             if (firstItem != null) addAgendaItemAndChildren(rootNode, firstItem);
 94  0
         } else {
 95  0
             agenda = new AgendaBo();
 96  
 
 97  
             // TODO: Remove.
 98  
             // For demo purposes, populate the tree even though it's bogus.
 99  
             
 100  0
             Node<AgendaTreeNode, String> child1 = new Node<AgendaTreeNode, String>();
 101  0
             child1.setNodeLabel("Bogus Agenda Data Check -- YES, this is bogus data.");
 102  0
             child1.setNodeType("agendaNode ruleNode");
 103  0
             child1.setData(new AgendaTreeRuleNode(new AgendaItemBo()));
 104  0
             rootNode.getChildren().add(child1);
 105  
 
 106  0
             Node<AgendaTreeNode, String> whenTrue1 = new Node<AgendaTreeNode, String>();
 107  0
             whenTrue1.setNodeLabel("When TRUE");
 108  0
             whenTrue1.setNodeType("agendaNode logicNode whenTrueNode");
 109  0
             whenTrue1.setData(new AgendaTreeLogicNode());
 110  0
             child1.getChildren().add(whenTrue1);
 111  
 
 112  0
             Node<AgendaTreeNode, String> whenFalse1 = new Node<AgendaTreeNode, String>();
 113  0
             whenFalse1.setNodeLabel("When FALSE");
 114  0
             whenFalse1.setNodeType("agendaNode logicNode whenFalseNode");
 115  0
             whenFalse1.setData(new AgendaTreeLogicNode());
 116  0
             child1.getChildren().add(whenFalse1);
 117  
 
 118  0
             Node<AgendaTreeNode, String> child2 = new Node<AgendaTreeNode, String>();
 119  0
             child2.setNodeLabel("Check for Animal Facility space");
 120  0
             child2.setNodeType("agendaNode ruleNode");
 121  0
             child2.setData(new AgendaTreeRuleNode(new AgendaItemBo()));
 122  0
             whenTrue1.getChildren().add(child2);
 123  
 
 124  0
             Node<AgendaTreeNode, String> child3 = new Node<AgendaTreeNode, String>();
 125  0
             child3.setNodeLabel("Exotic animal check");
 126  0
             child3.setNodeType("agendaNode ruleNode");
 127  0
             child3.setData(new AgendaTreeRuleNode(new AgendaItemBo()));
 128  0
             whenFalse1.getChildren().add(child3);
 129  
 
 130  0
             Node<AgendaTreeNode, String> child4 = new Node<AgendaTreeNode, String>();
 131  0
             child4.setNodeLabel("Reptile escape insurance check");
 132  0
             child4.setNodeType("agendaNode ruleNode");
 133  0
             child4.setData(new AgendaTreeRuleNode(new AgendaItemBo()));
 134  0
             whenFalse1.getChildren().add(child4);
 135  
 
 136  0
             Node<AgendaTreeNode, String> child5 = new Node<AgendaTreeNode, String>();
 137  0
             child5.setNodeLabel("Alien abduction permitting check");
 138  0
             child5.setNodeType("agendaNode ruleNode");
 139  0
             child5.setData(new AgendaTreeRuleNode(new AgendaItemBo()));
 140  0
             rootNode.getChildren().add(child5);
 141  
 
 142  
         }
 143  
         
 144  0
         return agendaTree;
 145  
     }        
 146  
         
 147  
         /**
 148  
      * @return the agendaItemAddLine
 149  
      */
 150  
     public AgendaItemBo getAgendaItemAddLine() {
 151  0
         return this.agendaItemAddLine;
 152  
     }
 153  
     /**
 154  
      * @param agendaItemAddLine the agendaItemAddLine to set
 155  
      */
 156  
     public void setAgendaItemAddLine(AgendaItemBo agendaItemAddLine) {
 157  0
         this.agendaItemAddLine = agendaItemAddLine;
 158  0
     }
 159  
     /**
 160  
          * @return the context
 161  
          */
 162  
         public ContextBo getContext() {
 163  0
                 return this.context;
 164  
         }
 165  
         /**
 166  
          * @param context the context to set
 167  
          */
 168  
         public void setContext(ContextBo context) {
 169  0
                 this.context = context;
 170  0
         }
 171  
         /**
 172  
          * @return the agenda
 173  
          */
 174  
         public AgendaBo getAgenda() {
 175  0
                 return this.agenda;
 176  
         }
 177  
         /**
 178  
          * @param agenda the agenda to set
 179  
          */
 180  
         public void setAgenda(AgendaBo agenda) {
 181  0
                 this.agenda = agenda;
 182  0
         }
 183  
         
 184  
         
 185  
 }