| 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.api.KewApiConstants; |
| 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().getDataObject(); |
| 50 | |
|
| 51 | 0 | if ( resp.getDocumentTypeName() != null |
| 52 | |
&& resp.getRouteNodeName() != null |
| 53 | |
&& !checkForDuplicateResponsibility( resp ) ) { |
| 54 | 0 | GlobalVariables.getMessageMap().putError( "documentTypeName", ERROR_DUPLICATE_RESPONSIBILITY ); |
| 55 | 0 | rulesPassed = false; |
| 56 | |
} |
| 57 | |
} finally { |
| 58 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath( MAINTAINABLE_ERROR_PATH ); |
| 59 | 0 | } |
| 60 | 0 | return rulesPassed; |
| 61 | |
} |
| 62 | |
|
| 63 | |
protected boolean checkForDuplicateResponsibility( ReviewResponsibilityBo resp ) { |
| 64 | 0 | QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); |
| 65 | 0 | Predicate p = and( |
| 66 | |
equal("template.namespaceCode", KewApiConstants.KEW_NAMESPACE ), |
| 67 | |
equal("template.name", KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME), |
| 68 | |
equal("attributes[documentTypeName]", resp.getDocumentTypeName()), |
| 69 | |
equal("attributes[routeNodeName]", resp.getRouteNodeName()) |
| 70 | |
); |
| 71 | 0 | builder.setPredicates(p); |
| 72 | 0 | ResponsibilityQueryResults results = KimApiServiceLocator.getResponsibilityService().findResponsibilities(builder.build()); |
| 73 | 0 | return results.getResults().isEmpty(); |
| 74 | |
} |
| 75 | |
} |