1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule.dao.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.ojb.broker.PersistenceBroker; |
20 | |
import org.apache.ojb.broker.query.Criteria; |
21 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
22 | |
import org.apache.ojb.broker.query.QueryFactory; |
23 | |
import org.apache.ojb.broker.query.ReportQueryByCriteria; |
24 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
25 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
26 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
27 | |
import org.kuali.rice.kew.rule.RuleExtensionBo; |
28 | |
import org.kuali.rice.kew.rule.RuleResponsibilityBo; |
29 | |
import org.kuali.rice.kew.rule.dao.RuleDAO; |
30 | |
import org.kuali.rice.kew.api.KewApiConstants; |
31 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
32 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
33 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
34 | |
import org.springmodules.orm.ojb.PersistenceBrokerCallback; |
35 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
36 | |
|
37 | |
import java.sql.PreparedStatement; |
38 | |
import java.sql.ResultSet; |
39 | |
import java.sql.Timestamp; |
40 | |
import java.util.ArrayList; |
41 | |
import java.util.Collection; |
42 | |
import java.util.Date; |
43 | |
import java.util.HashMap; |
44 | |
import java.util.HashSet; |
45 | |
import java.util.Iterator; |
46 | |
import java.util.List; |
47 | |
import java.util.Map; |
48 | |
import java.util.Set; |
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<RuleBaseValues> fetchAllCurrentRulesForTemplateDocCombination(String 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("active", 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<RuleBaseValues> fetchAllCurrentRulesForTemplateDocCombination(String 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("active", 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("fromDateValue"); |
104 | 0 | Criteria fromLessOrEqualCrit = new Criteria(); |
105 | 0 | fromLessOrEqualCrit.addLessOrEqualThan("fromDateValue", 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("toDateValue"); |
112 | 0 | Criteria toGreaterOrEqualCrit = new Criteria(); |
113 | 0 | toGreaterOrEqualCrit.addGreaterOrEqualThan("toDateValue", 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<RuleBaseValues> 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(String ruleBaseValuesId) { |
136 | 0 | this.getPersistenceBrokerTemplate().delete(findRuleBaseValuesById(ruleBaseValuesId)); |
137 | 0 | } |
138 | |
|
139 | |
public List<RuleBaseValues> 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(String ruleBaseValuesId) { |
153 | 0 | Criteria crit = new Criteria(); |
154 | 0 | crit.addEqualTo("id", ruleBaseValuesId); |
155 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
156 | 0 | criteria.put("id", ruleBaseValuesId); |
157 | |
|
158 | 0 | return KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(RuleBaseValues.class, criteria); |
159 | |
|
160 | |
} |
161 | |
|
162 | |
public List<RuleBaseValues> findRuleBaseValuesByResponsibilityReviewer(String reviewerName, String type) { |
163 | 0 | Criteria crit = new Criteria(); |
164 | 0 | crit.addEqualTo("ruleResponsibilityName", reviewerName); |
165 | 0 | crit.addEqualTo("ruleResponsibilityType", type); |
166 | |
|
167 | 0 | List responsibilities = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleResponsibilityBo.class, crit)); |
168 | 0 | List rules = new ArrayList(); |
169 | |
|
170 | 0 | for (Iterator iter = responsibilities.iterator(); iter.hasNext();) { |
171 | 0 | RuleResponsibilityBo responsibility = (RuleResponsibilityBo) iter.next(); |
172 | 0 | RuleBaseValues rule = responsibility.getRuleBaseValues(); |
173 | 0 | if (rule != null && rule.getCurrentInd() != null && rule.getCurrentInd().booleanValue()) { |
174 | 0 | rules.add(rule); |
175 | |
} |
176 | 0 | } |
177 | 0 | return rules; |
178 | |
} |
179 | |
|
180 | |
public List<RuleBaseValues> findRuleBaseValuesByResponsibilityReviewerTemplateDoc(String ruleTemplateName, String documentType, String reviewerName, String type) { |
181 | 0 | Criteria crit = new Criteria(); |
182 | 0 | crit.addEqualTo("ruleResponsibilityName", reviewerName); |
183 | 0 | crit.addEqualTo("ruleResponsibilityType", type); |
184 | 0 | crit.addEqualTo("ruleBaseValues.currentInd", Boolean.TRUE); |
185 | 0 | if (!StringUtils.isBlank(ruleTemplateName)) { |
186 | 0 | crit.addLike("ruleBaseValues.ruleTemplate.name", ruleTemplateName.replace("*", "%").concat("%")); |
187 | |
} |
188 | 0 | if (!StringUtils.isBlank(documentType)) { |
189 | 0 | crit.addLike("ruleBaseValues.docTypeName", documentType.replace("*", "%").concat("%")); |
190 | |
} |
191 | |
|
192 | 0 | List responsibilities = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleResponsibilityBo.class, crit)); |
193 | 0 | List rules = new ArrayList(); |
194 | |
|
195 | 0 | for (Iterator iter = responsibilities.iterator(); iter.hasNext();) { |
196 | 0 | RuleResponsibilityBo responsibility = (RuleResponsibilityBo) iter.next(); |
197 | 0 | RuleBaseValues rule = responsibility.getRuleBaseValues(); |
198 | 0 | if (rule != null && rule.getCurrentInd() != null && rule.getCurrentInd().booleanValue()) { |
199 | 0 | rules.add(rule); |
200 | |
} |
201 | 0 | } |
202 | 0 | return rules; |
203 | |
} |
204 | |
|
205 | |
public List findRuleBaseValuesByObjectGraph(RuleBaseValues ruleBaseValues) { |
206 | 0 | ruleBaseValues.setCurrentInd(Boolean.TRUE); |
207 | 0 | ruleBaseValues.setTemplateRuleInd(Boolean.FALSE); |
208 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ruleBaseValues)); |
209 | |
} |
210 | |
|
211 | |
public RuleResponsibilityBo findRuleResponsibility(String responsibilityId) { |
212 | |
|
213 | |
ReportQueryByCriteria subQuery; |
214 | 0 | Criteria subCrit = new Criteria(); |
215 | 0 | Criteria crit2 = new Criteria(); |
216 | 0 | subCrit.addLike("responsibilityId", responsibilityId); |
217 | 0 | subQuery = QueryFactory.newReportQuery(RuleResponsibilityBo.class, subCrit); |
218 | 0 | subQuery.setAttributes(new String[] {"RULE_ID"}); |
219 | 0 | crit2.addIn("id", subQuery); |
220 | 0 | crit2.addEqualTo("currentInd", 1); |
221 | 0 | QueryByCriteria outerQuery = QueryFactory.newQuery(RuleBaseValues.class, crit2); |
222 | 0 | RuleBaseValues rbv = (RuleBaseValues)this.getPersistenceBrokerTemplate().getObjectByQuery(outerQuery); |
223 | 0 | Criteria finalCrit = new Criteria(); |
224 | 0 | finalCrit.addEqualTo("responsibilityId", responsibilityId); |
225 | 0 | finalCrit.addEqualTo("ruleBaseValuesId", rbv.getId()); |
226 | |
RuleResponsibilityBo |
227 | 0 | rResp = (RuleResponsibilityBo)this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(RuleResponsibilityBo.class, finalCrit)); |
228 | |
|
229 | 0 | if(rResp != null){ |
230 | 0 | if(rResp.getRuleBaseValuesId().equals(rbv.getId())){ |
231 | 0 | return rResp; |
232 | |
} |
233 | |
} |
234 | |
|
235 | 0 | return null; |
236 | |
} |
237 | |
|
238 | |
public List<RuleBaseValues> search(String docTypeName, String ruleId, String ruleTemplateId, String ruleDescription, String workgroupId, String principalId, Boolean delegateRule, Boolean activeInd, Map extensionValues, String workflowIdDirective) { |
239 | 0 | Criteria crit = getSearchCriteria(docTypeName, ruleTemplateId, ruleDescription, delegateRule, activeInd, extensionValues); |
240 | 0 | if (ruleId != null) { |
241 | 0 | crit.addEqualTo("id", ruleId); |
242 | |
} |
243 | 0 | if (workgroupId != null) { |
244 | 0 | crit.addIn("id", getResponsibilitySubQuery(workgroupId)); |
245 | |
} |
246 | 0 | List<String> workgroupIds = new ArrayList<String>(); |
247 | 0 | Boolean searchUser = Boolean.FALSE; |
248 | 0 | Boolean searchUserInWorkgroups = Boolean.FALSE; |
249 | |
|
250 | 0 | if ("group".equals(workflowIdDirective)) { |
251 | 0 | searchUserInWorkgroups = Boolean.TRUE; |
252 | 0 | } else if (StringUtils.isBlank(workflowIdDirective)) { |
253 | 0 | searchUser = Boolean.TRUE; |
254 | 0 | searchUserInWorkgroups = Boolean.TRUE; |
255 | |
} else { |
256 | 0 | searchUser = Boolean.TRUE; |
257 | |
} |
258 | |
|
259 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(principalId) && searchUserInWorkgroups) |
260 | |
{ |
261 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId); |
262 | |
|
263 | 0 | if (principal == null) |
264 | |
{ |
265 | 0 | throw new RiceRuntimeException("Failed to locate user for the given workflow id: " + principalId); |
266 | |
} |
267 | 0 | workgroupIds = KimApiServiceLocator.getGroupService().getGroupIdsByPrincipalId(principalId); |
268 | |
} |
269 | 0 | ReportQueryByCriteria query = getResponsibilitySubQuery(workgroupIds, principalId, searchUser, searchUserInWorkgroups); |
270 | 0 | if (query != null) { |
271 | 0 | crit.addIn("id", query); |
272 | |
} |
273 | |
|
274 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit, true)); |
275 | |
} |
276 | |
|
277 | |
public List<RuleBaseValues> search(String docTypeName, String ruleTemplateId, String ruleDescription, Collection<String> workgroupIds, String workflowId, Boolean delegateRule, Boolean activeInd, Map extensionValues, Collection actionRequestCodes) { |
278 | 0 | List results = null; |
279 | 0 | Criteria crit = getSearchCriteria(docTypeName, ruleTemplateId, ruleDescription, delegateRule, activeInd, extensionValues); |
280 | 0 | ReportQueryByCriteria query = getResponsibilitySubQuery(workgroupIds, workflowId, actionRequestCodes, (workflowId != null), ((workgroupIds != null) && !workgroupIds.isEmpty())); |
281 | 0 | if (query != null) { |
282 | 0 | crit.addIn("ruleResponsibilities.ruleBaseValuesId", query); |
283 | |
} |
284 | 0 | results = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit, true)); |
285 | 0 | return results; |
286 | |
} |
287 | |
|
288 | |
private ReportQueryByCriteria getResponsibilitySubQuery(List<String> workgroupIds, String workflowId, Boolean searchUser, Boolean searchUserInWorkgroups) { |
289 | 0 | Collection<String> workgroupIdStrings = new ArrayList<String>(); |
290 | 0 | for (String workgroupId : workgroupIds) { |
291 | 0 | workgroupIdStrings.add(workgroupId); |
292 | |
} |
293 | 0 | return getResponsibilitySubQuery(workgroupIdStrings,workflowId,new ArrayList<String>(), searchUser, searchUserInWorkgroups); |
294 | |
} |
295 | |
|
296 | |
private ReportQueryByCriteria getResponsibilitySubQuery(Collection<String> workgroupIds, String workflowId, Collection actionRequestCodes, Boolean searchUser, Boolean searchUserInWorkgroups) { |
297 | 0 | Criteria responsibilityCrit = null; |
298 | 0 | if ( (actionRequestCodes != null) && (!actionRequestCodes.isEmpty()) ) { |
299 | 0 | responsibilityCrit = new Criteria(); |
300 | 0 | responsibilityCrit.addIn("actionRequestedCd", actionRequestCodes); |
301 | |
} |
302 | |
|
303 | 0 | ReportQueryByCriteria query = null; |
304 | 0 | Criteria ruleResponsibilityNameCrit = null; |
305 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(workflowId)) { |
306 | |
|
307 | 0 | if (searchUser != null && searchUser) { |
308 | |
|
309 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
310 | 0 | ruleResponsibilityNameCrit.addLike("ruleResponsibilityName", workflowId); |
311 | 0 | ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType", KewApiConstants.RULE_RESPONSIBILITY_WORKFLOW_ID); |
312 | |
} |
313 | 0 | if ( (searchUserInWorkgroups != null && searchUserInWorkgroups) && (workgroupIds != null) && (!workgroupIds.isEmpty()) ) { |
314 | |
|
315 | 0 | if (ruleResponsibilityNameCrit == null) { |
316 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
317 | |
} |
318 | 0 | Criteria workgroupCrit = new Criteria(); |
319 | 0 | workgroupCrit.addIn("ruleResponsibilityName", workgroupIds); |
320 | 0 | workgroupCrit.addEqualTo("ruleResponsibilityType", KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID); |
321 | 0 | ruleResponsibilityNameCrit.addOrCriteria(workgroupCrit); |
322 | 0 | } |
323 | 0 | } else if ( (workgroupIds != null) && (workgroupIds.size() == 1) ) { |
324 | |
|
325 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
326 | 0 | ruleResponsibilityNameCrit.addLike("ruleResponsibilityName", workgroupIds.iterator().next()); |
327 | 0 | ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType", KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID); |
328 | 0 | } else if ( (workgroupIds != null) && (workgroupIds.size() > 1) ) { |
329 | |
|
330 | 0 | ruleResponsibilityNameCrit = new Criteria(); |
331 | 0 | ruleResponsibilityNameCrit.addIn("ruleResponsibilityName", workgroupIds); |
332 | 0 | ruleResponsibilityNameCrit.addEqualTo("ruleResponsibilityType", KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID); |
333 | |
} |
334 | 0 | if (ruleResponsibilityNameCrit != null) { |
335 | 0 | if (responsibilityCrit == null) { |
336 | 0 | responsibilityCrit = new Criteria(); |
337 | |
} |
338 | 0 | responsibilityCrit.addAndCriteria(ruleResponsibilityNameCrit); |
339 | |
} |
340 | 0 | if (responsibilityCrit != null) { |
341 | 0 | query = QueryFactory.newReportQuery(RuleResponsibilityBo.class, responsibilityCrit); |
342 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
343 | |
} |
344 | 0 | return query; |
345 | |
} |
346 | |
|
347 | |
private Criteria getSearchCriteria(String docTypeName, String ruleTemplateId, String ruleDescription, Boolean delegateRule, Boolean activeInd, Map extensionValues) { |
348 | 0 | Criteria crit = new Criteria(); |
349 | 0 | crit.addEqualTo("currentInd", Boolean.TRUE); |
350 | 0 | crit.addEqualTo("templateRuleInd", Boolean.FALSE); |
351 | 0 | if (activeInd != null) { |
352 | 0 | crit.addEqualTo("active", activeInd); |
353 | |
} |
354 | 0 | if (docTypeName != null) { |
355 | 0 | crit.addLike("UPPER(docTypeName)", docTypeName.toUpperCase()); |
356 | |
} |
357 | 0 | if (ruleDescription != null && !ruleDescription.trim().equals("")) { |
358 | 0 | crit.addLike("UPPER(description)", ruleDescription.toUpperCase()); |
359 | |
} |
360 | 0 | if (ruleTemplateId != null) { |
361 | 0 | crit.addEqualTo("ruleTemplateId", ruleTemplateId); |
362 | |
} |
363 | 0 | if (delegateRule != null) { |
364 | 0 | crit.addEqualTo("delegateRule", delegateRule); |
365 | |
} |
366 | 0 | if (extensionValues != null && !extensionValues.isEmpty()) { |
367 | 0 | for (Iterator iter2 = extensionValues.entrySet().iterator(); iter2.hasNext();) { |
368 | 0 | Map.Entry entry = (Map.Entry) iter2.next(); |
369 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty((String) entry.getValue())) { |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | 0 | Criteria extensionCrit2 = new Criteria(); |
377 | 0 | extensionCrit2.addEqualTo("extensionValues.key", entry.getKey()); |
378 | 0 | extensionCrit2.addLike("UPPER(extensionValues.value)", ("%" + (String) entry.getValue() + "%").toUpperCase()); |
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleExtensionBo.class, extensionCrit2); |
389 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
390 | 0 | crit.addIn("ruleExtensions.ruleBaseValuesId", query); |
391 | |
} |
392 | 0 | } |
393 | |
} |
394 | 0 | return crit; |
395 | |
} |
396 | |
|
397 | |
private Criteria getWorkgroupOrCriteria(Collection workgroupIds) { |
398 | 0 | Criteria responsibilityCrit = new Criteria(); |
399 | 0 | for (Iterator iter = workgroupIds.iterator(); iter.hasNext();) { |
400 | 0 | String workgroupIdFromList = (String) iter.next(); |
401 | 0 | Criteria orCriteria = new Criteria(); |
402 | 0 | orCriteria.addLike("ruleResponsibilityName", workgroupIdFromList); |
403 | 0 | responsibilityCrit.addOrCriteria(orCriteria); |
404 | 0 | } |
405 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.class, responsibilityCrit); |
406 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
407 | 0 | Criteria crit = new Criteria(); |
408 | 0 | crit.addIn("responsibilities.ruleBaseValuesId", query); |
409 | 0 | return crit; |
410 | |
} |
411 | |
|
412 | |
private ReportQueryByCriteria getResponsibilitySubQuery(String ruleResponsibilityName) { |
413 | 0 | Criteria responsibilityCrit = new Criteria(); |
414 | 0 | responsibilityCrit.addLike("ruleResponsibilityName", ruleResponsibilityName); |
415 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.class, responsibilityCrit); |
416 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
417 | 0 | return query; |
418 | |
} |
419 | |
|
420 | |
private ReportQueryByCriteria getWorkgroupResponsibilitySubQuery(Set<Long> workgroupIds) { |
421 | 0 | Set<String> workgroupIdStrings = new HashSet<String>(); |
422 | 0 | for (Long workgroupId : workgroupIds) { |
423 | 0 | workgroupIdStrings.add(workgroupId.toString()); |
424 | |
} |
425 | 0 | Criteria responsibilityCrit = new Criteria(); |
426 | 0 | responsibilityCrit.addIn("ruleResponsibilityName", workgroupIds); |
427 | 0 | responsibilityCrit.addEqualTo("ruleResponsibilityType", KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID); |
428 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(RuleResponsibilityBo.class, responsibilityCrit); |
429 | 0 | query.setAttributes(new String[] { "ruleBaseValuesId" }); |
430 | 0 | return query; |
431 | |
} |
432 | |
|
433 | |
public List<RuleBaseValues> findByPreviousRuleId(String previousRuleId) { |
434 | 0 | Criteria crit = new Criteria(); |
435 | 0 | crit.addEqualTo("previousRuleId", previousRuleId); |
436 | 0 | return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
437 | |
} |
438 | |
|
439 | |
public RuleBaseValues findDefaultRuleByRuleTemplateId(String ruleTemplateId) { |
440 | 0 | Criteria crit = new Criteria(); |
441 | 0 | crit.addEqualTo("ruleTemplateId", ruleTemplateId); |
442 | 0 | crit.addEqualTo("templateRuleInd", Boolean.TRUE); |
443 | 0 | List rules = (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(RuleBaseValues.class, crit)); |
444 | 0 | if (rules != null && !rules.isEmpty()) { |
445 | 0 | return (RuleBaseValues) rules.get(0); |
446 | |
} |
447 | 0 | return null; |
448 | |
} |
449 | |
|
450 | |
public void retrieveAllReferences(RuleBaseValues rule) { |
451 | |
|
452 | 0 | } |
453 | |
|
454 | |
public RuleBaseValues getParentRule(String 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.setString(1, oldRule.getId()); |
478 | 0 | ps.setString(2, newRule.getId()); |
479 | 0 | rs = ps.executeQuery(); |
480 | 0 | while (rs.next()) { |
481 | 0 | oldDelegations.add(findRuleBaseValuesById(rs.getString(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 String 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(RuleResponsibilityBo.class, crit)); |
513 | 0 | if (responsibilities != null) { |
514 | 0 | for (Iterator iter = responsibilities.iterator(); iter.hasNext();) { |
515 | 0 | RuleResponsibilityBo responsibility = (RuleResponsibilityBo) iter.next(); |
516 | 0 | return responsibility.getResponsibilityId(); |
517 | |
} |
518 | |
} |
519 | 0 | return null; |
520 | |
} |
521 | |
|
522 | |
} |