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.dto.ActionRequestDTO; |
25 | |
import org.kuali.rice.kew.exception.WorkflowException; |
26 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
27 | |
import org.kuali.rice.kew.util.KEWConstants; |
28 | |
import org.kuali.rice.kim.api.entity.principal.Principal; |
29 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class NotificationWorkflowDocumentServiceImpl implements NotificationWorkflowDocumentService { |
38 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
39 | |
.getLogger(NotificationWorkflowDocumentServiceImpl.class); |
40 | |
|
41 | |
private NotificationMessageContentService messageContentService; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public NotificationWorkflowDocumentServiceImpl(NotificationMessageContentService messageContentService) { |
48 | 0 | this.messageContentService = messageContentService; |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public String createAndAdHocRouteNotificationWorkflowDocument(NotificationMessageDelivery messageDelivery, String initiatorUserId, |
57 | |
String recipientUserId, String annotation) throws WorkflowException { |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | 0 | NotificationWorkflowDocument document = NotificationWorkflowDocument.createNotificationDocument(initiatorUserId); |
63 | |
|
64 | |
|
65 | 0 | document.getRouteHeader().setAppDocId(messageDelivery.getId().toString()); |
66 | |
|
67 | |
|
68 | |
|
69 | 0 | document.setApplicationContent(messageContentService.generateNotificationMessage(messageDelivery.getNotification(), messageDelivery.getUserRecipientId())); |
70 | |
|
71 | 0 | if (!StringUtils.isBlank(messageDelivery.getNotification().getTitle())) { |
72 | 0 | document.setTitle(messageDelivery.getNotification().getTitle()); |
73 | |
} else { |
74 | 0 | LOG.error("Encountered notification with no title set: Message Delivery #" + messageDelivery.getId() + ", Notification #" + messageDelivery.getNotification().getId()); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
String actionRequested; |
79 | 0 | if(NotificationConstants.DELIVERY_TYPES.ACK.equals(messageDelivery.getNotification().getDeliveryType())) { |
80 | 0 | actionRequested = NotificationConstants.KEW_CONSTANTS.ACK_AD_HOC_ROUTE; |
81 | |
} else { |
82 | 0 | actionRequested = NotificationConstants.KEW_CONSTANTS.FYI_AD_HOC_ROUTE; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | 0 | Principal principal = KimApiServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(recipientUserId); |
94 | 0 | document.adHocRouteDocumentToPrincipal(actionRequested, annotation, principal.getPrincipalId(), |
95 | |
messageDelivery.getNotification().getProducer().getName(), true); |
96 | |
|
97 | |
|
98 | 0 | document.routeDocument(annotation); |
99 | |
|
100 | 0 | return document.getDocumentId(); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public NotificationWorkflowDocument getNotificationWorkflowDocumentByDocumentId(String initiatorUserId, String workflowDocumentId) throws WorkflowException { |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | 0 | return NotificationWorkflowDocument.loadNotificationDocument(initiatorUserId, workflowDocumentId); |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void clearAllFyisAndAcknowledgeNotificationWorkflowDocument(String initiatorUserId, NotificationWorkflowDocument workflowDocument, String annotation) throws WorkflowException { |
122 | 0 | ActionRequestDTO[] reqs = workflowDocument.getActionRequests(); |
123 | 0 | for(int i = 0; i < reqs.length; i++) { |
124 | 0 | LOG.info("Action Request[" + i + "] = " + reqs[i].getActionRequested()); |
125 | 0 | if(reqs[i].getActionRequested().equals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ)) { |
126 | 0 | workflowDocument.acknowledge(annotation); |
127 | 0 | } else if(reqs[i].getActionRequested().equals(KEWConstants.ACTION_REQUEST_FYI_REQ)) { |
128 | 0 | workflowDocument.logDocumentAction(annotation); |
129 | 0 | workflowDocument.clearFYI(); |
130 | |
} else { |
131 | 0 | throw new WorkflowException("Invalid notification action request in workflow document (" + workflowDocument.getDocumentId() + ") was encountered. Should be either an acknowledge or fyi and was not."); |
132 | |
} |
133 | |
} |
134 | 0 | } |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public void terminateWorkflowDocument(WorkflowDocument document) throws WorkflowException { |
140 | 0 | document.superUserCancel("terminating document: documentId=" + document.getDocumentId() + ", appDocId=" + document.getAppDocId()); |
141 | 0 | } |
142 | |
} |