use of org.nhindirect.stagent.IncomingMessage 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.IncomingMessage 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.IncomingMessage in project nhin-d by DirectProject.
the class NotificationProducerTest method getMessageFromFile.
private IncomingMessage getMessageFromFile(String fileName, Collection<String> domains) throws Exception {
String text = TestUtils.readMessageResource(fileName);
IncomingMessage retVal = new IncomingMessage(text);
MockNHINDAgent mockAgent = new MockNHINDAgent(domains);
retVal.setAgent(mockAgent);
return retVal;
}
use of org.nhindirect.stagent.IncomingMessage 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.IncomingMessage 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());
}
Aggregations