View Javadoc

1   /**
2    * Copyright 2005-2015 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  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      @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  		return name;
94  	}
95  	
96  	public void setName(String name) {
97  		this.name = name;	
98  	}
99  	
100     public RouteNodeInstance getSplitNode() {
101         return splitNode;
102     }
103     public void setSplitNode(RouteNodeInstance splitNode) {
104         this.splitNode = splitNode;
105     }
106     public RouteNodeInstance getInitialNode() {
107 		return initialNode;
108 	}
109 	public void setInitialNode(RouteNodeInstance activeNode) {
110 		this.initialNode = activeNode;
111 	}
112 	public String getBranchId() {
113 		return branchId;
114 	}
115 	public void setBranchId(String branchId) {
116 		this.branchId = branchId;
117 	}
118 	public RouteNodeInstance getJoinNode() {
119 		return joinNode;
120 	}
121 	public void setJoinNode(RouteNodeInstance joinNode) {
122 		this.joinNode = joinNode;
123 	}
124 	public Branch getParentBranch() {
125 		return parentBranch;
126 	}
127 	public void setParentBranch(Branch parentBranch) {
128 		this.parentBranch = parentBranch;
129 	}
130     public BranchState getBranchState(String key) {
131         for (Iterator iter = branchState.iterator(); iter.hasNext();) {
132             BranchState branchState = (BranchState) iter.next();
133             if (branchState.getKey().equals(key)) {
134                 return branchState;
135             }
136         }
137         return null;
138     }
139     public void addBranchState(BranchState state) {
140         branchState.add(state);
141         state.setBranch(this);
142     }
143     public List<BranchState> getBranchState() {
144         return branchState;
145     }
146     public void setBranchState(List<BranchState> branchState) {
147         this.branchState.clear();
148         this.branchState.addAll(branchState);
149     	//this.branchState = branchState;
150     }
151     
152     public BranchState getDocBranchState(int index){
153     	while (branchState.size() <= index) {
154             branchState.add(new BranchState());
155         }
156         return (BranchState) branchState.get(index);
157    
158     }
159     
160 	public Integer getLockVerNbr() {
161         return lockVerNbr;
162     }
163     public void setLockVerNbr(Integer lockVerNbr) {
164         this.lockVerNbr = lockVerNbr;
165     }
166 
167     public String toString() {
168         return "[Branch: branchId=" + branchId +
169                       ", parentBranch=" + (parentBranch == null ? "null" : parentBranch.getBranchId()) +
170                       "]";
171     }
172 
173 	//@PrePersist
174     public void beforeInsert(){
175     	OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
176     }    
177 }
178