Search in sources :

Example 1 with IncomingMessage

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);
    }
}
Also used : NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) IncomingMessage(org.nhindirect.stagent.IncomingMessage) AuditEvent(org.nhindirect.common.audit.AuditEvent) AuditContext(org.nhindirect.common.audit.AuditContext) DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) MessagingException(javax.mail.MessagingException) AgentException(org.nhindirect.stagent.AgentException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NHINDException(org.nhindirect.stagent.NHINDException)

Example 2 with IncomingMessage

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);
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) IncomingMessage(org.nhindirect.stagent.IncomingMessage)

Example 3 with IncomingMessage

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;
}
Also used : MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) IncomingMessage(org.nhindirect.stagent.IncomingMessage)

Example 4 with IncomingMessage

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());
}
Also used : NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) IncomingMessage(org.nhindirect.stagent.IncomingMessage)

Example 5 with IncomingMessage

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());
}
Also used : NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) IncomingMessage(org.nhindirect.stagent.IncomingMessage)

Aggregations

IncomingMessage (org.nhindirect.stagent.IncomingMessage)9 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)7 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 MessagingException (javax.mail.MessagingException)1 CMSSignedData (org.bouncycastle.cms.CMSSignedData)1 AuditContext (org.nhindirect.common.audit.AuditContext)1 AuditEvent (org.nhindirect.common.audit.AuditEvent)1 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)1 AgentException (org.nhindirect.stagent.AgentException)1 MockNHINDAgent (org.nhindirect.stagent.MockNHINDAgent)1 NHINDAddress (org.nhindirect.stagent.NHINDAddress)1 NHINDException (org.nhindirect.stagent.NHINDException)1 SMIMECryptographerImpl (org.nhindirect.stagent.cryptography.SMIMECryptographerImpl)1 Message (org.nhindirect.stagent.mail.Message)1