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 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 public KEWActionListMessageDeliverer() {
52 this.notificationWorkflowDocumentService = GlobalNotificationServiceLocator.getInstance()
53 .getNotificationWorkflowDocumentService();
54 }
55
56
57
58
59
60
61 public void deliverMessage(NotificationMessageDelivery messageDelivery) throws NotificationMessageDeliveryException {
62
63 String documentId = notificationWorkflowDocumentService.createAndAdHocRouteNotificationWorkflowDocument(
64 messageDelivery,
65 Util.getNotificationSystemUser(),
66 messageDelivery.getUserRecipientId(),
67 NotificationConstants.KEW_CONSTANTS.GENERIC_DELIVERY_ANNOTATION);
68
69
70 messageDelivery.setDeliverySystemId(documentId);
71 LOG.debug("Message Delivery: " + messageDelivery.toString());
72 }
73
74
75
76
77
78
79
80 public void autoRemoveMessageDelivery(NotificationMessageDelivery messageDelivery)
81 throws NotificationAutoRemoveException {
82
83 WorkflowDocument workflowDoc = null;
84 String sysId = messageDelivery.getDeliverySystemId();
85 if (sysId == null) {
86 LOG.error("NotificationMessageDelivery " + messageDelivery.getId()
87 + " is missing delivery system id (workflow document id");
88
89
90 return;
91 }
92
93 workflowDoc = notificationWorkflowDocumentService.getNotificationWorkflowDocumentByDocumentId(
94 messageDelivery.getUserRecipientId(), sysId);
95
96 flagWorkflowDocument(workflowDoc);
97
98 notificationWorkflowDocumentService.clearAllFyisAndAcknowledgeNotificationWorkflowDocument(
99 messageDelivery.getUserRecipientId(), workflowDoc,
100 NotificationConstants.KEW_CONSTANTS.GENERIC_AUTO_REMOVE_ANNOTATION);
101 }
102
103
104
105
106
107 public void dismissMessageDelivery(NotificationMessageDelivery messageDelivery, String user, String cause) {
108
109 LOG.info("Dismissing as user '" + user + "' workflow document '" + messageDelivery.getDeliverySystemId()
110 + "' corresponding to message delivery #" + messageDelivery.getId() + " due to cause: " + cause);
111 if (NotificationConstants.AUTO_REMOVE_CAUSE.equals(cause)) {
112
113
114 } else {
115 WorkflowDocument nwd;
116 nwd = notificationWorkflowDocumentService.getNotificationWorkflowDocumentByDocumentId(user,
117 messageDelivery.getDeliverySystemId());
118
119 flagWorkflowDocument(nwd);
120
121 if (NotificationConstants.ACK_CAUSE.equals(cause)) {
122
123
124
125
126 if (nwd.isAcknowledgeRequested()) {
127 nwd.acknowledge("This notification has been acknowledged.");
128 LOG.debug("acknowledged " + nwd.getTitle());
129 LOG.debug("status display value: " + nwd.getStatus().getLabel());
130 } else {
131 LOG.debug("Acknowledgement was not needed for document " + nwd.getDocumentId());
132 }
133 } else if (NotificationConstants.FYI_CAUSE.equals(cause)) {
134
135
136
137
138 if (nwd.isFYIRequested()) {
139 nwd.fyi();
140 LOG.debug("fyi " + nwd.getTitle());
141 LOG.debug("status display value: " + nwd.getStatus().getLabel());
142 } else {
143 LOG.debug("FYI was not needed for document " + nwd.getDocumentId());
144 }
145 }
146 }
147 }
148
149
150
151
152
153
154 protected void flagWorkflowDocument(WorkflowDocument doc) {
155 Properties p = new Properties();
156 p.setProperty(INTERNAL_COMMAND_FLAG, "true");
157 ByteArrayOutputStream baos = new ByteArrayOutputStream(100);
158 try {
159 p.store(baos, null);
160 } catch (IOException ioe) {
161 throw new RuntimeException("Could not store properties", ioe);
162 }
163 doc.setAttributeContent("<whatever>" + new String(baos.toByteArray()) + "</whatever>");
164 }
165 }