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.xml.XmlJotter; |
21 | |
import org.kuali.rice.edl.impl.EDLContext; |
22 | |
import org.kuali.rice.edl.impl.EDLModelComponent; |
23 | |
import org.kuali.rice.edl.impl.EDLXmlUtils; |
24 | |
import org.kuali.rice.edl.impl.RequestParser; |
25 | |
import org.kuali.rice.edl.impl.UserAction; |
26 | |
import org.kuali.rice.kew.api.WorkflowDocument; |
27 | |
import org.kuali.rice.kew.api.WorkflowDocumentFactory; |
28 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
29 | |
import org.kuali.rice.kew.api.document.DocumentStatus; |
30 | |
import org.kuali.rice.kew.exception.WorkflowException; |
31 | |
import org.w3c.dom.Document; |
32 | |
import org.w3c.dom.Element; |
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 = WorkflowDocumentFactory.createDocument(edlContext.getUserSession().getPrincipalId(), edlContext |
72 | |
.getEdocLiteAssociation().getEdlName()); |
73 | 0 | document.setTitle("Routing Document Type '" + document.getDocumentTypeName() + "'"); |
74 | 0 | document.getDocumentId(); |
75 | 0 | LOG.info("Created document " + document.getDocumentId()); |
76 | |
} else { |
77 | 0 | document = (WorkflowDocument) requestParser.getAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
78 | 0 | if (document == null) { |
79 | 0 | String docId = (String) requestParser.getAttribute("docId"); |
80 | 0 | if (docId == null) { |
81 | 0 | LOG.info("no document found for edl " + edlContext.getEdocLiteAssociation().getEdlName()); |
82 | 0 | return; |
83 | |
} else { |
84 | 0 | document = WorkflowDocumentFactory |
85 | |
.loadDocument(edlContext.getUserSession().getPrincipalId(), docId); |
86 | |
} |
87 | |
} |
88 | |
} |
89 | |
|
90 | 0 | requestParser.setAttribute(RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY, document); |
91 | 0 | } |
92 | |
|
93 | |
private void doPostProcessWork(Document dom, EDLContext edlContext) throws Exception { |
94 | 0 | RequestParser requestParser = edlContext.getRequestParser(); |
95 | |
|
96 | 0 | if (edlContext.isInError()) { |
97 | 0 | return; |
98 | |
} |
99 | 0 | WorkflowDocument document = (WorkflowDocument) edlContext.getRequestParser().getAttribute( |
100 | |
RequestParser.WORKFLOW_DOCUMENT_SESSION_KEY); |
101 | 0 | if (document == null) { |
102 | 0 | return; |
103 | |
} |
104 | |
|
105 | 0 | Element dataElement = (Element) dom.getElementsByTagName(EDLXmlUtils.DATA_E).item(0); |
106 | 0 | String docContent = XmlJotter.jotNode(dataElement); |
107 | 0 | document.setApplicationContent(docContent); |
108 | 0 | takeAction(document, dom, edlContext); |
109 | 0 | } |
110 | |
|
111 | |
public static void takeAction(WorkflowDocument document, Document dom, EDLContext edlContext) |
112 | |
throws WorkflowException { |
113 | 0 | RequestParser requestParser = edlContext.getRequestParser(); |
114 | 0 | UserAction userAction = edlContext.getUserAction(); |
115 | 0 | String annotation = requestParser.getParameterValue("annotation"); |
116 | 0 | String action = userAction.getAction(); |
117 | 0 | String previousNodeName = requestParser.getParameterValue("previousNode"); |
118 | |
|
119 | 0 | if (!userAction.isValidatableAction()) { |
120 | |
|
121 | |
|
122 | 0 | document.clearAttributeDefinitions(); |
123 | |
} |
124 | |
|
125 | 0 | boolean actionTaken = true; |
126 | |
|
127 | 0 | if (UserAction.ACTION_ROUTE.equals(action)) { |
128 | 0 | document.route(annotation); |
129 | 0 | } else if (UserAction.ACTION_APPROVE.equals(action)) { |
130 | 0 | document.approve(annotation); |
131 | 0 | } else if (UserAction.ACTION_DISAPPROVE.equals(action)) { |
132 | 0 | document.disapprove(annotation); |
133 | 0 | } else if (UserAction.ACTION_CANCEL.equals(action)) { |
134 | 0 | document.cancel(annotation); |
135 | 0 | } else if (UserAction.ACTION_BLANKETAPPROVE.equals(action)) { |
136 | 0 | document.blanketApprove(annotation); |
137 | 0 | } else if (UserAction.ACTION_FYI.equals(action)) { |
138 | 0 | document.fyi(); |
139 | 0 | } else if (UserAction.ACTION_ACKNOWLEDGE.equals(action)) { |
140 | 0 | document.acknowledge(annotation); |
141 | 0 | } else if (UserAction.ACTION_SAVE.equals(action)) { |
142 | 0 | if (document.getStatus().equals(DocumentStatus.INITIATED)) { |
143 | 0 | document.saveDocument(annotation); |
144 | |
} else { |
145 | 0 | document.saveDocumentData(); |
146 | |
} |
147 | 0 | } else if (UserAction.ACTION_COMPLETE.equals(action)) { |
148 | 0 | document.complete(annotation); |
149 | 0 | } else if (UserAction.ACTION_DELETE.equals(action)) { |
150 | 0 | document.delete(); |
151 | 0 | } else if (UserAction.ACTION_RETURN_TO_PREVIOUS.equals(action)) { |
152 | 0 | document.returnToPreviousNode(annotation, previousNodeName); |
153 | |
} else { |
154 | 0 | actionTaken = false; |
155 | |
} |
156 | |
|
157 | 0 | if (actionTaken) { |
158 | 0 | Element actionTakenElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), ACTION_TAKEN, |
159 | |
true); |
160 | 0 | actionTakenElement.appendChild(dom.createTextNode(action)); |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
} |