|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.ken.web.spring;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  20 |     | 
   import org.apache.log4j.Logger;  | 
  |  21 |     | 
   import org.kuali.rice.core.framework.persistence.dao.GenericDao;  | 
  |  22 |     | 
   import org.kuali.rice.ken.bo.Notification;  | 
  |  23 |     | 
   import org.kuali.rice.ken.bo.NotificationChannel;  | 
  |  24 |     | 
   import org.kuali.rice.ken.bo.NotificationChannelReviewer;  | 
  |  25 |     | 
   import org.kuali.rice.ken.bo.NotificationContentType;  | 
  |  26 |     | 
   import org.kuali.rice.ken.bo.NotificationPriority;  | 
  |  27 |     | 
   import org.kuali.rice.ken.bo.NotificationProducer;  | 
  |  28 |     | 
   import org.kuali.rice.ken.bo.NotificationRecipient;  | 
  |  29 |     | 
   import org.kuali.rice.ken.bo.NotificationSender;  | 
  |  30 |     | 
   import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument;  | 
  |  31 |     | 
   import org.kuali.rice.ken.exception.ErrorList;  | 
  |  32 |     | 
   import org.kuali.rice.ken.service.NotificationChannelService;  | 
  |  33 |     | 
   import org.kuali.rice.ken.service.NotificationMessageContentService;  | 
  |  34 |     | 
   import org.kuali.rice.ken.service.NotificationRecipientService;  | 
  |  35 |     | 
   import org.kuali.rice.ken.service.NotificationService;  | 
  |  36 |     | 
   import org.kuali.rice.ken.service.NotificationWorkflowDocumentService;  | 
  |  37 |     | 
   import org.kuali.rice.ken.util.NotificationConstants;  | 
  |  38 |     | 
   import org.kuali.rice.ken.util.Util;  | 
  |  39 |     | 
   import org.kuali.rice.kew.dto.WorkflowIdDTO;  | 
  |  40 |     | 
   import org.kuali.rice.kew.rule.GenericAttributeContent;  | 
  |  41 |     | 
   import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes;  | 
  |  42 |     | 
   import org.springframework.web.servlet.ModelAndView;  | 
  |  43 |     | 
     | 
  |  44 |     | 
   import javax.servlet.ServletException;  | 
  |  45 |     | 
   import javax.servlet.http.HttpServletRequest;  | 
  |  46 |     | 
   import javax.servlet.http.HttpServletResponse;  | 
  |  47 |     | 
   import java.io.IOException;  | 
  |  48 |     | 
   import java.sql.Timestamp;  | 
  |  49 |     | 
   import java.text.ParseException;  | 
  |  50 |     | 
   import java.util.Date;  | 
  |  51 |     | 
   import java.util.HashMap;  | 
  |  52 |     | 
   import java.util.List;  | 
  |  53 |     | 
   import java.util.Map;  | 
  |  54 |     | 
     | 
  |  55 |     | 
     | 
  |  56 |     | 
     | 
  |  57 |     | 
     | 
  |  58 |     | 
     | 
  |  59 |     | 
     | 
  |  60 |    0 |    public class SendEventNotificationMessageController extends BaseSendNotificationController { | 
  |  61 |     | 
         | 
  |  62 |    0 |        private static final Logger LOG = Logger  | 
  |  63 |     | 
               .getLogger(SendEventNotificationMessageController.class);  | 
  |  64 |     | 
     | 
  |  65 |     | 
       private static final String NONE_CHANNEL = "___NONE___";  | 
  |  66 |     | 
       private static final long REASONABLE_IMMEDIATE_TIME_THRESHOLD = 1000 * 60 * 5;   | 
  |  67 |     | 
     | 
  |  68 |     | 
         | 
  |  69 |     | 
     | 
  |  70 |     | 
     | 
  |  71 |     | 
     | 
  |  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 |     | 
     | 
  |  81 |     | 
     | 
  |  82 |     | 
     | 
  |  83 |     | 
     | 
  |  84 |     | 
     | 
  |  85 |     | 
     | 
  |  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 |     | 
     | 
  |  108 |     | 
     | 
  |  109 |     | 
     | 
  |  110 |     | 
       public void setNotificationService(NotificationService notificationService) { | 
  |  111 |    0 |            this.notificationService = notificationService;  | 
  |  112 |    0 |        }  | 
  |  113 |     | 
     | 
  |  114 |     | 
         | 
  |  115 |     | 
     | 
  |  116 |     | 
     | 
  |  117 |     | 
     | 
  |  118 |     | 
       public void setNotificationWorkflowDocumentService(  | 
  |  119 |     | 
               NotificationWorkflowDocumentService s) { | 
  |  120 |    0 |            this.notificationWorkflowDocService = s;  | 
  |  121 |    0 |        }  | 
  |  122 |     | 
     | 
  |  123 |     | 
         | 
  |  124 |     | 
     | 
  |  125 |     | 
     | 
  |  126 |     | 
     | 
  |  127 |     | 
       public void setNotificationChannelService(  | 
  |  128 |     | 
               NotificationChannelService notificationChannelService) { | 
  |  129 |    0 |            this.notificationChannelService = notificationChannelService;  | 
  |  130 |    0 |        }  | 
  |  131 |     | 
     | 
  |  132 |     | 
         | 
  |  133 |     | 
     | 
  |  134 |     | 
     | 
  |  135 |     | 
     | 
  |  136 |     | 
       public void setNotificationRecipientService(  | 
  |  137 |     | 
               NotificationRecipientService notificationRecipientService) { | 
  |  138 |    0 |            this.notificationRecipientService = notificationRecipientService;  | 
  |  139 |    0 |        }  | 
  |  140 |     | 
     | 
  |  141 |     | 
         | 
  |  142 |     | 
     | 
  |  143 |     | 
     | 
  |  144 |     | 
     | 
  |  145 |     | 
       public void setMessageContentService(  | 
  |  146 |     | 
               NotificationMessageContentService notificationMessageContentService) { | 
  |  147 |    0 |            this.messageContentService = notificationMessageContentService;  | 
  |  148 |    0 |        }  | 
  |  149 |     | 
     | 
  |  150 |     | 
         | 
  |  151 |     | 
     | 
  |  152 |     | 
     | 
  |  153 |     | 
     | 
  |  154 |     | 
       public void setBusinessObjectDao(GenericDao businessObjectDao) { | 
  |  155 |    0 |            this.businessObjectDao = businessObjectDao;  | 
  |  156 |    0 |        }  | 
  |  157 |     | 
     | 
  |  158 |     | 
         | 
  |  159 |     | 
     | 
  |  160 |     | 
     | 
  |  161 |     | 
     | 
  |  162 |     | 
     | 
  |  163 |     | 
     | 
  |  164 |     | 
     | 
  |  165 |     | 
     | 
  |  166 |     | 
       public ModelAndView sendEventNotificationMessage(  | 
  |  167 |     | 
               HttpServletRequest request, HttpServletResponse response)  | 
  |  168 |     | 
               throws ServletException, IOException { | 
  |  169 |    0 |            String view = "SendEventNotificationMessage";  | 
  |  170 |    0 |            LOG.debug("remoteUser: " + request.getRemoteUser()); | 
  |  171 |     | 
     | 
  |  172 |    0 |            Map<String, Object> model = setupModelForSendEventNotification(request);  | 
  |  173 |    0 |            model.put("errors", new ErrorList());  | 
  |  174 |     | 
     | 
  |  175 |    0 |            return new ModelAndView(view, model);  | 
  |  176 |     | 
       }  | 
  |  177 |     | 
     | 
  |  178 |     | 
         | 
  |  179 |     | 
     | 
  |  180 |     | 
     | 
  |  181 |     | 
     | 
  |  182 |     | 
     | 
  |  183 |     | 
       private Map<String, Object> setupModelForSendEventNotification(  | 
  |  184 |     | 
               HttpServletRequest request) { | 
  |  185 |    0 |            Map<String, Object> model = new HashMap<String, Object>();  | 
  |  186 |    0 |            model.put("defaultSender", request.getRemoteUser()); | 
  |  187 |    0 |            model.put("channels", notificationChannelService | 
  |  188 |     | 
                   .getAllNotificationChannels());  | 
  |  189 |    0 |            model.put("priorities", businessObjectDao | 
  |  190 |     | 
                   .findAll(NotificationPriority.class));  | 
  |  191 |     | 
             | 
  |  192 |    0 |            String sendDateTime = request.getParameter("sendDateTime"); | 
  |  193 |    0 |            String currentDateTime = Util.getCurrentDateTime();  | 
  |  194 |    0 |            if (StringUtils.isEmpty(sendDateTime)) { | 
  |  195 |    0 |                sendDateTime = currentDateTime;  | 
  |  196 |     | 
           }  | 
  |  197 |    0 |            model.put("sendDateTime", sendDateTime); | 
  |  198 |     | 
     | 
  |  199 |     | 
             | 
  |  200 |     | 
             | 
  |  201 |    0 |            if (request.getParameter("originalDateTime") == null) { | 
  |  202 |    0 |               model.put("originalDateTime", currentDateTime); | 
  |  203 |     | 
           } else { | 
  |  204 |    0 |               model.put("originalDateTime", request.getParameter("originalDateTime")); | 
  |  205 |     | 
           }  | 
  |  206 |    0 |            model.put("summary", request.getParameter("summary")); | 
  |  207 |    0 |            model.put("description", request.getParameter("description")); | 
  |  208 |    0 |            model.put("location", request.getParameter("location")); | 
  |  209 |    0 |            model.put("startDateTime", request.getParameter("startDateTime")); | 
  |  210 |    0 |            model.put("stopDateTime", request.getParameter("stopDateTime")); | 
  |  211 |     | 
     | 
  |  212 |    0 |            model.put("userRecipients", request.getParameter("userRecipients")); | 
  |  213 |    0 |            model.put("workgroupRecipients", request.getParameter("workgroupRecipients")); | 
  |  214 |    0 |            model.put("workgroupNamespaceCodes", request.getParameter("workgroupNamespaceCodes")); | 
  |  215 |     | 
     | 
  |  216 |    0 |            return model;  | 
  |  217 |     | 
       }  | 
  |  218 |     | 
     | 
  |  219 |     | 
         | 
  |  220 |     | 
     | 
  |  221 |     | 
     | 
  |  222 |     | 
     | 
  |  223 |     | 
     | 
  |  224 |     | 
     | 
  |  225 |     | 
     | 
  |  226 |     | 
     | 
  |  227 |     | 
       public ModelAndView submitEventNotificationMessage(  | 
  |  228 |     | 
               HttpServletRequest request, HttpServletResponse response)  | 
  |  229 |     | 
               throws ServletException, IOException { | 
  |  230 |    0 |            LOG.debug("remoteUser: " + request.getRemoteUser()); | 
  |  231 |     | 
     | 
  |  232 |     | 
             | 
  |  233 |    0 |            WorkflowIdDTO initiator = new WorkflowIdDTO(request.getRemoteUser());  | 
  |  234 |     | 
     | 
  |  235 |     | 
             | 
  |  236 |     | 
           NotificationWorkflowDocument document;  | 
  |  237 |    0 |            Map<String, Object> model = new HashMap<String, Object>();  | 
  |  238 |     | 
           String view;  | 
  |  239 |     | 
           try { | 
  |  240 |    0 |                document = new NotificationWorkflowDocument(  | 
  |  241 |     | 
                       initiator,  | 
  |  242 |     | 
                       NotificationConstants.KEW_CONSTANTS.SEND_NOTIFICATION_REQ_DOC_TYPE);  | 
  |  243 |     | 
     | 
  |  244 |     | 
                 | 
  |  245 |    0 |                Notification notification = populateNotificationInstance(request, model);  | 
  |  246 |     | 
     | 
  |  247 |     | 
                 | 
  |  248 |    0 |                String notificationAsXml = messageContentService  | 
  |  249 |     | 
                       .generateNotificationMessage(notification);  | 
  |  250 |     | 
     | 
  |  251 |    0 |                Map<String, String> attrFields = new HashMap<String,String>();  | 
  |  252 |    0 |                List<NotificationChannelReviewer> reviewers = notification.getChannel().getReviewers();  | 
  |  253 |    0 |                int ui = 0;  | 
  |  254 |    0 |                int gi = 0;  | 
  |  255 |    0 |                for (NotificationChannelReviewer reviewer: reviewers) { | 
  |  256 |     | 
                   String prefix;  | 
  |  257 |     | 
                   int index;  | 
  |  258 |    0 |                    if (KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(reviewer.getReviewerType())) { | 
  |  259 |    0 |                        prefix = "user";  | 
  |  260 |    0 |                        index = ui;  | 
  |  261 |    0 |                        ui++;  | 
  |  262 |    0 |                    } else if (KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(reviewer.getReviewerType())) { | 
  |  263 |    0 |                        prefix = "group";  | 
  |  264 |    0 |                        index = gi;  | 
  |  265 |    0 |                        gi++;  | 
  |  266 |     | 
                   } else { | 
  |  267 |    0 |                        LOG.error("Invalid type for reviewer " + reviewer.getReviewerId() + ": " + reviewer.getReviewerType()); | 
  |  268 |    0 |                        continue;  | 
  |  269 |     | 
                   }  | 
  |  270 |    0 |                    attrFields.put(prefix + index, reviewer.getReviewerId());  | 
  |  271 |    0 |                }  | 
  |  272 |    0 |                GenericAttributeContent gac = new GenericAttributeContent("channelReviewers"); | 
  |  273 |    0 |                document.getDocumentContent().setApplicationContent(notificationAsXml);  | 
  |  274 |    0 |                document.getDocumentContent().setAttributeContent("<attributeContent>" + gac.generateContent(attrFields) + "</attributeContent>"); | 
  |  275 |     | 
     | 
  |  276 |    0 |                document.setTitle(notification.getTitle());  | 
  |  277 |     | 
     | 
  |  278 |    0 |                document.routeDocument("This message was submitted via the event notification message submission form by user " | 
  |  279 |     | 
                               + initiator.getWorkflowId());  | 
  |  280 |     | 
     | 
  |  281 |    0 |                view = "SendEventNotificationMessage";  | 
  |  282 |     | 
                 | 
  |  283 |     | 
                 | 
  |  284 |    0 |                ErrorList el = new ErrorList();  | 
  |  285 |    0 |                el.addError("Notification(s) sent."); | 
  |  286 |    0 |                model.put("errors", el); | 
  |  287 |     | 
                 | 
  |  288 |    0 |            } catch (ErrorList el) { | 
  |  289 |     | 
                 | 
  |  290 |    0 |                Map<String, Object> model2 = setupModelForSendEventNotification(request);  | 
  |  291 |    0 |                model.putAll(model2);  | 
  |  292 |    0 |                model.put("errors", el); | 
  |  293 |     | 
     | 
  |  294 |    0 |                view = "SendEventNotificationMessage";  | 
  |  295 |    0 |            } catch (Exception e) { | 
  |  296 |    0 |                throw new RuntimeException(e);  | 
  |  297 |    0 |            }  | 
  |  298 |     | 
     | 
  |  299 |    0 |            return new ModelAndView(view, model);  | 
  |  300 |     | 
       }  | 
  |  301 |     | 
     | 
  |  302 |     | 
         | 
  |  303 |     | 
     | 
  |  304 |     | 
     | 
  |  305 |     | 
     | 
  |  306 |     | 
     | 
  |  307 |     | 
     | 
  |  308 |     | 
     | 
  |  309 |     | 
       private Notification populateNotificationInstance(  | 
  |  310 |     | 
               HttpServletRequest request, Map<String, Object> model)  | 
  |  311 |     | 
               throws IllegalArgumentException, ErrorList { | 
  |  312 |    0 |            ErrorList errors = new ErrorList();  | 
  |  313 |     | 
     | 
  |  314 |    0 |            Notification notification = new Notification();  | 
  |  315 |     | 
     | 
  |  316 |     | 
             | 
  |  317 |     | 
             | 
  |  318 |    0 |            String channelName = request.getParameter("channelName"); | 
  |  319 |    0 |            if (StringUtils.isEmpty(channelName) || StringUtils.equals(channelName, NONE_CHANNEL)) { | 
  |  320 |    0 |                errors.addError("You must choose a channel."); | 
  |  321 |     | 
           } else { | 
  |  322 |    0 |                model.put("channelName", channelName); | 
  |  323 |     | 
           }  | 
  |  324 |     | 
     | 
  |  325 |     | 
             | 
  |  326 |    0 |            String priorityName = request.getParameter("priorityName"); | 
  |  327 |    0 |            if (StringUtils.isEmpty(priorityName)) { | 
  |  328 |    0 |                errors.addError("You must choose a priority."); | 
  |  329 |     | 
           } else { | 
  |  330 |    0 |                model.put("priorityName", priorityName); | 
  |  331 |     | 
           }  | 
  |  332 |     | 
     | 
  |  333 |     | 
             | 
  |  334 |    0 |            String senderNames = request.getParameter("senderNames"); | 
  |  335 |    0 |            String[] senders = null;  | 
  |  336 |    0 |            if (StringUtils.isEmpty(senderNames)) { | 
  |  337 |    0 |                errors.addError("You must enter at least one sender."); | 
  |  338 |     | 
           } else { | 
  |  339 |    0 |                senders = StringUtils.split(senderNames, ",");  | 
  |  340 |     | 
     | 
  |  341 |    0 |                model.put("senderNames", senderNames); | 
  |  342 |     | 
           }  | 
  |  343 |     | 
     | 
  |  344 |     | 
             | 
  |  345 |    0 |            String deliveryType = request.getParameter("deliveryType"); | 
  |  346 |    0 |            if (StringUtils.isEmpty(deliveryType)) { | 
  |  347 |    0 |                errors.addError("You must choose a type."); | 
  |  348 |     | 
           } else { | 
  |  349 |    0 |                if (deliveryType  | 
  |  350 |     | 
                       .equalsIgnoreCase(NotificationConstants.DELIVERY_TYPES.FYI)) { | 
  |  351 |    0 |                    deliveryType = NotificationConstants.DELIVERY_TYPES.FYI;  | 
  |  352 |     | 
               } else { | 
  |  353 |    0 |                    deliveryType = NotificationConstants.DELIVERY_TYPES.ACK;  | 
  |  354 |     | 
               }  | 
  |  355 |    0 |                model.put("deliveryType", deliveryType); | 
  |  356 |     | 
           }  | 
  |  357 |     | 
     | 
  |  358 |     | 
             | 
  |  359 |    0 |            String originalDateTime = request.getParameter("originalDateTime"); | 
  |  360 |    0 |            Date origdate = null;  | 
  |  361 |    0 |            Date senddate = null;  | 
  |  362 |    0 |            Date removedate = null;  | 
  |  363 |     | 
           try { | 
  |  364 |    0 |                origdate = Util.parseUIDateTime(originalDateTime);  | 
  |  365 |    0 |            } catch (ParseException pe) { | 
  |  366 |    0 |                errors.addError("Original date is invalid."); | 
  |  367 |    0 |            }  | 
  |  368 |     | 
             | 
  |  369 |    0 |            String sendDateTime = request.getParameter("sendDateTime"); | 
  |  370 |    0 |            if (StringUtils.isBlank(sendDateTime)) { | 
  |  371 |    0 |                sendDateTime = Util.getCurrentDateTime();  | 
  |  372 |     | 
           }  | 
  |  373 |     | 
     | 
  |  374 |     | 
           try { | 
  |  375 |    0 |                senddate = Util.parseUIDateTime(sendDateTime);  | 
  |  376 |    0 |            } catch (ParseException pe) { | 
  |  377 |    0 |                errors.addError("You specified an invalid Send Date/Time.  Please use the calendar picker."); | 
  |  378 |    0 |            }  | 
  |  379 |     | 
     | 
  |  380 |    0 |            if(senddate != null && senddate.before(origdate)) { | 
  |  381 |    0 |                errors.addError("Send Date/Time cannot be in the past."); | 
  |  382 |     | 
           }  | 
  |  383 |     | 
     | 
  |  384 |    0 |            model.put("sendDateTime", sendDateTime); | 
  |  385 |     | 
     | 
  |  386 |     | 
             | 
  |  387 |    0 |            String autoRemoveDateTime = request.getParameter("autoRemoveDateTime"); | 
  |  388 |    0 |            if (StringUtils.isNotBlank(autoRemoveDateTime)) { | 
  |  389 |     | 
               try { | 
  |  390 |    0 |                    removedate = Util.parseUIDateTime(autoRemoveDateTime);  | 
  |  391 |    0 |                } catch (ParseException pe) { | 
  |  392 |    0 |                    errors.addError("You specified an invalid Auto-Remove Date/Time.  Please use the calendar picker."); | 
  |  393 |    0 |                }  | 
  |  394 |     | 
     | 
  |  395 |    0 |                if(removedate != null) { | 
  |  396 |    0 |                    if(removedate.before(origdate)) { | 
  |  397 |    0 |                        errors.addError("Auto-Remove Date/Time cannot be in the past."); | 
  |  398 |    0 |                    } else if (senddate != null && removedate.before(senddate)){ | 
  |  399 |    0 |                        errors.addError("Auto-Remove Date/Time cannot be before the Send Date/Time."); | 
  |  400 |     | 
                   }  | 
  |  401 |     | 
               }  | 
  |  402 |     | 
           }  | 
  |  403 |     | 
     | 
  |  404 |    0 |            model.put("autoRemoveDateTime", autoRemoveDateTime); | 
  |  405 |     | 
     | 
  |  406 |     | 
             | 
  |  407 |    0 |            String[] userRecipients = parseUserRecipients(request);  | 
  |  408 |     | 
     | 
  |  409 |     | 
             | 
  |  410 |    0 |            String[] workgroupRecipients = parseWorkgroupRecipients(request);  | 
  |  411 |     | 
     | 
  |  412 |     | 
             | 
  |  413 |    0 |            String[] workgroupNamespaceCodes = parseWorkgroupNamespaceCodes(request);  | 
  |  414 |     | 
             | 
  |  415 |     | 
             | 
  |  416 |    0 |            String title = request.getParameter("title"); | 
  |  417 |    0 |            if (!StringUtils.isEmpty(title)) { | 
  |  418 |    0 |                model.put("title", title); | 
  |  419 |     | 
           } else { | 
  |  420 |    0 |                errors.addError("You must fill in a title"); | 
  |  421 |     | 
           }  | 
  |  422 |     | 
     | 
  |  423 |     | 
             | 
  |  424 |    0 |            String message = request.getParameter("message"); | 
  |  425 |    0 |            if (StringUtils.isEmpty(message)) { | 
  |  426 |    0 |                errors.addError("You must fill in a message."); | 
  |  427 |     | 
           } else { | 
  |  428 |    0 |                model.put("message", message); | 
  |  429 |     | 
           }  | 
  |  430 |     | 
     | 
  |  431 |     | 
             | 
  |  432 |     | 
     | 
  |  433 |     | 
             | 
  |  434 |    0 |            String startDateTime = request.getParameter("startDateTime"); | 
  |  435 |    0 |            if (StringUtils.isEmpty(startDateTime)) { | 
  |  436 |    0 |                errors.addError("You must fill in a start date/time."); | 
  |  437 |     | 
           } else { | 
  |  438 |    0 |                model.put("startDateTime", startDateTime); | 
  |  439 |     | 
           }  | 
  |  440 |     | 
     | 
  |  441 |     | 
             | 
  |  442 |    0 |            String stopDateTime = request.getParameter("stopDateTime"); | 
  |  443 |    0 |            if (StringUtils.isEmpty(stopDateTime)) { | 
  |  444 |    0 |                errors.addError("You must fill in a stop date/time."); | 
  |  445 |     | 
           } else { | 
  |  446 |    0 |                model.put("stopDateTime", stopDateTime); | 
  |  447 |     | 
           }  | 
  |  448 |     | 
     | 
  |  449 |     | 
             | 
  |  450 |    0 |            String summary = request.getParameter("summary"); | 
  |  451 |    0 |            if (StringUtils.isEmpty(summary)) { | 
  |  452 |    0 |                errors.addError("You must fill in a summary."); | 
  |  453 |     | 
           } else { | 
  |  454 |    0 |                model.put("summary", summary); | 
  |  455 |     | 
           }  | 
  |  456 |     | 
     | 
  |  457 |     | 
             | 
  |  458 |    0 |            String description = request.getParameter("description"); | 
  |  459 |    0 |            if (StringUtils.isEmpty(description)) { | 
  |  460 |    0 |                errors.addError("You must fill in a description."); | 
  |  461 |     | 
           } else { | 
  |  462 |    0 |                model.put("description", description); | 
  |  463 |     | 
           }  | 
  |  464 |     | 
     | 
  |  465 |     | 
             | 
  |  466 |    0 |            String location = request.getParameter("location"); | 
  |  467 |    0 |            if (StringUtils.isEmpty(location)) { | 
  |  468 |    0 |                errors.addError("You must fill in a location."); | 
  |  469 |     | 
           } else { | 
  |  470 |    0 |                model.put("location", location); | 
  |  471 |     | 
           }  | 
  |  472 |     | 
     | 
  |  473 |     | 
             | 
  |  474 |    0 |            if (errors.getErrors().size() > 0) { | 
  |  475 |    0 |                throw errors;  | 
  |  476 |     | 
           }  | 
  |  477 |     | 
     | 
  |  478 |     | 
             | 
  |  479 |    0 |            NotificationChannel channel = Util.retrieveFieldReference("channel", | 
  |  480 |     | 
                   "name", channelName, NotificationChannel.class,  | 
  |  481 |     | 
                   businessObjectDao);  | 
  |  482 |    0 |            notification.setChannel(channel);  | 
  |  483 |     | 
     | 
  |  484 |    0 |            NotificationPriority priority = Util.retrieveFieldReference("priority", | 
  |  485 |     | 
                   "name", priorityName, NotificationPriority.class,  | 
  |  486 |     | 
                   businessObjectDao);  | 
  |  487 |    0 |            notification.setPriority(priority);  | 
  |  488 |     | 
     | 
  |  489 |    0 |            NotificationContentType contentType = Util.retrieveFieldReference(  | 
  |  490 |     | 
                   "contentType", "name",  | 
  |  491 |     | 
                   NotificationConstants.CONTENT_TYPES.EVENT_CONTENT_TYPE,  | 
  |  492 |     | 
                   NotificationContentType.class, businessObjectDao);  | 
  |  493 |    0 |            notification.setContentType(contentType);  | 
  |  494 |     | 
     | 
  |  495 |    0 |            NotificationProducer producer = Util  | 
  |  496 |     | 
                   .retrieveFieldReference(  | 
  |  497 |     | 
                           "producer",  | 
  |  498 |     | 
                           "name",  | 
  |  499 |     | 
                           NotificationConstants.KEW_CONSTANTS.NOTIFICATION_SYSTEM_USER_NAME,  | 
  |  500 |     | 
                           NotificationProducer.class, businessObjectDao);  | 
  |  501 |    0 |            notification.setProducer(producer);  | 
  |  502 |     | 
     | 
  |  503 |    0 |            for (String senderName : senders) { | 
  |  504 |    0 |                if (StringUtils.isEmpty(senderName)) { | 
  |  505 |    0 |                    errors.addError("A sender's name cannot be blank."); | 
  |  506 |     | 
               } else { | 
  |  507 |    0 |                    NotificationSender ns = new NotificationSender();  | 
  |  508 |    0 |                    ns.setSenderName(senderName.trim());  | 
  |  509 |    0 |                    notification.addSender(ns);  | 
  |  510 |     | 
               }  | 
  |  511 |     | 
           }  | 
  |  512 |     | 
     | 
  |  513 |    0 |            boolean recipientsExist = false;  | 
  |  514 |     | 
     | 
  |  515 |    0 |            if (userRecipients != null && userRecipients.length > 0) { | 
  |  516 |    0 |                recipientsExist = true;  | 
  |  517 |    0 |                for (String userRecipientId : userRecipients) { | 
  |  518 |    0 |                    if (isUserRecipientValid(userRecipientId, errors)) { | 
  |  519 |    0 |                            NotificationRecipient recipient = new NotificationRecipient();  | 
  |  520 |    0 |                            recipient.setRecipientType(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE);  | 
  |  521 |    0 |                            recipient.setRecipientId(userRecipientId);  | 
  |  522 |    0 |                            notification.addRecipient(recipient);  | 
  |  523 |     | 
                   }  | 
  |  524 |     | 
               }  | 
  |  525 |     | 
           }  | 
  |  526 |     | 
     | 
  |  527 |    0 |            if (workgroupRecipients != null && workgroupRecipients.length > 0) { | 
  |  528 |    0 |                recipientsExist = true;  | 
  |  529 |    0 |                if (workgroupNamespaceCodes != null && workgroupNamespaceCodes.length > 0) { | 
  |  530 |    0 |                        if (workgroupNamespaceCodes.length == workgroupRecipients.length) { | 
  |  531 |    0 |                                for (int i = 0; i < workgroupRecipients.length; i++) { | 
  |  532 |    0 |                                        if (isWorkgroupRecipientValid(workgroupRecipients[i], workgroupNamespaceCodes[i], errors)) { | 
  |  533 |    0 |                                                NotificationRecipient recipient = new NotificationRecipient();  | 
  |  534 |    0 |                                                recipient.setRecipientType(KimGroupMemberTypes.GROUP_MEMBER_TYPE);  | 
  |  535 |    0 |                                                recipient.setRecipientId(  | 
  |  536 |     | 
                                                               getIdentityManagementService().getGroupByName(workgroupNamespaceCodes[i], workgroupRecipients[i]).getGroupId());  | 
  |  537 |    0 |                                                notification.addRecipient(recipient);  | 
  |  538 |     | 
                                       }  | 
  |  539 |     | 
                               }  | 
  |  540 |     | 
                       } else { | 
  |  541 |    0 |                                errors.addError("The number of groups must match the number of namespace codes"); | 
  |  542 |     | 
                       }  | 
  |  543 |     | 
               } else { | 
  |  544 |    0 |                            errors.addError("You must specify a namespace code for every group name"); | 
  |  545 |     | 
                   }  | 
  |  546 |    0 |            } else if (workgroupNamespaceCodes != null && workgroupNamespaceCodes.length > 0) { | 
  |  547 |    0 |                    errors.addError("You must specify a group name for every namespace code"); | 
  |  548 |     | 
           }  | 
  |  549 |     | 
     | 
  |  550 |     | 
             | 
  |  551 |    0 |            if (errors.getErrors().size() > 0) { | 
  |  552 |    0 |                throw errors;  | 
  |  553 |     | 
           }  | 
  |  554 |     | 
     | 
  |  555 |    0 |            notification.setTitle(title);  | 
  |  556 |     | 
     | 
  |  557 |    0 |            notification.setDeliveryType(deliveryType);  | 
  |  558 |     | 
     | 
  |  559 |    0 |            Date startDate = null;  | 
  |  560 |    0 |            Date stopDate = null;  | 
  |  561 |     | 
             | 
  |  562 |    0 |            Date d = null;  | 
  |  563 |    0 |            if (StringUtils.isNotBlank(sendDateTime)) { | 
  |  564 |     | 
               try { | 
  |  565 |    0 |                    d = Util.parseUIDateTime(sendDateTime);  | 
  |  566 |    0 |                } catch (ParseException pe) { | 
  |  567 |    0 |                    errors.addError("You specified an invalid send date and time.  Please use the calendar picker."); | 
  |  568 |    0 |                }  | 
  |  569 |    0 |                notification.setSendDateTime(new Timestamp(d.getTime()));  | 
  |  570 |     | 
           }  | 
  |  571 |     | 
     | 
  |  572 |    0 |            Date d2 = null;  | 
  |  573 |    0 |            if (StringUtils.isNotBlank(autoRemoveDateTime)) { | 
  |  574 |     | 
               try { | 
  |  575 |    0 |                    d2 = Util.parseUIDateTime(autoRemoveDateTime);  | 
  |  576 |    0 |                    if (d2.before(d)) { | 
  |  577 |    0 |                        errors.addError("Auto Remove Date/Time cannot be before Send Date/Time."); | 
  |  578 |     | 
                   }  | 
  |  579 |    0 |                } catch (ParseException pe) { | 
  |  580 |    0 |                    errors.addError("You specified an invalid auto-remove date and time.  Please use the calendar picker."); | 
  |  581 |    0 |                }  | 
  |  582 |    0 |                notification.setAutoRemoveDateTime(new Timestamp(d2.getTime()));  | 
  |  583 |     | 
           }  | 
  |  584 |     | 
     | 
  |  585 |    0 |            if (StringUtils.isNotBlank(startDateTime)) { | 
  |  586 |     | 
               try { | 
  |  587 |    0 |                    startDate = Util.parseUIDateTime(startDateTime);  | 
  |  588 |    0 |                } catch (ParseException pe) { | 
  |  589 |    0 |                    errors.addError("You specified an invalid start date and time.  Please use the calendar picker."); | 
  |  590 |    0 |                }  | 
  |  591 |     | 
           }  | 
  |  592 |     | 
     | 
  |  593 |    0 |            if (StringUtils.isNotBlank(stopDateTime)) { | 
  |  594 |     | 
               try { | 
  |  595 |    0 |                    stopDate = Util.parseUIDateTime(stopDateTime);  | 
  |  596 |    0 |                } catch (ParseException pe) { | 
  |  597 |    0 |                    errors.addError("You specified an invalid stop date and time.  Please use the calendar picker."); | 
  |  598 |    0 |                }  | 
  |  599 |     | 
           }  | 
  |  600 |     | 
     | 
  |  601 |    0 |            if(stopDate != null && startDate != null) { | 
  |  602 |    0 |                if (stopDate.before(startDate)) { | 
  |  603 |    0 |                    errors.addError("Event Stop Date/Time cannot be before Event Start Date/Time."); | 
  |  604 |     | 
               }  | 
  |  605 |     | 
           }  | 
  |  606 |     | 
     | 
  |  607 |    0 |            if (!recipientsExist && !hasPotentialRecipients(notification)) { | 
  |  608 |    0 |                errors.addError("You must specify at least one user or group recipient."); | 
  |  609 |     | 
           }  | 
  |  610 |     | 
     | 
  |  611 |     | 
             | 
  |  612 |    0 |            if (errors.getErrors().size() > 0) { | 
  |  613 |    0 |                throw errors;  | 
  |  614 |     | 
           }  | 
  |  615 |     | 
     | 
  |  616 |    0 |            notification  | 
  |  617 |     | 
                   .setContent(NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_EVENT_OPEN  | 
  |  618 |     | 
                           + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_OPEN  | 
  |  619 |     | 
                           + message  | 
  |  620 |     | 
                           + NotificationConstants.XML_MESSAGE_CONSTANTS.MESSAGE_CLOSE  | 
  |  621 |     | 
                           + "<event>\n"  | 
  |  622 |     | 
                           + "  <summary>" + summary + "</summary>\n"  | 
  |  623 |     | 
                           + "  <description>" + description + "</description>\n"  | 
  |  624 |     | 
                           + "  <location>" + location + "</location>\n"  | 
  |  625 |     | 
                           + "  <startDateTime>" + Util.toUIDateTimeString(startDate) + "</startDateTime>\n"  | 
  |  626 |     | 
                           + "  <stopDateTime>" + Util.toUIDateTimeString(stopDate) + "</stopDateTime>\n"  | 
  |  627 |     | 
                           + "</event>"  | 
  |  628 |     | 
                           + NotificationConstants.XML_MESSAGE_CONSTANTS.CONTENT_CLOSE);  | 
  |  629 |     | 
     | 
  |  630 |    0 |            return notification;  | 
  |  631 |     | 
       }  | 
  |  632 |     | 
   }  |