Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SimpleDocumentActionsWebServiceImpl |
|
| 2.5609756097560976;2.561 |
1 | /* | |
2 | * Copyright 2005-2007 The Kuali Foundation | |
3 | * | |
4 | * | |
5 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.opensource.org/licenses/ecl2.php | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.kuali.rice.kew.webservice.impl; | |
18 | ||
19 | import java.sql.Timestamp; | |
20 | import java.text.DateFormat; | |
21 | import java.text.SimpleDateFormat; | |
22 | import java.util.ArrayList; | |
23 | import java.util.Calendar; | |
24 | import java.util.GregorianCalendar; | |
25 | import java.util.List; | |
26 | ||
27 | import javax.jws.WebService; | |
28 | ||
29 | import org.apache.commons.lang.StringUtils; | |
30 | import org.kuali.rice.kew.dto.AdHocRevokeDTO; | |
31 | import org.kuali.rice.kew.dto.NoteDTO; | |
32 | import org.kuali.rice.kew.dto.RouteHeaderDTO; | |
33 | import org.kuali.rice.kew.exception.WorkflowException; | |
34 | import org.kuali.rice.kew.exception.WorkflowServiceErrorException; | |
35 | import org.kuali.rice.kew.service.KEWServiceLocator; | |
36 | import org.kuali.rice.kew.service.WorkflowDocument; | |
37 | import org.kuali.rice.kew.service.WorkflowInfo; | |
38 | import org.kuali.rice.kew.util.KEWConstants; | |
39 | import org.kuali.rice.kew.util.KEWWebServiceConstants; | |
40 | import org.kuali.rice.kew.util.Utilities; | |
41 | import org.kuali.rice.kew.webservice.DocumentResponse; | |
42 | import org.kuali.rice.kew.webservice.ErrorResponse; | |
43 | import org.kuali.rice.kew.webservice.NoteDetail; | |
44 | import org.kuali.rice.kew.webservice.NoteResponse; | |
45 | import org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService; | |
46 | import org.kuali.rice.kew.webservice.StandardResponse; | |
47 | import org.kuali.rice.kew.webservice.UserInRouteLogResponse; | |
48 | import org.kuali.rice.kim.bo.Person; | |
49 | import org.kuali.rice.kim.service.KIMServiceLocator; | |
50 | ||
51 | ||
52 | /** | |
53 | * Implementation of the SimpleDocumentActionsWebService | |
54 | * | |
55 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
56 | */ | |
57 | @WebService(endpointInterface = KEWWebServiceConstants.SimpleDocumentActionsWebService.INTERFACE_CLASS, | |
58 | serviceName = KEWWebServiceConstants.SimpleDocumentActionsWebService.WEB_SERVICE_NAME, | |
59 | portName = KEWWebServiceConstants.SimpleDocumentActionsWebService.WEB_SERVICE_PORT, | |
60 | targetNamespace = KEWWebServiceConstants.MODULE_TARGET_NAMESPACE) | |
61 | 0 | public class SimpleDocumentActionsWebServiceImpl implements SimpleDocumentActionsWebService { |
62 | ||
63 | /** | |
64 | * <ol> | |
65 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
66 | * <li>Acknowledge the document with the passed in annotation</li> | |
67 | * <li>Return the standard set of return values.</li> | |
68 | * </ol> | |
69 | * | |
70 | * @param docId KEW document id of the document to acknowledge | |
71 | * @param principalId principal id of the user who is acknowledging the document | |
72 | * @param annotation a comment associated with this request | |
73 | * @return Map including the standard set of return values | |
74 | * | |
75 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#acknowledge(java.lang.String, java.lang.String, java.lang.String) | |
76 | */ | |
77 | public StandardResponse acknowledge(String docId, String principalId, String annotation) { | |
78 | StandardResponse results; | |
79 | ||
80 | try { | |
81 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
82 | ||
83 | 0 | workflowDocument.acknowledge(annotation); |
84 | 0 | results = createResults(workflowDocument); |
85 | 0 | } catch (WorkflowException e) { |
86 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
87 | 0 | } |
88 | ||
89 | 0 | return results; |
90 | } | |
91 | ||
92 | /** | |
93 | * <ol> | |
94 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
95 | * <li>Set the docTitle and docContent if they are passed in</li> | |
96 | * <li>Approve the document with the passed in annotation</li> | |
97 | * <li>Return the standard set of return values</li> | |
98 | * </ol> | |
99 | * | |
100 | * @param docId KEW document id of the document to approve | |
101 | * @param principalId principal id of the user who is approving the document | |
102 | * @param docTitle title for this document | |
103 | * @param docContent xml content for this document | |
104 | * @param annotation a comment associated with this request | |
105 | * @return Map including the standard set of return values | |
106 | * | |
107 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#approve(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
108 | */ | |
109 | public StandardResponse approve(String docId, String principalId, String docTitle, | |
110 | String docContent, String annotation) { | |
111 | //Map<String, Object> results; | |
112 | StandardResponse results; | |
113 | ||
114 | try { | |
115 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
116 | ||
117 | 0 | workflowDocument.approve(annotation); |
118 | 0 | results = createResults(workflowDocument); |
119 | 0 | } catch (WorkflowException e) { |
120 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
121 | 0 | } |
122 | ||
123 | 0 | return results; |
124 | } | |
125 | ||
126 | /** | |
127 | * <ol> | |
128 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
129 | * <li>Set the docTitle and docContent if they are passed in</li> | |
130 | * <li>Blanket Approve the document with the passed in annotation</li> | |
131 | * <li>Return the standard set of return values</li> | |
132 | * </ol> | |
133 | * | |
134 | * Blanket Approval means all future approval requests will be satisfied | |
135 | * Can only be performed by a super user. | |
136 | * | |
137 | * @param docId KEW document id of the document to blanket approve | |
138 | * @param principalId principal id of the user who is blanket approving the document | |
139 | * @param docTitle title for this document | |
140 | * @param docContent xml content for this document | |
141 | * @param annotation a comment associated with this request | |
142 | * @return Map including the standard set of return values | |
143 | * | |
144 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#blanketApprove(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
145 | */ | |
146 | public StandardResponse blanketApprove(String docId, String principalId, String docTitle, | |
147 | String docContent, String annotation) { | |
148 | //Map<String, Object> results; | |
149 | StandardResponse results; | |
150 | ||
151 | try { | |
152 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
153 | ||
154 | 0 | workflowDocument.blanketApprove(annotation); |
155 | 0 | results = createResults(workflowDocument); |
156 | 0 | } catch (WorkflowException e) { |
157 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
158 | 0 | } |
159 | ||
160 | 0 | return results; |
161 | } | |
162 | ||
163 | /** | |
164 | * <ol> | |
165 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
166 | * <li>Cancel the document with the passed in annotation</li> | |
167 | * <li>Return the standard set of return values</li> | |
168 | * </ol> | |
169 | * | |
170 | * @param docId KEW document id of the document to cancel | |
171 | * @param principalId principal id of the user who is canceling the document | |
172 | * @param annotation a comment associated with this request | |
173 | * @return Map including the standard set of return values | |
174 | * | |
175 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#cancel(java.lang.String, java.lang.String, java.lang.String) | |
176 | */ | |
177 | public StandardResponse cancel(String docId, String principalId, String annotation) { | |
178 | //Map<String, Object> results; | |
179 | StandardResponse results; | |
180 | try { | |
181 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
182 | ||
183 | 0 | workflowDocument.cancel(annotation); |
184 | 0 | results = createResults(workflowDocument); |
185 | 0 | } catch (WorkflowException e) { |
186 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
187 | 0 | } |
188 | ||
189 | 0 | return results; |
190 | } | |
191 | ||
192 | /** | |
193 | * <ol> | |
194 | * <li>Create a WorkflowDocument with the docType and principalId passed in</li> | |
195 | * <li>Set the document title to be the docTitle that was passed in</li | |
196 | * <li>Save the Routing data (Route Header info)</li> | |
197 | * <li>Return the standard set of return values and the docId of the newly created document</li> | |
198 | * </ol> | |
199 | * | |
200 | * @param initiatorPrincipalId principal id of the document initiator | |
201 | * @param appDocId application specific document id | |
202 | * @param docType KEW document type for the document to be created | |
203 | * @param docTitle title for this document | |
204 | * @return Map including the standard set of return values and the docId of the newly created document | |
205 | * | |
206 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#create(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
207 | */ | |
208 | public DocumentResponse create(String initiatorPrincipalId, String appDocId, String docType, | |
209 | String docTitle) { | |
210 | ||
211 | // Map<String, Object> results; | |
212 | StandardResponse results; | |
213 | ||
214 | 0 | String docId = ""; |
215 | ||
216 | try { | |
217 | 0 | WorkflowDocument workflowDocument = new WorkflowDocument(initiatorPrincipalId, docType); |
218 | 0 | workflowDocument.setTitle(docTitle); |
219 | 0 | workflowDocument.setAppDocId(appDocId); |
220 | 0 | workflowDocument.saveRoutingData(); |
221 | ||
222 | 0 | results = createResults(workflowDocument); |
223 | 0 | if (workflowDocument.getRouteHeaderId() != null) { |
224 | 0 | docId = workflowDocument.getRouteHeaderId().toString(); |
225 | } | |
226 | 0 | DocumentResponse docResponse = new DocumentResponse(results); |
227 | 0 | docResponse.setDocId(docId); |
228 | 0 | docResponse.setDocContent(workflowDocument.getApplicationContent()); |
229 | 0 | docResponse.setTitle(workflowDocument.getTitle()); |
230 | 0 | docResponse.setNotes(new ArrayList<NoteDetail>()); |
231 | 0 | if (workflowDocument.isApprovalRequested()) { |
232 | 0 | docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL); |
233 | 0 | } else if (workflowDocument.isAcknowledgeRequested()) { |
234 | 0 | docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL); |
235 | 0 | } else if (workflowDocument.isFYIRequested()) { |
236 | 0 | docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL); |
237 | 0 | } else if (workflowDocument.isCompletionRequested()) { |
238 | // TODO: how do we want to handle a "Complete" request? | |
239 | 0 | docResponse.setActionRequested(KEWConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL); |
240 | } | |
241 | 0 | return docResponse; |
242 | 0 | } catch (WorkflowException e) { |
243 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
244 | 0 | DocumentResponse docResponse = new DocumentResponse(results); |
245 | 0 | docResponse.setDocId(docId); |
246 | 0 | return docResponse; |
247 | } | |
248 | } | |
249 | ||
250 | /** | |
251 | * <ol> | |
252 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
253 | * <li>Disapprove the document with the passed in annotation</li> | |
254 | * <li>Return the standard set of return values</li> | |
255 | * </ol> | |
256 | * | |
257 | * @param docId KEW document id of the document to disapprove | |
258 | * @param principalId principal id of the user who is disapproving the document | |
259 | * @param annotation a comment associated with this request | |
260 | * @return Map including the standard set of return values | |
261 | * | |
262 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#disapprove(java.lang.String, java.lang.String, java.lang.String) | |
263 | */ | |
264 | public StandardResponse disapprove(String docId, String principalId, String annotation) { | |
265 | // Map<String, Object> results; | |
266 | StandardResponse results; | |
267 | ||
268 | try { | |
269 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
270 | ||
271 | 0 | workflowDocument.disapprove(annotation); |
272 | 0 | results = createResults(workflowDocument); |
273 | 0 | } catch (WorkflowException e) { |
274 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
275 | 0 | } |
276 | ||
277 | 0 | return results; |
278 | } | |
279 | ||
280 | /** | |
281 | * <ol> | |
282 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
283 | * <li>Clear the FYI request on the document</li> | |
284 | * <li>Return the standard set of return values</li> | |
285 | * </ol> | |
286 | * | |
287 | * @param docId KEW document id of the document to acknowledge | |
288 | * @param principalId principal id of the user who is acknowledging the document | |
289 | * @return Map including the standard set of return values | |
290 | * | |
291 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#fyi(java.lang.String, java.lang.String) | |
292 | */ | |
293 | public StandardResponse fyi(String docId, String principalId) { | |
294 | // Map<String, Object> results; | |
295 | StandardResponse results; | |
296 | ||
297 | try { | |
298 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
299 | ||
300 | 0 | workflowDocument.fyi(); |
301 | 0 | results = createResults(workflowDocument); |
302 | 0 | } catch (WorkflowException e) { |
303 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
304 | 0 | } |
305 | ||
306 | 0 | return results; |
307 | } | |
308 | ||
309 | /** | |
310 | * <ol> | |
311 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
312 | * <li>Get the document content and the action requested (Approve, Acknowledge, etc) of the user</li> | |
313 | * <li>Return the standard set of return values, the docContent, the title, | |
314 | * and the actionRequested</li> | |
315 | * </ol> | |
316 | * | |
317 | * @param docId KEW document id of the document to retrieve information about | |
318 | * @param principalId principal id of the user to retrieve the document for | |
319 | * @return Map including the standard set of return values, the xml document content, | |
320 | * the action requested ( Approve, Acknowledge, Fyi, Complete ) and an array of Maps | |
321 | * containing the following for each Note (author, noteId, timestamp, noteText). | |
322 | * | |
323 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#getDocument(java.lang.String, java.lang.String) | |
324 | */ | |
325 | public DocumentResponse getDocument(String docId, String principalId) { | |
326 | // Map<String, Object> results; | |
327 | StandardResponse results; | |
328 | 0 | List<NoteDetail> noteDetails = new ArrayList<NoteDetail>(0); |
329 | 0 | String actionRequested = ""; |
330 | 0 | String docContent = ""; |
331 | 0 | String title = ""; |
332 | ||
333 | try { | |
334 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
335 | 0 | RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader(); |
336 | ||
337 | 0 | if (routeHeader == null) { |
338 | 0 | results = createErrorResults("Error: NULL Route Header"); |
339 | } else { | |
340 | 0 | results = createStandardResults(routeHeader); |
341 | 0 | docContent = workflowDocument.getApplicationContent(); |
342 | 0 | title = workflowDocument.getTitle(); |
343 | 0 | List notes = workflowDocument.getNoteList(); |
344 | 0 | noteDetails = buildNoteDetails(notes); |
345 | ||
346 | 0 | if (routeHeader.isApproveRequested()) { |
347 | 0 | actionRequested = KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL; |
348 | 0 | } else if (routeHeader.isAckRequested()) { |
349 | 0 | actionRequested = KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL; |
350 | 0 | } else if (routeHeader.isFyiRequested()) { |
351 | 0 | actionRequested = KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL; |
352 | 0 | } else if (routeHeader.isCompleteRequested()) { |
353 | // TODO: how do we want to handle a "Complete" request? | |
354 | 0 | actionRequested = KEWConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL; |
355 | } | |
356 | } | |
357 | 0 | } catch (WorkflowException e) { |
358 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
359 | 0 | } |
360 | ||
361 | 0 | DocumentResponse docResponse = new DocumentResponse(results); |
362 | ||
363 | // results.put(DOC_CONTENT_LABEL, docContent); | |
364 | // results.put(TITLE_LABEL, title); | |
365 | // results.put(NOTES_LABEL, noteDetails); | |
366 | // results.put(ACTION_REQUESTED_LABEL, actionRequested); | |
367 | ||
368 | 0 | docResponse.setDocId(docId); |
369 | 0 | docResponse.setDocContent(docContent); |
370 | 0 | docResponse.setTitle(title); |
371 | 0 | docResponse.setNotes(noteDetails); |
372 | 0 | docResponse.setActionRequested(actionRequested); |
373 | ||
374 | 0 | return docResponse; |
375 | } | |
376 | ||
377 | /** | |
378 | * <ol> | |
379 | * <li>Create a new WorkflowInfo object</li> | |
380 | * <li>Call isUserAuthenticatedByRouteLog on the WorkflowInfo object to see if the user is in the route log</li> | |
381 | * <li>Return True/False and an error message if any</li> | |
382 | * </ol> | |
383 | * Useful for security purposes (if return is False, user shouldn't | |
384 | * be able to see the document unless it's public.) | |
385 | * | |
386 | * Call isUserAuthenticatedByRouteLog with true for the lookFuture parameter so that | |
387 | * we will check future workflow requests as well as currently outstanding requests. | |
388 | * | |
389 | * @param docId KEW document id of the document to check | |
390 | * @param principalId principal id of the user to check | |
391 | * @return Map containing True/False for isUserInRouteLog and an error message if | |
392 | * a problem occured | |
393 | * | |
394 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#isUserInRouteLog(java.lang.String, java.lang.String) | |
395 | */ | |
396 | public UserInRouteLogResponse isUserInRouteLog(String docId, String principalId) { | |
397 | //Map<String, Object> results = new HashMap<String, Object>(6); | |
398 | ||
399 | 0 | UserInRouteLogResponse results = new UserInRouteLogResponse(); |
400 | 0 | String errorMessage = ""; |
401 | 0 | boolean isUserInRouteLog = false; |
402 | 0 | WorkflowInfo info = new WorkflowInfo(); |
403 | try { | |
404 | 0 | Long id = Long.parseLong(docId); |
405 | 0 | isUserInRouteLog = info.isUserAuthenticatedByRouteLog(id, principalId, true); |
406 | 0 | } catch (NumberFormatException e) { |
407 | 0 | errorMessage = "Invalid (non-numeric) docId"; |
408 | 0 | } catch (WorkflowException e) { |
409 | 0 | errorMessage = "Workflow Error: " + e.getLocalizedMessage(); |
410 | 0 | } |
411 | ||
412 | 0 | results.setIsUserInRouteLog(String.valueOf(isUserInRouteLog)); |
413 | 0 | results.setErrorMessage(errorMessage); |
414 | 0 | return results; |
415 | } | |
416 | ||
417 | /** | |
418 | * <ol> | |
419 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
420 | * <li>Add the adhoc acknowlege request (app specific route) to the passed in group with the passed in annotation</li> | |
421 | * <li>Return the standard set of return values</li> | |
422 | * </ol> | |
423 | * | |
424 | * @param docId KEW document id of the document to create the adhoc request for | |
425 | * @param principalId principal id of the user who is making this request | |
426 | * @param recipientGroupId workgroupId of the group to create this request for | |
427 | * @param annotation a comment associated with this request | |
428 | * @return Map including the standard set of return values | |
429 | * | |
430 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#requestAdHocAckToGroup(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
431 | */ | |
432 | public StandardResponse requestAdHocAckToGroup(String docId, String principalId, | |
433 | String recipientGroupId, String annotation) { | |
434 | 0 | return requestAdHocToGroup(docId, principalId, recipientGroupId, annotation, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL); |
435 | } | |
436 | ||
437 | /** | |
438 | * <ol> | |
439 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
440 | * <li>Add the adhoc acknowlege request (app specific route) to the passed in user with the passed in annotation</li> | |
441 | * <li>Return the standard set of return values</li> | |
442 | * </ol> | |
443 | * | |
444 | * @param docId KEW document id of the document to create the adhoc request for | |
445 | * @param principalId principal id of the user who is making this request | |
446 | * @param recipientPrincipalId principal id of the user for whom the request is being created | |
447 | * @param annotation a comment associated with this request | |
448 | * @return Map including the standard set of return values | |
449 | */ | |
450 | public StandardResponse requestAdHocAckToPrincipal(String docId, String principalId, | |
451 | String recipientPrincipalId, String annotation) { | |
452 | 0 | return requestAdHocToPrincipal(docId, principalId, recipientPrincipalId, annotation, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL); |
453 | } | |
454 | ||
455 | /** | |
456 | * <ol> | |
457 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
458 | * <li>Add the adhoc approve request (app specific route) to the passed in group with the passed in annotation</li> | |
459 | * <li>Return the standard set of return values</li> | |
460 | * </ol> | |
461 | * | |
462 | * @param docId KEW document id of the document to create the adhoc request for | |
463 | * @param principalId principal id of the user who is making this request | |
464 | * @param recipientGroupId workgroupId of the group to create this request for | |
465 | * @param annotation a comment associated with this request | |
466 | * @return Map including the standard set of return values | |
467 | * | |
468 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#requestAdHocApproveToGroup(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
469 | */ | |
470 | public StandardResponse requestAdHocApproveToGroup(String docId, String principalId, | |
471 | String recipientGroupId, String annotation) { | |
472 | 0 | return requestAdHocToGroup(docId, principalId, recipientGroupId, annotation, KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL); |
473 | } | |
474 | ||
475 | /** | |
476 | * <ol> | |
477 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
478 | * <li>Add the adhoc approve request (app specific route) to the passed in user with the passed in annotation</li> | |
479 | * <li>Return the standard set of return values</li> | |
480 | * </ol> | |
481 | * | |
482 | * @param docId KEW document id of the document to create the adhoc request for | |
483 | * @param principalId principal id of the user who is making this request | |
484 | * @param recipientPrincipalId principal id of the user for whom the request is being created | |
485 | * @param annotation a comment associated with this request | |
486 | * @return Map including the standard set of return values | |
487 | */ | |
488 | public StandardResponse requestAdHocApproveToPrincipal(String docId, String principalId, | |
489 | String recipientPrincipalId, String annotation) { | |
490 | ||
491 | 0 | return requestAdHocToPrincipal(docId, principalId, recipientPrincipalId, annotation, KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL); |
492 | } | |
493 | ||
494 | /** | |
495 | * <ol> | |
496 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
497 | * <li>Add the adhoc fyi request (app specific route) to the passed in group with the passed in annotation</li> | |
498 | * <li>Return the standard set of return values</li> | |
499 | * </ol> | |
500 | * | |
501 | * @param docId KEW document id of the document to create the adhoc request for | |
502 | * @param principalId principal id of the user who is making this request | |
503 | * @param recipientGroupId workgroupId of the group to create this request for | |
504 | * @param annotation a comment associated with this request | |
505 | * @return Map including the standard set of return values | |
506 | * | |
507 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#requestAdHocFyiToGroup(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
508 | */ | |
509 | public StandardResponse requestAdHocFyiToGroup(String docId, String principalId, String recipientGroupId, String annotation) { | |
510 | 0 | return requestAdHocToGroup(docId, principalId, recipientGroupId, annotation, KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL); |
511 | } | |
512 | ||
513 | /** | |
514 | * <ol> | |
515 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
516 | * <li>Add the adhoc fyi request (app specific route) to the passed in user with the passed in annotation</li> | |
517 | * <li>Return the standard set of return values</li> | |
518 | * </ol> | |
519 | * | |
520 | * @param docId KEW document id of the document to create the adhoc request for | |
521 | * @param principalId principal id of the user who is making this request | |
522 | * @param recipientPrincipalId principal id of the user for whom the request is being created | |
523 | * @param annotation a comment associated with this request | |
524 | * @return Map including the standard set of return values | |
525 | */ | |
526 | public StandardResponse requestAdHocFyiToPrincipal(String docId, String principalId, | |
527 | String recipientPrincipalId, String annotation) { | |
528 | 0 | return requestAdHocToPrincipal(docId, principalId, recipientPrincipalId, annotation, KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL); |
529 | } | |
530 | ||
531 | /** | |
532 | * Create the adhoc request for the specified group. | |
533 | * | |
534 | * @param docId KEW document id of the document to create the adhoc request for | |
535 | * @param principalId principal id of the user who is making this request | |
536 | * @param recipientGroupId workflowid of the group for whom the request is being created | |
537 | * @param annotation a comment associated with this request | |
538 | * @param actionRequested the action for this adhoc request ( A)pprove, aK)nowledge, F)yi ) | |
539 | * @param responsibilityDesc description of the type of responsibility for this request | |
540 | * @return Map including the standard set of return values | |
541 | */ | |
542 | private StandardResponse requestAdHocToGroup(String docId, String principalId, | |
543 | String groupId, String annotation, String actionRequested, String responsibilityDesc) { | |
544 | // Map<String, Object> results; | |
545 | StandardResponse results; | |
546 | ||
547 | try { | |
548 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
549 | 0 | workflowDocument.adHocRouteDocumentToGroup(actionRequested, annotation, groupId, responsibilityDesc, true); |
550 | 0 | results = createResults(workflowDocument); |
551 | 0 | } catch (WorkflowException e) { |
552 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
553 | 0 | } |
554 | ||
555 | 0 | return results; |
556 | } | |
557 | ||
558 | /** | |
559 | * Create the adhoc request for the specified user. | |
560 | * | |
561 | * @param docId KEW document id of the document to create the adhoc request for | |
562 | * @param principalId principal id of the user who is making this request | |
563 | * @param recipientPrincipalId principal id of the user for whom the request is being created | |
564 | * @param annotation a comment associated with this request | |
565 | * @param actionRequested the action for this adhoc request ( A)pprove, aK)nowledge, F)yi ) | |
566 | * @param responsibilityDesc description of the type of responsibility for this request | |
567 | * @return Map including the standard set of return values | |
568 | */ | |
569 | private StandardResponse requestAdHocToPrincipal(String docId, String principalId, | |
570 | String recipientPrincipalId, String annotation, String actionRequested, String responsibilityDesc) { | |
571 | StandardResponse results; | |
572 | try { | |
573 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
574 | 0 | workflowDocument.adHocRouteDocumentToPrincipal(actionRequested, annotation, recipientPrincipalId, responsibilityDesc, true); |
575 | 0 | results = createResults(workflowDocument); |
576 | 0 | } catch (WorkflowException e) { |
577 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
578 | 0 | } |
579 | 0 | return results; |
580 | } | |
581 | ||
582 | /** | |
583 | * <ol> | |
584 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
585 | * <li>Set the docTitle and docContent if they are passed in</li> | |
586 | * <li>Route the document with the passed in annotation</li> | |
587 | * <li>Return the standard set of return values.</li> | |
588 | * </ol> | |
589 | * | |
590 | * @param docId KEW document id of the document to route | |
591 | * @param principalId principal id of the user who is routing the document | |
592 | * @param docTitle title for this document | |
593 | * @param docContent xml content for this document | |
594 | * @param annotation a comment associated with this request | |
595 | * @return Map including the standard set of return values | |
596 | * | |
597 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#route(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
598 | */ | |
599 | public StandardResponse route(String docId, String principalId, String docTitle, | |
600 | String docContent, String annotation) { | |
601 | ||
602 | //Map<String, Object> results; | |
603 | StandardResponse results; | |
604 | ||
605 | try { | |
606 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
607 | ||
608 | 0 | workflowDocument.routeDocument(annotation); |
609 | 0 | results = createResults(workflowDocument); |
610 | 0 | } catch (WorkflowException e) { |
611 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
612 | 0 | } |
613 | ||
614 | 0 | return results; |
615 | } | |
616 | ||
617 | /** | |
618 | * <ol> | |
619 | * <li>Create a WorkflowDocument based on the docId and principalId passed in</li> | |
620 | * <li>Set the docTitle if it was passed in</li> | |
621 | * <li>Save the document with the passed in annotation (keep in user's action list)</li> | |
622 | * <li>Return the standard set of return values.</li> | |
623 | * </ol> | |
624 | * | |
625 | * @param docId KEW document id of the document to save | |
626 | * @param principalId principal id of the user who is saving the document | |
627 | * @param docTitle title for this document | |
628 | * @param docContent xml content for this document | |
629 | * @param annotation a comment associated with this request | |
630 | * @return Map including the standard set of return values | |
631 | * | |
632 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#save(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
633 | */ | |
634 | public StandardResponse save(String docId, String principalId, String docTitle, String docContent, String annotation) { | |
635 | StandardResponse results; | |
636 | ||
637 | try { | |
638 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
639 | 0 | workflowDocument.saveDocument(annotation); |
640 | 0 | results = createResults(workflowDocument); |
641 | 0 | } catch (WorkflowException e) { |
642 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
643 | 0 | } |
644 | ||
645 | 0 | return results; |
646 | } | |
647 | ||
648 | /** | |
649 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#saveDocumentContent(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
650 | */ | |
651 | public StandardResponse saveDocumentContent(String docId, String principalId, String docTitle, String docContent) { | |
652 | StandardResponse results; | |
653 | ||
654 | try { | |
655 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
656 | 0 | workflowDocument.saveRoutingData(); |
657 | 0 | results = createResults(workflowDocument); |
658 | 0 | } catch (WorkflowException e) { |
659 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
660 | 0 | } |
661 | ||
662 | 0 | return results; |
663 | } | |
664 | ||
665 | /** | |
666 | * Add a note to this KEW document. | |
667 | * | |
668 | * @param docId KEW document id of the document to add the note to | |
669 | * @param principalId principal id of the user who is adding the note | |
670 | * @param noteText text of the note | |
671 | * @return Map containing relevant note information (author, noteId, timestamp, noteText) | |
672 | * along with an error message (if any) | |
673 | * | |
674 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#addNote(java.lang.String, java.lang.String, java.lang.String) | |
675 | */ | |
676 | public NoteResponse addNote(String docId, String principalId, String noteText) { | |
677 | // Map<String, Object> results = new HashMap<String, Object>(5); | |
678 | 0 | NoteResponse results = new NoteResponse(); |
679 | ||
680 | 0 | String author = ""; |
681 | 0 | String noteId = ""; |
682 | 0 | String timestamp = ""; |
683 | 0 | String resultsNoteText = ""; |
684 | 0 | String errorMessage = ""; |
685 | ||
686 | // results.put(ERROR_MESSAGE_LABEL, ""); | |
687 | ||
688 | 0 | results.setErrorMessage(""); |
689 | ||
690 | try { | |
691 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
692 | ||
693 | // setup note | |
694 | 0 | NoteDTO noteVO = new NoteDTO(); |
695 | 0 | noteVO.setNoteAuthorWorkflowId(principalId); |
696 | 0 | noteVO.setNoteCreateDate(new GregorianCalendar()); |
697 | 0 | noteVO.setNoteText(noteText); |
698 | 0 | noteVO.setRouteHeaderId(workflowDocument.getRouteHeaderId()); |
699 | 0 | workflowDocument.updateNote(noteVO); |
700 | ||
701 | //TODO: is this necessary? | |
702 | 0 | workflowDocument.saveRoutingData(); |
703 | 0 | RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader(); |
704 | ||
705 | //TODO: do we need to return the standard result set? | |
706 | //results = createResults(workflowDocument); | |
707 | ||
708 | 0 | noteVO = routeHeader.getNotes()[routeHeader.getNotes().length-1]; |
709 | ||
710 | // return note info | |
711 | 0 | Person person = KIMServiceLocator.getPersonService().getPerson(noteVO.getNoteAuthorWorkflowId()); |
712 | 0 | author = person.getName(); |
713 | 0 | noteId = noteVO.getNoteId().toString(); |
714 | 0 | timestamp = formatCalendar(noteVO.getNoteCreateDate()); |
715 | 0 | resultsNoteText = noteVO.getNoteText(); |
716 | 0 | } catch (WorkflowException e) { |
717 | 0 | errorMessage = "Workflow Error: " + e.getLocalizedMessage(); |
718 | 0 | } |
719 | 0 | results.setAuthor(author); |
720 | 0 | results.setNoteId(noteId); |
721 | 0 | results.setTimestamp(timestamp); |
722 | 0 | results.setNoteText(resultsNoteText); |
723 | 0 | results.setErrorMessage(errorMessage); |
724 | ||
725 | 0 | return results; |
726 | } | |
727 | ||
728 | /** | |
729 | * Update an existing note to this KEW document. | |
730 | * | |
731 | * @param docId KEW document id of the document to update the note for | |
732 | * @param noteId the id of the note to update | |
733 | * @param principalId principal id of the user who is updating the note | |
734 | * @param noteText text of the note if changed | |
735 | * @return Map containing relevant note information (author, noteId, timestamp, noteText) | |
736 | * along with an error message (if any) | |
737 | * | |
738 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#updateNote(java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
739 | */ | |
740 | public NoteResponse updateNote(String docId, String noteId, String principalId, String noteText) { | |
741 | // Map<String, Object> results = new HashMap<String, Object>(5); | |
742 | 0 | String author = ""; |
743 | 0 | String resultsNoteId = ""; |
744 | 0 | String timestamp = ""; |
745 | 0 | String resultsNoteText = ""; |
746 | 0 | String errorMessage = ""; |
747 | ||
748 | try { | |
749 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
750 | 0 | RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader(); |
751 | ||
752 | // setup note | |
753 | 0 | NoteDTO noteVO = getNote(routeHeader.getNotes(), noteId); |
754 | 0 | noteVO.setNoteText(noteText); |
755 | 0 | workflowDocument.updateNote(noteVO); |
756 | ||
757 | //TODO: is this necessary? | |
758 | 0 | workflowDocument.saveRoutingData(); |
759 | 0 | routeHeader = workflowDocument.getRouteHeader(); |
760 | ||
761 | //TODO: do we need to return the standard result set? | |
762 | //results = createResults(workflowDocument); | |
763 | ||
764 | 0 | noteVO = getNote(routeHeader.getNotes(), noteId); |
765 | ||
766 | 0 | if (noteVO == null) { |
767 | 0 | errorMessage = "Error retrieving note for id [" + noteId + "]."; |
768 | } else { | |
769 | // return note info | |
770 | 0 | Person person = KIMServiceLocator.getPersonService().getPerson(noteVO.getNoteAuthorWorkflowId()); |
771 | 0 | author = person.getName(); |
772 | 0 | resultsNoteId = noteVO.getNoteId().toString(); |
773 | 0 | timestamp = formatCalendar(noteVO.getNoteCreateDate()); |
774 | 0 | resultsNoteText = noteVO.getNoteText(); |
775 | } | |
776 | 0 | } catch (WorkflowException e) { |
777 | 0 | errorMessage = "Workflow Error: " + e.getLocalizedMessage(); |
778 | 0 | } |
779 | ||
780 | 0 | NoteResponse results = new NoteResponse(); |
781 | ||
782 | 0 | results.setAuthor(author); |
783 | 0 | results.setNoteId(resultsNoteId); |
784 | 0 | results.setTimestamp(timestamp); |
785 | 0 | results.setNoteText(resultsNoteText); |
786 | 0 | results.setErrorMessage(errorMessage); |
787 | ||
788 | 0 | return results; |
789 | } | |
790 | ||
791 | /** | |
792 | * Delete an existing note. | |
793 | * | |
794 | * @param docId KEW document id of the document to delete the note from | |
795 | * @param noteId the id of the note to delete | |
796 | * @param principalId principal id of the user who is deleting the note | |
797 | * @return Map containing an error message if any | |
798 | * | |
799 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#deleteNote(java.lang.String, java.lang.String, java.lang.String) | |
800 | */ | |
801 | public ErrorResponse deleteNote(String docId, String noteId, String principalId) { | |
802 | //Map<String, Object> results = new HashMap<String, Object>(1); | |
803 | ||
804 | 0 | ErrorResponse results = new ErrorResponse(); |
805 | ||
806 | 0 | String errorMessage = ""; |
807 | ||
808 | try { | |
809 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId); |
810 | 0 | RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader(); |
811 | ||
812 | // setup note | |
813 | 0 | NoteDTO noteVO = getNote(routeHeader.getNotes(), noteId); |
814 | 0 | workflowDocument.deleteNote(noteVO); |
815 | ||
816 | //TODO: is this necessary? | |
817 | 0 | workflowDocument.saveRoutingData(); |
818 | ||
819 | //// update notes database based on notes and notesToDelete arrays in routeHeaderVO | |
820 | // DTOConverter.updateNotes(routeHeader, routeHeader.getRouteHeaderId()); | |
821 | 0 | } catch (WorkflowException e) { |
822 | 0 | errorMessage = "Workflow Error: " + e.getLocalizedMessage(); |
823 | 0 | } |
824 | //results.put(ERROR_MESSAGE_LABEL, errorMessage); | |
825 | ||
826 | 0 | results.setErrorMessage(errorMessage); |
827 | ||
828 | 0 | return results; |
829 | } | |
830 | ||
831 | /** | |
832 | * Return a KEW document to a previous route node. This method should | |
833 | * be used with caution. | |
834 | * | |
835 | * @param docId KEW document id of the document that is being returned | |
836 | * @param principalId principal id of the user who is returning the doc | |
837 | * @param annotation a comment associated with this request | |
838 | * @param nodeName name of the route node to return to | |
839 | * @return Map including the standard set of return values | |
840 | * | |
841 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#returnToPreviousNode(java.lang.String, java.lang.String) | |
842 | */ | |
843 | public StandardResponse returnToPreviousNode(String docId, String principalId, String annotation, String nodeName) { | |
844 | 0 | return returnToPreviousNodeWithUpdates(docId, principalId, annotation, nodeName, null, null); |
845 | } | |
846 | ||
847 | /** | |
848 | * Return a KEW document to a previous route node. This method should | |
849 | * be used with caution. | |
850 | * | |
851 | * @param docId KEW document id of the document that is being returned | |
852 | * @param principalId principal id of the user who is returning the doc | |
853 | * @param annotation a comment associated with this request | |
854 | * @param nodeName name of the route node to return to | |
855 | * @param docTitle title for this document | |
856 | * @param docContent xml content for this document | |
857 | * @return Map including the standard set of return values | |
858 | * | |
859 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#returnToPreviousNode(java.lang.String, java.lang.String) | |
860 | */ | |
861 | public StandardResponse returnToPreviousNodeWithUpdates(String docId, String principalId, String annotation, String nodeName, String docTitle, String docContent) { | |
862 | StandardResponse results; | |
863 | ||
864 | try { | |
865 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
866 | ||
867 | 0 | workflowDocument.returnToPreviousNode(annotation, nodeName); |
868 | 0 | results = createResults(workflowDocument); |
869 | 0 | } catch (WorkflowException e) { |
870 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
871 | 0 | } |
872 | ||
873 | 0 | return results; |
874 | } | |
875 | ||
876 | /** | |
877 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByNodeName(java.lang.String, | |
878 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
879 | */ | |
880 | public StandardResponse revokeAdHocRequestsByNodeName(String docId, String principalId, String docTitle, String docContent, String nodeName, String annotation) { | |
881 | StandardResponse results; | |
882 | ||
883 | try { | |
884 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
885 | 0 | AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO(); |
886 | 0 | revokeDTO.setNodeName(nodeName); |
887 | 0 | workflowDocument.revokeAdHocRequests(revokeDTO, annotation); |
888 | 0 | results = createResults(workflowDocument); |
889 | 0 | } catch (WorkflowException e) { |
890 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
891 | 0 | } |
892 | ||
893 | 0 | return results; |
894 | } | |
895 | ||
896 | /** | |
897 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByPrincipalId(java.lang.String, | |
898 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
899 | */ | |
900 | public StandardResponse revokeAdHocRequestsByPrincipalId(String docId, String principalId, String docTitle, String docContent, String adhocPrincipalId, String annotation) { | |
901 | StandardResponse results; | |
902 | ||
903 | try { | |
904 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
905 | 0 | AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO(); |
906 | 0 | revokeDTO.setPrincipalId(adhocPrincipalId); |
907 | 0 | workflowDocument.revokeAdHocRequests(revokeDTO, annotation); |
908 | 0 | results = createResults(workflowDocument); |
909 | 0 | } catch (WorkflowException e) { |
910 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
911 | 0 | } |
912 | ||
913 | 0 | return results; |
914 | } | |
915 | ||
916 | /** | |
917 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByGroupId(java.lang.String, | |
918 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
919 | */ | |
920 | public StandardResponse revokeAdHocRequestsByGroupId(String docId, String principalId, String docTitle, String docContent, String groupId, String annotation) { | |
921 | StandardResponse results; | |
922 | ||
923 | try { | |
924 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
925 | 0 | AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO(); |
926 | 0 | revokeDTO.setGroupId(groupId); |
927 | 0 | workflowDocument.revokeAdHocRequests(revokeDTO, annotation); |
928 | 0 | results = createResults(workflowDocument); |
929 | 0 | } catch (WorkflowException e) { |
930 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
931 | 0 | } |
932 | ||
933 | 0 | return results; |
934 | } | |
935 | ||
936 | /** | |
937 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#revokeAdHocRequestsByActionRequestId(java.lang.String, | |
938 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
939 | */ | |
940 | public StandardResponse revokeAdHocRequestsByActionRequestId(String docId, String principalId, String docTitle, String docContent, String actionRequestId, String annotation) { | |
941 | StandardResponse results; | |
942 | ||
943 | try { | |
944 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, principalId, docTitle, docContent); |
945 | 0 | AdHocRevokeDTO revokeDTO = new AdHocRevokeDTO(); |
946 | 0 | revokeDTO.setActionRequestId(Long.valueOf(actionRequestId)); |
947 | 0 | workflowDocument.revokeAdHocRequests(revokeDTO, annotation); |
948 | 0 | results = createResults(workflowDocument); |
949 | 0 | } catch (WorkflowException e) { |
950 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
951 | 0 | } |
952 | ||
953 | 0 | return results; |
954 | } | |
955 | ||
956 | /** | |
957 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#superUserApprove(java.lang.String, | |
958 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
959 | */ | |
960 | public StandardResponse superUserApprove(String docId, String superUserPrincipalId, String docTitle, String docContent, String annotation) { | |
961 | StandardResponse results; | |
962 | ||
963 | try { | |
964 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent); |
965 | ||
966 | 0 | workflowDocument.superUserApprove(annotation); |
967 | 0 | results = createResults(workflowDocument); |
968 | 0 | } catch (WorkflowServiceErrorException e) { |
969 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
970 | 0 | } catch (WorkflowException e) { |
971 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
972 | 0 | } |
973 | ||
974 | 0 | return results; |
975 | } | |
976 | ||
977 | /** | |
978 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#superUserDisapprove(java.lang.String, | |
979 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
980 | */ | |
981 | public StandardResponse superUserDisapprove(String docId, String superUserPrincipalId, String docTitle, String docContent, String annotation) { | |
982 | StandardResponse results; | |
983 | ||
984 | try { | |
985 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent); |
986 | ||
987 | 0 | workflowDocument.superUserDisapprove(annotation); |
988 | 0 | results = createResults(workflowDocument); |
989 | 0 | } catch (WorkflowServiceErrorException e) { |
990 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
991 | 0 | } catch (WorkflowException e) { |
992 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
993 | 0 | } |
994 | ||
995 | 0 | return results; |
996 | } | |
997 | ||
998 | /** | |
999 | * @see org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService#superUserCancel(java.lang.String, | |
1000 | * java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
1001 | */ | |
1002 | public StandardResponse superUserCancel(String docId, String superUserPrincipalId, String docTitle, String docContent, String annotation) { | |
1003 | StandardResponse results; | |
1004 | ||
1005 | try { | |
1006 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent); |
1007 | ||
1008 | 0 | workflowDocument.superUserCancel(annotation); |
1009 | 0 | results = createResults(workflowDocument); |
1010 | 0 | } catch (WorkflowServiceErrorException e) { |
1011 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
1012 | 0 | } catch (WorkflowException e) { |
1013 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
1014 | 0 | } |
1015 | ||
1016 | 0 | return results; |
1017 | } | |
1018 | ||
1019 | public StandardResponse superUserReturnToPrevious(String docId, String superUserPrincipalId, String docTitle, String docContent, String nodeName, String annotation) { | |
1020 | StandardResponse results; | |
1021 | ||
1022 | try { | |
1023 | // verify that the doc id has been sent in correctly | |
1024 | 0 | if (StringUtils.isBlank(docId)) { |
1025 | 0 | throw new WorkflowException("Invalid Parameter: docId is required but was blank"); |
1026 | } | |
1027 | // if the docTitle or docContent has been updated then update it with a saveRoutingData call | |
1028 | 0 | if (StringUtils.isNotEmpty(docTitle) || StringUtils.isNotEmpty(docContent)) { |
1029 | 0 | WorkflowDocument workflowDocument = setupWorkflowDocument(docId, superUserPrincipalId, docTitle, docContent); |
1030 | 0 | workflowDocument.saveRoutingData(); |
1031 | } | |
1032 | // perform the return to previous | |
1033 | 0 | KEWServiceLocator.getWorkflowDocumentActionsService().superUserReturnToPreviousNode(superUserPrincipalId, Long.valueOf(docId), nodeName, annotation); |
1034 | // refetch the WorkflowDocument after the return to previous is completed | |
1035 | 0 | results = createResults(new WorkflowDocument(superUserPrincipalId, Long.decode(docId))); |
1036 | 0 | } catch (WorkflowServiceErrorException e) { |
1037 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
1038 | 0 | } catch (WorkflowException e) { |
1039 | 0 | results = createErrorResults("Workflow Error: " + e.getLocalizedMessage()); |
1040 | 0 | } |
1041 | ||
1042 | 0 | return results; |
1043 | } | |
1044 | ||
1045 | private NoteDTO getNote(NoteDTO[] notes, String noteId) { | |
1046 | 0 | NoteDTO note = null; |
1047 | ||
1048 | 0 | if (notes != null){ |
1049 | 0 | for (int i=0; i<notes.length; i++){ |
1050 | 0 | if (notes[i].getNoteId().toString().equals(noteId)) { |
1051 | 0 | note = notes[i]; |
1052 | 0 | break; |
1053 | } | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | 0 | return note; |
1058 | } | |
1059 | ||
1060 | /** | |
1061 | * Convenience method to setup workflow document without title or content. | |
1062 | * | |
1063 | * @param docId KEW document id for the document to setup | |
1064 | * @param principalId KEW principal id for the user associated with this document | |
1065 | * @return populated WorkflowDocument object | |
1066 | * @throws WorkflowException if something goes wrong | |
1067 | */ | |
1068 | private WorkflowDocument setupWorkflowDocument(String docId, String principalId) throws WorkflowException { | |
1069 | 0 | return setupWorkflowDocument(docId, principalId, null, null); |
1070 | } | |
1071 | ||
1072 | /** | |
1073 | * Instantiate and setup the WorkflowDocument object. | |
1074 | * | |
1075 | * @param docId KEW document id for the document to setup | |
1076 | * @param principalId KEW principal id for the user associated with this document | |
1077 | * @param docTitle title for this document | |
1078 | * @param docContent xml content for this document | |
1079 | * @return populated WorkflowDocument object | |
1080 | * @throws WorkflowException if something goes wrong | |
1081 | */ | |
1082 | private WorkflowDocument setupWorkflowDocument(String docId, String principalId, String docTitle, String docContent) throws WorkflowException { | |
1083 | 0 | WorkflowDocument workflowDocument = new WorkflowDocument(principalId, Long.decode(docId)); |
1084 | 0 | if (StringUtils.isNotEmpty(docTitle)) { |
1085 | 0 | workflowDocument.setTitle(docTitle); |
1086 | } | |
1087 | 0 | if (StringUtils.isNotEmpty(docContent)) { |
1088 | 0 | workflowDocument.setApplicationContent(docContent); |
1089 | } | |
1090 | 0 | return workflowDocument; |
1091 | } | |
1092 | ||
1093 | /** | |
1094 | * Create the note details result set. | |
1095 | * | |
1096 | * @param notes List of notes to build details Map array for | |
1097 | * @return Map[] containing note details | |
1098 | * @throws WorkflowException if an error occurs retrieving user display name | |
1099 | */ | |
1100 | private List<NoteDetail> buildNoteDetails(List notes) throws WorkflowException { | |
1101 | List<NoteDetail> noteDetails; | |
1102 | ||
1103 | 0 | if (notes == null) { |
1104 | 0 | noteDetails = new ArrayList<NoteDetail>(0); |
1105 | } else { | |
1106 | 0 | noteDetails = new ArrayList<NoteDetail>(notes.size()); |
1107 | 0 | for (int i=0;i<notes.size();i++) { |
1108 | //Map<String, String> noteDetail = new HashMap<String, String>(4); | |
1109 | ||
1110 | 0 | NoteDetail noteDetail = new NoteDetail(); |
1111 | 0 | NoteDTO note = (NoteDTO)notes.get(i); |
1112 | //author, noteId, timestamp, noteText | |
1113 | 0 | Person person = KIMServiceLocator.getPersonService().getPerson(note.getNoteAuthorWorkflowId()); |
1114 | 0 | noteDetail.setAuthor(person.getName()); |
1115 | 0 | noteDetail.setId(note.getNoteId().toString()); |
1116 | 0 | noteDetail.setTimestamp(formatCalendar(note.getNoteCreateDate())); |
1117 | 0 | noteDetail.setNoteText(note.getNoteText()); |
1118 | ||
1119 | 0 | noteDetails.add(noteDetail); |
1120 | } | |
1121 | } | |
1122 | ||
1123 | 0 | return noteDetails; |
1124 | } | |
1125 | ||
1126 | ||
1127 | /** | |
1128 | * Create the result set, either the standard results or error results | |
1129 | * if the routeHeader is null. | |
1130 | * | |
1131 | * @param workflowDocument WorkflowDocument used to get route header info | |
1132 | * @return Map containing results of the call (either standard or error version) | |
1133 | */ | |
1134 | private StandardResponse createResults(WorkflowDocument workflowDocument) { | |
1135 | //Map<String, Object> results; | |
1136 | ||
1137 | StandardResponse response; | |
1138 | ||
1139 | 0 | RouteHeaderDTO routeHeader = workflowDocument.getRouteHeader(); |
1140 | ||
1141 | 0 | if (routeHeader == null) { |
1142 | 0 | response = createErrorResults("Error: NULL Route Header"); |
1143 | } else { | |
1144 | 0 | response = createStandardResults(routeHeader); |
1145 | } | |
1146 | ||
1147 | 0 | return response; |
1148 | } | |
1149 | ||
1150 | /** | |
1151 | * Create the standard result set with only the error message populated. | |
1152 | * | |
1153 | * @param errorMessage the message describing what error occured in the KEW engine | |
1154 | * @return Map containing the standard result set with only the error message populated | |
1155 | */ | |
1156 | private StandardResponse createErrorResults(String errorMessage) { | |
1157 | 0 | StandardResponse response = new StandardResponse(); |
1158 | 0 | response.setDocStatus(""); |
1159 | 0 | response.setCreateDate(""); |
1160 | 0 | response.setInitiatorPrincipalId(""); |
1161 | 0 | response.setRoutedByPrincipalId(""); |
1162 | 0 | response.setAppDocId(""); |
1163 | 0 | response.setInitiatorName(""); |
1164 | 0 | response.setRoutedByUserName(""); |
1165 | 0 | response.setErrorMessage(errorMessage); |
1166 | ||
1167 | 0 | return response; |
1168 | } | |
1169 | ||
1170 | /** | |
1171 | * Create the standard result set populated with values contained in the | |
1172 | * documents route header. | |
1173 | * | |
1174 | * @param routeHeader RouteHeaderVO for this document | |
1175 | * @return Map containing the standard result set populated with values contained in the | |
1176 | * documents route header. | |
1177 | */ | |
1178 | private StandardResponse createStandardResults(RouteHeaderDTO routeHeader) { | |
1179 | 0 | String docStatus = ""; |
1180 | 0 | String createDate = ""; |
1181 | 0 | String initiatorPrincipalId = ""; |
1182 | 0 | String routedByPrincipalId = ""; |
1183 | 0 | String appDocId = ""; |
1184 | 0 | String initiatorName = ""; |
1185 | 0 | String routedByUserName = ""; |
1186 | 0 | String errorMessage = ""; |
1187 | ||
1188 | 0 | if (routeHeader == null) { |
1189 | 0 | errorMessage = "Error: NULL Route Header"; |
1190 | } else { | |
1191 | 0 | if (routeHeader.getDocRouteStatus() == null) { |
1192 | 0 | errorMessage = "Error: NULL Route Status; "; |
1193 | } else { | |
1194 | 0 | docStatus = routeHeader.getDocRouteStatus(); |
1195 | } | |
1196 | ||
1197 | 0 | if (routeHeader.getDateCreated() == null) { |
1198 | 0 | errorMessage += "Error: NULL Date Created; "; |
1199 | } else { | |
1200 | 0 | createDate = formatCalendar(routeHeader.getDateCreated()); |
1201 | } | |
1202 | ||
1203 | 0 | if (routeHeader.getInitiatorPrincipalId() == null) { |
1204 | 0 | errorMessage += "Error: NULL Initiator; "; |
1205 | } else { | |
1206 | 0 | initiatorPrincipalId = routeHeader.getInitiatorPrincipalId(); |
1207 | 0 | Person initiator = KIMServiceLocator.getPersonService().getPerson(initiatorPrincipalId); |
1208 | 0 | if (initiator != null) { |
1209 | 0 | initiatorName = initiator.getName(); |
1210 | } | |
1211 | } | |
1212 | ||
1213 | 0 | if (routeHeader.getRoutedByPrincipalId() == null) { |
1214 | // of the document has been routed, but there is no routed-by user, that is an error | |
1215 | 0 | if (KEWConstants.ROUTE_HEADER_ENROUTE_CD.equals(routeHeader.getDocRouteStatus())) { |
1216 | 0 | errorMessage += "Error: NULL routedBy user; "; |
1217 | } | |
1218 | } else { | |
1219 | 0 | routedByPrincipalId = routeHeader.getRoutedByPrincipalId(); |
1220 | 0 | Person routedByUser = KIMServiceLocator.getPersonService().getPerson(initiatorPrincipalId); |
1221 | 0 | if (routedByUser != null) { |
1222 | 0 | routedByUserName = routedByUser.getName(); |
1223 | } | |
1224 | } | |
1225 | ||
1226 | 0 | if (routeHeader.getAppDocId() != null) { |
1227 | 0 | appDocId = routeHeader.getAppDocId(); |
1228 | } | |
1229 | } | |
1230 | ||
1231 | //Map<String, Object> results = new HashMap<String, Object>(6); | |
1232 | 0 | StandardResponse response = new StandardResponse(); |
1233 | ||
1234 | // results.put(DOC_STATUS_LABEL, docStatus); | |
1235 | // results.put(CREATE_DATE_LABEL, createDate); | |
1236 | // results.put(INITIATOR_ID_LABEL, initiatorPrincipalId); | |
1237 | // results.put(ROUTED_BY_USER_ID_LABEL, routedByprincipalId); | |
1238 | // results.put(APP_DOC_ID_LABEL, appDocId); | |
1239 | // results.put(INITIATOR_NAME_LABEL, initiatorName); | |
1240 | // results.put(ROUTED_BY_USER_NAME_LABEL, routedByUserName); | |
1241 | // results.put(ERROR_MESSAGE_LABEL, errorMessage); | |
1242 | ||
1243 | 0 | response.setDocStatus(docStatus); |
1244 | 0 | response.setCreateDate(createDate); |
1245 | 0 | response.setInitiatorPrincipalId(initiatorPrincipalId); |
1246 | 0 | response.setRoutedByPrincipalId(routedByPrincipalId); |
1247 | 0 | response.setAppDocId(appDocId); |
1248 | 0 | response.setInitiatorName(initiatorName); |
1249 | 0 | response.setRoutedByUserName(routedByUserName); |
1250 | 0 | response.setErrorMessage(errorMessage); |
1251 | ||
1252 | 0 | return response; |
1253 | } | |
1254 | ||
1255 | ||
1256 | /** | |
1257 | * Format a String date based on a given Calendar object. | |
1258 | * | |
1259 | * @param calendar Calendar date to format | |
1260 | * @return String formatted date | |
1261 | */ | |
1262 | private String formatCalendar(Calendar calendar) { | |
1263 | 0 | String formattedDate = ""; |
1264 | ||
1265 | 0 | DateFormat dateFormat = new SimpleDateFormat(); |
1266 | 0 | Timestamp dateCreated = Utilities.convertCalendar(calendar); |
1267 | 0 | formattedDate = dateFormat.format(dateCreated); |
1268 | ||
1269 | 0 | return formattedDate; |
1270 | } | |
1271 | ||
1272 | } |