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 | 0 | public RuleExtension() { |
94 | 0 | extensionValues = new ArrayList<RuleExtensionValue>(); |
95 | 0 | } |
96 | |
|
97 | |
@PrePersist |
98 | |
public void beforeInsert(){ |
99 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
100 | 0 | } |
101 | |
|
102 | |
public List<RuleExtensionValue> getExtensionValues() { |
103 | 0 | return extensionValues; |
104 | |
} |
105 | |
|
106 | |
public void setExtensionValues(List<RuleExtensionValue> extensionValues) { |
107 | 0 | this.extensionValues = extensionValues; |
108 | 0 | } |
109 | |
|
110 | |
public RuleTemplateAttribute getRuleTemplateAttribute() { |
111 | 0 | return ruleTemplateAttribute; |
112 | |
} |
113 | |
|
114 | |
public void setRuleTemplateAttribute(RuleTemplateAttribute ruleTemplateAttribute) { |
115 | 0 | this.ruleTemplateAttribute = ruleTemplateAttribute; |
116 | 0 | } |
117 | |
|
118 | |
public RuleExtensionValue getRuleExtensionValue(int index) { |
119 | 0 | while (getExtensionValues().size() <= index) { |
120 | 0 | getExtensionValues().add(new RuleExtensionValue()); |
121 | |
} |
122 | 0 | return (RuleExtensionValue) getExtensionValues().get(index); |
123 | |
} |
124 | |
|
125 | |
public RuleBaseValues getRuleBaseValues() { |
126 | 0 | return ruleBaseValues; |
127 | |
} |
128 | |
|
129 | |
public void setRuleBaseValues(RuleBaseValues ruleBaseValues) { |
130 | 0 | this.ruleBaseValues = ruleBaseValues; |
131 | 0 | } |
132 | |
|
133 | |
public Integer getLockVerNbr() { |
134 | 0 | return lockVerNbr; |
135 | |
} |
136 | |
|
137 | |
public void setLockVerNbr(Integer lockVerNbr) { |
138 | 0 | this.lockVerNbr = lockVerNbr; |
139 | 0 | } |
140 | |
|
141 | |
public Long getRuleBaseValuesId() { |
142 | 0 | return ruleBaseValuesId; |
143 | |
} |
144 | |
|
145 | |
public void setRuleBaseValuesId(Long ruleBaseValuesId) { |
146 | 0 | this.ruleBaseValuesId = ruleBaseValuesId; |
147 | 0 | } |
148 | |
|
149 | |
public Long getRuleExtensionId() { |
150 | 0 | return ruleExtensionId; |
151 | |
} |
152 | |
|
153 | |
public void setRuleExtensionId(Long ruleExtensionId) { |
154 | 0 | this.ruleExtensionId = ruleExtensionId; |
155 | 0 | } |
156 | |
|
157 | |
public Long getRuleTemplateAttributeId() { |
158 | 0 | return ruleTemplateAttributeId; |
159 | |
} |
160 | |
|
161 | |
public void setRuleTemplateAttributeId(Long ruleTemplateAttributeId) { |
162 | 0 | this.ruleTemplateAttributeId = ruleTemplateAttributeId; |
163 | 0 | } |
164 | |
|
165 | |
public Object copy(boolean preserveKeys) { |
166 | 0 | RuleExtension ruleExtensionClone = new RuleExtension(); |
167 | 0 | if (preserveKeys && (ruleExtensionId != null)) { |
168 | 0 | ruleExtensionClone.setRuleExtensionId(new Long(ruleExtensionId.longValue())); |
169 | |
} |
170 | 0 | if ((extensionValues != null) && !extensionValues.isEmpty()) { |
171 | 0 | List extensionValueList = new ArrayList(); |
172 | |
|
173 | 0 | for (Iterator i = extensionValues.iterator(); i.hasNext();) { |
174 | 0 | RuleExtensionValue ruleExtensionValue = (RuleExtensionValue) i.next(); |
175 | 0 | RuleExtensionValue ruleExtensionValueCopy = (RuleExtensionValue) ruleExtensionValue.copy(preserveKeys); |
176 | 0 | ruleExtensionValueCopy.setExtension(ruleExtensionClone); |
177 | 0 | extensionValueList.add(ruleExtensionValueCopy); |
178 | 0 | } |
179 | 0 | ruleExtensionClone.setExtensionValues(extensionValueList); |
180 | |
} |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | 0 | ruleExtensionClone.setRuleTemplateAttribute(getRuleTemplateAttribute()); |
186 | 0 | ruleExtensionClone.setRuleTemplateAttributeId(getRuleTemplateAttributeId()); |
187 | 0 | return ruleExtensionClone; |
188 | |
} |
189 | |
|
190 | |
public boolean equals(Object o) { |
191 | 0 | if (o == null) return false; |
192 | 0 | if (!(o instanceof RuleExtension)) return false; |
193 | 0 | RuleExtension pred = (RuleExtension) o; |
194 | 0 | 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 | 0 | 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 | |
} |