| 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.kuali.rice.kew.actionrequest.ActionRequestValue; |
| 20 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
| 21 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 22 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
| 23 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 24 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
| 25 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
| 26 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 27 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 28 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
| 29 | |
|
| 30 | |
|
| 31 | |
import java.util.ArrayList; |
| 32 | |
import java.util.List; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public abstract class SuperUserActionTakenEvent extends ActionTakenEvent { |
| 41 | |
|
| 42 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SuperUserActionTakenEvent.class); |
| 43 | |
|
| 44 | |
protected String superUserAction; |
| 45 | |
|
| 46 | |
private ActionRequestValue actionRequest; |
| 47 | 0 | public static String AUTHORIZATION = "general.routing.superuser.notAuthorized"; |
| 48 | |
|
| 49 | |
public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal) { |
| 50 | 0 | super(actionTakenCode, routeHeader, principal); |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
public SuperUserActionTakenEvent(String actionTakenCode, DocumentRouteHeaderValue routeHeader, PrincipalContract principal, String annotation, boolean runPostProcessor) { |
| 54 | 0 | super(actionTakenCode, routeHeader, principal, annotation, runPostProcessor); |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
@Override |
| 61 | |
public String validateActionRules() { |
| 62 | 0 | DocumentType docType = getRouteHeader().getDocumentType(); |
| 63 | 0 | if (!KEWServiceLocator.getDocumentTypePermissionService().canAdministerRouting(getPrincipal().getPrincipalId(), docType)) { |
| 64 | 0 | return "User not authorized for super user action"; |
| 65 | |
} |
| 66 | 0 | return ""; |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
| 71 | 0 | return validateActionRules(); |
| 72 | |
} |
| 73 | |
|
| 74 | |
public void recordAction() throws InvalidActionTakenException { |
| 75 | |
|
| 76 | 0 | String errorMessage = validateActionRules(); |
| 77 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
| 78 | 0 | LOG.info("User not authorized"); |
| 79 | 0 | List<WorkflowServiceErrorImpl> errors = new ArrayList<WorkflowServiceErrorImpl>(); |
| 80 | 0 | errors.add(new WorkflowServiceErrorImpl(errorMessage, AUTHORIZATION)); |
| 81 | 0 | throw new WorkflowServiceErrorException(errorMessage, errors); |
| 82 | |
} |
| 83 | |
|
| 84 | 0 | processActionRequests(); |
| 85 | |
|
| 86 | |
try { |
| 87 | 0 | String oldStatus = getRouteHeader().getDocRouteStatus(); |
| 88 | |
|
| 89 | 0 | if (getRouteHeader().isStateInitiated()) { |
| 90 | 0 | getRouteHeader().markDocumentEnroute(); |
| 91 | 0 | notifyStatusChange(getRouteHeader().getDocRouteStatus(), oldStatus); |
| 92 | |
} |
| 93 | 0 | markDocument(); |
| 94 | 0 | String newStatus = getRouteHeader().getDocRouteStatus(); |
| 95 | 0 | notifyStatusChange(newStatus, oldStatus); |
| 96 | 0 | } catch (Exception ex) { |
| 97 | 0 | LOG.error("Caught Exception talking to post processor", ex); |
| 98 | 0 | throw new RuntimeException(ex.getMessage()); |
| 99 | 0 | } |
| 100 | |
|
| 101 | 0 | } |
| 102 | |
|
| 103 | |
protected abstract void markDocument() throws WorkflowException; |
| 104 | |
|
| 105 | |
protected void processActionRequests() throws InvalidActionTakenException { |
| 106 | 0 | LOG.debug("Processing pending action requests"); |
| 107 | |
|
| 108 | 0 | ActionTakenValue actionTaken = saveActionTaken(); |
| 109 | |
|
| 110 | 0 | List<ActionRequestValue> actionRequests = getActionRequestService().findPendingByDoc(getDocumentId()); |
| 111 | |
|
| 112 | 0 | for (ActionRequestValue actionRequest : actionRequests) |
| 113 | |
{ |
| 114 | 0 | getActionRequestService().deactivateRequest(actionTaken, actionRequest); |
| 115 | |
} |
| 116 | |
|
| 117 | 0 | notifyActionTaken(actionTaken); |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
public ActionRequestValue getActionRequest() { |
| 121 | 0 | return actionRequest; |
| 122 | |
} |
| 123 | |
|
| 124 | |
public void setActionRequest(ActionRequestValue actionRequest) { |
| 125 | 0 | this.actionRequest = actionRequest; |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
} |