Search in sources :

Example 66 with TxDetail

use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.

the class VariableCompletionCondition_isTimelyAndRequiredTest method testIsTimelyAndRequired_NoMNDOptionDetails_assertFalse.

@Test
public void testIsTimelyAndRequired_NoMNDOptionDetails_assertFalse() {
    TxCompletionCondition cond1 = mock(TxCompletionCondition.class);
    TxCompletionCondition cond2 = mock(TxCompletionCondition.class);
    VariableCompletionCondition cond = new VariableCompletionCondition(cond1, cond2);
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    details.put(TxDetailType.FROM.getType(), new TxDetail(TxDetailType.FROM, "me@test.com"));
    Tx msg = new Tx(TxMessageType.IMF, details);
    assertFalse(cond.isRelAndTimelyRequired(msg));
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 67 with TxDetail

use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.

the class TimelyAndReliableCompletionCondition method getIncompleteRecipients.

/**
	 * {@inheritDoc}
	 */
@Override
public Collection<String> getIncompleteRecipients(Collection<Tx> txs) {
    if (txs == null || txs.size() == 0)
        return Collections.emptyList();
    final Tx originalMessage = getMessageToTrackInternal(txs);
    if (originalMessage == null)
        return Collections.emptyList();
    final TxDetail originalRecipDetail = originalMessage.getDetail(TxDetailType.RECIPIENTS.getType());
    if (originalRecipDetail == null)
        return Collections.emptyList();
    // add the original recipient list to a map of recipients to status
    final Map<String, RecipientResponseStatus> recipStatuses = new HashMap<String, RecipientResponseStatus>();
    for (String recip : originalRecipDetail.getDetailValue().split(",")) recipStatuses.put(recip, new RecipientResponseStatus(recip));
    for (Tx tx : txs) {
        final TxDetail finalRecipDetail = tx.getDetail(TxDetailType.FINAL_RECIPIENTS);
        if (finalRecipDetail != null) {
            switch(tx.getMsgType()) {
                case MDN:
                    {
                        // an MDN is sent per original message recipient, so we should only be able
                        // to extract one original recipient from this message
                        final RecipientResponseStatus recipStatus = recipStatuses.get(finalRecipDetail.getDetailValue());
                        final TxDetail dispDetail = tx.getDetail(TxDetailType.DISPOSITION);
                        if (dispDetail != null && recipStatus != null) {
                            final String dispValue = dispDetail.getDetailValue();
                            // check if this is an MDN processed message
                            if (dispValue.contains(MDNStandard.Disposition_Processed))
                                recipStatus.addReceivedStatus(RecipientResponseStatus.MDNProcessReceived);
                            else // check if this is an MDN dispatched message
                            if (dispValue.contains(MDNStandard.Disposition_Dispatched)) {
                                // check for the reliable and timely option
                                final TxDetail mdnOptionDetail = tx.getDetail(TxDetailType.DISPOSITION_OPTIONS);
                                if (mdnOptionDetail != null && mdnOptionDetail.getDetailValue().contains(MDNStandard.DispositionOption_TimelyAndReliable))
                                    recipStatus.addReceivedStatus(RecipientResponseStatus.MDNDispatchedReceived);
                            } else // check if this is an MDN failed message
                            if (dispValue.contains(MDNStandard.Disposition_Denied) || dispValue.contains(MDNStandard.Disposition_Error))
                                recipStatus.addReceivedStatus(RecipientResponseStatus.MDNFailedReceived);
                        }
                        break;
                    }
                case DSN:
                    {
                        // get DSN action
                        final TxDetail actionDetail = tx.getDetail(TxDetailType.DSN_ACTION);
                        if (actionDetail != null) {
                            final String actionValue = actionDetail.getDetailValue();
                            if (actionValue.contains(DSNStandard.DSNAction.FAILED.toString())) {
                                // there can be multiple final recipients in a DNS message
                                for (String finalRecip : finalRecipDetail.getDetailValue().split(",")) {
                                    final RecipientResponseStatus recipStatus = recipStatuses.get(finalRecip);
                                    if (recipStatus != null)
                                        recipStatus.addReceivedStatus(RecipientResponseStatus.DSNFailedReceived);
                                }
                            }
                        }
                    }
            }
        }
    }
    final Collection<String> retVal = new ArrayList<String>();
    // iterate through the recipient list and make sure each one is complete
    for (RecipientResponseStatus status : recipStatuses.values()) {
        if (!(// did we receive both processed and dispatched
        (status.isMDNDispatchedReceived() && status.isMDNProcessedReceived()) || // did we receive an MDN or DSN failure
        (status.isMDNFailedReceived() || status.isDSNFailedReceived()))) {
            // if at least one of the conditions above is not true (that being why the entire statement is 
            // precceeded with a !, then that recipeint is not complete
            // the completion condition of the original message is not considered complete until all recipients
            // have been accounted for
            retVal.add(status.getRecipient());
        } else {
            TxDetail detail = originalMessage.getDetail(TxDetailType.MSG_ID);
            if (detail != null)
                addMessageToDuplicateStore(detail.getDetailValue(), status.getRecipient());
        }
    }
    return retVal;
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) ArrayList(java.util.ArrayList)

Example 68 with TxDetail

use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.

the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated.

@Test
public void testGenerateDSNFailureMessage_assertMessageCreated() throws Exception {
    Exchange exchange = new DefaultExchange(mock(CamelContext.class));
    String message = TestUtils.readMessageFromFile("MessageWithAttachment.txt");
    DefaultTxDetailParser parser = new DefaultTxDetailParser();
    InputStream str = IOUtils.toInputStream(message);
    try {
        // send original message
        final MimeMessage mimeMessage = new MimeMessage(null, str);
        // change the message id
        mimeMessage.saveChanges();
        Map<String, TxDetail> details = parser.getMessageDetails(mimeMessage);
        Tx originalMessage = new Tx(TxMessageType.IMF, details);
        Collection<Tx> txs = new ArrayList<Tx>();
        txs.add(originalMessage);
        DSNMessageGenerator generator = createGenerator();
        generator.generateDSNFailureMessage(txs, exchange);
        MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
        assertNotNull(dsnMessage);
        // check the subject
        String newSubject = MailStandard.getHeader(dsnMessage, MailStandard.Headers.Subject);
        assertTrue(newSubject.contains(MailStandard.getHeader(mimeMessage, MailStandard.Headers.Subject)));
        // check for the original message id in the in-reply-to
        String originalMessageId = MailStandard.getHeader(dsnMessage, MailStandard.Headers.InReplyTo);
        assertEquals(MailStandard.getHeader(mimeMessage, MailStandard.Headers.MessageID), originalMessageId);
    } finally {
        IOUtils.closeQuietly(str);
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Tx(org.nhindirect.common.tx.model.Tx) InputStream(java.io.InputStream) TxDetail(org.nhindirect.common.tx.model.TxDetail) ArrayList(java.util.ArrayList) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 69 with TxDetail

use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_IMFMessage_msgIdExists_assertMessageIdEvaluated.

@Test
public void testEvaluate_IMFMessage_msgIdExists_assertMessageIdEvaluated() {
    MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
    String msgId = UUID.randomUUID().toString();
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    details.put(TxDetailType.MSG_ID.getType(), new TxDetail(TxDetailType.MSG_ID, msgId));
    Tx tx = new Tx(TxMessageType.IMF, details);
    CamelContext context = mock(CamelContext.class);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    assertEquals(msgId, exp.evaluate(exchange, String.class));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 70 with TxDetail

use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.

the class TestUtils method makeReliableMessage.

public static Tx makeReliableMessage(TxMessageType type, String msgId, String parentId, String from, String recip, String finalRecip, String action, String disposition) {
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    if (msgId != null && !msgId.isEmpty())
        details.put(TxDetailType.MSG_ID.getType(), new TxDetail(TxDetailType.MSG_ID, msgId));
    if (parentId != null && !parentId.isEmpty())
        details.put(TxDetailType.PARENT_MSG_ID.getType(), new TxDetail(TxDetailType.PARENT_MSG_ID, parentId));
    if (from != null && !from.isEmpty())
        details.put(TxDetailType.FROM.getType(), new TxDetail(TxDetailType.FROM, from));
    if (recip != null && !recip.isEmpty())
        details.put(TxDetailType.RECIPIENTS.getType(), new TxDetail(TxDetailType.RECIPIENTS, recip));
    if (finalRecip != null && !finalRecip.isEmpty())
        details.put(TxDetailType.FINAL_RECIPIENTS.getType(), new TxDetail(TxDetailType.FINAL_RECIPIENTS, finalRecip));
    if (action != null && !action.isEmpty())
        details.put(TxDetailType.DSN_ACTION.getType(), new TxDetail(TxDetailType.DSN_ACTION, action));
    if (disposition != null && !disposition.isEmpty())
        details.put(TxDetailType.DISPOSITION.getType(), new TxDetail(TxDetailType.DISPOSITION, disposition));
    details.put(TxDetailType.DISPOSITION_OPTIONS.getType(), new TxDetail(TxDetailType.DISPOSITION_OPTIONS, "X-DIRECT-FINAL-DESTINATION-DELIVERY"));
    return new Tx(type, details);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail)

Aggregations

TxDetail (org.nhindirect.common.tx.model.TxDetail)70 Test (org.junit.Test)50 Tx (org.nhindirect.common.tx.model.Tx)35 MimeMessage (javax.mail.internet.MimeMessage)32 HashMap (java.util.HashMap)20 Exchange (org.apache.camel.Exchange)10 CamelContext (org.apache.camel.CamelContext)9 DefaultExchange (org.apache.camel.impl.DefaultExchange)9 ArrayList (java.util.ArrayList)7 TxMessageType (org.nhindirect.common.tx.model.TxMessageType)6 NotificationDAOException (org.nhindirect.monitor.dao.NotificationDAOException)5 InputStream (java.io.InputStream)4 Address (javax.mail.Address)4 InternetAddress (javax.mail.internet.InternetAddress)4 DefaultTxDetailParser (org.nhindirect.common.tx.impl.DefaultTxDetailParser)4 TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)4 Header (javax.mail.Header)3 MessagingException (javax.mail.MessagingException)3 MimeBodyPart (javax.mail.internet.MimeBodyPart)3 DSNMessageHeaders (org.nhindirect.common.mail.dsn.DSNMessageHeaders)3