| 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.apache.log4j.MDC; |
| 19 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
| 20 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
| 21 | |
import org.kuali.rice.kew.api.exception.InvalidActionTakenException; |
| 22 | |
import org.kuali.rice.kew.doctype.DocumentTypePolicy; |
| 23 | |
import org.kuali.rice.kew.api.exception.ResourceUnavailableException; |
| 24 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
| 25 | |
import org.kuali.rice.kew.api.KewApiConstants; |
| 26 | |
import org.kuali.rice.kim.api.identity.principal.PrincipalContract; |
| 27 | |
|
| 28 | |
|
| 29 | |
import java.util.Iterator; |
| 30 | |
import java.util.List; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public class ClearFYIAction extends ActionTakenEvent { |
| 45 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ClearFYIAction.class); |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public ClearFYIAction(DocumentRouteHeaderValue rh, PrincipalContract principal) { |
| 54 | 0 | super(KewApiConstants.ACTION_TAKEN_FYI_CD, rh, principal); |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public ClearFYIAction(DocumentRouteHeaderValue rh, PrincipalContract principal, String annotation) { |
| 66 | 0 | super(KewApiConstants.ACTION_TAKEN_FYI_CD, rh, principal, annotation); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
public String validateActionRules() { |
| 74 | 0 | return validateActionRules(getActionRequestService().findAllPendingRequests(routeHeader.getDocumentId())); |
| 75 | |
} |
| 76 | |
|
| 77 | |
public String validateActionRules(List<ActionRequestValue> actionRequests) { |
| 78 | 0 | if (!getRouteHeader().isValidActionToTake(getActionPerformedCode())) { |
| 79 | 0 | return "Document is not in a state to have FYI processed"; |
| 80 | |
} |
| 81 | 0 | List<ActionRequestValue> filteredActionRequests = filterActionRequestsByCode(actionRequests, KewApiConstants.ACTION_REQUEST_FYI_REQ); |
| 82 | 0 | if (!isActionCompatibleRequest(filteredActionRequests)) { |
| 83 | 0 | return "No request for the user is compatible " + "with the ClearFYI action"; |
| 84 | |
} |
| 85 | 0 | return ""; |
| 86 | |
} |
| 87 | |
|
| 88 | |
public boolean isActionCompatibleRequest(List requests) { |
| 89 | |
|
| 90 | |
|
| 91 | 0 | if (routeHeader.isStateInitiated() || routeHeader.isStateSaved()) { |
| 92 | 0 | return true; |
| 93 | |
} |
| 94 | |
|
| 95 | 0 | boolean actionCompatible = false; |
| 96 | 0 | Iterator ars = requests.iterator(); |
| 97 | 0 | ActionRequestValue actionRequest = null; |
| 98 | |
|
| 99 | 0 | while (ars.hasNext()) { |
| 100 | 0 | actionRequest = (ActionRequestValue) ars.next(); |
| 101 | |
|
| 102 | |
|
| 103 | 0 | if (KewApiConstants.ACTION_REQUEST_FYI_REQ.equals(actionRequest.getActionRequested())) { |
| 104 | 0 | actionCompatible = true; |
| 105 | 0 | break; |
| 106 | |
} |
| 107 | |
} |
| 108 | |
|
| 109 | 0 | return actionCompatible; |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
public void recordAction() throws InvalidActionTakenException { |
| 119 | 0 | MDC.put("docId", getRouteHeader().getDocumentId()); |
| 120 | 0 | updateSearchableAttributesIfPossible(); |
| 121 | |
|
| 122 | 0 | LOG.debug("Clear FYI for document : " + annotation); |
| 123 | 0 | LOG.debug("Checking to see if the action is legal"); |
| 124 | |
|
| 125 | 0 | List actionRequests = getActionRequestService().findAllValidRequests(getPrincipal().getPrincipalId(), getDocumentId(), KewApiConstants.ACTION_REQUEST_FYI_REQ); |
| 126 | 0 | if (actionRequests == null || actionRequests.isEmpty()) { |
| 127 | 0 | DocumentTypePolicy allowUnrequested = getRouteHeader().getDocumentType().getAllowUnrequestedActionPolicy(); |
| 128 | 0 | if (allowUnrequested != null) { |
| 129 | 0 | if (!allowUnrequested.getPolicyValue()) { |
| 130 | 0 | throw new InvalidActionTakenException("No request for the user is compatible " + "with the ClearFYI action. " + "Doctype policy ALLOW_UNREQUESTED_ACTION is set to false and someone else likely just took action on the document."); |
| 131 | |
} |
| 132 | |
} |
| 133 | |
} |
| 134 | |
|
| 135 | 0 | String errorMessage = validateActionRules(actionRequests); |
| 136 | 0 | if (!org.apache.commons.lang.StringUtils.isEmpty(errorMessage)) { |
| 137 | 0 | throw new InvalidActionTakenException(errorMessage); |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | ActionTakenValue actionTaken = saveActionTaken(findDelegatorForActionRequests(actionRequests)); |
| 141 | |
|
| 142 | 0 | LOG.debug("Deactivate all pending action requests"); |
| 143 | 0 | getActionRequestService().deactivateRequests(actionTaken, actionRequests); |
| 144 | 0 | notifyActionTaken(actionTaken); |
| 145 | 0 | } |
| 146 | |
} |