use of org.nhindirect.stagent.mail.notifications.NotificationMessage in project nhin-d by DirectProject.
the class DefaultSmtpAgent method postProcessIncomingMessage.
private void postProcessIncomingMessage(MessageProcessResult result) {
this.copyMessage(result.getProcessedMessage().getMessage(), settings.getIncomingMessageSettings());
// check if we need to create notification messages
try {
if (settings.getNotificationProducer() != null) {
result.setNotificationMessages(settings.getNotificationProducer().produce((IncomingMessage) result.getProcessedMessage()));
if (result.getNotificationMessages() != null && auditor != null) {
for (NotificationMessage noteMsg : result.getNotificationMessages()) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(noteMsg, Arrays.asList(AuditEvents.MDN_HEADER_CONTEXT));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.PRODUCE_MDN_NAME, AuditEvents.EVENT_TYPE), contexts);
}
}
}
} catch (Exception e) {
// don't bail on the whole process if we can't create notifications messages
LOGGER.error("Failed to create notification messages.", e);
}
// check if this is an incoming MDN message... is so, audit it
if (NotificationHelper.isMDN(result.getProcessedMessage().getMessage())) {
Collection<AuditContext> contexts = createContextCollectionFromMessage(result.getProcessedMessage(), Arrays.asList(AuditEvents.MDN_RECEIVED_CONTEXT));
auditor.audit(PRINICPAL, new AuditEvent(AuditEvents.MDN_RECEIVED_NAME, AuditEvents.EVENT_TYPE), contexts);
}
}
use of org.nhindirect.stagent.mail.notifications.NotificationMessage in project nhin-d by DirectProject.
the class NotificationProducerTest method testProduceMDN_MultipleRecipients.
public void testProduceMDN_MultipleRecipients() throws Exception {
NotificationSettings setting = new NotificationSettings(true, "", "");
NotificationProducer prod = new NotificationProducer(setting);
IncomingMessage msg = getMessageFromFile("MultipleRecipientsIncomingMessage.txt", Arrays.asList("cerner.com", "securehealthemail.com"));
Collection<NotificationMessage> notes = prod.produce(msg);
assertNotNull(notes);
assertEquals(2, notes.size());
boolean foundCernerCom = false;
boolean foundSecureHealth = false;
for (NHINDAddress noteMsg : msg.getDomainRecipients()) {
if (noteMsg.toString().contains("cerner.com"))
foundCernerCom = true;
else if (noteMsg.toString().contains("securehealthemail.com"))
foundSecureHealth = true;
}
assertTrue(foundCernerCom);
assertTrue(foundSecureHealth);
}
use of org.nhindirect.stagent.mail.notifications.NotificationMessage in project nhin-d by DirectProject.
the class NotificationProducerTest method testProduce_NoDomainRecipients_AssertEmptyList.
public void testProduce_NoDomainRecipients_AssertEmptyList() throws Exception {
NotificationSettings setting = new NotificationSettings(true, "", "");
NotificationProducer prod = new NotificationProducer(setting);
IncomingMessage msg = getMessageFromFile("PlainIncomingMessage.txt", Arrays.asList("otherdomain.com"));
Collection<NotificationMessage> notes = prod.produce(msg);
assertNotNull(notes);
assertEquals(0, notes.size());
}
use of org.nhindirect.stagent.mail.notifications.NotificationMessage in project nhin-d by DirectProject.
the class NotificationProducerTest method testProduce_AuthResponseFalse_AssertEmptyList.
public void testProduce_AuthResponseFalse_AssertEmptyList() throws Exception {
NotificationSettings setting = new NotificationSettings(false, "", "");
NotificationProducer prod = new NotificationProducer(setting);
IncomingMessage msg = getMessageFromFile("PlainIncomingMessage.txt", Arrays.asList("cerner.com"));
Collection<NotificationMessage> notes = prod.produce(msg);
assertNotNull(notes);
assertEquals(0, notes.size());
}
use of org.nhindirect.stagent.mail.notifications.NotificationMessage in project nhin-d by DirectProject.
the class DirectXdMailet method service.
/*
* (non-Javadoc)
*
* @see org.apache.mailet.base.GenericMailet#service(org.apache.mailet.Mail)
*/
@Override
public void service(Mail mail) throws MessagingException {
LOGGER.info("Servicing DirectXdMailet");
if (StringUtils.isBlank(endpointUrl)) {
LOGGER.error("DirectXdMailet endpoint URL cannot be empty or null.");
throw new MessagingException("DirectXdMailet endpoint URL cannot be empty or null.");
}
boolean successfulTransaction = false;
final MimeMessage msg = mail.getMessage();
final boolean isReliableAndTimely = TxUtil.isReliableAndTimelyRequested(msg);
final NHINDAddressCollection initialRecipients = getMailRecipients(mail);
final NHINDAddressCollection xdRecipients = new NHINDAddressCollection();
final NHINDAddress sender = getMailSender(mail);
Tx txToTrack = null;
// Get recipients and create a collection of Strings
final List<String> recipAddresses = new ArrayList<String>();
for (NHINDAddress addr : initialRecipients) {
recipAddresses.add(addr.getAddress());
}
// Service XD* addresses
if (getResolver().hasXdEndpoints(recipAddresses)) {
LOGGER.info("Recipients include XD endpoints");
try {
//List<Address> xdAddresses = new ArrayList<Address>();
for (String s : getResolver().getXdEndpoints(recipAddresses)) {
//xdAddresses.add((new MailAddress(s)).toInternetAddress());
xdRecipients.add(new NHINDAddress(s));
}
txToTrack = this.getTxToTrack(msg, sender, xdRecipients);
// Replace recipients with only XD* addresses
//msg.setRecipients(RecipientType.TO, xdAddresses.toArray(new Address[0]));
msg.setRecipients(RecipientType.TO, xdRecipients.toArray(new Address[0]));
// Transform MimeMessage into ProvideAndRegisterDocumentSetRequestType object
ProvideAndRegisterDocumentSetRequestType request = getMimeXDSTransformer().transform(msg);
for (String directTo : recipAddresses) {
String response = getDocumentRepository().forwardRequest(endpointUrl, request, directTo, sender.toString());
if (!isSuccessful(response)) {
LOGGER.error("DirectXdMailet failed to deliver XD message.");
LOGGER.error(response);
} else {
successfulTransaction = true;
if (isReliableAndTimely && txToTrack != null && txToTrack.getMsgType() == TxMessageType.IMF) {
// send MDN dispatch for messages the recipients that were successful
final Collection<NotificationMessage> notifications = notificationProducer.produce(new Message(msg), xdRecipients.toInternetAddressCollection());
if (notifications != null && notifications.size() > 0) {
LOGGER.debug("Sending MDN \"dispathed\" messages");
// create a message for each notification and put it on James "stack"
for (NotificationMessage message : notifications) {
try {
getMailetContext().sendMail(message);
} catch (Throwable t) {
// don't kill the process if this fails
LOGGER.error("Error sending MDN dispatched message.", t);
}
}
}
}
}
}
} catch (Throwable e) {
LOGGER.error("DirectXdMailet delivery failure", e);
}
}
// this basically sets the message back to it's original state with SMTP addresses only
if (getResolver().hasSmtpEndpoints(recipAddresses)) {
LOGGER.info("Recipients include SMTP endpoints");
mail.setRecipients(getSmtpRecips(recipAddresses));
} else {
LOGGER.info("Recipients do not include SMTP endpoints");
// No SMTP addresses, ghost it
mail.setState(Mail.GHOST);
}
if (!successfulTransaction) {
if (txToTrack != null && txToTrack.getMsgType() == TxMessageType.IMF) {
// for good measure, send DSN messages back to the original sender on failure
// create a DSN message
this.sendDSN(txToTrack, xdRecipients, false);
}
}
}
Aggregations