Search in sources :

Example 71 with Tx

use of org.nhindirect.common.tx.model.Tx 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)

Example 72 with Tx

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

the class GeneralCompletionCondition method getIncompleteRecipients.

/**
	 * {@inheritDoc}
	 */
@Override
public Collection<String> getIncompleteRecipients(Collection<Tx> txs) {
    if (txs == null || txs.size() == 0)
        return Collections.emptyList();
    final Tx originalMessage = getMessageToTrack(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.getType());
        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());
                        if (recipStatus != null)
                            recipStatus.addReceivedStatus(RecipientResponseStatus.MDNReceived);
                        break;
                    }
                case DSN:
                    {
                        // need to split the recipients out
                        for (String finalRecip : finalRecipDetail.getDetailValue().split(",")) {
                            final RecipientResponseStatus recipStatus = recipStatuses.get(finalRecip);
                            if (recipStatus != null)
                                recipStatus.addReceivedStatus(RecipientResponseStatus.DSNReceived);
                        }
                        break;
                    }
            }
        }
    }
    final Collection<String> retVal = new ArrayList<String>();
    // have received some type of notification
    for (RecipientResponseStatus status : recipStatuses.values()) if (status.getReceivedStatus() == 0) {
        retVal.add(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 73 with Tx

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

the class VariableTimeoutCondition method getTimeout.

/**
	 * {@inheritDoc}
	 */
@Override
public long getTimeout(Collection<Tx> txs, long exchangeStartTime) {
    TxTimeoutCondition conditionToUse = null;
    final Tx messageToTrack = getMessageToTrack(txs);
    // the general timeout condition
    if (messageToTrack == null)
        conditionToUse = generalExpression;
    else
        conditionToUse = isRelAndTimelyRequired(messageToTrack) ? timelyExpression : generalExpression;
    return conditionToUse.getTimeout(txs, exchangeStartTime);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxTimeoutCondition(org.nhindirect.monitor.condition.TxTimeoutCondition)

Example 74 with Tx

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

the class TestSingleRecipReliableMessageMonitorRoute method testSingleRecip_MDNDeniedReceived_assertConditionComplete.

@Test
public void testSingleRecip_MDNDeniedReceived_assertConditionComplete() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // send MDN error to original message
    Tx mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Denied);
    template.sendBody("direct:start", mdnMessage);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 75 with Tx

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

the class TestSingleRecipReliableMessageMonitorRoute method testSingleRecip_MDNProcessedAndDispatchedReceived_assertConditionComplete.

@Test
public void testSingleRecip_MDNProcessedAndDispatchedReceived_assertConditionComplete() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // send MDN processed to original message
    Tx mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Processed);
    template.sendBody("direct:start", mdnMessage);
    // send MDN dispatched to original message
    mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Dispatched);
    template.sendBody("direct:start", mdnMessage);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

Tx (org.nhindirect.common.tx.model.Tx)174 Test (org.junit.Test)156 Exchange (org.apache.camel.Exchange)83 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)49 TxDetail (org.nhindirect.common.tx.model.TxDetail)35 DefaultExchange (org.apache.camel.impl.DefaultExchange)32 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)19 MimeMessage (javax.mail.internet.MimeMessage)17 CamelContext (org.apache.camel.CamelContext)17 ConcurrentJPAAggregationRepository (org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository)15 TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)14 TxTimeoutCondition (org.nhindirect.monitor.condition.TxTimeoutCondition)8 Collection (java.util.Collection)7 NotificationDuplicationDAO (org.nhindirect.monitor.dao.NotificationDuplicationDAO)7 NHINDAddress (org.nhindirect.stagent.NHINDAddress)6 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)6 Response (javax.ws.rs.core.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 MessagingException (javax.mail.MessagingException)4