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