1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.ken.service.impl; |
18 | |
|
19 | |
import com.thoughtworks.xstream.XStream; |
20 | |
import com.thoughtworks.xstream.io.xml.DomDriver; |
21 | |
import org.apache.commons.io.IOUtils; |
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.log4j.Logger; |
24 | |
import org.kuali.rice.core.framework.persistence.dao.GenericDao; |
25 | |
import org.kuali.rice.core.util.xml.XmlException; |
26 | |
import org.kuali.rice.core.util.xml.XmlJotter; |
27 | |
import org.kuali.rice.ken.bo.Notification; |
28 | |
import org.kuali.rice.ken.bo.NotificationChannel; |
29 | |
import org.kuali.rice.ken.bo.NotificationContentType; |
30 | |
import org.kuali.rice.ken.bo.NotificationPriority; |
31 | |
import org.kuali.rice.ken.bo.NotificationProducer; |
32 | |
import org.kuali.rice.ken.bo.NotificationRecipient; |
33 | |
import org.kuali.rice.ken.bo.NotificationResponse; |
34 | |
import org.kuali.rice.ken.bo.NotificationSender; |
35 | |
import org.kuali.rice.ken.service.NotificationContentTypeService; |
36 | |
import org.kuali.rice.ken.service.NotificationMessageContentService; |
37 | |
import org.kuali.rice.ken.util.CompoundNamespaceContext; |
38 | |
import org.kuali.rice.ken.util.ConfiguredNamespaceContext; |
39 | |
import org.kuali.rice.ken.util.NotificationConstants; |
40 | |
import org.kuali.rice.ken.util.Util; |
41 | |
import org.kuali.rice.kew.util.Utilities; |
42 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
43 | |
import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes; |
44 | |
import org.w3c.dom.Document; |
45 | |
import org.w3c.dom.Element; |
46 | |
import org.w3c.dom.Node; |
47 | |
import org.w3c.dom.NodeList; |
48 | |
import org.xml.sax.InputSource; |
49 | |
import org.xml.sax.SAXException; |
50 | |
|
51 | |
import javax.xml.parsers.ParserConfigurationException; |
52 | |
import javax.xml.xpath.XPath; |
53 | |
import javax.xml.xpath.XPathConstants; |
54 | |
import javax.xml.xpath.XPathExpressionException; |
55 | |
import javax.xml.xpath.XPathFactory; |
56 | |
import java.io.ByteArrayInputStream; |
57 | |
import java.io.IOException; |
58 | |
import java.io.InputStream; |
59 | |
import java.sql.Timestamp; |
60 | |
import java.text.DateFormat; |
61 | |
import java.text.ParseException; |
62 | |
import java.text.SimpleDateFormat; |
63 | |
import java.util.ArrayList; |
64 | |
import java.util.Date; |
65 | |
import java.util.HashMap; |
66 | |
import java.util.List; |
67 | |
import java.util.Map; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public class NotificationMessageContentServiceImpl implements NotificationMessageContentService { |
76 | 0 | private static final Logger LOG = Logger.getLogger(NotificationMessageContentServiceImpl.class); |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
static final String CONTENT_TYPE_NAMESPACE_PREFIX = "ns:notification/ContentType"; |
82 | |
|
83 | |
|
84 | 0 | private static final DateFormat DATEFORMAT_CURR_TZ = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
private GenericDao boDao; |
90 | |
|
91 | |
|
92 | |
|
93 | |
private NotificationContentTypeService notificationContentTypeService; |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 0 | public NotificationMessageContentServiceImpl(GenericDao boDao, NotificationContentTypeService notificationContentTypeService) { |
101 | 0 | this.boDao = boDao; |
102 | 0 | this.notificationContentTypeService = notificationContentTypeService; |
103 | 0 | } |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public Notification parseNotificationRequestMessage(String notificationMessageAsXml) throws IOException, XmlException { |
110 | |
|
111 | |
|
112 | |
|
113 | 0 | byte[] bytes = notificationMessageAsXml.getBytes(); |
114 | |
|
115 | 0 | return parseNotificationRequestMessage(bytes); |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public Notification parseNotificationRequestMessage(InputStream stream) throws IOException, XmlException { |
123 | |
|
124 | |
|
125 | |
|
126 | 0 | byte[] bytes = IOUtils.toByteArray(stream); |
127 | |
|
128 | 0 | return parseNotificationRequestMessage(bytes); |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
private Notification parseNotificationRequestMessage(byte[] bytes) throws IOException, XmlException { |
141 | |
|
142 | |
Document doc; |
143 | |
try { |
144 | 0 | doc = Util.parseWithNotificationEntityResolver(new InputSource(new ByteArrayInputStream(bytes)), true, true, notificationContentTypeService); |
145 | 0 | } catch (ParserConfigurationException pce) { |
146 | 0 | throw new XmlException("Error obtaining XML parser", pce); |
147 | 0 | } catch (SAXException se) { |
148 | 0 | throw new XmlException("Error validating notification request", se); |
149 | 0 | } |
150 | |
|
151 | 0 | Element root = doc.getDocumentElement(); |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | 0 | XPath xpath = XPathFactory.newInstance().newXPath(); |
173 | 0 | xpath.setNamespaceContext(Util.getNotificationNamespaceContext(doc)); |
174 | |
|
175 | |
|
176 | 0 | LOG.debug("URI: " + xpath.getNamespaceContext().getNamespaceURI("nreq")); |
177 | |
try { |
178 | 0 | String channelName = (String) xpath.evaluate("/nreq:notification/nreq:channel", root); |
179 | 0 | LOG.debug("CHANNELNAME: "+ channelName); |
180 | 0 | String producerName = xpath.evaluate("/nreq:notification/nreq:producer", root); |
181 | |
|
182 | 0 | List<String> senders = new ArrayList<String>(); |
183 | 0 | NodeList nodes = (NodeList) xpath.evaluate("/nreq:notification/nreq:senders/nreq:sender", root, XPathConstants.NODESET); |
184 | 0 | for (int i = 0; i < nodes.getLength(); i++) { |
185 | 0 | LOG.debug("sender node: " + nodes.item(i)); |
186 | 0 | LOG.debug("sender node VALUE: " + nodes.item(i).getTextContent()); |
187 | 0 | senders.add(nodes.item(i).getTextContent()); |
188 | |
} |
189 | 0 | nodes = (NodeList) xpath.evaluate("/nreq:notification/nreq:recipients/nreq:group|/nreq:notification/nreq:recipients/nreq:user", root, XPathConstants.NODESET); |
190 | 0 | List<NotificationRecipient> recipients = new ArrayList<NotificationRecipient>(); |
191 | 0 | for (int i = 0; i < nodes.getLength(); i++) { |
192 | 0 | Node node = nodes.item(i); |
193 | 0 | NotificationRecipient recipient = new NotificationRecipient(); |
194 | |
|
195 | 0 | if (NotificationConstants.RECIPIENT_TYPES.GROUP.equalsIgnoreCase(node.getLocalName())) { |
196 | |
|
197 | 0 | recipient.setRecipientType(KimGroupMemberTypes.GROUP_MEMBER_TYPE); |
198 | 0 | recipient.setRecipientId(KimApiServiceLocator.getGroupService().getGroupByName(Utilities.parseGroupNamespaceCode(node.getTextContent()), Utilities.parseGroupName(node.getTextContent())).getId()); |
199 | 0 | } else if (NotificationConstants.RECIPIENT_TYPES.USER.equalsIgnoreCase(node.getLocalName())){ |
200 | |
|
201 | 0 | recipient.setRecipientType(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE); |
202 | 0 | recipient.setRecipientId(node.getTextContent()); |
203 | |
} else { |
204 | 0 | throw new XmlException("Invalid 'recipientType' value: '" + node.getLocalName() + |
205 | |
"'. Needs to either be 'user' or 'group'"); |
206 | |
} |
207 | 0 | recipients.add(recipient); |
208 | |
} |
209 | |
|
210 | 0 | String deliveryType = xpath.evaluate("/nreq:notification/nreq:deliveryType", root); |
211 | 0 | String sendDateTime = xpath.evaluate("/nreq:notification/nreq:sendDateTime", root); |
212 | 0 | String autoRemoveDateTime = xpath.evaluate("/nreq:notification/nreq:autoRemoveDateTime", root); |
213 | |
|
214 | 0 | String priorityName = xpath.evaluate("/nreq:notification/nreq:priority", root); |
215 | 0 | String title = xpath.evaluate("/nreq:notification/nreq:title", root); |
216 | 0 | String contentTypeName = xpath.evaluate("/nreq:notification/nreq:contentType", root); |
217 | |
|
218 | |
|
219 | |
|
220 | 0 | Notification notification = new Notification(); |
221 | |
|
222 | 0 | if (!StringUtils.isBlank(title)) { |
223 | 0 | notification.setTitle(title); |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | 0 | NotificationChannel channel = Util.retrieveFieldReference("channel", "name", channelName, NotificationChannel.class, boDao); |
230 | 0 | notification.setChannel(channel); |
231 | |
|
232 | 0 | NotificationProducer producer = Util.retrieveFieldReference("producer", "name", producerName, NotificationProducer.class, boDao); |
233 | 0 | notification.setProducer(producer); |
234 | |
|
235 | 0 | for (String sender: senders) { |
236 | 0 | NotificationSender ns = new NotificationSender(); |
237 | 0 | LOG.debug("Setting sender: " + sender); |
238 | 0 | ns.setSenderName(sender); |
239 | 0 | notification.addSender(ns); |
240 | 0 | } |
241 | |
|
242 | 0 | for (NotificationRecipient recipient: recipients) { |
243 | 0 | LOG.debug("Setting recipient id: "+ recipient.getRecipientId()); |
244 | 0 | notification.addRecipient(recipient); |
245 | |
} |
246 | |
|
247 | |
|
248 | 0 | if(!NotificationConstants.DELIVERY_TYPES.ACK.equalsIgnoreCase(deliveryType) && |
249 | |
!NotificationConstants.DELIVERY_TYPES.FYI.equalsIgnoreCase(deliveryType)) { |
250 | 0 | throw new XmlException("Invalid 'deliveryType' value: '" + deliveryType + |
251 | |
"'. Must be either 'ACK' or 'FYI'."); |
252 | |
} |
253 | 0 | notification.setDeliveryType(deliveryType); |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
Date d; |
259 | 0 | if(StringUtils.isNotBlank(sendDateTime)) { |
260 | |
try { |
261 | 0 | d = Util.parseXSDDateTime(sendDateTime); |
262 | 0 | } catch (ParseException pe) { |
263 | 0 | throw new XmlException("Invalid 'sendDateTime' value: " + sendDateTime, pe); |
264 | 0 | } |
265 | 0 | notification.setSendDateTime(new Timestamp(d.getTime())); |
266 | |
} |
267 | 0 | if(StringUtils.isNotBlank(autoRemoveDateTime)) { |
268 | |
try { |
269 | 0 | d = Util.parseXSDDateTime(autoRemoveDateTime); |
270 | 0 | } catch (ParseException pe) { |
271 | 0 | throw new XmlException("Invalid 'autoRemoveDateTime' value: " + autoRemoveDateTime, pe); |
272 | 0 | } |
273 | 0 | notification.setAutoRemoveDateTime(new Timestamp(d.getTime())); |
274 | |
} |
275 | |
|
276 | |
|
277 | |
|
278 | 0 | NotificationPriority priority = Util.retrieveFieldReference("priority", "name", priorityName, NotificationPriority.class, boDao); |
279 | 0 | notification.setPriority(priority); |
280 | |
|
281 | 0 | NotificationContentType contentType = Util.retrieveFieldReference("contentType", "name", contentTypeName, NotificationContentType.class, boDao); |
282 | 0 | notification.setContentType(contentType); |
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | 0 | Map<String, String> contentTypeNamespace = new HashMap<String, String>(); |
308 | 0 | String ephemeralNamespace = "contentNS_" + System.currentTimeMillis(); |
309 | 0 | contentTypeNamespace.put(ephemeralNamespace, CONTENT_TYPE_NAMESPACE_PREFIX + contentType.getName()); |
310 | 0 | xpath.setNamespaceContext(new CompoundNamespaceContext(new ConfiguredNamespaceContext(contentTypeNamespace), xpath.getNamespaceContext())); |
311 | 0 | Node contentNode = (Node) xpath.evaluate("/nreq:notification/" + ephemeralNamespace + ":content", root, XPathConstants.NODE); |
312 | 0 | Element contentElement = null; |
313 | 0 | String content = ""; |
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | 0 | if (contentNode == null) { |
320 | 0 | throw new XmlException("The 'content' element is mandatory."); |
321 | |
} |
322 | 0 | if (contentNode != null) { |
323 | 0 | if (!(contentNode instanceof Element)) { |
324 | |
|
325 | 0 | throw new XmlException("The 'content' node is not an Element! (???)."); |
326 | |
} |
327 | 0 | contentElement = (Element) contentNode; |
328 | |
|
329 | |
|
330 | 0 | content = XmlJotter.jotNode(contentNode, true); |
331 | |
} |
332 | |
|
333 | 0 | notification.setContent(content); |
334 | |
|
335 | 0 | LOG.debug("Content type: " + contentType.getName()); |
336 | 0 | LOG.debug("Content: " + content); |
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | 0 | validateContent(notification, contentType.getName(), contentElement, content); |
342 | |
|
343 | 0 | return notification; |
344 | 0 | } catch (XPathExpressionException xpee) { |
345 | 0 | throw new XmlException("Error parsing request", xpee); |
346 | |
} |
347 | |
} |
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
private void validateContent(Notification notification, String contentType, Element contentElement, String content) throws IOException, XmlException { |
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | 0 | String contentTypeTitleCase = Character.toTitleCase(contentType.charAt(0)) + contentType.substring(1); |
375 | 0 | String expectedNamespaceURI = CONTENT_TYPE_NAMESPACE_PREFIX + contentTypeTitleCase; |
376 | 0 | String actualNamespaceURI = contentElement.getNamespaceURI(); |
377 | 0 | if (!actualNamespaceURI.equals(expectedNamespaceURI)) { |
378 | 0 | throw new XmlException("Namespace URI of 'content' node, '" + actualNamespaceURI + "', does not match expected namespace URI, '" + expectedNamespaceURI + "', for content type '" + contentType + "'"); |
379 | |
} |
380 | 0 | } |
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
public String generateNotificationResponseMessage(NotificationResponse response) { |
387 | 0 | XStream xstream = new XStream(new DomDriver()); |
388 | 0 | xstream.alias("response", NotificationResponse.class); |
389 | 0 | xstream.alias("status", String.class); |
390 | 0 | xstream.alias("message", String.class); |
391 | 0 | xstream.alias("notificationId", Long.class); |
392 | 0 | String xml = xstream.toXML(response); |
393 | 0 | return xml; |
394 | |
} |
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
public String generateNotificationMessage(Notification notification, String userRecipientId) { |
402 | |
|
403 | 0 | Notification clone = Util.cloneNotificationWithoutObjectReferences(notification); |
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | 0 | if(StringUtils.isNotBlank(userRecipientId)) { |
418 | 0 | clone.getRecipients().clear(); |
419 | |
|
420 | 0 | NotificationRecipient recipient = new NotificationRecipient(); |
421 | 0 | recipient.setRecipientId(userRecipientId); |
422 | 0 | recipient.setRecipientType(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE); |
423 | |
|
424 | 0 | clone.getRecipients().add(recipient); |
425 | |
} |
426 | |
|
427 | |
|
428 | 0 | XStream xstream = new XStream(new DomDriver()); |
429 | 0 | xstream.alias("notification", Notification.class); |
430 | 0 | xstream.alias("channel", NotificationChannel.class); |
431 | 0 | xstream.alias("contentType", NotificationContentType.class); |
432 | 0 | xstream.alias("title", String.class); |
433 | 0 | xstream.alias("priority", NotificationPriority.class); |
434 | 0 | xstream.alias("producer", NotificationProducer.class); |
435 | 0 | xstream.alias("recipient", NotificationRecipient.class); |
436 | 0 | xstream.alias("sender", NotificationSender.class); |
437 | 0 | String xml = xstream.toXML(clone); |
438 | 0 | return xml; |
439 | |
} |
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
public String generateNotificationMessage(Notification notification) { |
446 | 0 | return generateNotificationMessage(notification, null); |
447 | |
} |
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
public Notification parseSerializedNotificationXml(byte[] xmlAsBytes) throws Exception { |
455 | |
Document doc; |
456 | 0 | Notification notification = new Notification(); |
457 | |
|
458 | |
try { |
459 | 0 | doc = Util.parse(new InputSource(new ByteArrayInputStream(xmlAsBytes)), false, false, null); |
460 | 0 | } catch (Exception pce) { |
461 | 0 | throw new XmlException("Error obtaining XML parser", pce); |
462 | 0 | } |
463 | |
|
464 | 0 | Element root = doc.getDocumentElement(); |
465 | 0 | XPath xpath = XPathFactory.newInstance().newXPath(); |
466 | 0 | xpath.setNamespaceContext(Util.getNotificationNamespaceContext(doc)); |
467 | |
|
468 | |
try { |
469 | |
|
470 | 0 | String title = ((String) xpath.evaluate("//notification/title", root)).trim(); |
471 | |
|
472 | 0 | String channelName = ((String) xpath.evaluate("//notification/channel/name", root)).trim(); |
473 | |
|
474 | 0 | String contentTypeName = ((String) xpath.evaluate("//notification/contentType/name", root)).trim(); |
475 | |
|
476 | 0 | String priorityName = ((String) xpath.evaluate("//notification/priority/name", root)).trim(); |
477 | |
|
478 | 0 | List<String> senders = new ArrayList<String>(); |
479 | 0 | NodeList senderNodes = (NodeList) xpath.evaluate("//notification/senders/sender/senderName", root, XPathConstants.NODESET); |
480 | 0 | for (int i = 0; i < senderNodes.getLength(); i++) { |
481 | 0 | senders.add(senderNodes.item(i).getTextContent().trim()); |
482 | |
} |
483 | |
|
484 | 0 | String deliveryType = ((String) xpath.evaluate("//notification/deliveryType", root)).trim(); |
485 | 0 | if(deliveryType.equalsIgnoreCase(NotificationConstants.DELIVERY_TYPES.FYI)) { |
486 | 0 | deliveryType = NotificationConstants.DELIVERY_TYPES.FYI; |
487 | |
} else { |
488 | 0 | deliveryType = NotificationConstants.DELIVERY_TYPES.ACK; |
489 | |
} |
490 | |
|
491 | 0 | String sendDateTime = ((String) xpath.evaluate("//notification/sendDateTime", root)).trim(); |
492 | |
|
493 | 0 | String autoRemoveDateTime = ((String) xpath.evaluate("//notification/autoRemoveDateTime", root)).trim(); |
494 | |
|
495 | 0 | List<String> userRecipients = new ArrayList<String>(); |
496 | 0 | List<String> workgroupRecipients = new ArrayList<String>(); |
497 | |
|
498 | 0 | NodeList recipientIds = (NodeList) xpath.evaluate("//notification/recipients/recipient/recipientId", root, XPathConstants.NODESET); |
499 | 0 | NodeList recipientTypes = (NodeList) xpath.evaluate("//notification/recipients/recipient/recipientType", root, XPathConstants.NODESET); |
500 | |
|
501 | 0 | for (int i = 0; i < recipientIds.getLength(); i++) { |
502 | 0 | if(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equalsIgnoreCase(recipientTypes.item(i).getTextContent().trim())) { |
503 | 0 | userRecipients.add(recipientIds.item(i).getTextContent().trim()); |
504 | |
} else { |
505 | |
|
506 | |
|
507 | |
|
508 | 0 | workgroupRecipients.add(recipientIds.item(i).getTextContent().trim()); |
509 | |
} |
510 | |
} |
511 | |
|
512 | 0 | String content = ((String) xpath.evaluate("//notification/content", root)).trim(); |
513 | |
|
514 | |
|
515 | 0 | NotificationChannel channel = Util.retrieveFieldReference("channel", "name", channelName, NotificationChannel.class, boDao); |
516 | 0 | notification.setChannel(channel); |
517 | |
|
518 | 0 | NotificationPriority priority = Util.retrieveFieldReference("priority", "name", priorityName, NotificationPriority.class, boDao); |
519 | 0 | notification.setPriority(priority); |
520 | |
|
521 | 0 | NotificationContentType contentType = Util.retrieveFieldReference("contentType", "name", contentTypeName, NotificationContentType.class, boDao); |
522 | 0 | notification.setContentType(contentType); |
523 | |
|
524 | 0 | NotificationProducer producer = Util.retrieveFieldReference("producer", "name", NotificationConstants.KEW_CONSTANTS.NOTIFICATION_SYSTEM_USER_NAME, |
525 | |
NotificationProducer.class, boDao); |
526 | 0 | notification.setProducer(producer); |
527 | |
|
528 | 0 | for (String senderName: senders) { |
529 | 0 | NotificationSender ns = new NotificationSender(); |
530 | 0 | ns.setSenderName(senderName); |
531 | 0 | notification.addSender(ns); |
532 | 0 | } |
533 | |
|
534 | 0 | for (String userRecipientId: userRecipients) { |
535 | 0 | NotificationRecipient recipient = new NotificationRecipient(); |
536 | 0 | recipient.setRecipientType(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE); |
537 | 0 | recipient.setRecipientId(userRecipientId); |
538 | 0 | notification.addRecipient(recipient); |
539 | 0 | } |
540 | |
|
541 | 0 | for (String workgroupRecipientId: workgroupRecipients) { |
542 | 0 | NotificationRecipient recipient = new NotificationRecipient(); |
543 | 0 | recipient.setRecipientType(KimGroupMemberTypes.GROUP_MEMBER_TYPE); |
544 | 0 | recipient.setRecipientId(workgroupRecipientId); |
545 | 0 | notification.addRecipient(recipient); |
546 | 0 | } |
547 | |
|
548 | 0 | if (!StringUtils.isBlank(title)) { |
549 | 0 | notification.setTitle(title); |
550 | |
} |
551 | |
|
552 | 0 | notification.setDeliveryType(deliveryType); |
553 | |
|
554 | |
|
555 | 0 | synchronized (DATEFORMAT_CURR_TZ) { |
556 | 0 | Date d = null; |
557 | 0 | if(StringUtils.isNotBlank(sendDateTime)) { |
558 | |
try { |
559 | 0 | d = DATEFORMAT_CURR_TZ.parse(sendDateTime); |
560 | 0 | } catch (ParseException pe) { |
561 | 0 | LOG.warn("Invalid 'sendDateTime' value: " + sendDateTime, pe); |
562 | 0 | } |
563 | 0 | notification.setSendDateTime(new Timestamp(d.getTime())); |
564 | |
} |
565 | |
|
566 | 0 | Date d2 = null; |
567 | 0 | if(StringUtils.isNotBlank(autoRemoveDateTime)) { |
568 | |
try { |
569 | 0 | d2 = DATEFORMAT_CURR_TZ.parse(autoRemoveDateTime); |
570 | 0 | } catch (ParseException pe) { |
571 | 0 | LOG.warn("Invalid 'autoRemoveDateTime' value: " + autoRemoveDateTime, pe); |
572 | 0 | } |
573 | 0 | notification.setAutoRemoveDateTime(new Timestamp(d2.getTime())); |
574 | |
} |
575 | 0 | } |
576 | |
|
577 | 0 | notification.setContent(content); |
578 | |
|
579 | 0 | return notification; |
580 | 0 | } catch (XPathExpressionException xpee) { |
581 | 0 | throw new XmlException("Error parsing request", xpee); |
582 | |
} |
583 | |
} |
584 | |
} |