View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.rule;
18  
19  import org.apache.commons.lang.ObjectUtils;
20  import org.hibernate.annotations.Fetch;
21  import org.hibernate.annotations.FetchMode;
22  import org.hibernate.annotations.GenericGenerator;
23  import org.hibernate.annotations.Parameter;
24  import org.kuali.rice.core.api.util.collect.CollectionUtils;
25  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
26  import org.kuali.rice.kew.rule.bo.RuleTemplateAttributeBo;
27  import org.kuali.rice.kew.service.KEWServiceLocator;
28  
29  import javax.persistence.CascadeType;
30  import javax.persistence.Column;
31  import javax.persistence.Entity;
32  import javax.persistence.FetchType;
33  import javax.persistence.GeneratedValue;
34  import javax.persistence.Id;
35  import javax.persistence.JoinColumn;
36  import javax.persistence.ManyToOne;
37  import javax.persistence.OneToMany;
38  import javax.persistence.Table;
39  import javax.persistence.Version;
40  import java.io.Serializable;
41  import java.util.ArrayList;
42  import java.util.List;
43  
44  
45  /**
46   * An extension of a {@link RuleBaseValues}.  Provides attribute-specific data
47   * extensions to the rule for a particular {@link org.kuali.rice.kew.rule.bo.RuleAttribute}.  Contains
48   * a List of {@link RuleExtensionValue}s.
49   * 
50   * @see RuleBaseValues
51   * @see org.kuali.rice.kew.rule.bo.RuleAttribute
52   * @see RuleExtensionValue
53   *
54   * @author Kuali Rice Team (rice.collab@kuali.org)
55   */
56  @Entity
57  @Table(name="KREW_RULE_EXT_T")
58  //@Sequence(name="KREW_RTE_TMPL_S", property="ruleExtensionId")
59  public class RuleExtension implements Serializable {
60  
61  	private static final long serialVersionUID = 8178135296413950516L;
62  
63  	@Id
64  	@GeneratedValue(generator="KREW_RTE_TMPL_S")
65  	@GenericGenerator(name="KREW_RTE_TMPL_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
66  			@Parameter(name="sequence_name",value="KREW_RTE_TMPL_S"),
67  			@Parameter(name="value_column",value="id")
68  	})
69  	@Column(name="RULE_EXT_ID")
70  	private String ruleExtensionId;
71  
72  	@Column(name="RULE_TMPL_ATTR_ID", insertable=false, updatable=false)
73  	private String ruleTemplateAttributeId;
74  
75  	@Column(name="RULE_ID", insertable=false, updatable=false)
76  	private String ruleBaseValuesId;
77  
78  	@Version
79  	@Column(name="VER_NBR")
80  	private Integer lockVerNbr;
81  	
82  	@ManyToOne(fetch=FetchType.EAGER)
83  	@JoinColumn(name="RULE_ID")
84  	private RuleBaseValues ruleBaseValues;
85  
86  	@ManyToOne(fetch=FetchType.EAGER)
87  	@JoinColumn(name="RULE_TMPL_ATTR_ID")
88  	private RuleTemplateAttributeBo ruleTemplateAttribute;
89  
90  	@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, mappedBy="extension")
91  	@Fetch(value = FetchMode.SELECT)
92  	private List<RuleExtensionValue> extensionValues;
93  
94  	public RuleExtension() {
95  		extensionValues = new ArrayList<RuleExtensionValue>();
96  	}
97  
98  	//@PrePersist
99      public void beforeInsert(){
100         OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
101     }
102 	
103 	public List<RuleExtensionValue> getExtensionValues() {
104 		return extensionValues;
105 	}
106 
107 	public void setExtensionValues(List<RuleExtensionValue> extensionValues) {
108 		this.extensionValues = extensionValues;
109 	}
110 
111 	public RuleTemplateAttributeBo getRuleTemplateAttribute() {
112 		return ruleTemplateAttribute;
113 	}
114 
115 	public void setRuleTemplateAttribute(RuleTemplateAttributeBo ruleTemplateAttribute) {
116 		this.ruleTemplateAttribute = ruleTemplateAttribute;
117 	}
118 
119 	public RuleExtensionValue getRuleExtensionValue(int index) {
120 		while (getExtensionValues().size() <= index) {
121 			getExtensionValues().add(new RuleExtensionValue());
122 		}
123 		return (RuleExtensionValue) getExtensionValues().get(index);
124 	}
125 
126 	public RuleBaseValues getRuleBaseValues() {
127 		return ruleBaseValues;
128 	}
129 
130 	public void setRuleBaseValues(RuleBaseValues ruleBaseValues) {
131 		this.ruleBaseValues = ruleBaseValues;
132 	}
133 
134 	public Integer getLockVerNbr() {
135 		return lockVerNbr;
136 	}
137 
138 	public void setLockVerNbr(Integer lockVerNbr) {
139 		this.lockVerNbr = lockVerNbr;
140 	}
141 
142 	public String getRuleBaseValuesId() {
143 		return ruleBaseValuesId;
144 	}
145 
146 	public void setRuleBaseValuesId(String ruleBaseValuesId) {
147 		this.ruleBaseValuesId = ruleBaseValuesId;
148 	}
149 
150 	public String getRuleExtensionId() {
151 		return ruleExtensionId;
152 	}
153 
154 	public void setRuleExtensionId(String ruleExtensionId) {
155 		this.ruleExtensionId = ruleExtensionId;
156 	}
157 
158 	public String getRuleTemplateAttributeId() {
159 		return ruleTemplateAttributeId;
160 	}
161 
162 	public void setRuleTemplateAttributeId(String ruleTemplateAttributeId) {
163 		this.ruleTemplateAttributeId = ruleTemplateAttributeId;
164 	}
165 
166     public boolean equals(Object o) {
167         if (o == null) return false;
168         if (!(o instanceof RuleExtension)) return false;
169         RuleExtension pred = (RuleExtension) o;
170         return ObjectUtils.equals(ruleBaseValues.getRuleTemplate(), pred.getRuleBaseValues().getRuleTemplate()) &&
171                ObjectUtils.equals(ruleTemplateAttribute, pred.getRuleTemplateAttribute()) &&
172                CollectionUtils.collectionsEquivalent(extensionValues, pred.getExtensionValues());
173     }
174 
175     public String toString() {
176         return "[RuleExtension:"
177                +  " ruleExtensionId=" + ruleExtensionId
178                + ", ruleTemplateAttributeId=" + ruleTemplateAttributeId
179                + ", ruleBaseValuesId=" + ruleBaseValuesId
180                + ", ruleBaseValues=" + ruleBaseValues
181                + ", ruleTemplateAttribute=" + ruleTemplateAttribute
182                + ", extensionValues=" + extensionValues
183                + ", lockVerNbr=" + lockVerNbr
184                + "]";
185     }
186 
187 }