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