1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.responsibility; |
17 | |
|
18 | |
import org.kuali.rice.core.api.criteria.Predicate; |
19 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
20 | |
import org.kuali.rice.kew.util.KEWConstants; |
21 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityQueryResults; |
22 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
23 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
24 | |
import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase; |
25 | |
import org.kuali.rice.krad.util.GlobalVariables; |
26 | |
|
27 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.and; |
28 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.equal; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class ReviewResponsibilityMaintenanceDocumentRule extends MaintenanceDocumentRuleBase { |
37 | |
|
38 | |
protected static final String ERROR_MESSAGE_PREFIX = "error.document.kim.reviewresponsibility."; |
39 | |
protected static final String ERROR_DUPLICATE_RESPONSIBILITY = ERROR_MESSAGE_PREFIX + "duplicateresponsibility"; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { |
46 | 0 | boolean rulesPassed = true; |
47 | 0 | GlobalVariables.getMessageMap().addToErrorPath( MAINTAINABLE_ERROR_PATH ); |
48 | |
try { |
49 | 0 | ReviewResponsibilityBo resp = (ReviewResponsibilityBo)document.getNewMaintainableObject().getBusinessObject(); |
50 | |
|
51 | 0 | if ( !checkForDuplicateResponsibility( resp ) ) { |
52 | 0 | GlobalVariables.getMessageMap().putError( "documentTypeName", ERROR_DUPLICATE_RESPONSIBILITY ); |
53 | 0 | rulesPassed = false; |
54 | |
} |
55 | |
} finally { |
56 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath( MAINTAINABLE_ERROR_PATH ); |
57 | 0 | } |
58 | 0 | return rulesPassed; |
59 | |
} |
60 | |
|
61 | |
protected boolean checkForDuplicateResponsibility( ReviewResponsibilityBo resp ) { |
62 | 0 | QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); |
63 | 0 | Predicate p = and( |
64 | |
equal("template.namespaceCode", KEWConstants.KEW_NAMESPACE ), |
65 | |
equal("template.name", KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME), |
66 | |
equal("attributes[documentTypeName]", resp.getDocumentTypeName()), |
67 | |
equal("attributes[routeNodeName]", resp.getRouteNodeName()) |
68 | |
); |
69 | 0 | builder.setPredicates(p); |
70 | 0 | ResponsibilityQueryResults results = KimApiServiceLocator.getResponsibilityService().findResponsibilities(builder.build()); |
71 | 0 | return results.getResults().isEmpty(); |
72 | |
} |
73 | |
} |