/** * Create a message object with the given parts. * * @param recipients the recipients of the message * @param sender the send of the message * @param subject the subject of the message * @param content the content or body of the message */ @Override public Message createMessage(String recipients, String sender, String subject, String content) throws MessageException { return Context.getMessageService().createMessage(recipients, sender, subject, content, null, null, null); }
/** * Create a message object with the given parts. * * @param sender the send of the message * @param subject the subject of the message * @param content the content or body of the message */ @Override public Message createMessage(String sender, String subject, String content) throws MessageException { return Context.getMessageService().createMessage(null, sender, subject, content); }
/** * Create a message object with the given parts. * * @param subject the subject of the message * @param content the content or body of the message */ @Override public Message createMessage(String subject, String content) throws MessageException { return Context.getMessageService().createMessage(null, null, subject, content); }
/** * Send alerts * * @param alerts the unread alerts * @param users the users who have not read the alerts */ private void sendAlertNotifications(Collection<Alert> alerts) { try { // Create a new message Message message = Context.getMessageService().createMessage("Alert Reminder", "You have unread alerts."); // Get all recipients Collection<User> users = getRecipients(alerts); // Send a message to each person only once Context.getMessageService().sendMessage(message, users); } catch (MessageException e) { log.error("Failed to send message", e); } }
/** * Sends a message to a group of users identifier by their role. */ @Override public void sendMessage(Message message, Role role) throws MessageException { log.debug("Sending message to role " + role); log.debug("User Service : " + Context.getUserService()); List<Role> roles = new ArrayList<>(); roles.add(role); Collection<User> users = Context.getUserService().getUsers(null, roles, false); log.debug("Sending message " + message + " to " + users); Context.getMessageService().sendMessage(message, users); }
/** * Send a message using the given parameters. This is a convenience method so that the client * does not need to create its own Message object. */ @Override public void sendMessage(String recipients, String sender, String subject, String content) throws MessageException { Message message = createMessage(recipients, sender, subject, content); Context.getMessageService().sendMessage(message); }
/** * Send a message to a group of users identified by their role. */ @Override public void sendMessage(Message message, String roleName) throws MessageException { log.debug("Sending message to role with name " + roleName); Role role = Context.getUserService().getRole(roleName); Context.getMessageService().sendMessage(message, role); }
/** * Send message to a collection of recipients. */ @Override public void sendMessage(Message message, Collection<User> users) throws MessageException { log.debug("Sending message to users " + users); for (User user : users) { String address = user.getUserProperty(OpenmrsConstants.USER_PROPERTY_NOTIFICATION_ADDRESS); if (address != null) { message.addRecipient(address); } } Context.getMessageService().sendMessage(message); }
/** * Send message to a single user. * * @param message the <code>Message</code> to be sent * @param user the recipient of the message */ @Override public void sendMessage(Message message, User user) throws MessageException { log.debug("Sending message to user " + user); String address = user.getUserProperty(OpenmrsConstants.USER_PROPERTY_NOTIFICATION_ADDRESS); if (address != null) { message.addRecipient(address); } Context.getMessageService().sendMessage(message); }
/** * Prepare a message based on a template and data used for variable substitution within template. * * @param templateName name of the template to be used * @param data mapping used for variable substitution within template * @return the prepared Message */ @Override @Transactional(readOnly = true) public Message prepareMessage(String templateName, Map data) throws MessageException { try { Template template = (Template) getTemplatesByName(templateName).get(0); template.setData(data); return Context.getMessageService().prepareMessage(template); } catch (Exception e) { throw new MessageException("Could not prepare message with template " + templateName, e); } }
Context.getMessageService().sendMessage(recipients, sender, subject, message.toString());
/** * Send a message to a user that is identified by the given identifier. * * @param message <code>Message</code> to be sent * @param recipientId Integer identifier of user (recipient) */ @Override public void sendMessage(Message message, Integer recipientId) throws MessageException { log.debug("Sending message to user with user id " + recipientId); User user = Context.getUserService().getUser(recipientId); message.addRecipient(user.getUserProperty(OpenmrsConstants.USER_PROPERTY_NOTIFICATION_ADDRESS)); Context.getMessageService().sendMessage(message); }
/** * Run this before each unit test in this class. The "@Before" method in * {@link BaseContextSensitiveTest} is run right before this method. * * @throws Exception */ @Before public void runBeforeEachTest() { executeDataSet("org/openmrs/notification/include/MessageServiceTest-initial.xml"); ms = Context.getMessageService(); }
/** * @throws APIException * @throws MessageException * @see org.openmrs.api.UserService#setUserActivationKey(org.openmrs.User) */ @Override public User setUserActivationKey(User user) throws MessageException { String token = RandomStringUtils.randomAlphanumeric(20); long time = System.currentTimeMillis() + getValidTime(); String hashedKey = Security.encodeString(token); String activationKey = hashedKey + ":" + time; LoginCredential credentials = dao.getLoginCredential(user); credentials.setActivationKey(activationKey); dao.setUserActivationKey(credentials); MessageSourceService messages = Context.getMessageSourceService(); AdministrationService adminService = Context.getAdministrationService(); String link = adminService.getGlobalProperty(OpenmrsConstants.GP_HOST_URL) .replace("{activationKey}", token); String msg = messages.getMessage("mail.passwordreset.content").replace("{name}", user.getUsername()) .replace("{link}", link) .replace("{time}", String.valueOf(getValidTime() / 60000)); Context.getMessageService().sendMessage(user.getEmail(), adminService.getGlobalProperty("mail.from"), messages.getMessage("mail.passwordreset.subject"), msg); return user; }