1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.routelog.web; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Collections; |
22 | |
import java.util.Comparator; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.HashSet; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
import java.util.Set; |
28 | |
|
29 | |
import javax.servlet.http.HttpServletRequest; |
30 | |
import javax.servlet.http.HttpServletResponse; |
31 | |
import javax.xml.namespace.QName; |
32 | |
|
33 | |
import org.apache.struts.action.ActionForm; |
34 | |
import org.apache.struts.action.ActionForward; |
35 | |
import org.apache.struts.action.ActionMapping; |
36 | |
import org.kuali.rice.core.resourceloader.GlobalResourceLoader; |
37 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
38 | |
import org.kuali.rice.kew.actionrequest.service.ActionRequestService; |
39 | |
import org.kuali.rice.kew.actiontaken.ActionTakenValue; |
40 | |
import org.kuali.rice.kew.doctype.SecuritySession; |
41 | |
import org.kuali.rice.kew.doctype.service.DocumentSecurityService; |
42 | |
import org.kuali.rice.kew.dto.ActionRequestDTO; |
43 | |
import org.kuali.rice.kew.dto.DTOConverter; |
44 | |
import org.kuali.rice.kew.dto.DocumentDetailDTO; |
45 | |
import org.kuali.rice.kew.dto.ReportCriteriaDTO; |
46 | |
import org.kuali.rice.kew.dto.RouteNodeInstanceDTO; |
47 | |
import org.kuali.rice.kew.dto.StateDTO; |
48 | |
import org.kuali.rice.kew.dto.DTOConverter.RouteNodeInstanceLoader; |
49 | |
import org.kuali.rice.kew.engine.node.Branch; |
50 | |
import org.kuali.rice.kew.engine.node.NodeState; |
51 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
52 | |
import org.kuali.rice.kew.engine.node.RouteNodeInstance; |
53 | |
import org.kuali.rice.kew.engine.node.service.RouteNodeService; |
54 | |
import org.kuali.rice.kew.exception.InvalidActionTakenException; |
55 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
56 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
57 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
58 | |
import org.kuali.rice.kew.service.WorkflowUtility; |
59 | |
import org.kuali.rice.kew.util.KEWConstants; |
60 | |
import org.kuali.rice.kew.util.Utilities; |
61 | |
import org.kuali.rice.kew.web.KewKualiAction; |
62 | |
import org.kuali.rice.kew.web.session.UserSession; |
63 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
64 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
65 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
66 | |
import org.kuali.rice.kim.util.KimConstants; |
67 | |
import org.kuali.rice.kns.exception.AuthorizationException; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 0 | public class RouteLogAction extends KewKualiAction { |
76 | |
|
77 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RouteLogAction.class); |
78 | 0 | private static Comparator<ActionRequestValue> ROUTE_LOG_ACTION_REQUEST_SORTER = new Utilities.RouteLogActionRequestSorter(); |
79 | |
|
80 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
81 | |
|
82 | 0 | RouteLogForm rlForm = (RouteLogForm) form; |
83 | 0 | Long routeHeaderId = null; |
84 | 0 | if (! Utilities.isEmpty(rlForm.getRouteHeaderId())) { |
85 | 0 | routeHeaderId = new Long(rlForm.getRouteHeaderId()); |
86 | 0 | } else if (! Utilities.isEmpty(rlForm.getDocId())) { |
87 | 0 | routeHeaderId = new Long(rlForm.getDocId()); |
88 | |
} else { |
89 | 0 | throw new WorkflowRuntimeException("No paramater provided to fetch document"); |
90 | |
} |
91 | |
|
92 | 0 | DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(routeHeaderId); |
93 | |
|
94 | 0 | DocumentSecurityService security = KEWServiceLocator.getDocumentSecurityService(); |
95 | 0 | if (!security.routeLogAuthorized(getUserSession(request), routeHeader, new SecuritySession(UserSession.getAuthenticatedUser()))) { |
96 | 0 | return mapping.findForward("NotAuthorized"); |
97 | |
} |
98 | |
|
99 | 0 | fixActionRequestsPositions(routeHeader); |
100 | 0 | populateRouteLogFormActionRequests(rlForm, routeHeader); |
101 | |
|
102 | 0 | rlForm.setLookFuture(routeHeader.getDocumentType().getLookIntoFuturePolicy().getPolicyValue().booleanValue()); |
103 | |
|
104 | 0 | if (rlForm.isShowFuture()) { |
105 | |
try { |
106 | 0 | populateRouteLogFutureRequests(rlForm, routeHeader); |
107 | 0 | } catch (Exception e) { |
108 | 0 | String errorMsg = "Unable to determine Future Action Requests"; |
109 | 0 | LOG.info(errorMsg,e); |
110 | 0 | rlForm.setShowFutureError(errorMsg); |
111 | 0 | } |
112 | |
} |
113 | 0 | request.setAttribute("routeHeader", routeHeader); |
114 | |
|
115 | |
|
116 | |
|
117 | 0 | boolean isAuthorizedToAddRouteLogMessage = KEWServiceLocator.getDocumentTypePermissionService() |
118 | |
.canAddRouteLogMessage(UserSession.getAuthenticatedUser().getPrincipalId(), routeHeader); |
119 | 0 | if (isAuthorizedToAddRouteLogMessage) { |
120 | 0 | rlForm.setEnableLogAction(true); |
121 | |
} else { |
122 | 0 | rlForm.setEnableLogAction(false); |
123 | |
} |
124 | |
|
125 | 0 | return super.execute(mapping, rlForm, request, response); |
126 | |
} |
127 | |
|
128 | |
@SuppressWarnings("unchecked") |
129 | |
public void populateRouteLogFormActionRequests(RouteLogForm rlForm, DocumentRouteHeaderValue routeHeader) { |
130 | 0 | List<ActionRequestValue> rootRequests = getActionRequestService().getRootRequests(routeHeader.getActionRequests()); |
131 | 0 | Collections.sort(rootRequests, ROUTE_LOG_ACTION_REQUEST_SORTER); |
132 | 0 | rootRequests = switchActionRequestPositionsIfPrimaryDelegatesPresent(rootRequests); |
133 | 0 | int arCount = 0; |
134 | 0 | for ( ActionRequestValue actionRequest : rootRequests ) { |
135 | 0 | if (actionRequest.isPending()) { |
136 | 0 | arCount++; |
137 | |
|
138 | 0 | if (KEWConstants.ACTION_REQUEST_INITIALIZED.equals(actionRequest.getStatus())) { |
139 | 0 | actionRequest.setDisplayStatus("PENDING"); |
140 | 0 | } else if (KEWConstants.ACTION_REQUEST_ACTIVATED.equals(actionRequest.getStatus())) { |
141 | 0 | actionRequest.setDisplayStatus("IN ACTION LIST"); |
142 | |
} |
143 | |
} |
144 | |
} |
145 | 0 | rlForm.setRootRequests(rootRequests); |
146 | 0 | rlForm.setPendingActionRequestCount(arCount); |
147 | 0 | } |
148 | |
|
149 | |
@SuppressWarnings("unchecked") |
150 | |
private ActionRequestValue switchActionRequestPositionIfPrimaryDelegatePresent( ActionRequestValue actionRequest ) { |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | 0 | if (!actionRequest.isRoleRequest()) { |
167 | 0 | List<ActionRequestValue> primaryDelegateRequests = actionRequest.getPrimaryDelegateRequests(); |
168 | |
|
169 | 0 | if ( primaryDelegateRequests.size() != 1) { |
170 | 0 | return actionRequest; |
171 | |
} |
172 | 0 | ActionRequestValue primaryDelegateRequest = primaryDelegateRequests.get(0); |
173 | 0 | actionRequest.getChildrenRequests().remove(primaryDelegateRequest); |
174 | 0 | primaryDelegateRequest.setChildrenRequests(actionRequest.getChildrenRequests()); |
175 | 0 | primaryDelegateRequest.setParentActionRequest(actionRequest.getParentActionRequest()); |
176 | 0 | primaryDelegateRequest.setParentActionRequestId(actionRequest.getParentActionRequestId()); |
177 | |
|
178 | 0 | actionRequest.setChildrenRequests( new ArrayList<ActionRequestValue>(0) ); |
179 | 0 | actionRequest.setParentActionRequest(primaryDelegateRequest); |
180 | 0 | actionRequest.setParentActionRequestId(primaryDelegateRequest.getActionRequestId()); |
181 | |
|
182 | 0 | primaryDelegateRequest.getChildrenRequests().add(0, actionRequest); |
183 | |
|
184 | 0 | for (ActionRequestValue delegateRequest : primaryDelegateRequest.getChildrenRequests()) { |
185 | 0 | delegateRequest.setParentActionRequest(primaryDelegateRequest); |
186 | 0 | delegateRequest.setParentActionRequestId(primaryDelegateRequest.getActionRequestId()); |
187 | |
} |
188 | |
|
189 | 0 | return primaryDelegateRequest; |
190 | |
} |
191 | |
|
192 | 0 | return actionRequest; |
193 | |
} |
194 | |
|
195 | |
private List<ActionRequestValue> switchActionRequestPositionsIfPrimaryDelegatesPresent( Collection<ActionRequestValue> actionRequests ) { |
196 | 0 | List<ActionRequestValue> results = new ArrayList<ActionRequestValue>( actionRequests.size() ); |
197 | 0 | for ( ActionRequestValue actionRequest : actionRequests ) { |
198 | 0 | results.add( switchActionRequestPositionIfPrimaryDelegatePresent(actionRequest) ); |
199 | |
} |
200 | 0 | return results; |
201 | |
} |
202 | |
|
203 | |
@SuppressWarnings("unchecked") |
204 | |
private void fixActionRequestsPositions(DocumentRouteHeaderValue routeHeader) { |
205 | 0 | for (ActionTakenValue actionTaken : routeHeader.getActionsTaken()) { |
206 | 0 | Collections.sort((List<ActionRequestValue>) actionTaken.getActionRequests(), ROUTE_LOG_ACTION_REQUEST_SORTER); |
207 | 0 | actionTaken.setActionRequests( actionTaken.getActionRequests() ); |
208 | |
} |
209 | 0 | } |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
public void populateRouteLogFutureRequests(RouteLogForm rlForm, DocumentRouteHeaderValue document) throws Exception { |
220 | |
|
221 | 0 | ReportCriteriaDTO reportCriteria = new ReportCriteriaDTO(document.getRouteHeaderId()); |
222 | 0 | String serviceNamespace = document.getDocumentType().getServiceNamespace(); |
223 | 0 | WorkflowUtility workflowUtility = |
224 | |
(WorkflowUtility)GlobalResourceLoader.getService(new QName(serviceNamespace, "WorkflowUtilityService")); |
225 | |
|
226 | |
|
227 | 0 | Set<Long> preexistingActionRequestIds = getActionRequestIds(document); |
228 | |
|
229 | |
|
230 | 0 | DocumentDetailDTO documentDetail = workflowUtility.routingReport(reportCriteria); |
231 | |
|
232 | |
|
233 | 0 | List<ActionRequestValue> futureActionRequests = |
234 | |
reconstituteActionRequestValues(documentDetail, preexistingActionRequestIds); |
235 | |
|
236 | 0 | Collections.sort(futureActionRequests, ROUTE_LOG_ACTION_REQUEST_SORTER); |
237 | |
|
238 | 0 | futureActionRequests = switchActionRequestPositionsIfPrimaryDelegatesPresent(futureActionRequests); |
239 | |
|
240 | 0 | int pendingActionRequestCount = 0; |
241 | 0 | for (ActionRequestValue actionRequest: futureActionRequests) { |
242 | 0 | if (actionRequest.isPending()) { |
243 | 0 | pendingActionRequestCount++; |
244 | |
|
245 | 0 | if (KEWConstants.ACTION_REQUEST_INITIALIZED.equals(actionRequest.getStatus())) { |
246 | 0 | actionRequest.setDisplayStatus("PENDING"); |
247 | 0 | } else if (KEWConstants.ACTION_REQUEST_ACTIVATED.equals(actionRequest.getStatus())) { |
248 | 0 | actionRequest.setDisplayStatus("IN ACTION LIST"); |
249 | |
} |
250 | |
} |
251 | |
} |
252 | |
|
253 | 0 | rlForm.setFutureRootRequests(futureActionRequests); |
254 | 0 | rlForm.setFutureActionRequestCount(pendingActionRequestCount); |
255 | 0 | } |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
@SuppressWarnings("unchecked") |
263 | |
private Set<Long> getActionRequestIds(DocumentRouteHeaderValue document) { |
264 | 0 | Set<Long> actionRequestIds = new HashSet<Long>(); |
265 | |
|
266 | 0 | List<ActionRequestValue> actionRequests = |
267 | |
KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId()); |
268 | |
|
269 | 0 | if (actionRequests != null) for (ActionRequestValue actionRequest : actionRequests) { |
270 | 0 | if (actionRequest.getActionRequestId() != null) { |
271 | 0 | actionRequestIds.add(actionRequest.getActionRequestId()); |
272 | |
} |
273 | |
} |
274 | 0 | return actionRequestIds; |
275 | |
} |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
private List<ActionRequestValue> reconstituteActionRequestValues(DocumentDetailDTO documentDetail, |
286 | |
Set<Long> preexistingActionRequestIds) { |
287 | |
|
288 | 0 | RouteNodeInstanceFabricator routeNodeInstanceFabricator = |
289 | |
new RouteNodeInstanceFabricator(KEWServiceLocator.getRouteNodeService()); |
290 | |
|
291 | 0 | if (documentDetail.getNodeInstances() != null && documentDetail.getNodeInstances().length > 0) { |
292 | 0 | for (RouteNodeInstanceDTO routeNodeInstanceVO : documentDetail.getNodeInstances()) { |
293 | 0 | routeNodeInstanceFabricator.importRouteNodeInstanceDTO(routeNodeInstanceVO); |
294 | |
} |
295 | |
} |
296 | |
|
297 | 0 | ActionRequestDTO[] actionRequestVOs = documentDetail.getActionRequests(); |
298 | 0 | List<ActionRequestValue> futureActionRequests = new ArrayList<ActionRequestValue>(); |
299 | 0 | if (actionRequestVOs != null) for (ActionRequestDTO actionRequestVO : actionRequestVOs) if (actionRequestVO != null) { |
300 | 0 | if (!preexistingActionRequestIds.contains(actionRequestVO.getActionRequestId())) { |
301 | 0 | ActionRequestValue converted = DTOConverter.convertActionRequestDTO(actionRequestVO, routeNodeInstanceFabricator); |
302 | 0 | futureActionRequests.add(converted); |
303 | |
} |
304 | |
} |
305 | 0 | return futureActionRequests; |
306 | |
} |
307 | |
|
308 | |
private ActionRequestService getActionRequestService() { |
309 | 0 | return (ActionRequestService) KEWServiceLocator.getService(KEWServiceLocator.ACTION_REQUEST_SRV); |
310 | |
} |
311 | |
|
312 | |
private UserSession getUserSession(HttpServletRequest request) { |
313 | 0 | return UserSession.getAuthenticatedUser(); |
314 | |
} |
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | 0 | private static class RouteNodeInstanceFabricator implements RouteNodeInstanceLoader { |
324 | |
|
325 | 0 | private Map<Long,Branch> branches = new HashMap<Long, Branch>();; |
326 | 0 | private Map<Long,RouteNodeInstance> routeNodeInstances = new HashMap<Long, RouteNodeInstance>(); |
327 | 0 | private Map<Long,RouteNode> routeNodes = new HashMap<Long, RouteNode>(); |
328 | 0 | private Map<Long,NodeState> nodeStates = new HashMap<Long, NodeState>(); |
329 | |
|
330 | |
private RouteNodeService routeNodeService; |
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | 0 | public RouteNodeInstanceFabricator(RouteNodeService routeNodeService) { |
338 | 0 | this.routeNodeService = routeNodeService; |
339 | 0 | } |
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
public void importRouteNodeInstanceDTO(RouteNodeInstanceDTO nodeInstanceDTO) { |
349 | 0 | _importRouteNodeInstanceDTO(nodeInstanceDTO); |
350 | 0 | } |
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
private RouteNodeInstance _importRouteNodeInstanceDTO(RouteNodeInstanceDTO nodeInstanceDTO) { |
362 | 0 | if (nodeInstanceDTO == null) { |
363 | 0 | return null; |
364 | |
} |
365 | 0 | RouteNodeInstance nodeInstance = new RouteNodeInstance(); |
366 | 0 | nodeInstance.setActive(nodeInstanceDTO.isActive()); |
367 | |
|
368 | 0 | nodeInstance.setComplete(nodeInstanceDTO.isComplete()); |
369 | 0 | nodeInstance.setDocumentId(nodeInstanceDTO.getDocumentId()); |
370 | 0 | nodeInstance.setInitial(nodeInstanceDTO.isInitial()); |
371 | |
|
372 | 0 | Branch branch = getBranch(nodeInstanceDTO.getBranchId()); |
373 | 0 | nodeInstance.setBranch(branch); |
374 | |
|
375 | 0 | if (nodeInstanceDTO.getRouteNodeId() != null) { |
376 | 0 | RouteNode routeNode = routeNodeService.findRouteNodeById(nodeInstanceDTO.getRouteNodeId()); |
377 | |
|
378 | 0 | if (routeNode == null) { |
379 | 0 | routeNode = getRouteNode(nodeInstanceDTO.getRouteNodeId()); |
380 | 0 | routeNode.setNodeType(nodeInstanceDTO.getName()); |
381 | |
} |
382 | |
|
383 | 0 | nodeInstance.setRouteNode(routeNode); |
384 | |
|
385 | 0 | if (routeNode.getBranch() != null) { |
386 | 0 | branch.setName(routeNode.getBranch().getName()); |
387 | |
} |
388 | |
} |
389 | |
|
390 | 0 | RouteNodeInstance process = getRouteNodeInstance(nodeInstanceDTO.getProcessId()); |
391 | 0 | nodeInstance.setProcess(process); |
392 | |
|
393 | 0 | nodeInstance.setRouteNodeInstanceId(nodeInstanceDTO.getRouteNodeInstanceId()); |
394 | 0 | DTOConverter.convertState(null); |
395 | |
|
396 | 0 | List<NodeState> nodeState = new ArrayList<NodeState>(); |
397 | 0 | if (nodeInstanceDTO.getState() != null) for (StateDTO stateDTO : nodeInstanceDTO.getState()) { |
398 | 0 | NodeState state = getNodeState(stateDTO.getStateId()); |
399 | 0 | if (state != null) { |
400 | 0 | state.setKey(stateDTO.getKey()); |
401 | 0 | state.setValue(stateDTO.getValue()); |
402 | 0 | state.setStateId(stateDTO.getStateId()); |
403 | 0 | state.setNodeInstance(nodeInstance); |
404 | 0 | nodeState.add(state); |
405 | |
} |
406 | |
} |
407 | 0 | nodeInstance.setState(nodeState); |
408 | |
|
409 | 0 | List<RouteNodeInstance> nextNodeInstances = new ArrayList<RouteNodeInstance>(); |
410 | 0 | nodeInstance.setNextNodeInstances(nextNodeInstances); |
411 | |
|
412 | 0 | for (RouteNodeInstanceDTO nextNodeInstanceVO : nodeInstanceDTO.getNextNodes()) { |
413 | |
|
414 | 0 | nextNodeInstances.add(_importRouteNodeInstanceDTO(nextNodeInstanceVO)); |
415 | |
} |
416 | |
|
417 | 0 | routeNodeInstances.put(nodeInstance.getRouteNodeInstanceId(), nodeInstance); |
418 | 0 | return nodeInstance; |
419 | |
} |
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
public RouteNodeInstance load(Long routeNodeInstanceID) { |
428 | 0 | return routeNodeInstances.get(routeNodeInstanceID); |
429 | |
} |
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
private Branch getBranch(Long branchId) { |
439 | 0 | Branch result = null; |
440 | |
|
441 | 0 | if (branchId != null) { |
442 | |
|
443 | 0 | if (!branches.containsKey(branchId)) { |
444 | 0 | result = new Branch(); |
445 | 0 | result.setBranchId(branchId); |
446 | 0 | branches.put(branchId, result); |
447 | |
} else { |
448 | 0 | result = branches.get(branchId); |
449 | |
} |
450 | |
} |
451 | 0 | return result; |
452 | |
} |
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
private RouteNode getRouteNode(Long routeNodeId) { |
461 | 0 | RouteNode result = null; |
462 | |
|
463 | 0 | if (routeNodeId != null) { |
464 | |
|
465 | 0 | if (!routeNodes.containsKey(routeNodeId)) { |
466 | 0 | result = new RouteNode(); |
467 | 0 | result.setRouteNodeId(routeNodeId); |
468 | 0 | routeNodes.put(routeNodeId, result); |
469 | |
} else { |
470 | 0 | result = routeNodes.get(routeNodeId); |
471 | |
} |
472 | |
} |
473 | 0 | return result; |
474 | |
} |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
public RouteNodeInstance getRouteNodeInstance(Long routeNodeInstanceId) { |
483 | 0 | RouteNodeInstance result = null; |
484 | |
|
485 | 0 | if (routeNodeInstanceId != null) { |
486 | |
|
487 | 0 | if (!routeNodeInstances.containsKey(routeNodeInstanceId)) { |
488 | 0 | result = new RouteNodeInstance(); |
489 | 0 | result.setRouteNodeInstanceId(routeNodeInstanceId); |
490 | 0 | routeNodeInstances.put(routeNodeInstanceId, result); |
491 | |
} else { |
492 | 0 | result = routeNodeInstances.get(routeNodeInstanceId); |
493 | |
} |
494 | |
} |
495 | 0 | return result; |
496 | |
} |
497 | |
|
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
private NodeState getNodeState(Long nodeStateId) { |
505 | 0 | NodeState result = null; |
506 | |
|
507 | 0 | if (nodeStateId != null) { |
508 | |
|
509 | 0 | if (!nodeStates.containsKey(nodeStateId)) { |
510 | 0 | result = new NodeState(); |
511 | 0 | result.setNodeStateId(nodeStateId); |
512 | 0 | nodeStates.put(nodeStateId, result); |
513 | |
} else { |
514 | 0 | result = nodeStates.get(nodeStateId); |
515 | |
} |
516 | |
} |
517 | 0 | return result; |
518 | |
} |
519 | |
|
520 | |
} |
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
public ActionForward logActionMessageInRouteLog(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
528 | |
HttpServletResponse response) throws Exception { |
529 | 0 | RouteLogForm routeLogForm = (RouteLogForm) form; |
530 | |
|
531 | 0 | Long routeHeaderId = null; |
532 | 0 | if (!Utilities.isEmpty(routeLogForm.getRouteHeaderId())) { |
533 | 0 | routeHeaderId = new Long(routeLogForm.getRouteHeaderId()); |
534 | 0 | } else if (!Utilities.isEmpty(routeLogForm.getDocId())) { |
535 | 0 | routeHeaderId = new Long(routeLogForm.getDocId()); |
536 | |
} else { |
537 | 0 | throw new WorkflowRuntimeException("No paramater provided to fetch document"); |
538 | |
} |
539 | |
|
540 | 0 | DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(routeHeaderId); |
541 | |
|
542 | |
|
543 | 0 | boolean isAuthorizedToAddRouteLogMessage = KEWServiceLocator.getDocumentTypePermissionService() |
544 | |
.canAddRouteLogMessage(UserSession.getAuthenticatedUser().getPrincipalId(), routeHeader); |
545 | |
|
546 | 0 | if (!isAuthorizedToAddRouteLogMessage) { |
547 | 0 | throw new InvalidActionTakenException("Principal with name '" |
548 | |
+ UserSession.getAuthenticatedUser().getPrincipalName() |
549 | |
+ "' is not authorized to add route log messages for documents of type '" |
550 | |
+ routeHeader.getDocumentType().getName()); |
551 | |
} |
552 | |
|
553 | 0 | LOG.info("Logging new action message for user " + UserSession.getAuthenticatedUser().getPrincipalName() |
554 | |
+ ", route header id " + routeHeader); |
555 | 0 | KEWServiceLocator.getWorkflowDocumentService().logDocumentAction( |
556 | |
UserSession.getAuthenticatedUser().getPrincipalId(), routeHeader, |
557 | |
routeLogForm.getNewRouteLogActionMessage()); |
558 | |
|
559 | 0 | routeLogForm.setNewRouteLogActionMessage(""); |
560 | |
|
561 | |
|
562 | 0 | routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(routeHeaderId, true); |
563 | 0 | fixActionRequestsPositions(routeHeader); |
564 | 0 | request.setAttribute("routeHeader", routeHeader); |
565 | |
|
566 | 0 | return mapping.findForward(getDefaultMapping()); |
567 | |
} |
568 | |
|
569 | |
} |