1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
35 | |
|
36 | |
|
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 | |
|
46 | |
|
47 | |
|
48 | 0 | public NotificationWorkflowDocumentServiceImpl(NotificationMessageContentService messageContentService) { |
49 | 0 | this.messageContentService = messageContentService; |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public String createAndAdHocRouteNotificationWorkflowDocument(NotificationMessageDelivery messageDelivery, |
59 | |
String initiatorUserId, |
60 | |
String recipientUserId, String annotation) { |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 0 | WorkflowDocument document = NotificationWorkflowDocument.createNotificationDocument(initiatorUserId); |
66 | |
|
67 | |
|
68 | 0 | document.setApplicationDocumentId(messageDelivery.getId().toString()); |
69 | |
|
70 | |
|
71 | |
|
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 | |
|
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 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName( |
99 | |
recipientUserId); |
100 | 0 | document.adHocToPrincipal(ActionRequestType.fromCode(actionRequested), annotation, principal.getPrincipalId(), |
101 | |
messageDelivery.getNotification().getProducer().getName(), true); |
102 | |
|
103 | |
|
104 | 0 | document.route(annotation); |
105 | |
|
106 | 0 | return document.getDocumentId(); |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public WorkflowDocument getNotificationWorkflowDocumentByDocumentId(String initiatorUserId, |
116 | |
String workflowDocumentId) { |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | 0 | return NotificationWorkflowDocument.loadNotificationDocument(initiatorUserId, workflowDocumentId); |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public void clearAllFyisAndAcknowledgeNotificationWorkflowDocument(String initiatorUserId, |
130 | |
WorkflowDocument workflowDocument, String annotation) { |
131 | 0 | List<ActionRequest> reqs = workflowDocument.getRootActionRequests(); |
132 | 0 | for (int i = 0; i < reqs.size(); i++) { |
133 | 0 | LOG.info("Action Request[" + i + "] = " + reqs.get(i).getActionRequested()); |
134 | 0 | if (reqs.get(i).getActionRequested().equals(ActionRequestType.ACKNOWLEDGE)) { |
135 | 0 | workflowDocument.acknowledge(annotation); |
136 | 0 | } else if (reqs.get(i).getActionRequested().equals(ActionRequestType.FYI)) { |
137 | 0 | workflowDocument.logAnnotation(annotation); |
138 | 0 | workflowDocument.fyi(); |
139 | |
} else { |
140 | 0 | throw new WorkflowRuntimeException("Invalid notification action request in workflow document (" |
141 | |
+ workflowDocument.getDocumentId() |
142 | |
+ ") was encountered. Should be either an acknowledge or fyi and was not."); |
143 | |
} |
144 | |
} |
145 | 0 | } |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public void terminateWorkflowDocument(WorkflowDocument document) { |
151 | 0 | document.superUserCancel("terminating document: documentId=" + document.getDocumentId() + ", appDocId=" |
152 | |
+ document.getApplicationDocumentId()); |
153 | 0 | } |
154 | |
} |