1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.rule.bo; |
18 | |
|
19 | |
import java.util.LinkedHashMap; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.persistence.Column; |
23 | |
import javax.persistence.Entity; |
24 | |
import javax.persistence.FetchType; |
25 | |
import javax.persistence.Id; |
26 | |
import javax.persistence.JoinColumn; |
27 | |
import javax.persistence.ManyToOne; |
28 | |
import javax.persistence.OneToMany; |
29 | |
import javax.persistence.Table; |
30 | |
import javax.persistence.Transient; |
31 | |
|
32 | |
import org.kuali.rice.core.jpa.annotations.Sequence; |
33 | |
import org.kuali.rice.core.reflect.ObjectDefinition; |
34 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
35 | |
import org.kuali.rice.kew.bo.KewPersistableBusinessObjectBase; |
36 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
37 | |
import org.kuali.rice.kew.rule.RuleExtension; |
38 | |
import org.kuali.rice.kew.rule.RuleValidationAttribute; |
39 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
40 | |
import org.kuali.rice.kew.rule.service.RuleAttributeService; |
41 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
42 | |
import org.kuali.rice.kew.util.KEWConstants; |
43 | |
import org.kuali.rice.kns.bo.Inactivateable; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | 0 | @Entity |
53 | |
@Table(name="KREW_RULE_TMPL_ATTR_T") |
54 | |
@Sequence(name="KREW_RTE_TMPL_S", property="ruleTemplateAttributeId") |
55 | |
public class RuleTemplateAttribute extends KewPersistableBusinessObjectBase implements Comparable<RuleTemplateAttribute>, Inactivateable { |
56 | |
|
57 | |
private static final long serialVersionUID = -3580049225424553828L; |
58 | |
@Id |
59 | |
@Column(name="RULE_TMPL_ATTR_ID") |
60 | |
private Long ruleTemplateAttributeId; |
61 | |
@Column(name="RULE_TMPL_ID", insertable=false, updatable=false) |
62 | |
private Long ruleTemplateId; |
63 | |
@Column(name="RULE_ATTR_ID", insertable=false, updatable=false) |
64 | |
private Long ruleAttributeId; |
65 | |
@Column(name="REQ_IND") |
66 | |
private Boolean required; |
67 | |
@Column(name="ACTV_IND") |
68 | |
private Boolean active; |
69 | |
@Column(name="DSPL_ORD") |
70 | |
private Integer displayOrder; |
71 | |
@Column(name="DFLT_VAL") |
72 | |
private String defaultValue; |
73 | |
|
74 | |
@ManyToOne(fetch=FetchType.EAGER) |
75 | |
@JoinColumn(name="RULE_TMPL_ID") |
76 | |
private RuleTemplate ruleTemplate; |
77 | |
@ManyToOne(fetch=FetchType.EAGER) |
78 | |
@JoinColumn(name="RULE_ATTR_ID") |
79 | |
private RuleAttribute ruleAttribute; |
80 | |
@OneToMany(mappedBy="ruleTemplateAttribute") |
81 | |
private List<RuleExtension> ruleExtensions; |
82 | |
|
83 | |
|
84 | 0 | public RuleTemplateAttribute() { |
85 | 0 | this.required = Boolean.FALSE; |
86 | 0 | this.active = Boolean.TRUE; |
87 | 0 | } |
88 | |
|
89 | |
public int compareTo(RuleTemplateAttribute ruleTemplateAttribute) { |
90 | 0 | if ((this.getDisplayOrder() != null) && (ruleTemplateAttribute.getDisplayOrder() != null)) { |
91 | 0 | return this.getDisplayOrder().compareTo(ruleTemplateAttribute.getDisplayOrder()); |
92 | |
} |
93 | 0 | return 0; |
94 | |
} |
95 | |
|
96 | |
public Object getAttribute() { |
97 | |
try { |
98 | 0 | ObjectDefinition objectDefinition = new ObjectDefinition(getRuleAttribute().getClassName(), getRuleAttribute().getServiceNamespace()); |
99 | 0 | Object attribute = GlobalResourceLoader.getObject(objectDefinition); |
100 | 0 | if (attribute == null) { |
101 | 0 | throw new WorkflowRuntimeException("Could not find attribute " + objectDefinition); |
102 | |
} |
103 | 0 | if (attribute instanceof WorkflowAttribute) { |
104 | 0 | ((WorkflowAttribute) attribute).setRequired(required.booleanValue()); |
105 | |
} |
106 | 0 | return attribute; |
107 | 0 | } catch (Exception e) { |
108 | 0 | throw new RuntimeException("Caught error attempting to load attribute class: " + getRuleAttribute().getClassName(), e); |
109 | |
} |
110 | |
} |
111 | |
|
112 | |
public boolean isWorkflowAttribute() { |
113 | |
try { |
114 | 0 | Object attributeObject = getAttribute(); |
115 | 0 | if (attributeObject == null) { |
116 | 0 | return false; |
117 | |
} |
118 | 0 | Class<?> attributeClass = attributeObject.getClass(); |
119 | 0 | return WorkflowAttribute.class.isAssignableFrom(attributeClass); |
120 | 0 | } catch (Exception e) { |
121 | 0 | throw new RuntimeException("Caught error attempting to load WorkflowAttribute class: " + getRuleAttribute().getClassName(), e); |
122 | |
} |
123 | |
} |
124 | |
|
125 | |
public boolean isRuleValidationAttribute() { |
126 | |
|
127 | 0 | return KEWConstants.RULE_VALIDATION_ATTRIBUTE_TYPE.equals(getRuleAttribute().getType()); |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public WorkflowAttribute getWorkflowAttribute() { |
136 | |
try { |
137 | 0 | ObjectDefinition objectDefinition = new ObjectDefinition(getRuleAttribute().getClassName(), getRuleAttribute().getServiceNamespace()); |
138 | 0 | WorkflowAttribute workflowAttribute = (WorkflowAttribute) GlobalResourceLoader.getResourceLoader().getObject(objectDefinition); |
139 | 0 | if (workflowAttribute == null) { |
140 | 0 | throw new WorkflowRuntimeException("Could not find workflow attribute " + objectDefinition); |
141 | |
} |
142 | 0 | workflowAttribute.setRequired(required.booleanValue()); |
143 | 0 | return workflowAttribute; |
144 | 0 | } catch (Exception e) { |
145 | 0 | throw new RuntimeException("Caught exception instantiating new " + getRuleAttribute().getClassName(), e); |
146 | |
} |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public RuleValidationAttribute getRuleValidationAttribute() { |
155 | |
try { |
156 | 0 | return (RuleValidationAttribute) getAttribute(); |
157 | 0 | } catch (Exception e) { |
158 | 0 | throw new RuntimeException("Caught exception instantiating new " + getRuleAttribute().getClassName(), e); |
159 | |
} |
160 | |
} |
161 | |
|
162 | |
public List<RuleExtension> getRuleExtensions() { |
163 | 0 | return ruleExtensions; |
164 | |
} |
165 | |
|
166 | |
public void setRuleExtensions(List<RuleExtension> ruleExtensions) { |
167 | 0 | this.ruleExtensions = ruleExtensions; |
168 | 0 | } |
169 | |
|
170 | |
public RuleAttribute getRuleAttribute() { |
171 | 0 | if (ruleAttribute == null && ruleAttributeId != null) { |
172 | 0 | ruleAttribute = ((RuleAttributeService) KEWServiceLocator.getService(KEWServiceLocator.RULE_ATTRIBUTE_SERVICE)).findByRuleAttributeId(ruleAttributeId); |
173 | |
} |
174 | 0 | return ruleAttribute; |
175 | |
} |
176 | |
|
177 | |
public void setRuleAttribute(RuleAttribute ruleAttribute) { |
178 | 0 | this.ruleAttribute = ruleAttribute; |
179 | 0 | } |
180 | |
|
181 | |
public RuleTemplate getRuleTemplate() { |
182 | 0 | return ruleTemplate; |
183 | |
} |
184 | |
|
185 | |
public void setRuleTemplate(RuleTemplate ruleTemplate) { |
186 | 0 | this.ruleTemplate = ruleTemplate; |
187 | 0 | } |
188 | |
|
189 | |
public String getDefaultValue() { |
190 | 0 | return defaultValue; |
191 | |
} |
192 | |
|
193 | |
public void setDefaultValue(String defaultValue) { |
194 | 0 | this.defaultValue = defaultValue; |
195 | 0 | } |
196 | |
|
197 | |
public Integer getDisplayOrder() { |
198 | 0 | return displayOrder; |
199 | |
} |
200 | |
|
201 | |
public void setDisplayOrder(Integer displayOrder) { |
202 | 0 | this.displayOrder = displayOrder; |
203 | 0 | } |
204 | |
|
205 | |
public boolean isRequired() { |
206 | 0 | return (getRequired() == null) || (getRequired().booleanValue()); |
207 | |
} |
208 | |
|
209 | |
public Boolean getRequired() { |
210 | 0 | return required; |
211 | |
} |
212 | |
|
213 | |
public void setRequired(Boolean required) { |
214 | 0 | this.required = required; |
215 | 0 | } |
216 | |
|
217 | |
public boolean isActive() { |
218 | 0 | return (getActive() == null) || (getActive().booleanValue()); |
219 | |
} |
220 | |
|
221 | |
public Boolean getActive() { |
222 | 0 | return active; |
223 | |
} |
224 | |
|
225 | |
public void setActive(Boolean active) { |
226 | 0 | this.active = active; |
227 | 0 | } |
228 | |
|
229 | |
public void setActive(boolean active) { |
230 | 0 | this.active = active; |
231 | 0 | } |
232 | |
|
233 | |
public Long getRuleAttributeId() { |
234 | 0 | return ruleAttributeId; |
235 | |
} |
236 | |
|
237 | |
public void setRuleAttributeId(Long ruleAttributeId) { |
238 | 0 | this.ruleAttributeId = ruleAttributeId; |
239 | 0 | } |
240 | |
|
241 | |
public Long getRuleTemplateAttributeId() { |
242 | 0 | return ruleTemplateAttributeId; |
243 | |
} |
244 | |
|
245 | |
public void setRuleTemplateAttributeId(Long ruleTemplateAttributeId) { |
246 | 0 | this.ruleTemplateAttributeId = ruleTemplateAttributeId; |
247 | 0 | } |
248 | |
|
249 | |
public Long getRuleTemplateId() { |
250 | 0 | return ruleTemplateId; |
251 | |
} |
252 | |
|
253 | |
public void setRuleTemplateId(Long ruleTemplateId) { |
254 | 0 | this.ruleTemplateId = ruleTemplateId; |
255 | 0 | } |
256 | |
|
257 | |
public Object copy(boolean preserveKeys) { |
258 | 0 | RuleTemplateAttribute ruleTemplateAttributeClone = new RuleTemplateAttribute(); |
259 | 0 | if (defaultValue != null) { |
260 | 0 | ruleTemplateAttributeClone.setDefaultValue(new String(defaultValue)); |
261 | |
} |
262 | 0 | if (displayOrder != null) { |
263 | 0 | ruleTemplateAttributeClone.setDisplayOrder(new Integer(displayOrder.intValue())); |
264 | |
} |
265 | 0 | if (required != null) { |
266 | 0 | ruleTemplateAttributeClone.setRequired(new Boolean(required.booleanValue())); |
267 | |
} |
268 | 0 | if (active != null) { |
269 | 0 | ruleTemplateAttributeClone.setActive(Boolean.valueOf(active.booleanValue())); |
270 | |
} |
271 | 0 | if (ruleAttribute != null) { |
272 | 0 | ruleTemplateAttributeClone.setRuleAttribute((RuleAttribute) ruleAttribute.copy(preserveKeys)); |
273 | |
} |
274 | 0 | if (preserveKeys && ruleTemplateAttributeId != null) { |
275 | 0 | ruleTemplateAttributeClone.setRuleTemplateAttributeId(new Long(ruleTemplateAttributeId.longValue())); |
276 | |
} |
277 | 0 | return ruleTemplateAttributeClone; |
278 | |
} |
279 | |
|
280 | |
@Override |
281 | |
protected LinkedHashMap<String, Object> toStringMapper() { |
282 | 0 | LinkedHashMap<String, Object> propMap = new LinkedHashMap<String, Object>(); |
283 | 0 | propMap.put("ruleTemplateAttributeId", getRuleTemplateAttributeId()); |
284 | 0 | propMap.put("ruleTemplateId", getRuleTemplateId()); |
285 | 0 | propMap.put("ruleAttributeId", getRuleAttributeId()); |
286 | 0 | propMap.put("required", getRequired()); |
287 | 0 | propMap.put("active", getActive()); |
288 | 0 | propMap.put("displayOrder", getDisplayOrder()); |
289 | 0 | propMap.put("defaultValue", getDefaultValue()); |
290 | 0 | return propMap; |
291 | |
} |
292 | |
|
293 | |
} |