1 | |
package org.kuali.rice.kew.impl.action; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.apache.log4j.Logger; |
5 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
6 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
7 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
8 | |
import org.kuali.rice.kew.api.action.ActionRequestType; |
9 | |
import org.kuali.rice.kew.api.action.ActionType; |
10 | |
import org.kuali.rice.kew.api.action.AdHocRevoke; |
11 | |
import org.kuali.rice.kew.api.action.AdHocToGroup; |
12 | |
import org.kuali.rice.kew.api.action.AdHocToPrincipal; |
13 | |
import org.kuali.rice.kew.api.action.DocumentActionParameters; |
14 | |
import org.kuali.rice.kew.api.action.DocumentActionResult; |
15 | |
import org.kuali.rice.kew.api.action.InvalidActionTakenException; |
16 | |
import org.kuali.rice.kew.api.action.MovePoint; |
17 | |
import org.kuali.rice.kew.api.action.RequestedActions; |
18 | |
import org.kuali.rice.kew.api.action.ReturnPoint; |
19 | |
import org.kuali.rice.kew.api.action.ValidActions; |
20 | |
import org.kuali.rice.kew.api.action.WorkflowDocumentActionsService; |
21 | |
import org.kuali.rice.kew.api.doctype.DocumentTypeService; |
22 | |
import org.kuali.rice.kew.api.doctype.IllegalDocumentTypeException; |
23 | |
import org.kuali.rice.kew.api.document.Document; |
24 | |
import org.kuali.rice.kew.api.document.DocumentContentUpdate; |
25 | |
import org.kuali.rice.kew.api.document.DocumentUpdate; |
26 | |
import org.kuali.rice.kew.api.document.PropertyDefinition; |
27 | |
import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition; |
28 | |
import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeValidationError; |
29 | |
import org.kuali.rice.kew.definition.AttributeDefinition; |
30 | |
import org.kuali.rice.kew.dto.DTOConverter; |
31 | |
import org.kuali.rice.kew.engine.node.RouteNodeInstance; |
32 | |
import org.kuali.rice.kew.exception.WorkflowException; |
33 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
34 | |
import org.kuali.rice.kew.rule.WorkflowAttribute; |
35 | |
import org.kuali.rice.kew.rule.WorkflowAttributeXmlValidator; |
36 | |
import org.kuali.rice.kew.rule.xmlrouting.GenericXMLRuleAttribute; |
37 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
38 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
39 | |
|
40 | |
import java.util.ArrayList; |
41 | |
import java.util.HashMap; |
42 | |
import java.util.HashSet; |
43 | |
import java.util.List; |
44 | |
import java.util.Map; |
45 | |
import java.util.Set; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | public class WorkflowDocumentActionsServiceImpl implements WorkflowDocumentActionsService { |
54 | |
|
55 | 0 | private static final Logger LOG = Logger.getLogger(WorkflowDocumentActionsServiceImpl.class); |
56 | |
|
57 | |
private DocumentTypeService documentTypeService; |
58 | |
|
59 | 0 | private static final DocumentActionCallback ACKNOWLEDGE_CALLBACK = new StandardDocumentActionCallback() { |
60 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
61 | |
String annotation) throws WorkflowException { |
62 | 0 | return KEWServiceLocator.getWorkflowDocumentService().acknowledgeDocument(principalId, documentBo, |
63 | |
annotation); |
64 | |
} |
65 | |
|
66 | |
public String getActionName() { |
67 | 0 | return ActionType.ACKNOWLEDGE.getLabel(); |
68 | |
} |
69 | |
}; |
70 | |
|
71 | 0 | private static final DocumentActionCallback APPROVE_CALLBACK = new StandardDocumentActionCallback() { |
72 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
73 | |
String annotation) throws WorkflowException { |
74 | 0 | return KEWServiceLocator.getWorkflowDocumentService().approveDocument(principalId, documentBo, annotation); |
75 | |
} |
76 | |
|
77 | |
public String getActionName() { |
78 | 0 | return ActionType.APPROVE.getLabel(); |
79 | |
} |
80 | |
}; |
81 | |
|
82 | 0 | private static final DocumentActionCallback CANCEL_CALLBACK = new StandardDocumentActionCallback() { |
83 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
84 | |
String annotation) throws WorkflowException { |
85 | 0 | return KEWServiceLocator.getWorkflowDocumentService().cancelDocument(principalId, documentBo, annotation); |
86 | |
} |
87 | |
|
88 | |
public String getActionName() { |
89 | 0 | return ActionType.CANCEL.getLabel(); |
90 | |
} |
91 | |
}; |
92 | |
|
93 | 0 | private static final DocumentActionCallback FYI_CALLBACK = new StandardDocumentActionCallback() { |
94 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
95 | |
String annotation) throws WorkflowException { |
96 | 0 | return KEWServiceLocator.getWorkflowDocumentService().clearFYIDocument(principalId, documentBo, annotation); |
97 | |
} |
98 | |
|
99 | |
public String getActionName() { |
100 | 0 | return ActionType.FYI.getLabel(); |
101 | |
} |
102 | |
}; |
103 | |
|
104 | 0 | private static final DocumentActionCallback COMPLETE_CALLBACK = new StandardDocumentActionCallback() { |
105 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
106 | |
String annotation) throws WorkflowException { |
107 | 0 | return KEWServiceLocator.getWorkflowDocumentService().completeDocument(principalId, documentBo, annotation); |
108 | |
} |
109 | |
|
110 | |
public String getActionName() { |
111 | 0 | return ActionType.COMPLETE.getLabel(); |
112 | |
} |
113 | |
}; |
114 | |
|
115 | 0 | private static final DocumentActionCallback DISAPPROVE_CALLBACK = new StandardDocumentActionCallback() { |
116 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
117 | |
String annotation) throws WorkflowException { |
118 | 0 | return KEWServiceLocator.getWorkflowDocumentService().disapproveDocument(principalId, documentBo, |
119 | |
annotation); |
120 | |
} |
121 | |
|
122 | |
public String getActionName() { |
123 | 0 | return ActionType.DISAPPROVE.getLabel(); |
124 | |
} |
125 | |
}; |
126 | |
|
127 | 0 | private static final DocumentActionCallback ROUTE_CALLBACK = new StandardDocumentActionCallback() { |
128 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
129 | |
String annotation) throws WorkflowException { |
130 | 0 | return KEWServiceLocator.getWorkflowDocumentService().routeDocument(principalId, documentBo, annotation); |
131 | |
} |
132 | |
|
133 | |
public String getActionName() { |
134 | 0 | return ActionType.ROUTE.getLabel(); |
135 | |
} |
136 | |
}; |
137 | |
|
138 | 0 | private static final DocumentActionCallback BLANKET_APPROVE_CALLBACK = new StandardDocumentActionCallback() { |
139 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
140 | |
String annotation) throws WorkflowException { |
141 | 0 | return KEWServiceLocator.getWorkflowDocumentService().blanketApproval(principalId, documentBo, annotation, |
142 | |
new HashSet<String>()); |
143 | |
} |
144 | |
|
145 | |
public String getActionName() { |
146 | 0 | return ActionType.BLANKET_APPROVE.getLabel(); |
147 | |
} |
148 | |
}; |
149 | |
|
150 | 0 | private static final DocumentActionCallback SAVE_CALLBACK = new StandardDocumentActionCallback() { |
151 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
152 | |
String annotation) throws WorkflowException { |
153 | 0 | return KEWServiceLocator.getWorkflowDocumentService().saveDocument(principalId, documentBo, annotation); |
154 | |
} |
155 | |
|
156 | |
public String getActionName() { |
157 | 0 | return ActionType.SAVE.getLabel(); |
158 | |
} |
159 | |
}; |
160 | |
|
161 | 0 | private static final DocumentActionCallback PLACE_IN_EXCEPTION_CALLBACK = new StandardDocumentActionCallback() { |
162 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
163 | |
String annotation) throws WorkflowException { |
164 | 0 | return KEWServiceLocator.getWorkflowDocumentService().placeInExceptionRouting(principalId, documentBo, |
165 | |
annotation); |
166 | |
} |
167 | |
|
168 | |
public String getActionName() { |
169 | 0 | return "Place In Exception"; |
170 | |
} |
171 | |
}; |
172 | |
|
173 | |
protected DocumentRouteHeaderValue init(DocumentActionParameters parameters) { |
174 | 0 | String documentId = parameters.getDocumentId(); |
175 | 0 | String principalId = parameters.getPrincipalId(); |
176 | 0 | DocumentUpdate documentUpdate = parameters.getDocumentUpdate(); |
177 | 0 | DocumentContentUpdate documentContentUpdate = parameters.getDocumentContentUpdate(); |
178 | 0 | incomingParamCheck(documentId, "documentId"); |
179 | 0 | incomingParamCheck(principalId, "principalId"); |
180 | 0 | if (LOG.isDebugEnabled()) { |
181 | 0 | LOG.debug("Initializing Document from incoming documentId: " + documentId); |
182 | |
} |
183 | 0 | KEWServiceLocator.getRouteHeaderService().lockRouteHeader(documentId, true); |
184 | |
|
185 | 0 | DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
186 | 0 | if (document == null) { |
187 | 0 | throw new RiceIllegalArgumentException("Failed to locate a document for document id: " + documentId); |
188 | |
} |
189 | 0 | boolean modified = false; |
190 | 0 | if (documentUpdate != null) { |
191 | 0 | document.applyDocumentUpdate(documentUpdate); |
192 | 0 | modified = true; |
193 | |
} |
194 | 0 | if (documentContentUpdate != null) { |
195 | 0 | String newDocumentContent = DTOConverter.buildUpdatedDocumentContent(document.getDocContent(), |
196 | |
documentContentUpdate, document.getDocumentTypeName()); |
197 | 0 | document.setDocContent(newDocumentContent); |
198 | 0 | modified = true; |
199 | |
} |
200 | |
|
201 | 0 | if (modified) { |
202 | 0 | KEWServiceLocator.getRouteHeaderService().saveRouteHeader(document); |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | 0 | this.saveRouteNodeInstances(document); |
217 | |
|
218 | |
} |
219 | |
|
220 | 0 | return document; |
221 | |
} |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
private void saveRouteNodeInstances(DocumentRouteHeaderValue routeHeader) { |
229 | |
|
230 | 0 | List<RouteNodeInstance> routeNodes = routeHeader.getInitialRouteNodeInstances(); |
231 | 0 | if (routeNodes != null && !routeNodes.isEmpty()) { |
232 | 0 | for (RouteNodeInstance rni : routeNodes) { |
233 | 0 | KEWServiceLocator.getRouteNodeService().save(rni); |
234 | |
} |
235 | |
} |
236 | |
|
237 | 0 | } |
238 | |
|
239 | |
@Override |
240 | |
public Document create(String documentTypeName, |
241 | |
String initiatorPrincipalId, DocumentUpdate documentUpdate, |
242 | |
DocumentContentUpdate documentContentUpdate) |
243 | |
throws RiceIllegalArgumentException, IllegalDocumentTypeException, InvalidActionTakenException { |
244 | |
|
245 | 0 | incomingParamCheck(documentTypeName, "documentTypeName"); |
246 | 0 | incomingParamCheck(initiatorPrincipalId, "initiatorPrincipalId"); |
247 | |
|
248 | 0 | if (LOG.isDebugEnabled()) { |
249 | 0 | LOG.debug("Create Document [documentTypeName=" + documentTypeName + ", initiatorPrincipalId=" |
250 | |
+ initiatorPrincipalId + "]"); |
251 | |
} |
252 | |
|
253 | 0 | String documentTypeId = documentTypeService.getIdByName(documentTypeName); |
254 | 0 | if (documentTypeId == null) { |
255 | 0 | throw new RiceIllegalArgumentException("Failed to locate a document type with the given name: " |
256 | |
+ documentTypeName); |
257 | |
} |
258 | |
|
259 | 0 | DocumentRouteHeaderValue documentBo = new DocumentRouteHeaderValue(); |
260 | 0 | documentBo.setDocumentTypeId(documentTypeId); |
261 | 0 | documentBo.setInitiatorWorkflowId(initiatorPrincipalId); |
262 | 0 | if (documentUpdate != null) { |
263 | 0 | documentBo.setDocTitle(documentUpdate.getTitle()); |
264 | 0 | documentBo.setAppDocId(documentUpdate.getApplicationDocumentId()); |
265 | |
} |
266 | 0 | if (documentContentUpdate != null) { |
267 | 0 | String newDocumentContent = DTOConverter.buildUpdatedDocumentContent(null, documentContentUpdate, |
268 | |
documentTypeName); |
269 | 0 | documentBo.setDocContent(newDocumentContent); |
270 | |
} |
271 | |
|
272 | |
try { |
273 | 0 | documentBo = KEWServiceLocator.getWorkflowDocumentService() |
274 | |
.createDocument(initiatorPrincipalId, documentBo); |
275 | 0 | } catch (WorkflowException e) { |
276 | |
|
277 | 0 | translateException(e); |
278 | 0 | } |
279 | 0 | return DocumentRouteHeaderValue.to(documentBo); |
280 | |
} |
281 | |
|
282 | |
@Override |
283 | |
public ValidActions determineValidActions(String documentId, String principalId) { |
284 | 0 | incomingParamCheck(documentId, "documentId"); |
285 | 0 | incomingParamCheck(principalId, "principalId"); |
286 | 0 | DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
287 | 0 | if (documentBo == null) { |
288 | 0 | throw new RiceIllegalArgumentException("Failed to locate a document for document id: " + documentId); |
289 | |
} |
290 | 0 | return determineValidActionsInternal(documentBo, principalId); |
291 | |
} |
292 | |
|
293 | |
protected ValidActions determineValidActionsInternal(DocumentRouteHeaderValue documentBo, String principalId) { |
294 | 0 | Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(principalId); |
295 | 0 | return KEWServiceLocator.getActionRegistry().getNewValidActions(principal, documentBo); |
296 | |
} |
297 | |
|
298 | |
@Override |
299 | |
public RequestedActions determineRequestedActions(String documentId, String principalId) { |
300 | 0 | incomingParamCheck(documentId, "documentId"); |
301 | 0 | incomingParamCheck(principalId, "principalId"); |
302 | 0 | DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
303 | 0 | if (documentBo == null) { |
304 | 0 | throw new RiceIllegalArgumentException("Failed to locate a document for document id: " + documentId); |
305 | |
} |
306 | 0 | KEWServiceLocator.getIdentityHelperService().validatePrincipalId(principalId); |
307 | 0 | return determineRequestedActionsInternal(documentBo, principalId); |
308 | |
} |
309 | |
|
310 | |
protected RequestedActions determineRequestedActionsInternal(DocumentRouteHeaderValue documentBo, String principalId) { |
311 | 0 | Map<String, String> actionsRequested = KEWServiceLocator.getActionRequestService().getActionsRequested(documentBo, |
312 | |
principalId, true); |
313 | 0 | boolean completeRequested = false; |
314 | 0 | boolean approveRequested = false; |
315 | 0 | boolean acknowledgeRequested = false; |
316 | 0 | boolean fyiRequested = false; |
317 | 0 | for (String actionRequestCode : actionsRequested.keySet()) { |
318 | 0 | if (ActionRequestType.FYI.getCode().equals(actionRequestCode)) { |
319 | 0 | fyiRequested = Boolean.parseBoolean(actionsRequested.get(actionRequestCode)); |
320 | 0 | } else if (ActionRequestType.ACKNOWLEDGE.getCode().equals(actionRequestCode)) { |
321 | 0 | acknowledgeRequested = Boolean.parseBoolean(actionsRequested.get(actionRequestCode)); |
322 | 0 | } else if (ActionRequestType.APPROVE.getCode().equals(actionRequestCode)) { |
323 | 0 | approveRequested = Boolean.parseBoolean(actionsRequested.get(actionRequestCode)); |
324 | 0 | } else if (ActionRequestType.COMPLETE.getCode().equals(actionRequestCode)) { |
325 | 0 | completeRequested = Boolean.parseBoolean(actionsRequested.get(actionRequestCode)); |
326 | |
} |
327 | |
} |
328 | 0 | return RequestedActions.create(completeRequested, approveRequested, acknowledgeRequested, fyiRequested); |
329 | |
} |
330 | |
|
331 | |
protected DocumentActionResult constructDocumentActionResult(DocumentRouteHeaderValue documentBo, String principalId) { |
332 | 0 | Document document = DocumentRouteHeaderValue.to(documentBo); |
333 | 0 | ValidActions validActions = determineValidActionsInternal(documentBo, principalId); |
334 | 0 | RequestedActions requestedActions = determineRequestedActionsInternal(documentBo, principalId); |
335 | 0 | return DocumentActionResult.create(document, validActions, requestedActions); |
336 | |
} |
337 | |
|
338 | |
@Override |
339 | |
public DocumentActionResult acknowledge(DocumentActionParameters parameters) { |
340 | 0 | return executeActionInternal(parameters, ACKNOWLEDGE_CALLBACK); |
341 | |
} |
342 | |
|
343 | |
@Override |
344 | |
public DocumentActionResult approve(DocumentActionParameters parameters) { |
345 | 0 | return executeActionInternal(parameters, APPROVE_CALLBACK); |
346 | |
} |
347 | |
|
348 | |
@Override |
349 | |
public DocumentActionResult adHocToPrincipal(DocumentActionParameters parameters, |
350 | |
final AdHocToPrincipal adHocToPrincipal) { |
351 | 0 | return executeActionInternal(parameters, |
352 | 0 | new DocumentActionCallback() { |
353 | |
@Override |
354 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
355 | 0 | return "AdHoc Route To Principal [principalId=" + principalId + |
356 | |
", docId=" + documentId + |
357 | |
", actionRequest=" + adHocToPrincipal.getActionRequested() + |
358 | |
", nodeName=" + adHocToPrincipal.getNodeName() + |
359 | |
", targetPrincipalId=" + adHocToPrincipal.getTargetPrincipalId() + |
360 | |
", forceAction=" + adHocToPrincipal.isForceAction() + |
361 | |
", annotation=" + annotation + |
362 | |
", requestLabel=" + adHocToPrincipal.getRequestLabel() + "]"; |
363 | |
} |
364 | |
|
365 | |
@Override |
366 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
367 | |
String principalId, String annotation) throws WorkflowException { |
368 | 0 | return KEWServiceLocator.getWorkflowDocumentService().adHocRouteDocumentToPrincipal( |
369 | |
principalId, |
370 | |
documentBo, |
371 | |
adHocToPrincipal.getActionRequested().getCode(), |
372 | |
adHocToPrincipal.getNodeName(), |
373 | |
annotation, |
374 | |
adHocToPrincipal.getTargetPrincipalId(), |
375 | |
adHocToPrincipal.getResponsibilityDescription(), |
376 | |
adHocToPrincipal.isForceAction(), |
377 | |
adHocToPrincipal.getRequestLabel()); |
378 | |
} |
379 | |
}); |
380 | |
} |
381 | |
|
382 | |
@Override |
383 | |
public DocumentActionResult adHocToGroup(DocumentActionParameters parameters, |
384 | |
final AdHocToGroup adHocToGroup) { |
385 | 0 | return executeActionInternal(parameters, |
386 | 0 | new DocumentActionCallback() { |
387 | |
@Override |
388 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
389 | 0 | return "AdHoc Route To Group [principalId=" + principalId + |
390 | |
", docId=" + documentId + |
391 | |
", actionRequest=" + adHocToGroup.getActionRequested() + |
392 | |
", nodeName=" + adHocToGroup.getNodeName() + |
393 | |
", targetGroupId=" + adHocToGroup.getTargetGroupId() + |
394 | |
", forceAction=" + adHocToGroup.isForceAction() + |
395 | |
", annotation=" + annotation + |
396 | |
", requestLabel=" + adHocToGroup.getRequestLabel() + "]"; |
397 | |
} |
398 | |
|
399 | |
@Override |
400 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
401 | |
String principalId, String annotation) throws WorkflowException { |
402 | 0 | return KEWServiceLocator.getWorkflowDocumentService().adHocRouteDocumentToGroup(principalId, |
403 | |
documentBo, |
404 | |
adHocToGroup.getActionRequested().getCode(), |
405 | |
adHocToGroup.getNodeName(), |
406 | |
annotation, |
407 | |
adHocToGroup.getTargetGroupId(), |
408 | |
adHocToGroup.getResponsibilityDescription(), |
409 | |
adHocToGroup.isForceAction(), |
410 | |
adHocToGroup.getRequestLabel()); |
411 | |
} |
412 | |
}); |
413 | |
} |
414 | |
|
415 | |
@Override |
416 | |
public DocumentActionResult revokeAdHocRequestById(DocumentActionParameters parameters, |
417 | |
final String actionRequestId) { |
418 | 0 | return executeActionInternal(parameters, |
419 | 0 | new DocumentActionCallback() { |
420 | |
@Override |
421 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
422 | 0 | return "Revoke AdHoc from Principal [principalId=" + principalId + |
423 | |
", documentId=" + documentId + |
424 | |
", annotation=" + annotation + |
425 | |
", actionRequestId=" + actionRequestId + "]"; |
426 | |
} |
427 | |
|
428 | |
@Override |
429 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
430 | |
String principalId, String annotation) throws WorkflowException { |
431 | 0 | return KEWServiceLocator.getWorkflowDocumentService().revokeAdHocRequests(principalId, |
432 | |
documentBo, actionRequestId, annotation); |
433 | |
} |
434 | |
}); |
435 | |
} |
436 | |
|
437 | |
@Override |
438 | |
public DocumentActionResult revokeAdHocRequests(DocumentActionParameters parameters, |
439 | |
final AdHocRevoke revoke) { |
440 | 0 | return executeActionInternal(parameters, |
441 | 0 | new DocumentActionCallback() { |
442 | |
@Override |
443 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
444 | 0 | return "Revoke AdHoc Requests [principalId=" + principalId + |
445 | |
", docId=" + documentId + |
446 | |
", annotation=" + annotation + |
447 | |
", revoke=" + revoke.toString() + "]"; |
448 | |
} |
449 | |
|
450 | |
@Override |
451 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
452 | |
String principalId, String annotation) throws WorkflowException { |
453 | 0 | return KEWServiceLocator.getWorkflowDocumentService().revokeAdHocRequests(principalId, |
454 | |
documentBo, revoke, annotation); |
455 | |
} |
456 | |
}); |
457 | |
} |
458 | |
|
459 | |
@Override |
460 | |
public DocumentActionResult revokeAllAdHocRequests(DocumentActionParameters parameters) { |
461 | 0 | return executeActionInternal(parameters, |
462 | 0 | new DocumentActionCallback() { |
463 | |
@Override |
464 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
465 | 0 | return "Revoke All AdHoc Requests [principalId=" + principalId + |
466 | |
", docId=" + documentId + |
467 | |
", annotation=" + annotation + "]"; |
468 | |
} |
469 | |
|
470 | |
@Override |
471 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
472 | |
String principalId, String annotation) throws WorkflowException { |
473 | 0 | return KEWServiceLocator.getWorkflowDocumentService().revokeAdHocRequests(principalId, |
474 | |
documentBo, (AdHocRevoke) null, annotation); |
475 | |
} |
476 | |
}); |
477 | |
} |
478 | |
|
479 | |
@Override |
480 | |
public DocumentActionResult cancel(DocumentActionParameters parameters) { |
481 | 0 | return executeActionInternal(parameters, CANCEL_CALLBACK); |
482 | |
} |
483 | |
|
484 | |
public DocumentActionResult clearFyi(DocumentActionParameters parameters) { |
485 | 0 | return executeActionInternal(parameters, FYI_CALLBACK); |
486 | |
} |
487 | |
|
488 | |
@Override |
489 | |
public DocumentActionResult complete(DocumentActionParameters parameters) { |
490 | 0 | return executeActionInternal(parameters, COMPLETE_CALLBACK); |
491 | |
} |
492 | |
|
493 | |
@Override |
494 | |
public DocumentActionResult disapprove(DocumentActionParameters parameters) { |
495 | 0 | return executeActionInternal(parameters, DISAPPROVE_CALLBACK); |
496 | |
} |
497 | |
|
498 | |
@Override |
499 | |
public DocumentActionResult route(DocumentActionParameters parameters) { |
500 | 0 | return executeActionInternal(parameters, ROUTE_CALLBACK); |
501 | |
} |
502 | |
|
503 | |
@Override |
504 | |
public DocumentActionResult blanketApprove(DocumentActionParameters parameters) { |
505 | 0 | return executeActionInternal(parameters, BLANKET_APPROVE_CALLBACK); |
506 | |
} |
507 | |
|
508 | |
@Override |
509 | |
public DocumentActionResult blanketApproveToNodes(DocumentActionParameters parameters, |
510 | |
final Set<String> nodeNames) { |
511 | 0 | return executeActionInternal(parameters, |
512 | 0 | new DocumentActionCallback() { |
513 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
514 | |
String principalId, String annotation) throws WorkflowException { |
515 | 0 | return KEWServiceLocator.getWorkflowDocumentService().blanketApproval(principalId, documentBo, |
516 | |
annotation, nodeNames); |
517 | |
} |
518 | |
|
519 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
520 | 0 | return "Blanket Approve [principalId=" + principalId + ", documentId=" + documentId |
521 | |
+ ", annotation=" + annotation + ", nodeNames=" + nodeNames + "]"; |
522 | |
} |
523 | |
}); |
524 | |
} |
525 | |
|
526 | |
@Override |
527 | |
public DocumentActionResult returnToPreviousNode(DocumentActionParameters parameters, |
528 | |
final ReturnPoint returnPoint) { |
529 | 0 | return executeActionInternal(parameters, |
530 | 0 | new DocumentActionCallback() { |
531 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
532 | |
String principalId, String annotation) throws WorkflowException { |
533 | 0 | return KEWServiceLocator.getWorkflowDocumentService().returnDocumentToPreviousNode(principalId, |
534 | |
documentBo, returnPoint.getNodeName(), annotation); |
535 | |
} |
536 | |
|
537 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
538 | 0 | return "Return to Previous [principalId=" + principalId + ", documentId=" + documentId |
539 | |
+ ", annotation=" + annotation + ", destNodeName=" + returnPoint.getNodeName() + "]"; |
540 | |
} |
541 | |
}); |
542 | |
} |
543 | |
|
544 | |
@Override |
545 | |
public DocumentActionResult move(DocumentActionParameters parameters, |
546 | |
final MovePoint movePoint) { |
547 | 0 | return executeActionInternal(parameters, |
548 | 0 | new DocumentActionCallback() { |
549 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
550 | |
String principalId, String annotation) throws WorkflowException { |
551 | 0 | return KEWServiceLocator.getWorkflowDocumentService().moveDocument(principalId, documentBo, |
552 | |
movePoint, annotation); |
553 | |
} |
554 | |
|
555 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
556 | 0 | return "Move Document [principalId=" + principalId + ", documentId=" + documentId |
557 | |
+ ", annotation=" + annotation + ", movePoint=" + movePoint + "]"; |
558 | |
} |
559 | |
}); |
560 | |
} |
561 | |
|
562 | |
@Override |
563 | |
public DocumentActionResult takeGroupAuthority(DocumentActionParameters parameters, |
564 | |
final String groupId) { |
565 | 0 | return executeActionInternal(parameters, |
566 | 0 | new StandardDocumentActionCallback() { |
567 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
568 | |
String principalId, String annotation) throws WorkflowException { |
569 | 0 | return KEWServiceLocator.getWorkflowDocumentService().takeGroupAuthority(principalId, |
570 | |
documentBo, groupId, annotation); |
571 | |
} |
572 | |
|
573 | |
public String getActionName() { |
574 | 0 | return ActionType.TAKE_GROUP_AUTHORITY.getLabel(); |
575 | |
} |
576 | |
}); |
577 | |
} |
578 | |
|
579 | |
@Override |
580 | |
public DocumentActionResult releaseGroupAuthority(DocumentActionParameters parameters, |
581 | |
final String groupId) { |
582 | 0 | return executeActionInternal(parameters, |
583 | 0 | new StandardDocumentActionCallback() { |
584 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
585 | |
String principalId, String annotation) throws WorkflowException { |
586 | 0 | return KEWServiceLocator.getWorkflowDocumentService().releaseGroupAuthority(principalId, |
587 | |
documentBo, groupId, annotation); |
588 | |
} |
589 | |
|
590 | |
public String getActionName() { |
591 | 0 | return ActionType.RELEASE_GROUP_AUTHORITY.getLabel(); |
592 | |
} |
593 | |
}); |
594 | |
|
595 | |
} |
596 | |
|
597 | |
@Override |
598 | |
public DocumentActionResult save(DocumentActionParameters parameters) { |
599 | 0 | return executeActionInternal(parameters, SAVE_CALLBACK); |
600 | |
} |
601 | |
|
602 | |
@Override |
603 | |
public DocumentActionResult saveDocumentData(DocumentActionParameters parameters) { |
604 | 0 | return executeActionInternal(parameters, new DocumentActionCallback() { |
605 | |
|
606 | |
@Override |
607 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
608 | 0 | return "Saving Routing Data [principalId=" + principalId + ", docId=" + documentId + "]"; |
609 | |
} |
610 | |
|
611 | |
@Override |
612 | |
public DocumentRouteHeaderValue doInDocumentBo( |
613 | |
DocumentRouteHeaderValue documentBo, String principalId, |
614 | |
String annotation) throws WorkflowException { |
615 | 0 | return KEWServiceLocator.getWorkflowDocumentService().saveRoutingData(principalId, documentBo); |
616 | |
} |
617 | |
}); |
618 | |
} |
619 | |
|
620 | |
@Override |
621 | |
public Document delete(String documentId, String principalId) { |
622 | 0 | DocumentRouteHeaderValue documentBo = init(DocumentActionParameters.create(documentId, principalId, null)); |
623 | 0 | if (LOG.isDebugEnabled()) { |
624 | 0 | LOG.debug("Delete [principalId=" + principalId + ", documentId=" + documentId + "]"); |
625 | |
} |
626 | 0 | Document document = null; |
627 | |
try { |
628 | 0 | document = DocumentRouteHeaderValue.to(documentBo); |
629 | 0 | KEWServiceLocator.getWorkflowDocumentService().deleteDocument(principalId, documentBo); |
630 | |
|
631 | 0 | } catch (WorkflowException e) { |
632 | 0 | translateException(e); |
633 | 0 | } |
634 | 0 | return document; |
635 | |
} |
636 | |
|
637 | |
@Override |
638 | |
public void logAnnotation(String documentId, String principalId, String annotation) { |
639 | 0 | DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentId); |
640 | |
try { |
641 | 0 | KEWServiceLocator.getWorkflowDocumentService().logDocumentAction(principalId, documentBo, annotation); |
642 | 0 | } catch (WorkflowException e) { |
643 | 0 | translateException(e); |
644 | 0 | } |
645 | 0 | } |
646 | |
|
647 | |
@Override |
648 | |
public void initiateIndexing(String documentId) { |
649 | |
|
650 | 0 | throw new UnsupportedOperationException("implement me!!!"); |
651 | |
} |
652 | |
|
653 | |
@Override |
654 | |
public DocumentActionResult superUserBlanketApprove(DocumentActionParameters parameters, |
655 | |
final boolean executePostProcessor) { |
656 | 0 | return executeActionInternal(parameters, |
657 | 0 | new DocumentActionCallback() { |
658 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
659 | |
String principalId, String annotation) throws WorkflowException { |
660 | 0 | return KEWServiceLocator.getWorkflowDocumentService().superUserApprove(principalId, documentBo, |
661 | |
annotation, executePostProcessor); |
662 | |
} |
663 | |
|
664 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
665 | 0 | return "SU Blanket Approve [principalId=" + principalId + ", documentId=" + documentId |
666 | |
+ ", annotation=" + annotation + "]"; |
667 | |
} |
668 | |
}); |
669 | |
} |
670 | |
|
671 | |
@Override |
672 | |
public DocumentActionResult superUserNodeApprove(DocumentActionParameters parameters, |
673 | |
final boolean executePostProcessor, final String nodeName) { |
674 | 0 | return executeActionInternal(parameters, |
675 | 0 | new DocumentActionCallback() { |
676 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
677 | |
String principalId, String annotation) throws WorkflowException { |
678 | 0 | return KEWServiceLocator.getWorkflowDocumentService().superUserNodeApproveAction(principalId, |
679 | |
documentBo, nodeName, annotation, executePostProcessor); |
680 | |
} |
681 | |
|
682 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
683 | 0 | return "SU Node Approve Action [principalId=" + principalId + ", documentId=" + documentId |
684 | |
+ ", nodeName=" + nodeName + ", annotation=" + annotation + "]"; |
685 | |
} |
686 | |
}); |
687 | |
|
688 | |
} |
689 | |
|
690 | |
@Override |
691 | |
public DocumentActionResult superUserTakeRequestedAction(DocumentActionParameters parameters, |
692 | |
final boolean executePostProcessor, final String actionRequestId) { |
693 | 0 | return executeActionInternal(parameters, |
694 | 0 | new DocumentActionCallback() { |
695 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
696 | |
String principalId, String annotation) throws WorkflowException { |
697 | 0 | return KEWServiceLocator.getWorkflowDocumentService().superUserActionRequestApproveAction( |
698 | |
principalId, documentBo, actionRequestId, annotation, |
699 | |
executePostProcessor); |
700 | |
} |
701 | |
|
702 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
703 | 0 | return "SU Take Requested Action [principalId=" + principalId + ", docume tId=" + documentId |
704 | |
+ ", actionRequestId=" + actionRequestId + ", annotation=" + annotation + "]"; |
705 | |
} |
706 | |
}); |
707 | |
} |
708 | |
|
709 | |
@Override |
710 | |
public DocumentActionResult superUserDisapprove(DocumentActionParameters parameters, |
711 | |
final boolean executePostProcessor) { |
712 | 0 | return executeActionInternal(parameters, |
713 | 0 | new DocumentActionCallback() { |
714 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
715 | |
String principalId, String annotation) throws WorkflowException { |
716 | 0 | return KEWServiceLocator.getWorkflowDocumentService().superUserDisapproveAction(principalId, |
717 | |
documentBo, annotation, executePostProcessor); |
718 | |
} |
719 | |
|
720 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
721 | 0 | return "SU Disapprove [principalId=" + principalId + ", documentId=" + documentId |
722 | |
+ ", annotation=" + annotation + "]"; |
723 | |
} |
724 | |
}); |
725 | |
} |
726 | |
|
727 | |
@Override |
728 | |
public DocumentActionResult superUserCancel(DocumentActionParameters parameters, final boolean executePostProcessor) { |
729 | 0 | return executeActionInternal(parameters, |
730 | 0 | new DocumentActionCallback() { |
731 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
732 | |
String principalId, String annotation) throws WorkflowException { |
733 | 0 | return KEWServiceLocator.getWorkflowDocumentService().superUserCancelAction(principalId, |
734 | |
documentBo, annotation, executePostProcessor); |
735 | |
} |
736 | |
|
737 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
738 | 0 | return "SU Cancel [principalId=" + principalId + ", documentId=" + documentId + ", annotation=" |
739 | |
+ annotation + "]"; |
740 | |
} |
741 | |
}); |
742 | |
} |
743 | |
|
744 | |
@Override |
745 | |
public DocumentActionResult superUserReturnToPreviousNode(DocumentActionParameters parameters, |
746 | |
final boolean executePostProcessor, final ReturnPoint returnPoint) { |
747 | 0 | return executeActionInternal(parameters, |
748 | 0 | new DocumentActionCallback() { |
749 | |
public DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, |
750 | |
String principalId, String annotation) throws WorkflowException { |
751 | 0 | return KEWServiceLocator.getWorkflowDocumentService().superUserReturnDocumentToPreviousNode( |
752 | |
principalId, documentBo, returnPoint.getNodeName(), annotation, executePostProcessor); |
753 | |
} |
754 | |
|
755 | |
public String getLogMessage(String documentId, String principalId, String annotation) { |
756 | 0 | return "SU Return to Previous Node [principalId=" + principalId + ", documentId=" + documentId |
757 | |
+ ", annotation=" + annotation + ", returnPoint=" + returnPoint + "]"; |
758 | |
} |
759 | |
}); |
760 | |
|
761 | |
} |
762 | |
|
763 | |
@Override |
764 | |
public DocumentActionResult placeInExceptionRouting(DocumentActionParameters parameters) { |
765 | 0 | return executeActionInternal(parameters, PLACE_IN_EXCEPTION_CALLBACK); |
766 | |
} |
767 | |
|
768 | |
@Override |
769 | |
public List<WorkflowAttributeValidationError> validateWorkflowAttributeDefinition( |
770 | |
WorkflowAttributeDefinition definition) { |
771 | 0 | if (definition == null) { |
772 | 0 | throw new RiceIllegalArgumentException("definition was null"); |
773 | |
} |
774 | 0 | if ( LOG.isDebugEnabled() ) { |
775 | 0 | LOG.debug("Validating WorkflowAttributeDefinition [attributeName="+definition.getAttributeName()+"]"); |
776 | |
} |
777 | 0 | AttributeDefinition attributeDefinition = DTOConverter.convertWorkflowAttributeDefinition(definition); |
778 | 0 | WorkflowAttribute attribute = null; |
779 | 0 | if (attributeDefinition != null) { |
780 | 0 | attribute = (WorkflowAttribute) GlobalResourceLoader.getObject(attributeDefinition.getObjectDefinition()); |
781 | |
} |
782 | 0 | if (attribute instanceof GenericXMLRuleAttribute) { |
783 | 0 | Map<String, String> attributePropMap = new HashMap<String, String>(); |
784 | 0 | GenericXMLRuleAttribute xmlAttribute = (GenericXMLRuleAttribute)attribute; |
785 | 0 | xmlAttribute.setRuleAttribute(attributeDefinition.getRuleAttribute()); |
786 | 0 | for (PropertyDefinition propertyDefinition : definition.getPropertyDefinitions()) { |
787 | 0 | attributePropMap.put(propertyDefinition.getName(), propertyDefinition.getValue()); |
788 | |
} |
789 | 0 | xmlAttribute.setParamMap(attributePropMap); |
790 | |
} |
791 | 0 | List<WorkflowAttributeValidationError> errors = new ArrayList<WorkflowAttributeValidationError>(); |
792 | |
|
793 | 0 | if (attribute instanceof WorkflowAttributeXmlValidator) { |
794 | 0 | List<org.kuali.rice.kew.rule.WorkflowAttributeValidationError> validationErrors = ((WorkflowAttributeXmlValidator)attribute).validateClientRoutingData(); |
795 | 0 | if (validationErrors != null) { |
796 | 0 | for (org.kuali.rice.kew.rule.WorkflowAttributeValidationError validationError : validationErrors) { |
797 | 0 | errors.add(org.kuali.rice.kew.rule.WorkflowAttributeValidationError.to(validationError)); |
798 | |
} |
799 | |
} |
800 | |
} |
801 | 0 | return errors; |
802 | |
} |
803 | |
|
804 | |
private void incomingParamCheck(Object object, String name) { |
805 | 0 | if (object == null) { |
806 | 0 | throw new RiceIllegalArgumentException(name + " was null"); |
807 | 0 | } else if (object instanceof String |
808 | |
&& StringUtils.isBlank((String) object)) { |
809 | 0 | throw new RiceIllegalArgumentException(name + " was blank"); |
810 | |
} |
811 | 0 | } |
812 | |
|
813 | |
public void setDocumentTypeService(DocumentTypeService documentTypeService) { |
814 | 0 | this.documentTypeService = documentTypeService; |
815 | 0 | } |
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
private void translateException(WorkflowException e) { |
822 | 0 | if (e instanceof org.kuali.rice.kew.exception.InvalidActionTakenException) { |
823 | 0 | throw new InvalidActionTakenException(e.getMessage(), e); |
824 | |
} |
825 | 0 | throw new WorkflowRuntimeException(e.getMessage(), e); |
826 | |
} |
827 | |
|
828 | |
protected DocumentActionResult executeActionInternal(DocumentActionParameters parameters, |
829 | |
DocumentActionCallback callback) { |
830 | 0 | if (parameters == null) { |
831 | 0 | throw new RiceIllegalArgumentException("Document action parameters was null."); |
832 | |
} |
833 | 0 | if (LOG.isDebugEnabled()) { |
834 | 0 | LOG.debug(callback.getLogMessage(parameters.getDocumentId(), parameters.getPrincipalId(), |
835 | |
parameters.getAnnotation())); |
836 | |
} |
837 | 0 | DocumentRouteHeaderValue documentBo = init(parameters); |
838 | |
try { |
839 | 0 | documentBo = callback.doInDocumentBo(documentBo, parameters.getPrincipalId(), parameters.getAnnotation()); |
840 | 0 | } catch (WorkflowException e) { |
841 | |
|
842 | 0 | translateException(e); |
843 | 0 | } |
844 | 0 | return constructDocumentActionResult(documentBo, parameters.getPrincipalId()); |
845 | |
} |
846 | |
|
847 | |
protected static interface DocumentActionCallback { |
848 | |
|
849 | |
DocumentRouteHeaderValue doInDocumentBo(DocumentRouteHeaderValue documentBo, String principalId, |
850 | |
String annotation) throws WorkflowException; |
851 | |
|
852 | |
String getLogMessage(String documentId, String principalId, String annotation); |
853 | |
|
854 | |
} |
855 | |
|
856 | 0 | protected static abstract class StandardDocumentActionCallback implements DocumentActionCallback { |
857 | |
|
858 | |
public final String getLogMessage(String documentId, String principalId, String annotation) { |
859 | 0 | return getActionName() + " [principalId=" + principalId + ", documentId=" + documentId + ", annotation=" |
860 | |
+ annotation + "]"; |
861 | |
} |
862 | |
|
863 | |
protected abstract String getActionName(); |
864 | |
|
865 | |
} |
866 | |
|
867 | |
} |