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