Coverage Report - org.kuali.rice.kew.engine.node.Branch
 
Classes in this File Line Coverage Branch Coverage Complexity
Branch
0%
0/42
0%
0/8
1.238
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.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/ecl2.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.kew.engine.node;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import javax.persistence.CascadeType;
 24  
 import javax.persistence.Column;
 25  
 import javax.persistence.Entity;
 26  
 import javax.persistence.FetchType;
 27  
 import javax.persistence.GeneratedValue;
 28  
 import javax.persistence.Id;
 29  
 import javax.persistence.JoinColumn;
 30  
 import javax.persistence.ManyToOne;
 31  
 import javax.persistence.OneToMany;
 32  
 import javax.persistence.OneToOne;
 33  
 import javax.persistence.Table;
 34  
 import javax.persistence.Version;
 35  
 
 36  
 import org.hibernate.annotations.Fetch;
 37  
 import org.hibernate.annotations.FetchMode;
 38  
 import org.hibernate.annotations.GenericGenerator;
 39  
 import org.hibernate.annotations.Parameter;
 40  
 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
 41  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 42  
 
 43  
 /**
 44  
  * Represents a branch in the routing path of the document.
 45  
  * 
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  */
 48  
 @Entity
 49  
 //@Sequence(name="KREW_RTE_NODE_S",property="branchId")
 50  
 @Table(name="KREW_RTE_BRCH_T")
 51  0
 public class Branch implements Serializable {
 52  
 
 53  
         private static final long serialVersionUID = 7164561979112939112L;
 54  
         
 55  
         @Id
 56  
         @GeneratedValue(generator="KREW_RTE_NODE_S")
 57  
         @GenericGenerator(name="KREW_RTE_NODE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
 58  
                         @Parameter(name="sequence_name",value="KREW_RTE_NODE_S"),
 59  
                         @Parameter(name="value_column",value="id")
 60  
         })
 61  
         @Column(name="RTE_BRCH_ID")
 62  
         private String branchId;
 63  
         @ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.PERSIST)
 64  
         @JoinColumn(name="PARNT_ID")
 65  
         private Branch parentBranch;
 66  
         @Column(name="NM")
 67  
         private String name;
 68  0
     @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST,CascadeType.MERGE}, mappedBy="branch", orphanRemoval=true)
 69  
     @Fetch(value=FetchMode.SELECT)
 70  
         private List<BranchState> branchState = new ArrayList<BranchState>();
 71  
 //          apache lazy list commented out due to not being serializable
 72  
 //    private List branchState = ListUtils.lazyList(new ArrayList(),
 73  
 //            new Factory() {
 74  
 //                                public Object create() {
 75  
 //                                        return new BranchState();
 76  
 //                                }
 77  
 //                        });
 78  
     @OneToOne(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST})
 79  
         @JoinColumn(name="INIT_RTE_NODE_INSTN_ID")
 80  
         private RouteNodeInstance initialNode;
 81  
     @ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.PERSIST)
 82  
         @JoinColumn(name="SPLT_RTE_NODE_INSTN_ID")
 83  
         private RouteNodeInstance splitNode;
 84  
         @ManyToOne(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST,CascadeType.MERGE})
 85  
         @JoinColumn(name="JOIN_RTE_NODE_INSTN_ID")
 86  
         private RouteNodeInstance joinNode;
 87  
                 
 88  
         @Version
 89  
         @Column(name="VER_NBR")
 90  
         private Integer lockVerNbr;
 91  
         
 92  
         public String getName() {
 93  0
                 return name;
 94  
         }
 95  
         
 96  
         public void setName(String name) {
 97  0
                 this.name = name;        
 98  0
         }
 99  
         
 100  
     public RouteNodeInstance getSplitNode() {
 101  0
         return splitNode;
 102  
     }
 103  
     public void setSplitNode(RouteNodeInstance splitNode) {
 104  0
         this.splitNode = splitNode;
 105  0
     }
 106  
     public RouteNodeInstance getInitialNode() {
 107  0
                 return initialNode;
 108  
         }
 109  
         public void setInitialNode(RouteNodeInstance activeNode) {
 110  0
                 this.initialNode = activeNode;
 111  0
         }
 112  
         public String getBranchId() {
 113  0
                 return branchId;
 114  
         }
 115  
         public void setBranchId(String branchId) {
 116  0
                 this.branchId = branchId;
 117  0
         }
 118  
         public RouteNodeInstance getJoinNode() {
 119  0
                 return joinNode;
 120  
         }
 121  
         public void setJoinNode(RouteNodeInstance joinNode) {
 122  0
                 this.joinNode = joinNode;
 123  0
         }
 124  
         public Branch getParentBranch() {
 125  0
                 return parentBranch;
 126  
         }
 127  
         public void setParentBranch(Branch parentBranch) {
 128  0
                 this.parentBranch = parentBranch;
 129  0
         }
 130  
     public BranchState getBranchState(String key) {
 131  0
         for (Iterator iter = branchState.iterator(); iter.hasNext();) {
 132  0
             BranchState branchState = (BranchState) iter.next();
 133  0
             if (branchState.getKey().equals(key)) {
 134  0
                 return branchState;
 135  
             }
 136  0
         }
 137  0
         return null;
 138  
     }
 139  
     public void addBranchState(BranchState state) {
 140  0
         branchState.add(state);
 141  0
         state.setBranch(this);
 142  0
     }
 143  
     public List<BranchState> getBranchState() {
 144  0
         return branchState;
 145  
     }
 146  
     public void setBranchState(List<BranchState> branchState) {
 147  0
         this.branchState.clear();
 148  0
         this.branchState.addAll(branchState);
 149  
             //this.branchState = branchState;
 150  0
     }
 151  
     
 152  
     public BranchState getDocBranchState(int index){
 153  0
             while (branchState.size() <= index) {
 154  0
             branchState.add(new BranchState());
 155  
         }
 156  0
         return (BranchState) branchState.get(index);
 157  
    
 158  
     }
 159  
     
 160  
         public Integer getLockVerNbr() {
 161  0
         return lockVerNbr;
 162  
     }
 163  
     public void setLockVerNbr(Integer lockVerNbr) {
 164  0
         this.lockVerNbr = lockVerNbr;
 165  0
     }
 166  
 
 167  
     public String toString() {
 168  0
         return "[Branch: branchId=" + branchId +
 169  
                       ", parentBranch=" + (parentBranch == null ? "null" : parentBranch.getBranchId()) +
 170  
                       "]";
 171  
     }
 172  
 
 173  
         //@PrePersist
 174  
     public void beforeInsert(){
 175  0
             OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
 176  0
     }    
 177  
 }
 178