Search in sources :

Example 1 with Tx

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

the class TxUtil method isReliableAndTimelyRequested.

/**
	 * Determines if the message is requesting timely and reliable delivery.  This is determined by 
     * the existence of the X-DIRECT-FINAL-DESTINATION-DELIVERY message disposition option on the original message.
	 * @param msg The message that is being inspected for timely and reliable messaging.
	 * @return true if the original message indicates that it requires timely and reliable delivery; false otherwise
	 */
public static boolean isReliableAndTimelyRequested(MimeMessage msg) {
    if (msg == null)
        return false;
    final TxDetailParser parser = new DefaultTxDetailParser();
    final Map<String, TxDetail> details = parser.getMessageDetails(msg);
    final Tx tx = new Tx(getMessageType(msg), details);
    return isReliableAndTimelyRequested(tx);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser)

Example 2 with Tx

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

the class TxUtil_isRelAndTimelyTest method testIsTimelyAndRequired_MDNOptionForTimely_assertTrue.

@Test
public void testIsTimelyAndRequired_MDNOptionForTimely_assertTrue() {
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    details.put(TxDetailType.DISPOSITION_OPTIONS.getType(), new TxDetail(TxDetailType.DISPOSITION_OPTIONS, MDNStandard.DispositionOption_TimelyAndReliable));
    Tx msg = new Tx(TxMessageType.IMF, details);
    assertTrue(TxUtil.isReliableAndTimelyRequested(msg));
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 3 with Tx

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

the class TxUtil_isRelAndTimelyTest method testIsTimelyAndRequired_caseInsensitiveOption_MDNOptionForTimely_assertTrue.

@Test
public void testIsTimelyAndRequired_caseInsensitiveOption_MDNOptionForTimely_assertTrue() {
    Map<String, TxDetail> details = new HashMap<String, TxDetail>();
    details.put(TxDetailType.DISPOSITION_OPTIONS.getType(), new TxDetail(TxDetailType.DISPOSITION_OPTIONS, MDNStandard.DispositionOption_TimelyAndReliable.toLowerCase()));
    Tx msg = new Tx(TxMessageType.IMF, details);
    assertTrue(TxUtil.isReliableAndTimelyRequested(msg));
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) HashMap(java.util.HashMap) TxDetail(org.nhindirect.common.tx.model.TxDetail) Test(org.junit.Test)

Example 4 with Tx

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

the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_fromJson_incomingAndCompleteRecips.

@Test
public void testGenerateDSNFailureMessage_fromJson_incomingAndCompleteRecips() throws Exception {
    Exchange exchange = new DefaultExchange(mock(CamelContext.class));
    final String json = FileUtils.readFileToString(new File("./src/test/resources/json/multiRecipEmailSingleDNSAndMDN.json"));
    final ObjectMapper jsonMapper = new ObjectMapper();
    jsonMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
    List<Tx> txs = jsonMapper.readValue(json, TypeFactory.collectionType(ArrayList.class, Tx.class));
    DSNMessageGenerator generator = createGenerator();
    generator.generateDSNFailureMessage(txs, exchange);
    MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
    assertNotNull(dsnMessage);
    ByteArrayOutputStream oStr = new ByteArrayOutputStream();
    dsnMessage.writeTo(oStr);
    final String dsnStr = new String(oStr.toByteArray());
    assertTrue(dsnStr.contains("gm2552@direct.securehealthemail.com"));
    assertFalse(dsnStr.contains("test@aol.com"));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Tx(org.nhindirect.common.tx.model.Tx) MimeMessage(javax.mail.internet.MimeMessage) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with Tx

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

the class TestTimeoutToDupStateManager method testTimeoutReliableMessage_conditionNotComplete_assertDupAdded.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertDupAdded() throws Exception {
    NotificationDuplicationDAO dao = context.getRegistry().lookup("notificationDuplicationDAO", NotificationDuplicationDAO.class);
    assertNotNull(dao);
    purgeNotifDAO(dao);
    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);
    // no MDN sent... messages should timeout after 2 seconds
    // sleep 3 seconds to make sure it completes
    Thread.sleep(3000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
    Exchange exchange = exchanges.iterator().next();
    // make sure there is only 1 message in the exchange
    MimeMessage message = exchange.getIn().getBody(MimeMessage.class);
    assertNotNull(message);
    assertEquals("timeout", exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY));
    Set<String> addresses = dao.getReceivedAddresses(originalMessageId + "\t" + message.getMessageID(), Arrays.asList("gm2552@direct.securehealthemail.com"));
    assertEquals(1, addresses.size());
    assertTrue(addresses.contains("gm2552@direct.securehealthemail.com"));
    addresses = dao.getReceivedAddresses(originalMessageId, Arrays.asList("gm2552@direct.securehealthemail.com"));
    assertEquals(1, addresses.size());
    assertTrue(addresses.contains("gm2552@direct.securehealthemail.com"));
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MimeMessage(javax.mail.internet.MimeMessage) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) 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