Coverage Report - org.kuali.rice.ken.web.spring.SendNotificationMessageController
 
Classes in this File Line Coverage Branch Coverage Complexity
SendNotificationMessageController
0%
0/210
0%
0/98
5.833
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ken.web.spring;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.sql.Timestamp;
 20  
 import java.text.ParseException;
 21  
 import java.util.Date;
 22  
 import java.util.HashMap;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import javax.servlet.ServletException;
 27  
 import javax.servlet.http.HttpServletRequest;
 28  
 import javax.servlet.http.HttpServletResponse;
 29  
 
 30  
 import org.apache.commons.lang.StringUtils;
 31  
 import org.apache.log4j.Logger;
 32  
 import org.kuali.rice.core.dao.GenericDao;
 33  
 import org.kuali.rice.ken.bo.Notification;
 34  
 import org.kuali.rice.ken.bo.NotificationChannel;
 35  
 import org.kuali.rice.ken.bo.NotificationChannelReviewer;
 36  
 import org.kuali.rice.ken.bo.NotificationContentType;
 37  
 import org.kuali.rice.ken.bo.NotificationPriority;
 38  
 import org.kuali.rice.ken.bo.NotificationProducer;
 39  
 import org.kuali.rice.ken.bo.NotificationRecipient;
 40  
 import org.kuali.rice.ken.bo.NotificationSender;
 41  
 import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument;
 42  
 import org.kuali.rice.ken.exception.ErrorList;
 43  
 import org.kuali.rice.ken.service.NotificationChannelService;
 44  
 import org.kuali.rice.ken.service.NotificationMessageContentService;
 45  
 import org.kuali.rice.ken.service.NotificationRecipientService;
 46  
 import org.kuali.rice.ken.service.NotificationService;
 47  
 import org.kuali.rice.ken.service.NotificationWorkflowDocumentService;
 48  
 import org.kuali.rice.ken.util.NotificationConstants;
 49  
 import org.kuali.rice.ken.util.Util;
 50  
 import org.kuali.rice.kew.dto.WorkflowIdDTO;
 51  
 import org.kuali.rice.kew.rule.GenericAttributeContent;
 52  
 import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes;
 53  
 import org.springframework.web.servlet.ModelAndView;
 54  
 
 55  
 
 56  
 /**
 57  
  * This class is the controller for sending Simple notification messages via an end user interface.
 58  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 59  
  */
 60  0
 public class SendNotificationMessageController extends BaseSendNotificationController {
 61  
         /** Logger for this class and subclasses */
 62  0
         private static final Logger LOG = Logger
 63  
         .getLogger(SendNotificationMessageController.class);
 64  
 
 65  
         private static final String NONE_CHANNEL = "___NONE___";
 66  
         private static final long REASONABLE_IMMEDIATE_TIME_THRESHOLD = 1000 * 60 * 5; // <= 5 minutes is "immediate"
 67  
 
 68  
         /**
 69  
          * Returns whether the specified time is considered "in the future", based on some reasonable threshold
 70  
          * @param time the time to test
 71  
          * @return whether the specified time is considered "in the future", based on some reasonable threshold
 72  
          */
 73  
         private boolean timeIsInTheFuture(long time) {
 74  0
                 boolean future = (time - System.currentTimeMillis()) > REASONABLE_IMMEDIATE_TIME_THRESHOLD;
 75  0
                 LOG.info("Time: " + new Date(time) + " is in the future? " + future);
 76  0
                 return future;
 77  
         }
 78  
 
 79  
         /**
 80  
          * Returns whether the specified Notification can be reasonably expected to have recipients.
 81  
          * This is determined on whether the channel has default recipients, is subscribably, and whether
 82  
          * the send date time is far enough in the future to expect that if there are no subscribers, there
 83  
          * may actually be some by the time the notification is sent.
 84  
          * @param notification the notification to test
 85  
          * @return whether the specified Notification can be reasonably expected to have recipients
 86  
          */
 87  
         private boolean hasPotentialRecipients(Notification notification) {
 88  0
                 LOG.info("notification channel " + notification.getChannel() + " is subscribable: " + notification.getChannel().isSubscribable());
 89  0
                 return notification.getChannel().getRecipientLists().size() > 0 ||
 90  
                 notification.getChannel().getSubscriptions().size() > 0 ||
 91  
                 (notification.getChannel().isSubscribable() && timeIsInTheFuture(notification.getSendDateTime().getTime()));
 92  
         }
 93  
 
 94  
         protected NotificationService notificationService;
 95  
 
 96  
         protected NotificationWorkflowDocumentService notificationWorkflowDocService;
 97  
 
 98  
         protected NotificationChannelService notificationChannelService;
 99  
 
 100  
         protected NotificationRecipientService notificationRecipientService;
 101  
 
 102  
         protected NotificationMessageContentService messageContentService;
 103  
 
 104  
         protected GenericDao businessObjectDao;
 105  
 
 106  
         /**
 107  
          * Set the NotificationService
 108  
          * @param notificationService
 109  
          */
 110  
         public void setNotificationService(NotificationService notificationService) {
 111  0
                 this.notificationService = notificationService;
 112  0
         }
 113  
 
 114  
         /**
 115  
          * This method sets the NotificationWorkflowDocumentService
 116  
          * @param s
 117  
          */
 118  
         public void setNotificationWorkflowDocumentService(
 119  
                         NotificationWorkflowDocumentService s) {
 120  0
                 this.notificationWorkflowDocService = s;
 121  0
         }
 122  
 
 123  
         /**
 124  
          * Sets the notificationChannelService attribute value.
 125  
          * @param notificationChannelService The notificationChannelService to set.
 126  
          */
 127  
         public void setNotificationChannelService(
 128  
                         NotificationChannelService notificationChannelService) {
 129  0
                 this.notificationChannelService = notificationChannelService;
 130  0
         }
 131  
 
 132  
         /**
 133  
          * Sets the notificationRecipientService attribute value.
 134  
          * @param notificationRecipientService
 135  
          */
 136  
         public void setNotificationRecipientService(
 137  
                         NotificationRecipientService notificationRecipientService) {
 138  0
                 this.notificationRecipientService = notificationRecipientService;
 139  0
         }
 140  
 
 141  
         /**
 142  
          * Sets the messageContentService attribute value.
 143  
          * @param messageContentService
 144  
          */
 145  
         public void setMessageContentService(
 146  
                         NotificationMessageContentService notificationMessageContentService) {
 147  0
                 this.messageContentService = notificationMessageContentService;
 148  0
         }
 149  
 
 150  
         /**
 151  
          * Sets the businessObjectDao attribute value.
 152  
          * @param businessObjectDao The businessObjectDao to set.
 153  
          */
 154  
         public void setBusinessObjectDao(GenericDao businessObjectDao) {
 155  0
                 this.businessObjectDao = businessObjectDao;
 156  0
         }
 157  
 
 158  
         /**
 159  
          * Handles the display of the form for sending a simple notification message
 160  
          * @param request : a servlet request
 161  
          * @param response : a servlet response
 162  
          * @throws ServletException : an exception
 163  
          * @throws IOException : an exception
 164  
          * @return a ModelAndView object
 165  
          */
 166  
         public ModelAndView sendSimpleNotificationMessage(
 167  
                         HttpServletRequest request, HttpServletResponse response)
 168  
         throws ServletException, IOException {
 169  0
                 String view = "SendSimpleNotificationMessage";
 170  
 
 171  0
                 LOG.debug("remoteUser: " + request.getRemoteUser());
 172  
 
 173  0
                 Map<String, Object> model = setupModelForSendSimpleNotification(request);
 174  0
                 model.put("errors", new ErrorList()); // need an empty one so we don't have an NPE
 175  
 
 176  0
                 return new ModelAndView(view, model);
 177  
         }
 178  
 
 179  
         /**
 180  
          * This method prepares the model used for the send simple notification message form.
 181  
          * @param request
 182  
          * @return Map<String, Object>
 183  
          */
 184  
         private Map<String, Object> setupModelForSendSimpleNotification(
 185  
                         HttpServletRequest request) {
 186  0
                 Map<String, Object> model = new HashMap<String, Object>();
 187  0
                 model.put("defaultSender", request.getRemoteUser());
 188  0
                 model.put("channels", notificationChannelService
 189  
                                 .getAllNotificationChannels());
 190  0
                 model.put("priorities", businessObjectDao
 191  
                                 .findAll(NotificationPriority.class));
 192  
                 // set sendDateTime to current datetime if not provided
 193  0
                 String sendDateTime = request.getParameter("sendDateTime");
 194  0
                 String currentDateTime = Util.getCurrentDateTime();
 195  0
                 if (StringUtils.isEmpty(sendDateTime)) {
 196  0
                         sendDateTime = currentDateTime;
 197  
                 }
 198  0
                 model.put("sendDateTime", sendDateTime);
 199  
 
 200  
                 // retain the original date time or set to current if
 201  
                 // it was not in the request
 202  0
                 if (request.getParameter("originalDateTime") == null) {
 203  0
                         model.put("originalDateTime", currentDateTime);
 204  
                 } else {
 205  0
                         model.put("originalDateTime", request.getParameter("originalDateTime"));
 206  
                 }
 207  
 
 208  0
                 model.put("userRecipients", request.getParameter("userRecipients"));
 209  0
                 model.put("workgroupRecipients", request.getParameter("workgroupRecipients"));
 210  0
                 model.put("workgroupNamespaceCodes", request.getParameter("workgroupNamespaceCodes"));
 211  
 
 212  0
                 return model;
 213  
         }
 214  
 
 215  
         /**
 216  
          * This method handles submitting the actual simple notification message.
 217  
          * @param request
 218  
          * @param response
 219  
          * @return ModelAndView
 220  
          * @throws ServletException
 221  
          * @throws IOException
 222  
          */
 223  
         public ModelAndView submitSimpleNotificationMessage(
 224  
                         HttpServletRequest request, HttpServletResponse response)
 225  
         throws ServletException, IOException {
 226  0
                 LOG.debug("remoteUser: " + request.getRemoteUser());
 227  
 
 228  
                 // obtain a workflow user object first
 229  0
                 WorkflowIdDTO initiator = new WorkflowIdDTO(request.getRemoteUser());
 230  
 
 231  
                 // now construct the workflow document, which will interact with workflow
 232  
                 NotificationWorkflowDocument document;
 233  0
                 Map<String, Object> model = new HashMap<String, Object>();
 234  
                 String view;
 235  
                 try {
 236  0
                         document = new NotificationWorkflowDocument(
 237  
                                         initiator,
 238  
                                         NotificationConstants.KEW_CONSTANTS.SEND_NOTIFICATION_REQ_DOC_TYPE);
 239  
 
 240  
                         //parse out the application content into a Notification BO
 241  0
                         Notification notification = populateNotificationInstance(request,
 242  
                                         model);
 243  
 
 244  
                         // now get that content in an understandable XML format and pass into document
 245  0
                         String notificationAsXml = messageContentService
 246  
                         .generateNotificationMessage(notification);
 247  
 
 248  0
                         Map<String, String> attrFields = new HashMap<String,String>();
 249  0
                         List<NotificationChannelReviewer> reviewers = notification.getChannel().getReviewers();
 250  0
                         int ui = 0;
 251  0
                         int gi = 0;
 252  0
                         for (NotificationChannelReviewer reviewer: reviewers) {
 253  
                                 String prefix;
 254  
                                 int index;
 255  0
                                 if (KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(reviewer.getReviewerType())) {
 256  0
                                         prefix = "user";
 257  0
                                         index = ui;
 258  0
                                         ui++;
 259  0
                                 } else if (KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(reviewer.getReviewerType())) {
 260  0
                                         prefix = "group";
 261  0
                                         index = gi;
 262  0
                                         gi++;
 263  
                                 } else {
 264  0
                                         LOG.error("Invalid type for reviewer " + reviewer.getReviewerId() + ": " + reviewer.getReviewerType());
 265  0
                                         continue;
 266  
                                 }
 267  0
                                 attrFields.put(prefix + index, reviewer.getReviewerId());
 268  0
                         }
 269  0
                         GenericAttributeContent gac = new GenericAttributeContent("channelReviewers");
 270  0
                         document.getDocumentContent().setApplicationContent(notificationAsXml);
 271  0
                         document.getDocumentContent().setAttributeContent("<attributeContent>" + gac.generateContent(attrFields) + "</attributeContent>");
 272  
 
 273  0
                         document.setTitle(notification.getTitle());
 274  
 
 275  0
                         document.routeDocument("This message was submitted via the simple notification message submission form by user "
 276  
                                         + initiator.getWorkflowId());
 277  
 
 278  0
                         view = "SendSimpleNotificationMessage";
 279  
 
 280  
                         // This ain't pretty, but it gets the job done for now.
 281  0
                         ErrorList el = new ErrorList();
 282  0
                         el.addError("Notification(s) sent.");
 283  0
                         model.put("errors", el);
 284  
 
 285  0
                 } catch (ErrorList el) {
 286  
                         // route back to the send form again
 287  0
                         Map<String, Object> model2 = setupModelForSendSimpleNotification(request);
 288  0
                         model.putAll(model2);
 289  0
                         model.put("errors", el);
 290  
 
 291  0
                         view = "SendSimpleNotificationMessage";
 292  0
                 } catch (Exception e) {
 293  0
                         throw new RuntimeException(e);
 294  0
                 }
 295  
 
 296  0
                 return new ModelAndView(view, model);
 297  
         }
 298  
 
 299  
         /**
 300  
          * This method creates a new Notification instance from the form values.
 301  
          * @param request
 302  
          * @param model
 303  
          * @return Notification
 304  
          * @throws IllegalArgumentException
 305  
          */
 306  
         private Notification populateNotificationInstance(
 307  
                         HttpServletRequest request, Map<String, Object> model)
 308  
         throws IllegalArgumentException, ErrorList {
 309  0
                 ErrorList errors = new ErrorList();
 310  
 
 311  0
                 Notification notification = new Notification();
 312  
 
 313  
                 // grab data from form
 314  
                 // channel name
 315  0
                 String channelName = request.getParameter("channelName");
 316  0
                 if (StringUtils.isEmpty(channelName) || StringUtils.equals(channelName, NONE_CHANNEL)) {
 317  0
                         errors.addError("You must choose a channel.");
 318  
                 } else {
 319  0
                         model.put("channelName", channelName);
 320  
                 }
 321  
 
 322  
                 // priority name
 323  0
                 String priorityName = request.getParameter("priorityName");
 324  0
                 if (StringUtils.isEmpty(priorityName)) {
 325  0
                         errors.addError("You must choose a priority.");
 326  
                 } else {
 327  0
                         model.put("priorityName", priorityName);
 328  
                 }
 329  
 
 330  
                 // sender names
 331  0
                 String senderNames = request.getParameter("senderNames");
 332  0
                 String[] senders = null;
 333  0
                 if (StringUtils.isEmpty(senderNames)) {
 334  0
                         errors.addError("You must enter at least one sender.");
 335  
                 } else {
 336  0
                         senders = StringUtils.split(senderNames, ",");
 337  
 
 338  0
                         model.put("senderNames", senderNames);
 339  
                 }
 340  
 
 341  
                 // delivery type
 342  0
                 String deliveryType = request.getParameter("deliveryType");
 343  0
                 if (StringUtils.isEmpty(deliveryType)) {
 344  0
                         errors.addError("You must choose a type.");
 345  
                 } else {
 346  0
                         if (deliveryType
 347  
                                         .equalsIgnoreCase(NotificationConstants.DELIVERY_TYPES.FYI)) {
 348  0
                                 deliveryType = NotificationConstants.DELIVERY_TYPES.FYI;
 349  
                         } else {
 350  0
                                 deliveryType = NotificationConstants.DELIVERY_TYPES.ACK;
 351  
                         }
 352  0
                         model.put("deliveryType", deliveryType);
 353  
                 }
 354  
 
 355  
                 // get datetime when form was initially rendered
 356  0
                 String originalDateTime = request.getParameter("originalDateTime");
 357  0
                 Date origdate = null;
 358  0
                 Date senddate = null;
 359  0
                 Date removedate = null;
 360  
                 try {
 361  0
                         origdate = Util.parseUIDateTime(originalDateTime);
 362  0
                 } catch (ParseException pe) {
 363  0
                         errors.addError("Original date is invalid.");
 364  0
                 }
 365  
                 // send date time
 366  0
                 String sendDateTime = request.getParameter("sendDateTime");
 367  0
                 if (StringUtils.isBlank(sendDateTime)) {
 368  0
                         sendDateTime = Util.getCurrentDateTime();
 369  
                 }
 370  
 
 371  
                 try {
 372  0
                         senddate = Util.parseUIDateTime(sendDateTime);
 373  0
                 } catch (ParseException pe) {
 374  0
                         errors.addError("You specified an invalid Send Date/Time.  Please use the calendar picker.");
 375  0
                 }
 376  
 
 377  0
                 if(senddate != null && senddate.before(origdate)) {
 378  0
                         errors.addError("Send Date/Time cannot be in the past.");
 379  
                 }
 380  
 
 381  0
                 model.put("sendDateTime", sendDateTime);
 382  
 
 383  
                 // auto remove date time
 384  0
                 String autoRemoveDateTime = request.getParameter("autoRemoveDateTime");
 385  0
                 if (StringUtils.isNotBlank(autoRemoveDateTime)) {
 386  
                         try {
 387  0
                                 removedate = Util.parseUIDateTime(autoRemoveDateTime);
 388  0
                         } catch (ParseException pe) {
 389  0
                                 errors.addError("You specified an invalid Auto-Remove Date/Time.  Please use the calendar picker.");
 390  0
                         }
 391  
 
 392  0
                         if(removedate != null) {
 393  0
                                 if(removedate.before(origdate)) {
 394  0
                                         errors.addError("Auto-Remove Date/Time cannot be in the past.");
 395  0
                                 } else if (senddate != null && removedate.before(senddate)){
 396  0
                                         errors.addError("Auto-Remove Date/Time cannot be before the Send Date/Time.");
 397  
                                 }
 398  
                         }
 399  
                 }
 400  
 
 401  0
                 model.put("autoRemoveDateTime", autoRemoveDateTime);
 402  
 
 403  
                 // user recipient names
 404  0
                 String[] userRecipients = parseUserRecipients(request);
 405  
 
 406  
                 // workgroup recipient names
 407  0
                 String[] workgroupRecipients = parseWorkgroupRecipients(request);
 408  
 
 409  
                 // workgroup namespace codes
 410  0
                 String[] workgroupNamespaceCodes = parseWorkgroupNamespaceCodes(request);
 411  
                 
 412  
                 // title
 413  0
                 String title = request.getParameter("title");
 414  0
                 if (!StringUtils.isEmpty(title)) {
 415  0
                         model.put("title", title);
 416  
                 } else {
 417  0
                         errors.addError("You must fill in a title");
 418  
                 }
 419  
 
 420  
                 // message
 421  0
                 String message = request.getParameter("message");
 422  0
                 if (StringUtils.isEmpty(message)) {
 423  0
                         errors.addError("You must fill in a message.");
 424  
                 } else {
 425  0
                         model.put("message", message);
 426  
                 }
 427  
 
 428  
                 // stop processing if there are errors
 429  0
                 if (errors.getErrors().size() > 0) {
 430  0
                         throw errors;
 431  
                 }
 432  
 
 433  
                 // now populate the notification BO instance
 434  0
                 NotificationChannel channel = Util.retrieveFieldReference("channel",
 435  
                                 "name", channelName, NotificationChannel.class,
 436  
                                 businessObjectDao);
 437  0
                 notification.setChannel(channel);
 438  
 
 439  0
                 NotificationPriority priority = Util.retrieveFieldReference("priority",
 440  
                                 "name", priorityName, NotificationPriority.class,
 441  
                                 businessObjectDao);
 442  0
                 notification.setPriority(priority);
 443  
 
 444  0
                 NotificationContentType contentType = Util.retrieveFieldReference(
 445  
                                 "contentType", "name",
 446  
                                 NotificationConstants.CONTENT_TYPES.SIMPLE_CONTENT_TYPE,
 447  
                                 NotificationContentType.class, businessObjectDao);
 448  0
                 notification.setContentType(contentType);
 449  
 
 450  0
                 NotificationProducer producer = Util
 451  
                 .retrieveFieldReference(
 452  
                                 "producer",
 453  
                                 "name",
 454  
                                 NotificationConstants.KEW_CONSTANTS.NOTIFICATION_SYSTEM_USER_NAME,
 455  
                                 NotificationProducer.class, businessObjectDao);
 456  0
                 notification.setProducer(producer);
 457  
 
 458  0
                 for (String senderName : senders) {
 459  0
                         if (StringUtils.isEmpty(senderName)) {
 460  0
                                 errors.addError("A sender's name cannot be blank.");
 461  
                         } else {
 462  0
                                 NotificationSender ns = new NotificationSender();
 463  0
                                 ns.setSenderName(senderName.trim());
 464  0
                                 notification.addSender(ns);
 465  
                         }
 466  
                 }
 467  
 
 468  0
                 boolean recipientsExist = false;
 469  
 
 470  0
                 if (userRecipients != null && userRecipients.length > 0) {
 471  0
                         recipientsExist = true;
 472  0
                         for (String userRecipientId : userRecipients) {
 473  0
                                 if (isUserRecipientValid(userRecipientId, errors)) {
 474  0
                                         NotificationRecipient recipient = new NotificationRecipient();
 475  0
                                         recipient.setRecipientType(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE);
 476  0
                                         recipient.setRecipientId(userRecipientId);
 477  0
                                         notification.addRecipient(recipient);
 478  
                                 }
 479  
                         }
 480  
                 }
 481  
 
 482  0
                 if (workgroupRecipients != null && workgroupRecipients.length > 0) {
 483  0
                         recipientsExist = true;
 484  0
                         if (workgroupNamespaceCodes != null && workgroupNamespaceCodes.length > 0) {
 485  0
                                 if (workgroupNamespaceCodes.length == workgroupRecipients.length) {
 486  0
                                         for (int i = 0; i < workgroupRecipients.length; i++) {
 487  0
                                                 if (isWorkgroupRecipientValid(workgroupRecipients[i], workgroupNamespaceCodes[i], errors)) {
 488  0
                                                         NotificationRecipient recipient = new NotificationRecipient();
 489  0
                                                         recipient.setRecipientType(KimGroupMemberTypes.GROUP_MEMBER_TYPE);
 490  0
                                                         recipient.setRecipientId(
 491  
                                                                         getIdentityManagementService().getGroupByName(workgroupNamespaceCodes[i], workgroupRecipients[i]).getGroupId());
 492  0
                                                         notification.addRecipient(recipient);
 493  
                                                 }
 494  
                                         }
 495  
                                 } else {
 496  0
                                         errors.addError("The number of groups must match the number of namespace codes");
 497  
                                 }
 498  
                         } else {
 499  0
                                 errors.addError("You must specify a namespace code for every group name");
 500  
                         }
 501  0
                 } else if (workgroupNamespaceCodes != null && workgroupNamespaceCodes.length > 0) {
 502  0
                         errors.addError("You must specify a group name for every namespace code");
 503  
                 }
 504  
 
 505  
                 // check to see if there were any errors
 506  0
                 if (errors.getErrors().size() > 0) {
 507  0
                         throw errors;
 508  
                 }
 509  
 
 510  0
                 notification.setTitle(title);
 511  
 
 512  0
                 notification.setDeliveryType(deliveryType);
 513  
 
 514  
                 // simpledateformat is not threadsafe, have to sync and validate
 515  0
                 Date d = null;
 516  0
                 if (StringUtils.isNotBlank(sendDateTime)) {
 517  
                         try {
 518  0
                                 d = Util.parseUIDateTime(sendDateTime);
 519  0
                         } catch (ParseException pe) {
 520  0
                                 errors.addError("You specified an invalid send date and time.  Please use the calendar picker.");
 521  0
                         }
 522  0
                         notification.setSendDateTime(new Timestamp(d.getTime()));
 523  
                 }
 524  
 
 525  0
                 Date d2 = null;
 526  0
                 if (StringUtils.isNotBlank(autoRemoveDateTime)) {
 527  
                         try {
 528  0
                                 d2 = Util.parseUIDateTime(autoRemoveDateTime);
 529  0
                                 if (d2.before(d)) {
 530  0
                                         errors.addError("Auto Remove Date/Time cannot be before Send Date/Time.");
 531  
                                 }
 532  0
                         } catch (ParseException pe) {
 533  0
                                 errors.addError("You specified an invalid auto remove date and time.  Please use the calendar picker.");
 534  0
                         }
 535  0
                         notification.setAutoRemoveDateTime(new Timestamp(d2.getTime()));
 536  
                 }
 537  
 
 538  
 
 539  0
                 if (!recipientsExist && !hasPotentialRecipients(notification)) {
 540  0
                         errors.addError("You must specify at least one user or group recipient.");
 541  
                 }
 542  
 
 543  
                 // check to see if there were any errors
 544  0
                 if (errors.getErrors().size() > 0) {
 545  0
                         throw errors;
 546  
                 }
 547  
 
 548  0
                 notification
 549  
                 .setContent(NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_SIMPLE_OPEN
 550  
                                 + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN
 551  
                                 + message
 552  
                                 + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE
 553  
                                 + NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_CLOSE);
 554  
 
 555  0
                 return notification;
 556  
         }
 557  
 }