| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.actions; |
| 17 | |
|
| 18 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
| 19 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
| 20 | |
import org.kuali.rice.kew.api.exception.InvalidActionTakenException; |
| 21 | |
import org.kuali.rice.kew.api.exception.WorkflowException; |
| 22 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 23 | |
import org.kuali.rice.kew.engine.BlanketApproveEngine; |
| 24 | |
import org.kuali.rice.kew.engine.OrchestrationConfig; |
| 25 | |
import org.kuali.rice.kew.engine.OrchestrationConfig.EngineCapability; |
| 26 | |
import org.kuali.rice.kew.exception.*; |
| 27 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 28 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 29 | |
import org.kuali.rice.kew.api.KewApiConstants; |
| 30 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
| 31 | |
|
| 32 | |
|
| 33 | |
import java.util.ArrayList; |
| 34 | |
import java.util.Collections; |
| 35 | |
import java.util.List; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public class SuperUserNodeApproveEvent extends SuperUserActionTakenEvent { |
| 46 | |
|
| 47 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserNodeApproveEvent.class); |
| 48 | |
private String nodeName; |
| 49 | |
|
| 50 | |
public SuperUserNodeApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
| 51 | 0 | super(KewApiConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, routeHeader, principal); |
| 52 | 0 | this.superUserAction = KewApiConstants.SUPER_USER_ROUTE_LEVEL_APPROVE; |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public SuperUserNodeApproveEvent(DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor, String nodeName) { |
| 56 | 0 | super(KewApiConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, routeHeader, principal, annotation, runPostProcessor); |
| 57 | 0 | this.superUserAction = KewApiConstants.SUPER_USER_ROUTE_LEVEL_APPROVE; |
| 58 | 0 | this.nodeName = nodeName; |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public void recordAction() throws InvalidActionTakenException { |
| 62 | |
|
| 63 | 0 | if (org.apache.commons.lang.StringUtils.isEmpty(nodeName)) { |
| 64 | 0 | throw new InvalidActionTakenException("No approval node name set"); |
| 65 | |
} |
| 66 | |
|
| 67 | 0 | DocumentType docType = getRouteHeader().getDocumentType(); |
| 68 | |
|
| 69 | 0 | String errorMessage = super.validateActionRules(); |
| 70 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
| 71 | 0 | LOG.info("User not authorized"); |
| 72 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
| 73 | 0 | errors.add(new WorkflowServiceErrorImpl(errorMessage, SuperUserActionTakenEvent.AUTHORIZATION)); |
| 74 | 0 | throw new WorkflowServiceErrorException(errorMessage, errors); |
| 75 | |
} |
| 76 | |
|
| 77 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
| 78 | |
|
| 79 | 0 | notifyActionTaken(actionTaken); |
| 80 | |
|
| 81 | 0 | if (getRouteHeader().isInException()) { |
| 82 | 0 | LOG.debug("Moving document back to Enroute from Exception"); |
| 83 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
| 84 | 0 | getRouteHeader().markDocumentEnroute(); |
| 85 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
| 86 | 0 | notifyStatusChange(newStatus, oldStatus); |
| 87 | 0 | KEWServiceLocator.getRouteHeaderService().saveRouteHeader(getRouteHeader()); |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | OrchestrationConfig config = new OrchestrationConfig(EngineCapability.BLANKET_APPROVAL, Collections.singleton(nodeName), actionTaken, docType.getSuperUserApproveNotificationPolicy().getPolicyValue(), isRunPostProcessorLogic()); |
| 91 | |
try { |
| 92 | 0 | BlanketApproveEngine blanketApproveEngine = KEWServiceLocator.getWorkflowEngineFactory().newEngine(config); |
| 93 | 0 | blanketApproveEngine.process(getRouteHeader().getDocumentId(), null); |
| 94 | 0 | } catch (Exception e) { |
| 95 | 0 | if (e instanceof RuntimeException) { |
| 96 | 0 | throw (RuntimeException)e; |
| 97 | |
} else { |
| 98 | 0 | throw new WorkflowRuntimeException(e.toString(), e); |
| 99 | |
} |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
|
| 103 | 0 | } |
| 104 | |
|
| 105 | |
protected void markDocument() throws WorkflowException { |
| 106 | |
|
| 107 | 0 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
} |