@Test public void shouldSendEmailWhenRnRStatusIsInApproval() throws Exception { Rnr rnr = make(a(defaultRequisition)); rnr.setId(1L); rnr.setProgram(new Program(1L, "VIA_ESS", "VIA_ESS", "", false, false)); rnr.setStatus(RnrStatus.AUTHORIZED); Facility facility = new Facility(); facility.setName("abc"); rnr.setFacility(facility); ConfigurationSetting setting = new ConfigurationSetting(); setting.setValue("abc"); when(configService.getByKey(anyString())).thenReturn(setting); final User user1 = new User(); final User user2 = new User(); ArrayList<User> userList = new ArrayList<User>(){{ add(user1); add(user2); }}; when(approverService.getNextApprovers(1L)).thenReturn(userList); when(staticReferenceDataService.getBoolean("toggle.email.attachment.simam")).thenReturn(true); notificationServices.notifyStatusChange(rnr); verify(requisitionEmailServiceForSIMAM).sendRequisitionEmailWithAttachment(rnr, userList); }
public void notifyStatusChange(Rnr requisition) { List<User> users = null; switch (requisition.getStatus()) { case SUBMITTED: users = approverService.getFacilityBasedAutorizers(requisition.getId()); break; case AUTHORIZED: users = approverService.getNextApprovers(requisition.getId()); break; case IN_APPROVAL: users = approverService.getNextApprovers(requisition.getId()); break; case RELEASED: default: break; } if (users != null) { if (staticReferenceDataService.getBoolean("toggle.email.attachment.simam")) { try { requisitionEmailServiceForSIMAM.sendRequisitionEmailWithAttachment(requisition, users); } catch (Throwable t) { LOGGER.error("There is a error when creating requisition email: " + t.getMessage()); } return; } for (User user : users) { if (user.isMobileUser()) { continue; } SimpleMailMessage message = new SimpleMailMessage(); String emailMessage = configService.getByKey(ConfigurationSettingKey.EMAIL_TEMPLATE_APPROVAL).getValue(); String approvalURL = String.format("%1$s/public/pages/logistics/rnr/index.html#/rnr-for-approval/%2$s/%3$s?supplyType=full-supply&page=1", baseURL, requisition.getId(), requisition.getProgram().getId()); emailMessage = emailMessage.replaceAll("\\{facility_name\\}", requisition.getFacility().getName()); emailMessage = emailMessage.replaceAll("\\{approver_name\\}", user.getFirstName() + " " + user.getLastName()); emailMessage = emailMessage.replaceAll("\\{period\\}", requisition.getPeriod().getName()); emailMessage = emailMessage.replaceAll("\\{link\\}", approvalURL); message.setText(emailMessage); message.setSubject(configService.getByKey(ConfigurationSettingKey.EMAIL_SUBJECT_APPROVAL).getValue()); message.setTo(user.getEmail()); try { emailService.queueMessage(message); } catch (Exception exp) { LOGGER.error("Notification was not sent due to the following exception ...", exp); } } } }
NotificationServices { public void notifyStatusChange(Rnr requisition) { List<User> users = null; switch (requisition.getStatus()) { case SUBMITTED: users = approverService.getFacilityBasedAutorizers(requisition.getId()); break; case AUTHORIZED: users = approverService.getNextApprovers(requisition.getId()); break; case IN_APPROVAL: users = approverService.getNextApprovers(requisition.getId()); break; case RELEASED: default: break; } if (users != null) { if (staticReferenceDataService.getBoolean("toggle.email.attachment.simam")) { try { requisitionEmailServiceForSIMAM.sendRequisitionEmailWithAttachment(requisition, users); } catch (Throwable t) { LOGGER.error("There is a error when creating requisition email: " + t.getMessage()); } return; } for (User user : users) { if (user.isMobileUser()) { continue; } SimpleMailMessage message = new SimpleMailMessage(); String emailMessage = configService.getByKey(ConfigurationSettingKey.EMAIL_TEMPLATE_APPROVAL).getValue(); String approvalURL = String.format("%1$s/public/pages/logistics/rnr/index.html#/rnr-for-approval/%2$s/%3$s?supplyType=full-supply&page=1", baseURL, requisition.getId(), requisition.getProgram().getId()); emailMessage = emailMessage.replaceAll("\\{facility_name\\}", requisition.getFacility().getName()); emailMessage = emailMessage.replaceAll("\\{approver_name\\}", user.getFirstName() + " " + user.getLastName()); emailMessage = emailMessage.replaceAll("\\{period\\}", requisition.getPeriod().getName()); emailMessage = emailMessage.replaceAll("\\{link\\}", approvalURL); message.setText(emailMessage); message.setSubject(configService.getByKey(ConfigurationSettingKey.EMAIL_SUBJECT_APPROVAL).getValue()); message.setTo(user.getEmail()); try { emailService.queueMessage(message); } catch (Exception exp) { LOGGER.error("Notification was not sent due to the following exception ...", exp); } } } } }
NotificationServices { public void notifyStatusChange(Rnr requisition) { List<User> users = null; switch (requisition.getStatus()) { case SUBMITTED: users = approverService.getFacilityBasedAutorizers(requisition.getId()); break; case AUTHORIZED: users = approverService.getNextApprovers(requisition.getId()); break; case IN_APPROVAL: users = approverService.getNextApprovers(requisition.getId()); break; case RELEASED: default: break; } if (users != null) { if (staticReferenceDataService.getBoolean("toggle.email.attachment.simam")) { try { requisitionEmailServiceForSIMAM.sendRequisitionEmailWithAttachment(requisition, users); } catch (Throwable t) { LOGGER.error("There is a error when creating requisition email: " + t.getMessage()); } return; } for (User user : users) { if (user.isMobileUser()) { continue; } SimpleMailMessage message = new SimpleMailMessage(); String emailMessage = configService.getByKey(ConfigurationSettingKey.EMAIL_TEMPLATE_APPROVAL).getValue(); String approvalURL = String.format("%1$s/public/pages/logistics/rnr/index.html#/rnr-for-approval/%2$s/%3$s?supplyType=full-supply&page=1", baseURL, requisition.getId(), requisition.getProgram().getId()); emailMessage = emailMessage.replaceAll("\\{facility_name\\}", requisition.getFacility().getName()); emailMessage = emailMessage.replaceAll("\\{approver_name\\}", user.getFirstName() + " " + user.getLastName()); emailMessage = emailMessage.replaceAll("\\{period\\}", requisition.getPeriod().getName()); emailMessage = emailMessage.replaceAll("\\{link\\}", approvalURL); message.setText(emailMessage); message.setSubject(configService.getByKey(ConfigurationSettingKey.EMAIL_SUBJECT_APPROVAL).getValue()); message.setTo(user.getEmail()); try { emailService.queueMessage(message); } catch (Exception exp) { LOGGER.error("Notification was not sent due to the following exception ...", exp); } } } }  }
NotificationServices { public void notifyStatusChange(Rnr requisition) { List<User> users = null; switch (requisition.getStatus()) { case SUBMITTED: users = approverService.getFacilityBasedAutorizers(requisition.getId()); break; case AUTHORIZED: users = approverService.getNextApprovers(requisition.getId()); break; case IN_APPROVAL: users = approverService.getNextApprovers(requisition.getId()); break; case RELEASED: default: break; } if (users != null) { if (staticReferenceDataService.getBoolean("toggle.email.attachment.simam")) { try { requisitionEmailServiceForSIMAM.sendRequisitionEmailWithAttachment(requisition, users); } catch (Throwable t) { LOGGER.error("There is a error when creating requisition email: " + t.getMessage()); } return; } for (User user : users) { if (user.isMobileUser()) { continue; } SimpleMailMessage message = new SimpleMailMessage(); String emailMessage = configService.getByKey(ConfigurationSettingKey.EMAIL_TEMPLATE_APPROVAL).getValue(); String approvalURL = String.format("%1$s/public/pages/logistics/rnr/index.html#/rnr-for-approval/%2$s/%3$s?supplyType=full-supply&page=1", baseURL, requisition.getId(), requisition.getProgram().getId()); emailMessage = emailMessage.replaceAll("\\{facility_name\\}", requisition.getFacility().getName()); emailMessage = emailMessage.replaceAll("\\{approver_name\\}", user.getFirstName() + " " + user.getLastName()); emailMessage = emailMessage.replaceAll("\\{period\\}", requisition.getPeriod().getName()); emailMessage = emailMessage.replaceAll("\\{link\\}", approvalURL); message.setText(emailMessage); message.setSubject(configService.getByKey(ConfigurationSettingKey.EMAIL_SUBJECT_APPROVAL).getValue()); message.setTo(user.getEmail()); try { emailService.queueMessage(message); } catch (Exception exp) { LOGGER.error("Notification was not sent due to the following exception ...", exp); } } } }  void notifyStatusChange(Rnr requisition); }
NotificationServices { public void notifyStatusChange(Rnr requisition) { List<User> users = null; switch (requisition.getStatus()) { case SUBMITTED: users = approverService.getFacilityBasedAutorizers(requisition.getId()); break; case AUTHORIZED: users = approverService.getNextApprovers(requisition.getId()); break; case IN_APPROVAL: users = approverService.getNextApprovers(requisition.getId()); break; case RELEASED: default: break; } if (users != null) { if (staticReferenceDataService.getBoolean("toggle.email.attachment.simam")) { try { requisitionEmailServiceForSIMAM.sendRequisitionEmailWithAttachment(requisition, users); } catch (Throwable t) { LOGGER.error("There is a error when creating requisition email: " + t.getMessage()); } return; } for (User user : users) { if (user.isMobileUser()) { continue; } SimpleMailMessage message = new SimpleMailMessage(); String emailMessage = configService.getByKey(ConfigurationSettingKey.EMAIL_TEMPLATE_APPROVAL).getValue(); String approvalURL = String.format("%1$s/public/pages/logistics/rnr/index.html#/rnr-for-approval/%2$s/%3$s?supplyType=full-supply&page=1", baseURL, requisition.getId(), requisition.getProgram().getId()); emailMessage = emailMessage.replaceAll("\\{facility_name\\}", requisition.getFacility().getName()); emailMessage = emailMessage.replaceAll("\\{approver_name\\}", user.getFirstName() + " " + user.getLastName()); emailMessage = emailMessage.replaceAll("\\{period\\}", requisition.getPeriod().getName()); emailMessage = emailMessage.replaceAll("\\{link\\}", approvalURL); message.setText(emailMessage); message.setSubject(configService.getByKey(ConfigurationSettingKey.EMAIL_SUBJECT_APPROVAL).getValue()); message.setTo(user.getEmail()); try { emailService.queueMessage(message); } catch (Exception exp) { LOGGER.error("Notification was not sent due to the following exception ...", exp); } } } }  void notifyStatusChange(Rnr requisition);  }