1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.rule;
18
19 import javax.persistence.GeneratedValue;
20 import javax.persistence.GenerationType;
21 import javax.persistence.OneToMany;
22 import javax.persistence.JoinColumn;
23 import javax.persistence.FetchType;
24 import javax.persistence.ManyToOne;
25 import javax.persistence.PrePersist;
26 import javax.persistence.SequenceGenerator;
27 import javax.persistence.Transient;
28 import javax.persistence.Version;
29 import javax.persistence.Column;
30 import javax.persistence.Id;
31 import javax.persistence.CascadeType;
32 import javax.persistence.Table;
33 import javax.persistence.Entity;
34
35 import org.kuali.rice.core.jpa.annotations.Sequence;
36 import org.kuali.rice.core.util.OrmUtils;
37 import org.kuali.rice.kew.bo.WorkflowPersistable;
38 import org.kuali.rice.kew.rule.bo.RuleAttribute;
39 import org.kuali.rice.kew.rule.bo.RuleTemplateAttribute;
40 import org.kuali.rice.kew.service.KEWServiceLocator;
41 import org.kuali.rice.kew.util.Utilities;
42 import org.kuali.rice.kns.util.Guid;
43
44 import java.util.ArrayList;
45 import java.util.Iterator;
46 import java.util.List;
47
48
49
50
51
52
53
54
55
56
57
58
59
60 @Entity
61 @Table(name="KREW_RULE_EXT_T")
62 @Sequence(name="KREW_RTE_TMPL_S", property="ruleExtensionId")
63 public class RuleExtension implements WorkflowPersistable {
64
65 private static final long serialVersionUID = 8178135296413950516L;
66
67 @Id
68 @Column(name="RULE_EXT_ID")
69 private Long ruleExtensionId;
70
71 @Column(name="RULE_TMPL_ATTR_ID", insertable=false, updatable=false)
72 private Long ruleTemplateAttributeId;
73
74 @Column(name="RULE_ID", insertable=false, updatable=false)
75 private Long ruleBaseValuesId;
76
77 @Version
78 @Column(name="VER_NBR")
79 private Integer lockVerNbr;
80
81 @ManyToOne(fetch=FetchType.EAGER)
82 @JoinColumn(name="RULE_ID")
83 private RuleBaseValues ruleBaseValues;
84
85 @ManyToOne(fetch=FetchType.EAGER)
86 @JoinColumn(name="RULE_TMPL_ATTR_ID")
87 private RuleTemplateAttribute ruleTemplateAttribute;
88
89 @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE},
90 mappedBy="extension")
91 private List<RuleExtensionValue> extensionValues;
92
93 public RuleExtension() {
94 extensionValues = new ArrayList<RuleExtensionValue>();
95 }
96
97 @PrePersist
98 public void beforeInsert(){
99 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
100 }
101
102 public List<RuleExtensionValue> getExtensionValues() {
103 return extensionValues;
104 }
105
106 public void setExtensionValues(List<RuleExtensionValue> extensionValues) {
107 this.extensionValues = extensionValues;
108 }
109
110 public RuleTemplateAttribute getRuleTemplateAttribute() {
111 return ruleTemplateAttribute;
112 }
113
114 public void setRuleTemplateAttribute(RuleTemplateAttribute ruleTemplateAttribute) {
115 this.ruleTemplateAttribute = ruleTemplateAttribute;
116 }
117
118 public RuleExtensionValue getRuleExtensionValue(int index) {
119 while (getExtensionValues().size() <= index) {
120 getExtensionValues().add(new RuleExtensionValue());
121 }
122 return (RuleExtensionValue) getExtensionValues().get(index);
123 }
124
125 public RuleBaseValues getRuleBaseValues() {
126 return ruleBaseValues;
127 }
128
129 public void setRuleBaseValues(RuleBaseValues ruleBaseValues) {
130 this.ruleBaseValues = ruleBaseValues;
131 }
132
133 public Integer getLockVerNbr() {
134 return lockVerNbr;
135 }
136
137 public void setLockVerNbr(Integer lockVerNbr) {
138 this.lockVerNbr = lockVerNbr;
139 }
140
141 public Long getRuleBaseValuesId() {
142 return ruleBaseValuesId;
143 }
144
145 public void setRuleBaseValuesId(Long ruleBaseValuesId) {
146 this.ruleBaseValuesId = ruleBaseValuesId;
147 }
148
149 public Long getRuleExtensionId() {
150 return ruleExtensionId;
151 }
152
153 public void setRuleExtensionId(Long ruleExtensionId) {
154 this.ruleExtensionId = ruleExtensionId;
155 }
156
157 public Long getRuleTemplateAttributeId() {
158 return ruleTemplateAttributeId;
159 }
160
161 public void setRuleTemplateAttributeId(Long ruleTemplateAttributeId) {
162 this.ruleTemplateAttributeId = ruleTemplateAttributeId;
163 }
164
165 public Object copy(boolean preserveKeys) {
166 RuleExtension ruleExtensionClone = new RuleExtension();
167 if (preserveKeys && (ruleExtensionId != null)) {
168 ruleExtensionClone.setRuleExtensionId(new Long(ruleExtensionId.longValue()));
169 }
170 if ((extensionValues != null) && !extensionValues.isEmpty()) {
171 List extensionValueList = new ArrayList();
172
173 for (Iterator i = extensionValues.iterator(); i.hasNext();) {
174 RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) i.next();
175 RuleExtensionValue ruleExtensionValueCopy = (RuleExtensionValue) ruleExtensionValue.copy(preserveKeys);
176 ruleExtensionValueCopy.setExtension(ruleExtensionClone);
177 extensionValueList.add(ruleExtensionValueCopy);
178 }
179 ruleExtensionClone.setExtensionValues(extensionValueList);
180 }
181
182
183
184
185 ruleExtensionClone.setRuleTemplateAttribute(getRuleTemplateAttribute());
186 ruleExtensionClone.setRuleTemplateAttributeId(getRuleTemplateAttributeId());
187 return ruleExtensionClone;
188 }
189
190 public boolean equals(Object o) {
191 if (o == null) return false;
192 if (!(o instanceof RuleExtension)) return false;
193 RuleExtension pred = (RuleExtension) o;
194 return Utilities.equals(ruleBaseValues.getRuleTemplate(), pred.getRuleBaseValues().getRuleTemplate()) &&
195 Utilities.equals(ruleTemplateAttribute, pred.getRuleTemplateAttribute()) &&
196 Utilities.collectionsEquivalent(extensionValues, pred.getExtensionValues());
197 }
198
199 public String toString() {
200 return "[RuleExtension:"
201 + " ruleExtensionId=" + ruleExtensionId
202 + ", ruleTemplateAttributeId=" + ruleTemplateAttributeId
203 + ", ruleBaseValuesId=" + ruleBaseValuesId
204 + ", ruleBaseValues=" + ruleBaseValues
205 + ", ruleTemplateAttribute=" + ruleTemplateAttribute
206 + ", extensionValues=" + extensionValues
207 + ", lockVerNbr=" + lockVerNbr
208 + "]";
209 }
210
211 }