| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.actions; |
| 18 | |
|
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.kuali.rice.kew.actionrequest.ActionRequestFactory; |
| 21 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
| 22 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
| 23 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 24 | |
import org.kuali.rice.kew.engine.BlanketApproveEngine; |
| 25 | |
import org.kuali.rice.kew.engine.OrchestrationConfig; |
| 26 | |
import org.kuali.rice.kew.engine.RouteContext; |
| 27 | |
import org.kuali.rice.kew.engine.OrchestrationConfig.EngineCapability; |
| 28 | |
import org.kuali.rice.kew.engine.node.RequestsNode; |
| 29 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
| 30 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 31 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
| 32 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
| 33 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 34 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 35 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 36 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
| 37 | |
|
| 38 | |
|
| 39 | |
import java.util.ArrayList; |
| 40 | |
import java.util.HashSet; |
| 41 | |
import java.util.List; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public class SuperUserApproveEvent extends SuperUserActionTakenEvent { |
| 51 | |
|
| 52 | 0 | private static final Logger LOG = Logger.getLogger(SuperUserApproveEvent.class); |
| 53 | |
|
| 54 | |
public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
| 55 | 0 | super(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal); |
| 56 | 0 | this.superUserAction = KEWConstants.SUPER_USER_APPROVE; |
| 57 | 0 | } |
| 58 | |
|
| 59 | |
public SuperUserApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) { |
| 60 | 0 | super(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor); |
| 61 | 0 | this.superUserAction = KEWConstants.SUPER_USER_APPROVE; |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
public void recordAction() throws InvalidActionTakenException { |
| 65 | |
|
| 66 | |
|
| 67 | 0 | setRouteHeader(KEWServiceLocator.getRouteHeaderService().getRouteHeader(getDocumentId(), true)); |
| 68 | |
|
| 69 | 0 | DocumentType docType = getRouteHeader().getDocumentType(); |
| 70 | |
|
| 71 | 0 | String errorMessage = super.validateActionRules(); |
| 72 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
| 73 | 0 | LOG.info("User not authorized"); |
| 74 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
| 75 | 0 | errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION)); |
| 76 | 0 | throw new WorkflowServiceErrorException(errorMessage, errors); |
| 77 | |
} |
| 78 | |
|
| 79 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
| 80 | |
|
| 81 | 0 | notifyActionTaken(actionTaken); |
| 82 | |
|
| 83 | 0 | if (getRouteHeader().isInException() || getRouteHeader().isStateInitiated()) { |
| 84 | 0 | LOG.debug("Moving document back to Enroute"); |
| 85 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
| 86 | 0 | getRouteHeader().markDocumentEnroute(); |
| 87 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
| 88 | 0 | notifyStatusChange(newStatus, oldStatus); |
| 89 | 0 | KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader()); |
| 90 | |
} |
| 91 | |
|
| 92 | 0 | OrchestrationConfig config = new OrchestrationConfig(EngineCapability.BLANKET_APPROVAL, new HashSet<String>(), actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue(), isRunPostProcessorLogic()); |
| 93 | 0 | RequestsNode.setSupressPolicyErrors(RouteContext.getCurrentRouteContext()); |
| 94 | |
try { |
| 95 | 0 | completeAnyOutstandingCompleteApproveRequests(actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue()); |
| 96 | 0 | BlanketApproveEngine blanketApproveEngine = KEWServiceLocator.getWorkflowEngineFactory().newEngine(config); |
| 97 | 0 | blanketApproveEngine.process(getRouteHeader().getDocumentId(), null); |
| 98 | 0 | } catch (Exception e) { |
| 99 | 0 | LOG.error("Failed to orchestrate the document to SuperUserApproved.", e); |
| 100 | 0 | throw new InvalidActionTakenException("Failed to orchestrate the document to SuperUserApproved.", e); |
| 101 | 0 | } |
| 102 | |
|
| 103 | 0 | } |
| 104 | |
|
| 105 | |
@SuppressWarnings("unchecked") |
| 106 | |
protected void completeAnyOutstandingCompleteApproveRequests(ActionTakenValue actionTaken, boolean sendNotifications) throws Exception { |
| 107 | 0 | List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KEWConstants.ACTION_REQUEST_APPROVE_REQ, getDocumentId()); |
| 108 | 0 | actionRequests.addAll(KEWServiceLocator.getActionRequestService().findPendingByActionRequestedAndDocId(KEWConstants.ACTION_REQUEST_COMPLETE_REQ, getDocumentId())); |
| 109 | 0 | for (ActionRequestValue actionRequest : actionRequests) { |
| 110 | 0 | KEWServiceLocator.getActionRequestService().deactivateRequest(actionTaken, actionRequest); |
| 111 | |
} |
| 112 | 0 | if (sendNotifications) { |
| 113 | 0 | new ActionRequestFactory(this.getRouteHeader()).generateNotifications(actionRequests, getPrincipal(), this.findDelegatorForActionRequests(actionRequests), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_TAKEN_SU_APPROVED_CD); |
| 114 | |
} |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
protected void markDocument() throws WorkflowException { |
| 118 | |
|
| 119 | 0 | } |
| 120 | |
} |