use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.
the class TimelyAndReliableCompletionCondition_isCompleteTest method testIsComplete_completedMDNs_assertTrue.
@Test
public void testIsComplete_completedMDNs_assertTrue() {
TimelyAndReliableCompletionCondition condition = new TimelyAndReliableCompletionCondition();
// original message
final String originalMessageId = UUID.randomUUID().toString();
Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "");
// MDN to original message, no reliable headers
Tx mdnProcessedMessage = TestUtils.makeMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Processed, "");
// MDN to original message, no reliable headers
Tx mdnDispatchedMessage = TestUtils.makeMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Dispatched, MDNStandard.DispositionOption_TimelyAndReliable);
List<Tx> txs = Arrays.asList(originalMessage, mdnProcessedMessage, mdnDispatchedMessage);
assertTrue(condition.isComplete(txs));
}
use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.
the class GeneralCompletionCondition_isCompleteTest method testIsComplete_nonQuotedFriendlyFinalRecipName_MDNMessageReceived_assertTrue.
@Test
public void testIsComplete_nonQuotedFriendlyFinalRecipName_MDNMessageReceived_assertTrue() {
GeneralCompletionCondition condition = new GeneralCompletionCondition();
// original message
final String originalMessageId = UUID.randomUUID().toString();
Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "");
// MDN to original message
Tx mdnMessage = TestUtils.makeMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "GregMeyer <gm2552@direct.securehealthemail.com>");
List<Tx> txs = Arrays.asList(originalMessage, mdnMessage);
assertTrue(condition.isComplete(txs));
}
use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.
the class TimelyAndReliableCompletionCondition_isCompleteTest method testIsComplete_failedDSNAction_assertTrue.
@Test
public void testIsComplete_failedDSNAction_assertTrue() {
TimelyAndReliableCompletionCondition condition = new TimelyAndReliableCompletionCondition();
// original message
final String originalMessageId = UUID.randomUUID().toString();
Tx originalMessage = TestUtils.makeMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "");
// DSN to original message, no reliable headers
Tx mdnMessage = TestUtils.makeMessage(TxMessageType.DSN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", DSNStandard.DSNAction.FAILED.toString(), "");
List<Tx> txs = Arrays.asList(originalMessage, mdnMessage);
assertTrue(condition.isComplete(txs));
}
use of org.nhindirect.common.tx.model.Tx 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;
}
use of org.nhindirect.common.tx.model.Tx 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);
}
}
}
Aggregations