Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NotificationWorkflowDocumentServiceImpl |
|
| 2.2;2.2 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.ken.service.impl; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.ken.bo.NotificationMessageDelivery; | |
20 | import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument; | |
21 | import org.kuali.rice.ken.service.NotificationMessageContentService; | |
22 | import org.kuali.rice.ken.service.NotificationWorkflowDocumentService; | |
23 | import org.kuali.rice.ken.util.NotificationConstants; | |
24 | import org.kuali.rice.kew.api.WorkflowDocument; | |
25 | import org.kuali.rice.kew.api.WorkflowRuntimeException; | |
26 | import org.kuali.rice.kew.api.action.ActionRequest; | |
27 | import org.kuali.rice.kew.api.action.ActionRequestType; | |
28 | import org.kuali.rice.kim.api.identity.principal.Principal; | |
29 | import org.kuali.rice.kim.api.services.KimApiServiceLocator; | |
30 | ||
31 | import java.util.List; | |
32 | ||
33 | /** | |
34 | * This class is responsible for interacting with KEW - this is the default implementation that | |
35 | * leverages the KEW client API. | |
36 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
37 | */ | |
38 | public class NotificationWorkflowDocumentServiceImpl implements NotificationWorkflowDocumentService { | |
39 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
40 | .getLogger(NotificationWorkflowDocumentServiceImpl.class); | |
41 | ||
42 | private NotificationMessageContentService messageContentService; | |
43 | ||
44 | /** | |
45 | * Constructs a NotificationWorkflowDocumentServiceImpl instance. | |
46 | * @param messageContentService | |
47 | */ | |
48 | 0 | public NotificationWorkflowDocumentServiceImpl(NotificationMessageContentService messageContentService) { |
49 | 0 | this.messageContentService = messageContentService; |
50 | 0 | } |
51 | ||
52 | /** | |
53 | * Implements by instantiating a NotificationWorkflowDocument, which in turn interacts with | |
54 | * Workflow to set it up with an initiator of the passed in user id. | |
55 | * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#createAndAdHocRouteNotificationWorkflowDocument(org.kuali.rice.ken.bo.NotificationMessageDelivery, | |
56 | * java.lang.String, java.lang.String, java.lang.String) | |
57 | */ | |
58 | public String createAndAdHocRouteNotificationWorkflowDocument(NotificationMessageDelivery messageDelivery, | |
59 | String initiatorUserId, | |
60 | String recipientUserId, String annotation) { | |
61 | // obtain a workflow user object first | |
62 | //WorkflowIdDTO initiator = new WorkflowIdDTO(initiatorUserId); | |
63 | ||
64 | // now construct the workflow document, which will interact with workflow | |
65 | 0 | WorkflowDocument document = NotificationWorkflowDocument.createNotificationDocument(initiatorUserId); |
66 | ||
67 | // this is our loose foreign key to our message delivery record in notification | |
68 | 0 | document.setApplicationDocumentId(messageDelivery.getId().toString()); |
69 | //document.setAppDocId(messageDelivery.getId().toString()); | |
70 | ||
71 | // now add the content of the notification as XML to the document | |
72 | 0 | document.setApplicationContent(messageContentService.generateNotificationMessage( |
73 | messageDelivery.getNotification(), messageDelivery.getUserRecipientId())); | |
74 | ||
75 | 0 | if (!StringUtils.isBlank(messageDelivery.getNotification().getTitle())) { |
76 | 0 | document.setTitle(messageDelivery.getNotification().getTitle()); |
77 | } else { | |
78 | 0 | LOG.error("Encountered notification with no title set: Message Delivery #" + messageDelivery.getId() |
79 | + ", Notification #" + messageDelivery.getNotification().getId()); | |
80 | } | |
81 | ||
82 | // now set up the ad hoc route | |
83 | String actionRequested; | |
84 | 0 | if (NotificationConstants.DELIVERY_TYPES.ACK.equals(messageDelivery.getNotification().getDeliveryType())) { |
85 | 0 | actionRequested = NotificationConstants.KEW_CONSTANTS.ACK_AD_HOC_ROUTE; |
86 | } else { | |
87 | 0 | actionRequested = NotificationConstants.KEW_CONSTANTS.FYI_AD_HOC_ROUTE; |
88 | } | |
89 | ||
90 | // Clarification of ad hoc route call | |
91 | // param 1 - actionRequested will be either ACK or FYI | |
92 | // param 2 - annotation is whatever text we pass in to describe the transaction - this will be system generated | |
93 | // param 3 - recipient is the person who will receive this request | |
94 | // param 4 - this is the responsibilityParty (a.k.a the system that produced this request), so we'll put the producer name in there | |
95 | // param 5 - this is the "force action" requests - if set to true, this will be delivered to the recipients list regardless of | |
96 | // whether the recipient has already taken action on this request; in our case, this doesn't really apply at this point in time, | |
97 | // so we'll set to true just to be safe | |
98 | ||
99 | // recipientUserId will always be a principal ID due to code changes in NotificationMessageDeliveryResolverServiceImpl.buildCompleteRecipientList() | |
100 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(recipientUserId); |
101 | ||
102 | 0 | document.adHocToPrincipal(ActionRequestType.fromCode(actionRequested), annotation, principal.getPrincipalId(), |
103 | messageDelivery.getNotification().getProducer().getName(), true); | |
104 | ||
105 | // now actually route it along its way | |
106 | 0 | document.route(annotation); |
107 | ||
108 | 0 | return document.getDocumentId(); |
109 | } | |
110 | ||
111 | /** | |
112 | * This service method is implemented by constructing a NotificationWorkflowDocument using the | |
113 | * pre-existing document Id that is passed in. | |
114 | * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#findNotificationWorkflowDocumentByDocumentId(java.lang.String, | |
115 | * java.lang.String) | |
116 | */ | |
117 | public WorkflowDocument getNotificationWorkflowDocumentByDocumentId(String initiatorUserId, | |
118 | String workflowDocumentId) { | |
119 | // construct the workflow id value object | |
120 | //WorkflowIdDTO initiator = new WorkflowIdDTO(initiatorUserId); | |
121 | ||
122 | // now return the actual document instance | |
123 | // this handles going out and getting the workflow document | |
124 | 0 | return NotificationWorkflowDocument.loadNotificationDocument(initiatorUserId, workflowDocumentId); |
125 | } | |
126 | ||
127 | /** | |
128 | * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#clearAllFyisAndAcknowledgeNotificationWorkflowDocument(java.lang.String, | |
129 | * org.kuali.rice.ken.document.kew.NotificationWorkflowDocument, java.lang.String) | |
130 | */ | |
131 | public void clearAllFyisAndAcknowledgeNotificationWorkflowDocument(String initiatorUserId, | |
132 | WorkflowDocument workflowDocument, String annotation) { | |
133 | 0 | List<ActionRequest> reqs = workflowDocument.getRootActionRequests(); |
134 | 0 | for (int i = 0; i < reqs.size(); i++) { |
135 | 0 | LOG.info("Action Request[" + i + "] = " + reqs.get(i).getActionRequested()); |
136 | 0 | if (reqs.get(i).getActionRequested().equals(ActionRequestType.ACKNOWLEDGE)) { |
137 | 0 | workflowDocument.acknowledge(annotation); |
138 | 0 | } else if (reqs.get(i).getActionRequested().equals(ActionRequestType.FYI)) { |
139 | 0 | workflowDocument.logAnnotation(annotation); |
140 | 0 | workflowDocument.fyi(); |
141 | } else { | |
142 | 0 | throw new WorkflowRuntimeException("Invalid notification action request in workflow document (" |
143 | + workflowDocument.getDocumentId() | |
144 | + ") was encountered. Should be either an acknowledge or fyi and was not."); | |
145 | } | |
146 | } | |
147 | 0 | } |
148 | ||
149 | /** | |
150 | * @see org.kuali.rice.ken.service.NotificationWorkflowDocumentService#terminateWorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) | |
151 | */ | |
152 | public void terminateWorkflowDocument(WorkflowDocument document) { | |
153 | 0 | document.superUserCancel("terminating document: documentId=" + document.getDocumentId() + ", appDocId=" |
154 | + document.getApplicationDocumentId()); | |
155 | 0 | } |
156 | } |