Search in sources :

Example 21 with TxDetail

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

the class TimeoutDupStateManager method suppressNotification.

/**
	 * {@inheritDoc}
	 */
@Override
public boolean suppressNotification(Tx notificationMessage) throws DuplicateNotificationStateManagerException {
    boolean retVal = false;
    if (dao == null)
        throw new IllegalArgumentException("Dao cannot be null");
    if (notificationMessage == null)
        throw new IllegalArgumentException("Notification message cannot be null");
    final TxMessageType type = notificationMessage.getMsgType();
    if (type == TxMessageType.DSN || type == TxMessageType.MDN) {
        final TxDetail dispositionDetail = notificationMessage.getDetail(TxDetailType.DISPOSITION);
        // if it's an MDN displayed, then don't suppress it and let it go through
        if (type == TxMessageType.MDN && (dispositionDetail == null || dispositionDetail.getDetailValue().contains(MDNStandard.Disposition_Displayed)))
            return retVal;
        final TxDetail originalMessageIdDetail = notificationMessage.getDetail(TxDetailType.PARENT_MSG_ID);
        final TxDetail origRecips = notificationMessage.getDetail(TxDetailType.FINAL_RECIPIENTS);
        if (originalMessageIdDetail != null && origRecips != null) {
            final String[] recipsArray = origRecips.getDetailValue().split(",");
            for (int idx = 0; idx < recipsArray.length; ++idx) recipsArray[idx] = AbstractCompletionCondition.normalizeFinalRecip(recipsArray[idx]);
            final Collection<String> recips = Arrays.asList(recipsArray);
            try {
                // try by tabbular concatenation first... we need to make sure DSN messages
                // generated by the message monitor are not supressed... these messages
                // should be the only ones that use the tabbular format
                final String queryMsgId = originalMessageIdDetail.getDetailValue() + "\t" + notificationMessage.getDetail(TxDetailType.MSG_ID).getDetailValue();
                Set<String> alreadyReceivedNotifs = dao.getReceivedAddresses(queryMsgId, recips);
                if (!alreadyReceivedNotifs.isEmpty())
                    // this is from a DSN message generated by the monitor... don't suppress it
                    retVal = false;
                else {
                    // ok, so it's not in the tabular list... so just do the normal suppression test
                    alreadyReceivedNotifs = dao.getReceivedAddresses(originalMessageIdDetail.getDetailValue(), recips);
                    if (!alreadyReceivedNotifs.isEmpty())
                        retVal = true;
                }
            } catch (NotificationDAOException e) {
                throw new DuplicateNotificationStateManagerException(e);
            }
        }
    }
    return retVal;
}
Also used : TxDetail(org.nhindirect.common.tx.model.TxDetail) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) TxMessageType(org.nhindirect.common.tx.model.TxMessageType)

Example 22 with TxDetail

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

the class TimeoutDupStateManager method addNotificationForMonitorGeneratedDSN.

/**
	 * Adds a duplication state entry for each final recipient in a DSN message that was generated by the message monitor
	 * @param dsnMessage The DSN message
	 * @param ex The aggregation exchange.  The property "ORGI_IS_TIMELY" is checked to see if this DSN is part of a timely and reliable
	 * exchange
	 * @throws DuplicateNotificationStateManagerException
	 */
public void addNotificationForMonitorGeneratedDSN(MimeMessage dsnMessage, Exchange ex) throws DuplicateNotificationStateManagerException {
    if (dao == null)
        throw new IllegalArgumentException("Dao cannot be null");
    if (dsnMessage == null)
        throw new IllegalArgumentException("DSN message cannot be null");
    if (TxUtil.getMessageType(dsnMessage).equals(TxMessageType.DSN) && ex.getProperty("ORIG_IS_TIMELY") != null) {
        final Map<String, TxDetail> details = parser.getMessageDetails(dsnMessage);
        final TxDetail origMsgId = details.get(TxDetailType.PARENT_MSG_ID.getType());
        final TxDetail finalRecipDetail = details.get(TxDetailType.FINAL_RECIPIENTS.getType());
        final TxDetail msgId = details.get(TxDetailType.MSG_ID.getType());
        if (origMsgId != null && finalRecipDetail != null && msgId != null) {
            final String[] finalRecips = finalRecipDetail.getDetailValue().split(",");
            for (String finalRecip : finalRecips) {
                try {
                    final String normalizedFinalRecip = AbstractCompletionCondition.normalizeFinalRecip(finalRecip);
                    final String addMsgId = origMsgId.getDetailValue() + "\t" + msgId.getDetailValue();
                    dao.addNotification(addMsgId, normalizedFinalRecip);
                    // also write it out with just the orig message id
                    // this is needed for DSN messages that are not generated by the message monitor
                    // so we can ensure that later messages are properly suppressed
                    dao.addNotification(origMsgId.getDetailValue(), normalizedFinalRecip);
                }///CLOVER:OFF
                 catch (NotificationDAOException e) {
                    LOGGER.warn("Can't add recipient " + finalRecip + " for message id " + msgId.getDetailValue() + " to dup store.  Possibly already exists in dup store.");
                }
            ///CLOVER:ON
            }
        }
    }
}
Also used : TxDetail(org.nhindirect.common.tx.model.TxDetail) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException)

Example 23 with TxDetail

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

the class AbstractCompletionCondition_getMessageToTrackTest method testGetMessageToTrack_assertMessageFound.

@Test
public void testGetMessageToTrack_assertMessageFound() {
    ConditionAdapter condition = new ConditionAdapter();
    Tx tx = new Tx(TxMessageType.IMF, new HashMap<String, TxDetail>());
    List<Tx> txs = Arrays.asList(tx);
    Tx foundTx = condition.getMessageToTrackInternal(txs);
    assertEquals(tx, foundTx);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 24 with TxDetail

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

the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject.

@Test
public void testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject() 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);
        mimeMessage.setHeader(MailStandard.Headers.Subject, "");
        // 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);
        assertEquals("Not Delivered:", newSubject);
    } 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 25 with TxDetail

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

the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_emptyDetails_assertNullId.

@Test
public void testEvaluate_emptyDetails_assertNullId() {
    MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
    Tx tx = new Tx(TxMessageType.IMF, new HashMap<String, TxDetail>());
    CamelContext context = mock(CamelContext.class);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(tx);
    assertNull(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) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

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