1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ken.deliverer.impl; |
17 | |
|
18 | |
import java.io.ByteArrayOutputStream; |
19 | |
import java.io.IOException; |
20 | |
import java.util.Properties; |
21 | |
|
22 | |
import org.kuali.rice.ken.bo.NotificationMessageDelivery; |
23 | |
import org.kuali.rice.ken.core.GlobalNotificationServiceLocator; |
24 | |
import org.kuali.rice.ken.deliverer.NotificationMessageDeliverer; |
25 | |
import org.kuali.rice.ken.exception.NotificationAutoRemoveException; |
26 | |
import org.kuali.rice.ken.exception.NotificationMessageDeliveryException; |
27 | |
import org.kuali.rice.ken.service.NotificationWorkflowDocumentService; |
28 | |
import org.kuali.rice.ken.util.NotificationConstants; |
29 | |
import org.kuali.rice.ken.util.Util; |
30 | |
import org.kuali.rice.kew.api.WorkflowDocument; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class KEWActionListMessageDeliverer implements NotificationMessageDeliverer { |
38 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KEWActionListMessageDeliverer.class); |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public static final String INTERNAL_COMMAND_FLAG = "internal_command"; |
45 | |
|
46 | |
private NotificationWorkflowDocumentService notificationWorkflowDocumentService; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public KEWActionListMessageDeliverer() { |
52 | 0 | this.notificationWorkflowDocumentService = GlobalNotificationServiceLocator.getInstance() |
53 | |
.getNotificationWorkflowDocumentService(); |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public void deliverMessage(NotificationMessageDelivery messageDelivery) throws NotificationMessageDeliveryException { |
62 | |
|
63 | 0 | String documentId = notificationWorkflowDocumentService.createAndAdHocRouteNotificationWorkflowDocument( |
64 | |
messageDelivery, |
65 | |
Util.getNotificationSystemUser(), |
66 | |
messageDelivery.getUserRecipientId(), |
67 | |
NotificationConstants.KEW_CONSTANTS.GENERIC_DELIVERY_ANNOTATION); |
68 | |
|
69 | |
|
70 | 0 | messageDelivery.setDeliverySystemId(documentId); |
71 | 0 | LOG.debug("Message Delivery: " + messageDelivery.toString()); |
72 | 0 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public void autoRemoveMessageDelivery(NotificationMessageDelivery messageDelivery) |
81 | |
throws NotificationAutoRemoveException { |
82 | |
|
83 | 0 | WorkflowDocument workflowDoc = null; |
84 | 0 | String sysId = messageDelivery.getDeliverySystemId(); |
85 | 0 | if (sysId == null) { |
86 | 0 | LOG.error("NotificationMessageDelivery " + messageDelivery.getId() |
87 | |
+ " is missing delivery system id (workflow document id"); |
88 | |
|
89 | |
|
90 | 0 | return; |
91 | |
} |
92 | |
|
93 | 0 | workflowDoc = notificationWorkflowDocumentService.getNotificationWorkflowDocumentByDocumentId( |
94 | |
messageDelivery.getUserRecipientId(), sysId); |
95 | |
|
96 | 0 | flagWorkflowDocument(workflowDoc); |
97 | |
|
98 | 0 | notificationWorkflowDocumentService.clearAllFyisAndAcknowledgeNotificationWorkflowDocument( |
99 | |
messageDelivery.getUserRecipientId(), workflowDoc, |
100 | |
NotificationConstants.KEW_CONSTANTS.GENERIC_AUTO_REMOVE_ANNOTATION); |
101 | 0 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
public void dismissMessageDelivery(NotificationMessageDelivery messageDelivery, String user, String cause) { |
108 | |
|
109 | 0 | LOG.info("Dismissing as user '" + user + "' workflow document '" + messageDelivery.getDeliverySystemId() |
110 | |
+ "' corresponding to message delivery #" + messageDelivery.getId() + " due to cause: " + cause); |
111 | 0 | if (NotificationConstants.AUTO_REMOVE_CAUSE.equals(cause)) { |
112 | |
|
113 | |
|
114 | |
} else { |
115 | |
WorkflowDocument nwd; |
116 | 0 | nwd = notificationWorkflowDocumentService.getNotificationWorkflowDocumentByDocumentId(user, |
117 | |
messageDelivery.getDeliverySystemId()); |
118 | |
|
119 | 0 | flagWorkflowDocument(nwd); |
120 | |
|
121 | 0 | if (NotificationConstants.ACK_CAUSE.equals(cause)) { |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | 0 | if (nwd.isAcknowledgeRequested()) { |
127 | 0 | nwd.acknowledge("This notification has been acknowledged."); |
128 | 0 | LOG.debug("acknowledged " + nwd.getTitle()); |
129 | 0 | LOG.debug("status display value: " + nwd.getStatus().getLabel()); |
130 | |
} else { |
131 | 0 | LOG.debug("Acknowledgement was not needed for document " + nwd.getDocumentId()); |
132 | |
} |
133 | 0 | } else if (NotificationConstants.FYI_CAUSE.equals(cause)) { |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | 0 | if (nwd.isFYIRequested()) { |
139 | 0 | nwd.fyi(); |
140 | 0 | LOG.debug("fyi " + nwd.getTitle()); |
141 | 0 | LOG.debug("status display value: " + nwd.getStatus().getLabel()); |
142 | |
} else { |
143 | 0 | LOG.debug("FYI was not needed for document " + nwd.getDocumentId()); |
144 | |
} |
145 | |
} |
146 | |
} |
147 | 0 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
protected void flagWorkflowDocument(WorkflowDocument doc) { |
155 | 0 | Properties p = new Properties(); |
156 | 0 | p.setProperty(INTERNAL_COMMAND_FLAG, "true"); |
157 | 0 | ByteArrayOutputStream baos = new ByteArrayOutputStream(100); |
158 | |
try { |
159 | 0 | p.store(baos, null); |
160 | 0 | } catch (IOException ioe) { |
161 | 0 | throw new RuntimeException("Could not store properties", ioe); |
162 | 0 | } |
163 | 0 | doc.setAttributeContent("<whatever>" + new String(baos.toByteArray()) + "</whatever>"); |
164 | 0 | } |
165 | |
} |