Search in sources :

Example 36 with TxDetail

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

the class TimelyAndReliableCompletionCondition_isCompleteTest method testIsComplete_noMessageToTrack_assertFalse.

@Test
public void testIsComplete_noMessageToTrack_assertFalse() {
    TimelyAndReliableCompletionCondition condition = new TimelyAndReliableCompletionCondition();
    Tx tx = new Tx(TxMessageType.DSN, new HashMap<String, TxDetail>());
    List<Tx> txs = Arrays.asList(tx);
    assertFalse(condition.isComplete(txs));
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 37 with TxDetail

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

the class MessageIdCorrelationExpression method evaluate.

/**
	 * {@inheritDoc}}
	 * This class specifically returns the message id or the parent message id based on the {@link Tx} type.
	 */
@SuppressWarnings({ "hiding", "unchecked" })
@Override
public <String> String evaluate(Exchange exchange, Class<String> type) {
    String retVal = null;
    final Tx tx = (Tx) exchange.getIn().getBody();
    final TxMessageType msgType = tx.getMsgType();
    final Map<java.lang.String, TxDetail> details = tx.getDetails();
    if (!details.isEmpty()) {
        // first check the type of message
        switch(msgType) {
            case IMF:
                {
                    final TxDetail msgIdDetail = details.get(TxDetailType.MSG_ID.getType());
                    if (msgIdDetail != null)
                        retVal = (String) msgIdDetail.getDetailValue().toString();
                    break;
                }
            case DSN:
            case MDN:
                {
                    final TxDetail msgIdDetail = details.get(TxDetailType.PARENT_MSG_ID.getType());
                    if (msgIdDetail != null)
                        retVal = (String) msgIdDetail.getDetailValue().toString();
                    break;
                }
        }
    }
    return retVal;
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) TxMessageType(org.nhindirect.common.tx.model.TxMessageType)

Example 38 with TxDetail

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

the class DSNMessageGenerator method generateDSNFailureMessage.

/**
	 * Generates the DSN message a replacing the existing exchange in body with the DSN message as a MimeMessage object.
	 * @param txs Collection of correlated Tx objects.
	 * @param ex The message exchange.
	 * @throws Exception
	 */
@Handler
public void generateDSNFailureMessage(Collection<Tx> txs, Exchange ex) throws Exception {
    // change the inbound message body to null
    ex.getIn().setBody(null);
    // get the message that is being tracked so we can generate an error message for it
    Tx messageToTrack = AbstractCompletionCondition.getMessageToTrack(txs);
    if (messageToTrack != null) {
        // make sure we have incomplete recipients
        final Collection<String> incompleteRecips = conditionChecker.getIncompleteRecipients(txs);
        if (incompleteRecips != null && !incompleteRecips.isEmpty()) {
            InternetAddress originalSender = null;
            String originalSubject = "";
            InternetAddress postmaster = null;
            String originalMessageId = "";
            Enumeration<Header> fullMessageHeaders = null;
            final List<DSNRecipientHeaders> recipientDSNHeaders = new ArrayList<DSNRecipientHeaders>();
            final List<Address> failedRecipAddresses = new ArrayList<Address>();
            final TxDetail sender = messageToTrack.getDetail(TxDetailType.FROM);
            if (sender != null) {
                originalSender = new InternetAddress(sender.getDetailValue());
                postmaster = new InternetAddress(postmasterMailbox + "@" + getAddressDomain(originalSender));
            }
            final TxDetail subject = messageToTrack.getDetail(TxDetailType.SUBJECT);
            if (subject != null)
                originalSubject = subject.getDetailValue();
            for (String incompleteRecip : incompleteRecips) {
                final Address failedRecipAddress = new InternetAddress(incompleteRecip);
                DSNRecipientHeaders dsnRecipHeaders = new DSNRecipientHeaders(DSNAction.FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.UNDEFINED_STATUS), failedRecipAddress);
                recipientDSNHeaders.add(dsnRecipHeaders);
                failedRecipAddresses.add(failedRecipAddress);
            }
            ///CLOVER:OFF
            final TxDetail origMessId = messageToTrack.getDetail(TxDetailType.MSG_ID);
            if (origMessId != null)
                originalMessageId = origMessId.getDetailValue();
            ///CLOVER:ON
            final DSNMessageHeaders messageDSNHeaders = new DSNMessageHeaders(reportingMta, originalMessageId, MtaNameType.DNS);
            final TxDetail fullHeaders = messageToTrack.getDetail(TxDetailType.MSG_FULL_HEADERS);
            if (fullHeaders != null)
                fullMessageHeaders = this.convertStringToHeaders(fullHeaders.getDetailValue());
            final MimeBodyPart textBodyPart = textGenerator.generate(originalSender, failedRecipAddresses, fullMessageHeaders);
            final MimeMessage dnsMessage = generator.createDSNMessage(originalSender, originalSubject, postmaster, recipientDSNHeaders, messageDSNHeaders, textBodyPart);
            ex.getIn().setBody(dnsMessage);
        }
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Tx(org.nhindirect.common.tx.model.Tx) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) DSNRecipientHeaders(org.nhindirect.common.mail.dsn.DSNRecipientHeaders) ArrayList(java.util.ArrayList) TxDetail(org.nhindirect.common.tx.model.TxDetail) Header(javax.mail.Header) MimeMessage(javax.mail.internet.MimeMessage) DSNMessageHeaders(org.nhindirect.common.mail.dsn.DSNMessageHeaders) MimeBodyPart(javax.mail.internet.MimeBodyPart) Handler(org.apache.camel.Handler)

Example 39 with TxDetail

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

the class DefaultDuplicateNotificationStateManager 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) {
            Collection<String> recips = Arrays.asList(origRecips.getDetailValue().split(","));
            try {
                final Set<String> 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 40 with TxDetail

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

the class AbstractCompletionCondition method isComplete.

/**
	 * {@inheritDoc}
	 */
@Override
public boolean isComplete(Collection<Tx> txs) {
    if (txs == null || txs.size() == 0)
        return false;
    final Tx originalMessage = getMessageToTrackInternal(txs);
    if (originalMessage == null)
        return false;
    final TxDetail originalRecipDetail = originalMessage.getDetail(TxDetailType.RECIPIENTS.getType());
    if (originalRecipDetail == null)
        return false;
    final Collection<String> incompleteRecips = getIncompleteRecipients(txs);
    return incompleteRecips.isEmpty();
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) 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