1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.rule.dao.impl; |
18 | |
|
19 | |
import java.sql.PreparedStatement; |
20 | |
import java.sql.ResultSet; |
21 | |
import java.sql.Timestamp; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Date; |
25 | |
import java.util.HashSet; |
26 | |
import java.util.Iterator; |
27 | |
import java.util.List; |
28 | |
import java.util.Map; |
29 | |
import java.util.Set; |
30 | |
|
31 | |
import org.apache.commons.lang.StringUtils; |
32 | |
import org.apache.ojb.broker.PersistenceBroker; |
33 | |
import org.apache.ojb.broker.query.Criteria; |
34 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
35 | |
import org.apache.ojb.broker.query.QueryFactory; |
36 | |
import org.apache.ojb.broker.query.ReportQueryByCriteria; |
37 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
38 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
39 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
40 | |
import org.kuali.rice.kew.rule.RuleExtension; |
41 | |
import org.kuali.rice.kew.rule.RuleResponsibility; |
42 | |
import org.kuali.rice.kew.rule.dao.RuleDAO; |
43 | |
import org.kuali.rice.kew.util.KEWConstants; |
44 | |
import org.kuali.rice.kim.api.entity.principal.Principal; |
45 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
46 | |
|
47 | |
import org.springmodules.orm.ojb.PersistenceBrokerCallback; |
48 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
49 | |
|
50 | |
|
51 | 0 | public class RuleDAOOjbImpl extends PersistenceBrokerDaoSupport implements RuleDAO { |
52 | |
|
53 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RuleDAOOjbImpl.class); |
54 | |
|
55 | |
private static final String OLD_DELEGATIONS_SQL = |
56 | |
"select oldDel.dlgn_rule_id "+ |
57 | |
"from krew_rule_rsp_t oldRsp, krew_dlgn_rsp_t oldDel "+ |
58 | |
"where oldRsp.rule_id=? and "+ |
59 | |
"oldRsp.rule_rsp_id=oldDel.rule_rsp_id and "+ |
60 | |
"oldDel.dlgn_rule_base_val_id not in "+ |
61 | |
"(select newDel.dlgn_rule_base_val_id from krew_rule_rsp_t newRsp, krew_dlgn_rsp_t newDel "+ |
62 | |
"where newRsp.rule_id=? and "+ |
63 | |
"newRsp.rule_rsp_id=newDel.rule_rsp_id)"; |
64 | |
|
65 | |
public void save(RuleBaseValues ruleBaseValues) { |
66 | 0 | this.getPersistenceBrokerTemplate().store(ruleBaseValues); |
67 | 0 | } |
68 | |
|
69 | |
public List fetchAllCurrentRulesForTemplateDocCombination(Long ruleTemplateId, List documentTypes) { |
70 | 0 | Criteria crit = new Criteria(); |
71 | 0 | crit.addIn("docTypeName", documentTypes); |
72 | 0 | crit.addEqualTo("ruleTemplateId", ruleTemplateId); |
73 | 0 | crit.addEqualTo("currentInd", Boolean.TRUE); |
74 | 0 | crit.addEqualTo("activeInd", Boolean.TRUE); |
75 | 0 | crit.addEqualTo("delegateRule", Boolean.FALSE); |
76 | 0 | crit.addEqualTo("templateRuleInd", Boolean.FALSE); |
77 | |
|
78 | 0 | crit.addAndCriteria(generateFromToDateCriteria(new Date())); |
79 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
80 | |
} |
81 | |
|
82 | |
public List fetchAllCurrentRulesForTemplateDocCombination(Long ruleTemplateId, List documentTypes, Timestamp effectiveDate) { |
83 | 0 | Criteria crit = new Criteria(); |
84 | 0 | crit.addIn("docTypeName", documentTypes); |
85 | 0 | crit.addEqualTo("ruleTemplateId", ruleTemplateId); |
86 | 0 | crit.addEqualTo("activeInd", Boolean.TRUE); |
87 | 0 | crit.addEqualTo("delegateRule", Boolean.FALSE); |
88 | 0 | crit.addEqualTo("templateRuleInd", Boolean.FALSE); |
89 | 0 | if (effectiveDate != null) { |
90 | 0 | crit.addLessOrEqualThan("activationDate", effectiveDate); |
91 | 0 | crit.addGreaterThan("deactivationDate", effectiveDate); |
92 | |
} |
93 | |
|
94 | 0 | crit.addAndCriteria(generateFromToDateCriteria(new Date())); |
95 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
96 | |
} |
97 | |
|
98 | |
public Criteria generateFromToDateCriteria(Date date) { |
99 | 0 | Criteria crit = new Criteria(); |
100 | |
|
101 | 0 | Criteria fromCrit = new Criteria(); |
102 | 0 | Criteria fromNullCrit = new Criteria(); |
103 | 0 | fromNullCrit.addIsNull("fromDate"); |
104 | 0 | Criteria fromLessOrEqualCrit = new Criteria(); |
105 | 0 | fromLessOrEqualCrit.addLessOrEqualThan("fromDate", new Timestamp(date.getTime())); |
106 | 0 | fromCrit.addOrCriteria(fromNullCrit); |
107 | 0 | fromCrit.addOrCriteria(fromLessOrEqualCrit); |
108 | |
|
109 | 0 | Criteria toCrit = new Criteria(); |
110 | 0 | Criteria toNullCrit = new Criteria(); |
111 | 0 | toNullCrit.addIsNull("toDate"); |
112 | 0 | Criteria toGreaterOrEqualCrit = new Criteria(); |
113 | 0 | toGreaterOrEqualCrit.addGreaterOrEqualThan("toDate", new Timestamp(date.getTime())); |
114 | 0 | toCrit.addOrCriteria(toNullCrit); |
115 | 0 | toCrit.addOrCriteria(toGreaterOrEqualCrit); |
116 | |
|
117 | 0 | crit.addAndCriteria(fromCrit); |
118 | 0 | crit.addAndCriteria(toCrit); |
119 | |
|
120 | 0 | return crit; |
121 | |
} |
122 | |
|
123 | |
public List fetchAllRules(boolean currentRules) { |
124 | 0 | Criteria crit = new Criteria(); |
125 | 0 | crit.addEqualTo("currentInd", new Boolean(currentRules)); |
126 | 0 | crit.addEqualTo("templateRuleInd", Boolean.FALSE); |
127 | |
|
128 | |
|
129 | 0 | QueryByCriteria query = new QueryByCriteria(RuleBaseValues.class, crit); |
130 | 0 | query.addOrderByDescending("activationDate"); |
131 | |
|
132 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(query); |
133 | |
} |
134 | |
|
135 | |
public void delete(Long ruleBaseValuesId) { |
136 | 0 | this.getPersistenceBrokerTemplate().delete(findRuleBaseValuesById(ruleBaseValuesId)); |
137 | 0 | } |
138 | |
|
139 | |
public List findByDocumentId(String documentId) { |
140 | 0 | Criteria crit = new Criteria(); |
141 | 0 | crit.addEqualTo("documentId", documentId); |
142 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
143 | |
} |
144 | |
|
145 | |
public RuleBaseValues findRuleBaseValuesByName(String name) { |
146 | 0 | Criteria crit = new Criteria(); |
147 | 0 | crit.addEqualTo("name", name); |
148 | 0 | crit.addEqualTo("currentInd", Boolean.TRUE); |
149 | 0 | return (RuleBaseValues) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
150 | |
} |
151 | |
|
152 | |
public RuleBaseValues findRuleBaseValuesById(Long ruleBaseValuesId) { |
153 | 0 | Criteria crit = new Criteria(); |
154 | 0 | crit.addEqualTo("ruleBaseValuesId", ruleBaseValuesId); |
155 | |
|
156 | 0 | return (RuleBaseValues) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
157 | |
} |
158 | |
|
159 | |
public List findRuleBaseValuesByResponsibilityReviewer(String reviewerName, String type) { |
160 | 0 | Criteria crit = new Criteria(); |
161 | 0 | crit.addEqualTo("ruleResponsibilityName", reviewerName); |
162 | 0 | crit.addEqualTo("ruleResponsibilityType", type); |
163 | |
|
164 | 0 | List responsibilities = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleResponsibility.class, crit)); |
165 | 0 | List rules = new ArrayList(); |
166 | |
|
167 | 0 | for (Iterator iter = responsibilities.iterator(); iter.hasNext();) { |
168 | 0 | RuleResponsibility responsibility = (RuleResponsibility) iter.next(); |
169 | 0 | RuleBaseValues rule = responsibility.getRuleBaseValues(); |
170 | 0 | if (rule != null && rule.getCurrentInd() != null && rule.getCurrentInd().booleanValue()) { |
171 | 0 | rules.add(rule); |
172 | |
} |
173 | 0 | } |
174 | 0 | return rules; |
175 | |
} |
176 | |
|
177 | |
public List findRuleBaseValuesByResponsibilityReviewerTemplateDoc(String ruleTemplateName, String documentType, String reviewerName, String type) { |
178 | 0 | Criteria crit = new Criteria(); |
179 | 0 | crit.addEqualTo("ruleResponsibilityName", reviewerName); |
180 | 0 | crit.addEqualTo("ruleResponsibilityType", type); |
181 | 0 | crit.addEqualTo("ruleBaseValues.currentInd", Boolean.TRUE); |
182 | 0 | if (!StringUtils.isBlank(ruleTemplateName)) { |
183 | 0 | crit.addLike("ruleBaseValues.ruleTemplate.name", ruleTemplateName.replace("*", "%").concat("%")); |
184 | |
} |
185 | 0 | if (!StringUtils.isBlank(documentType)) { |
186 | 0 | crit.addLike("ruleBaseValues.docTypeName", documentType.replace("*", "%").concat("%")); |
187 | |
} |
188 | |
|
189 | 0 | List responsibilities = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleResponsibility.class, crit)); |
190 | 0 | List rules = new ArrayList(); |
191 | |
|
192 | 0 | for (Iterator iter = responsibilities.iterator(); iter.hasNext();) { |
193 | 0 | RuleResponsibility responsibility = (RuleResponsibility) iter.next(); |
194 | 0 | RuleBaseValues rule = responsibility.getRuleBaseValues(); |
195 | 0 | if (rule != null && rule.getCurrentInd() != null && rule.getCurrentInd().booleanValue()) { |
196 | 0 | rules.add(rule); |
197 | |
} |
198 | 0 | } |
199 | 0 | return rules; |
200 | |
} |
201 | |
|
202 | |
public List findRuleBaseValuesByObjectGraph(RuleBaseValues ruleBaseValues) { |
203 | 0 | ruleBaseValues.setCurrentInd(Boolean.TRUE); |
204 | 0 | ruleBaseValues.setTemplateRuleInd(Boolean.FALSE); |
205 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ruleBaseValues)); |
206 | |
} |
207 | |
|
208 | |
public RuleResponsibility findRuleResponsibility(Long responsibilityId) { |
209 | |
|
210 | |
ReportQueryByCriteria subQuery; |
211 | 0 | Criteria subCrit = new Criteria(); |
212 | 0 | Criteria crit2 = new Criteria(); |
213 | 0 | subCrit.addLike("responsibilityId", responsibilityId); |
214 | 0 | subQuery = QueryFactory.newReportQuery(RuleResponsibility.class, subCrit); |
215 | 0 | subQuery.setAttributes(new String[] {"RULE_ID"}); |
216 | 0 | crit2.addIn("ruleBaseValuesId", subQuery); |
217 | 0 | crit2.addEqualTo("currentInd", 1); |
218 | 0 | QueryByCriteria outerQuery = QueryFactory.newQuery(RuleBaseValues.class, crit2); |
219 | 0 | RuleBaseValues rbv = (RuleBaseValues)this.getPersistenceBrokerTemplate().getObjectByQuery(outerQuery); |
220 | 0 | Criteria finalCrit = new Criteria(); |
221 | 0 | finalCrit.addEqualTo("responsibilityId", responsibilityId); |
222 | 0 | finalCrit.addEqualTo("ruleBaseValuesId", rbv.getRuleBaseValuesId()); |
223 | 0 | RuleResponsibility rResp = (RuleResponsibility)this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleResponsibility.class, finalCrit)); |
224 | |
|
225 | 0 | if(rResp != null){ |
226 | 0 | if(rResp.getRuleBaseValuesId().equals(rbv.getRuleBaseValuesId())){ |
227 | 0 | return rResp; |
228 | |
} |
229 | |
} |
230 | |
|
231 | 0 | return null; |
232 | |
} |
233 | |
|
234 | |
public List search(String docTypeName, Long ruleId, Long ruleTemplateId, String ruleDescription, String workgroupId, String principalId, Boolean delegateRule, Boolean activeInd, Map extensionValues, String workflowIdDirective) { |
235 | 0 | Criteria crit = getSearchCriteria(docTypeName, ruleTemplateId, ruleDescription, delegateRule, activeInd, extensionValues); |
236 | 0 | if (ruleId != null) { |
237 | 0 | crit.addEqualTo("ruleBaseValuesId", ruleId); |
238 | |
} |
239 | 0 | if (workgroupId != null) { |
240 | 0 | crit.addIn("responsibilities.ruleBaseValuesId", getResponsibilitySubQuery(workgroupId)); |
241 | |
} |
242 | 0 | List<String> workgroupIds = new ArrayList<String>(); |
243 | 0 | Boolean searchUser = Boolean.FALSE; |
244 | 0 | Boolean searchUserInWorkgroups = Boolean.FALSE; |
245 | |
|
246 | 0 | if ("group".equals(workflowIdDirective)) { |
247 | 0 | searchUserInWorkgroups = Boolean.TRUE; |
248 | 0 | } else if (StringUtils.isBlank(workflowIdDirective)) { |
249 | 0 | searchUser = Boolean.TRUE; |
250 | 0 | searchUserInWorkgroups = Boolean.TRUE; |
251 | |
} else { |
252 | 0 | searchUser = Boolean.TRUE; |
253 | |
} |
254 | |
|
255 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(principalId) && searchUserInWorkgroups) |
256 | |
{ |
257 | 0 | Principal principal = KimApiServiceLocator.getIdentityManagementService().getPrincipal(principalId); |
258 | |
|
259 | 0 | if (principal == null) |
260 | |
{ |
261 | 0 | throw new RiceRuntimeException("Failed to locate user for the given workflow id: " + principalId); |
262 | |
} |
263 | 0 | workgroupIds = KimApiServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId); |
264 | |
} |
265 | 0 | ReportQueryByCriteria query = getResponsibilitySubQuery(workgroupIds, principalId, searchUser, searchUserInWorkgroups); |
266 | 0 | if (query != null) { |
267 | 0 | crit.addIn("responsibilities.ruleBaseValuesId", query); |
268 | |
} |
269 | |
|
270 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit, true)); |
271 | |
} |
272 | |
|
273 | |
public List search(String docTypeName, Long ruleTemplateId, String ruleDescription, Collection<String> workgroupIds, String workflowId, Boolean delegateRule, Boolean activeInd, Map extensionValues, Collection actionRequestCodes) { |
274 | 0 | List results = null; |
275 | 0 | Criteria crit = getSearchCriteria(docTypeName, ruleTemplateId, ruleDescription, delegateRule, activeInd, extensionValues); |
276 | 0 | ReportQueryByCriteria query = getResponsibilitySubQuery(workgroupIds, workflowId, actionRequestCodes, (workflowId != null), ((workgroupIds != null) && !workgroupIds.isEmpty())); |
277 | 0 | if (query != null) { |
278 | 0 | crit.addIn("responsibilities.ruleBaseValuesId", query); |
279 | |
} |
280 | 0 | results = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit, true)); |
281 | 0 | return results; |
282 | |
} |
283 | |
|
284 | |
private ReportQueryByCriteria getResponsibilitySubQuery(List<String> workgroupIds, String workflowId, Boolean searchUser, Boolean searchUserInWorkgroups) { |
285 | 0 | Collection<String> workgroupIdStrings = new ArrayList<String>(); |
286 | 0 | for (String workgroupId : workgroupIds) { |
287 | 0 | workgroupIdStrings.add(workgroupId); |
288 | |
} |
289 | 0 | return getResponsibilitySubQuery(workgroupIdStrings,workflowId,new ArrayList<String>(), searchUser, searchUserInWorkgroups); |
290 | |
} |
291 | |
|
292 | |
private ReportQueryByCriteria getResponsibilitySubQuery(Collection<String> workgroupIds, String workflowId, Collection actionRequestCodes, Boolean searchUser, Boolean searchUserInWorkgroups) { |
293 | 0 | Criteria responsibilityCrit = null; |
294 | 0 | if ( (actionRequestCodes != null) && (!actionRequestCodes.isEmpty()) ) { |
295 | 0 | responsibilityCrit = new Criteria(); |
296 | 0 | responsibilityCrit.addIn("actionRequestedCd", actionRequestCodes); |
297 | |
} |
298 | |
|
299 | 0 | ReportQueryByCriteria query = null; |
300 | 0 | Criteria ruleResponsibilityNameCrit = null; |
301 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(workflowId)) { |
302 | |
|
303 | 0 | if (searchUser != null && searchUser) { |
304 | |
|
305 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
306 | 0 | ruleResponsibilityNameCrit.addLike("ruleResponsibilityName", workflowId); |
307 | 0 | ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType", KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID); |
308 | |
} |
309 | 0 | if ( (searchUserInWorkgroups != null && searchUserInWorkgroups) && (workgroupIds != null) && (!workgroupIds.isEmpty()) ) { |
310 | |
|
311 | 0 | if (ruleResponsibilityNameCrit == null) { |
312 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
313 | |
} |
314 | 0 | Criteria workgroupCrit = new Criteria(); |
315 | 0 | workgroupCrit.addIn("ruleResponsibilityName", workgroupIds); |
316 | 0 | workgroupCrit.addEqualTo("ruleResponsibilityType", KEWConstants.RULE_RESPONSIBILITY_GROUP_ID); |
317 | 0 | ruleResponsibilityNameCrit.addOrCriteria(workgroupCrit); |
318 | 0 | } |
319 | 0 | } else if ( (workgroupIds != null) && (workgroupIds.size() == 1) ) { |
320 | |
|
321 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
322 | 0 | ruleResponsibilityNameCrit.addLike("ruleResponsibilityName", workgroupIds.iterator().next()); |
323 | 0 | ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType", KEWConstants.RULE_RESPONSIBILITY_GROUP_ID); |
324 | 0 | } else if ( (workgroupIds != null) && (workgroupIds.size() > 1) ) { |
325 | |
|
326 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
327 | 0 | ruleResponsibilityNameCrit.addIn("ruleResponsibilityName", workgroupIds); |
328 | 0 | ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType", KEWConstants.RULE_RESPONSIBILITY_GROUP_ID); |
329 | |
} |
330 | 0 | if (ruleResponsibilityNameCrit != null) { |
331 | 0 | if (responsibilityCrit == null) { |
332 | 0 | responsibilityCrit = new Criteria(); |
333 | |
} |
334 | 0 | responsibilityCrit.addAndCriteria(ruleResponsibilityNameCrit); |
335 | |
} |
336 | 0 | if (responsibilityCrit != null) { |
337 | 0 | query = QueryFactory.newReportQuery(RuleResponsibility.class, responsibilityCrit); |
338 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
339 | |
} |
340 | 0 | return query; |
341 | |
} |
342 | |
|
343 | |
private Criteria getSearchCriteria(String docTypeName, Long ruleTemplateId, String ruleDescription, Boolean delegateRule, Boolean activeInd, Map extensionValues) { |
344 | 0 | Criteria crit = new Criteria(); |
345 | 0 | crit.addEqualTo("currentInd", Boolean.TRUE); |
346 | 0 | crit.addEqualTo("templateRuleInd", Boolean.FALSE); |
347 | 0 | if (activeInd != null) { |
348 | 0 | crit.addEqualTo("activeInd", activeInd); |
349 | |
} |
350 | 0 | if (docTypeName != null) { |
351 | 0 | crit.addLike("UPPER(docTypeName)", docTypeName.toUpperCase()); |
352 | |
} |
353 | 0 | if (ruleDescription != null && !ruleDescription.trim().equals("")) { |
354 | 0 | crit.addLike("UPPER(description)", ruleDescription.toUpperCase()); |
355 | |
} |
356 | 0 | if (ruleTemplateId != null) { |
357 | 0 | crit.addEqualTo("ruleTemplateId", ruleTemplateId); |
358 | |
} |
359 | 0 | if (delegateRule != null) { |
360 | 0 | crit.addEqualTo("delegateRule", delegateRule); |
361 | |
} |
362 | 0 | if (extensionValues != null && !extensionValues.isEmpty()) { |
363 | 0 | for (Iterator iter2 = extensionValues.entrySet().iterator(); iter2.hasNext();) { |
364 | 0 | Map.Entry entry = (Map.Entry) iter2.next(); |
365 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty((String) entry.getValue())) { |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | 0 | Criteria extensionCrit2 = new Criteria(); |
373 | 0 | extensionCrit2.addEqualTo("extensionValues.key", entry.getKey()); |
374 | 0 | extensionCrit2.addLike("UPPER(extensionValues.value)", ("%" + (String) entry.getValue() + "%").toUpperCase()); |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleExtension.class, extensionCrit2); |
385 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
386 | 0 | crit.addIn("ruleExtensions.ruleBaseValuesId", query); |
387 | |
} |
388 | 0 | } |
389 | |
} |
390 | 0 | return crit; |
391 | |
} |
392 | |
|
393 | |
private Criteria getWorkgroupOrCriteria(Collection workgroupIds) { |
394 | 0 | Criteria responsibilityCrit = new Criteria(); |
395 | 0 | for (Iterator iter = workgroupIds.iterator(); iter.hasNext();) { |
396 | 0 | String workgroupIdFromList = (String) iter.next(); |
397 | 0 | Criteria orCriteria = new Criteria(); |
398 | 0 | orCriteria.addLike("ruleResponsibilityName", workgroupIdFromList); |
399 | 0 | responsibilityCrit.addOrCriteria(orCriteria); |
400 | 0 | } |
401 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibility.class, responsibilityCrit); |
402 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
403 | 0 | Criteria crit = new Criteria(); |
404 | 0 | crit.addIn("responsibilities.ruleBaseValuesId", query); |
405 | 0 | return crit; |
406 | |
} |
407 | |
|
408 | |
private ReportQueryByCriteria getResponsibilitySubQuery(String ruleResponsibilityName) { |
409 | 0 | Criteria responsibilityCrit = new Criteria(); |
410 | 0 | responsibilityCrit.addLike("ruleResponsibilityName", ruleResponsibilityName); |
411 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibility.class, responsibilityCrit); |
412 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
413 | 0 | return query; |
414 | |
} |
415 | |
|
416 | |
private ReportQueryByCriteria getWorkgroupResponsibilitySubQuery(Set<Long> workgroupIds) { |
417 | 0 | Set<String> workgroupIdStrings = new HashSet<String>(); |
418 | 0 | for (Long workgroupId : workgroupIds) { |
419 | 0 | workgroupIdStrings.add(workgroupId.toString()); |
420 | |
} |
421 | 0 | Criteria responsibilityCrit = new Criteria(); |
422 | 0 | responsibilityCrit.addIn("ruleResponsibilityName", workgroupIds); |
423 | 0 | responsibilityCrit.addEqualTo("ruleResponsibilityType", KEWConstants.RULE_RESPONSIBILITY_GROUP_ID); |
424 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibility.class, responsibilityCrit); |
425 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
426 | 0 | return query; |
427 | |
} |
428 | |
|
429 | |
public List findByPreviousVersionId(Long previousVersionId) { |
430 | 0 | Criteria crit = new Criteria(); |
431 | 0 | crit.addEqualTo("previousVersionId", previousVersionId); |
432 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
433 | |
} |
434 | |
|
435 | |
public RuleBaseValues findDefaultRuleByRuleTemplateId(Long ruleTemplateId) { |
436 | 0 | Criteria crit = new Criteria(); |
437 | 0 | crit.addEqualTo("ruleTemplateId", ruleTemplateId); |
438 | 0 | crit.addEqualTo("templateRuleInd", Boolean.TRUE); |
439 | 0 | List rules = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
440 | 0 | if (rules != null && !rules.isEmpty()) { |
441 | 0 | return (RuleBaseValues) rules.get(0); |
442 | |
} |
443 | 0 | return null; |
444 | |
} |
445 | |
|
446 | |
public void clearCache() { |
447 | 0 | this.getPersistenceBroker(false).clearCache(); |
448 | 0 | } |
449 | |
|
450 | |
public void retrieveAllReferences(RuleBaseValues rule) { |
451 | |
|
452 | 0 | } |
453 | |
|
454 | |
public RuleBaseValues getParentRule(Long ruleBaseValuesId) { |
455 | 0 | Criteria criteria = new Criteria(); |
456 | 0 | criteria.addEqualTo("currentInd", Boolean.TRUE); |
457 | 0 | criteria.addEqualTo("responsibilities.delegationRules.delegateRuleId", ruleBaseValuesId); |
458 | 0 | Collection rules = this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, criteria)); |
459 | 0 | RuleBaseValues rule = null; |
460 | 0 | for (Iterator iterator = rules.iterator(); iterator.hasNext();) { |
461 | 0 | RuleBaseValues currentRule = (RuleBaseValues) iterator.next(); |
462 | 0 | if (rule == null || currentRule.getVersionNbr().intValue() > rule.getVersionNbr().intValue()) { |
463 | 0 | rule = currentRule; |
464 | |
} |
465 | 0 | } |
466 | 0 | return rule; |
467 | |
} |
468 | |
|
469 | |
public List findOldDelegations(final RuleBaseValues oldRule, final RuleBaseValues newRule) { |
470 | 0 | return (List)this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() { |
471 | |
public Object doInPersistenceBroker(PersistenceBroker pb) { |
472 | 0 | List oldDelegations = new ArrayList(); |
473 | 0 | PreparedStatement ps = null; |
474 | 0 | ResultSet rs = null; |
475 | |
try { |
476 | 0 | ps = pb.serviceConnectionManager().getConnection().prepareStatement(OLD_DELEGATIONS_SQL); |
477 | 0 | ps.setLong(1, oldRule.getRuleBaseValuesId().longValue()); |
478 | 0 | ps.setLong(2, newRule.getRuleBaseValuesId().longValue()); |
479 | 0 | rs = ps.executeQuery(); |
480 | 0 | while (rs.next()) { |
481 | 0 | oldDelegations.add(findRuleBaseValuesById(new Long(rs.getLong(1)))); |
482 | |
} |
483 | 0 | } catch (Exception e) { |
484 | 0 | throw new WorkflowRuntimeException("error saving deactivation date", e); |
485 | |
} finally { |
486 | 0 | if (rs != null) { |
487 | |
try { |
488 | 0 | rs.close(); |
489 | 0 | } catch (Exception e) { |
490 | 0 | LOG.error("error closing result set", e); |
491 | 0 | } |
492 | |
} |
493 | 0 | if (ps != null) { |
494 | |
try { |
495 | 0 | ps.close(); |
496 | 0 | } catch (Exception e) { |
497 | 0 | LOG.error("error closing preparedstatement", e); |
498 | 0 | } |
499 | |
} |
500 | |
} |
501 | 0 | return oldDelegations; |
502 | |
} |
503 | |
}); |
504 | |
} |
505 | |
|
506 | |
public Long findResponsibilityIdForRule(String ruleName, String ruleResponsibilityName, String ruleResponsibilityType) { |
507 | 0 | Criteria crit = new Criteria(); |
508 | 0 | crit.addEqualTo("ruleResponsibilityName", ruleResponsibilityName); |
509 | 0 | crit.addEqualTo("ruleResponsibilityType", ruleResponsibilityType); |
510 | 0 | crit.addEqualTo("ruleBaseValues.currentInd", Boolean.TRUE); |
511 | 0 | crit.addEqualTo("ruleBaseValues.name", ruleName); |
512 | 0 | List responsibilities = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleResponsibility.class, crit)); |
513 | 0 | if (responsibilities != null) { |
514 | 0 | for (Iterator iter = responsibilities.iterator(); iter.hasNext();) { |
515 | 0 | RuleResponsibility responsibility = (RuleResponsibility) iter.next(); |
516 | 0 | return responsibility.getResponsibilityId(); |
517 | |
} |
518 | |
} |
519 | 0 | return null; |
520 | |
} |
521 | |
|
522 | |
} |