Search in sources :

Example 1 with Template

use of org.openmrs.notification.Template in project openmrs-core by openmrs.

the class MessageServiceImpl method prepareMessage.

/**
 * 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);
    }
}
Also used : MessageException(org.openmrs.notification.MessageException) MessageException(org.openmrs.notification.MessageException) Template(org.openmrs.notification.Template) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

MessageException (org.openmrs.notification.MessageException)1 Template (org.openmrs.notification.Template)1 Transactional (org.springframework.transaction.annotation.Transactional)1