| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.edl.impl.components; |
| 18 | |
|
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.kuali.rice.core.util.XmlJotter; |
| 21 | |
import org.kuali.rice.edl.impl.*; |
| 22 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 23 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 24 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
| 25 | |
import org.w3c.dom.Document; |
| 26 | |
import org.w3c.dom.Element; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | public class WorkflowDocumentActions implements EDLModelComponent { |
| 38 | |
|
| 39 | 0 | private static final Logger LOG = Logger.getLogger(WorkflowDocumentActions.class); |
| 40 | |
|
| 41 | |
public static final String ACTION_TAKEN = "actionTaken"; |
| 42 | |
|
| 43 | |
boolean isPreProcessor; |
| 44 | |
|
| 45 | |
public void updateDOM(Document dom, Element configElement, EDLContext edlContext) { |
| 46 | |
|
| 47 | |
try { |
| 48 | 0 | isPreProcessor = configElement.getTagName().equals("preProcessor"); |
| 49 | 0 | if (isPreProcessor) { |
| 50 | 0 | doPreProcessWork(edlContext); |
| 51 | |
} else { |
| 52 | 0 | doPostProcessWork(dom, edlContext); |
| 53 | |
} |
| 54 | 0 | } catch (Exception e) { |
| 55 | 0 | throw new WorkflowRuntimeException(e); |
| 56 | 0 | } |
| 57 | |
|
| 58 | 0 | } |
| 59 | |
|
| 60 | |
private void doPreProcessWork(EDLContext edlContext) throws Exception { |
| 61 | 0 | RequestParser requestParser = edlContext.getRequestParser(); |
| 62 | |
|
| 63 | 0 | UserAction userAction = edlContext.getUserAction(); |
| 64 | 0 | WorkflowDocument document = null; |
| 65 | 0 | if (UserAction.ACTION_CREATE.equals(userAction.getAction())) { |
| 66 | 0 | document = new WorkflowDocument(edlContext.getUserSession().getPrincipalId(), edlContext.getEdocLiteAssociation().getEdlName()); |
| 67 | 0 | document.setTitle("Routing Document Type '" + document.getDocumentType() + "'"); |
| 68 | 0 | document.getRouteHeaderId(); |
| 69 | 0 | LOG.info("Created document " + document.getRouteHeaderId()); |
| 70 | |
} else { |
| 71 | 0 | document = (WorkflowDocument)requestParser.getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
| 72 | 0 | if (document == null) { |
| 73 | 0 | String docId = (String) requestParser.getAttribute("docId"); |
| 74 | 0 | if (docId == null) { |
| 75 | 0 | LOG.info("no document found for edl " + edlContext.getEdocLiteAssociation().getEdlName()); |
| 76 | 0 | return; |
| 77 | |
} else { |
| 78 | 0 | document = new WorkflowDocument(edlContext.getUserSession().getPrincipalId(), new Long(docId)); |
| 79 | |
} |
| 80 | |
} |
| 81 | |
} |
| 82 | |
|
| 83 | 0 | requestParser.setAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY, document); |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
private void doPostProcessWork(Document dom, EDLContext edlContext) throws Exception { |
| 87 | 0 | RequestParser requestParser = edlContext.getRequestParser(); |
| 88 | |
|
| 89 | 0 | if (edlContext.isInError()) { |
| 90 | 0 | return; |
| 91 | |
} |
| 92 | 0 | WorkflowDocument document = (WorkflowDocument)edlContext.getRequestParser().getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
| 93 | 0 | if (document == null) { |
| 94 | 0 | return; |
| 95 | |
} |
| 96 | |
|
| 97 | 0 | Element dataElement = (Element) dom.getElementsByTagName(EDLXmlUtils.DATA_E).item(0); |
| 98 | 0 | String docContent = XmlJotter.jotNode(dataElement); |
| 99 | 0 | document.setApplicationContent(docContent); |
| 100 | 0 | takeAction(document, dom, edlContext); |
| 101 | 0 | } |
| 102 | |
|
| 103 | |
public static void takeAction(WorkflowDocument document, Document dom, EDLContext edlContext) throws WorkflowException { |
| 104 | 0 | RequestParser requestParser = edlContext.getRequestParser(); |
| 105 | 0 | UserAction userAction = edlContext.getUserAction(); |
| 106 | 0 | String annotation = requestParser.getParameterValue("annotation"); |
| 107 | 0 | String action = userAction.getAction(); |
| 108 | 0 | String previousNodeName = requestParser.getParameterValue("previousNode"); |
| 109 | |
|
| 110 | 0 | if (!userAction.isValidatableAction()) { |
| 111 | |
|
| 112 | |
|
| 113 | 0 | document.clearAttributeDefinitions(); |
| 114 | |
} |
| 115 | |
|
| 116 | 0 | boolean actionTaken = true; |
| 117 | |
|
| 118 | 0 | if (UserAction.ACTION_ROUTE.equals(action)) { |
| 119 | 0 | document.routeDocument(annotation); |
| 120 | 0 | } else if (UserAction.ACTION_APPROVE.equals(action)) { |
| 121 | 0 | document.approve(annotation); |
| 122 | 0 | } else if (UserAction.ACTION_DISAPPROVE.equals(action)) { |
| 123 | 0 | document.disapprove(annotation); |
| 124 | 0 | } else if (UserAction.ACTION_CANCEL.equals(action)) { |
| 125 | 0 | document.cancel(annotation); |
| 126 | 0 | } else if (UserAction.ACTION_BLANKETAPPROVE.equals(action)) { |
| 127 | 0 | document.blanketApprove(annotation); |
| 128 | 0 | } else if (UserAction.ACTION_FYI.equals(action)) { |
| 129 | 0 | document.fyi(); |
| 130 | 0 | } else if (UserAction.ACTION_ACKNOWLEDGE.equals(action)) { |
| 131 | 0 | document.acknowledge(annotation); |
| 132 | 0 | } else if (UserAction.ACTION_SAVE.equals(action)) { |
| 133 | 0 | if (document.getStatusDisplayValue().equals("INITIATED")) { |
| 134 | 0 | document.saveDocument(annotation); |
| 135 | |
} else { |
| 136 | 0 | document.saveRoutingData(); |
| 137 | |
} |
| 138 | 0 | } else if (UserAction.ACTION_COMPLETE.equals(action)) { |
| 139 | 0 | document.complete(annotation); |
| 140 | 0 | } else if (UserAction.ACTION_DELETE.equals(action)) { |
| 141 | 0 | document.delete(); |
| 142 | 0 | } else if (UserAction.ACTION_RETURN_TO_PREVIOUS.equals(action)) { |
| 143 | 0 | document.returnToPreviousNode(annotation, previousNodeName); |
| 144 | |
} else { |
| 145 | 0 | actionTaken = false; |
| 146 | |
} |
| 147 | |
|
| 148 | 0 | if (actionTaken) { |
| 149 | 0 | Element actionTakenElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), ACTION_TAKEN, true); |
| 150 | 0 | actionTakenElement.appendChild(dom.createTextNode(action)); |
| 151 | |
} |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
} |