use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class VariableCompletionCondition_isTimelyAndRequiredTest method testIsTimelyAndRequired_NoMNDOptionDetails_assertFalse.
@Test
public void testIsTimelyAndRequired_NoMNDOptionDetails_assertFalse() {
TxCompletionCondition cond1 = mock(TxCompletionCondition.class);
TxCompletionCondition cond2 = mock(TxCompletionCondition.class);
VariableCompletionCondition cond = new VariableCompletionCondition(cond1, cond2);
Map<String, TxDetail> details = new HashMap<String, TxDetail>();
details.put(TxDetailType.FROM.getType(), new TxDetail(TxDetailType.FROM, "me@test.com"));
Tx msg = new Tx(TxMessageType.IMF, details);
assertFalse(cond.isRelAndTimelyRequired(msg));
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class TimelyAndReliableCompletionCondition method getIncompleteRecipients.
/**
* {@inheritDoc}
*/
@Override
public Collection<String> getIncompleteRecipients(Collection<Tx> txs) {
if (txs == null || txs.size() == 0)
return Collections.emptyList();
final Tx originalMessage = getMessageToTrackInternal(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);
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());
final TxDetail dispDetail = tx.getDetail(TxDetailType.DISPOSITION);
if (dispDetail != null && recipStatus != null) {
final String dispValue = dispDetail.getDetailValue();
// check if this is an MDN processed message
if (dispValue.contains(MDNStandard.Disposition_Processed))
recipStatus.addReceivedStatus(RecipientResponseStatus.MDNProcessReceived);
else // check if this is an MDN dispatched message
if (dispValue.contains(MDNStandard.Disposition_Dispatched)) {
// check for the reliable and timely option
final TxDetail mdnOptionDetail = tx.getDetail(TxDetailType.DISPOSITION_OPTIONS);
if (mdnOptionDetail != null && mdnOptionDetail.getDetailValue().contains(MDNStandard.DispositionOption_TimelyAndReliable))
recipStatus.addReceivedStatus(RecipientResponseStatus.MDNDispatchedReceived);
} else // check if this is an MDN failed message
if (dispValue.contains(MDNStandard.Disposition_Denied) || dispValue.contains(MDNStandard.Disposition_Error))
recipStatus.addReceivedStatus(RecipientResponseStatus.MDNFailedReceived);
}
break;
}
case DSN:
{
// get DSN action
final TxDetail actionDetail = tx.getDetail(TxDetailType.DSN_ACTION);
if (actionDetail != null) {
final String actionValue = actionDetail.getDetailValue();
if (actionValue.contains(DSNStandard.DSNAction.FAILED.toString())) {
// there can be multiple final recipients in a DNS message
for (String finalRecip : finalRecipDetail.getDetailValue().split(",")) {
final RecipientResponseStatus recipStatus = recipStatuses.get(finalRecip);
if (recipStatus != null)
recipStatus.addReceivedStatus(RecipientResponseStatus.DSNFailedReceived);
}
}
}
}
}
}
}
final Collection<String> retVal = new ArrayList<String>();
// iterate through the recipient list and make sure each one is complete
for (RecipientResponseStatus status : recipStatuses.values()) {
if (!(// did we receive both processed and dispatched
(status.isMDNDispatchedReceived() && status.isMDNProcessedReceived()) || // did we receive an MDN or DSN failure
(status.isMDNFailedReceived() || status.isDSNFailedReceived()))) {
// if at least one of the conditions above is not true (that being why the entire statement is
// precceeded with a !, then that recipeint is not complete
// the completion condition of the original message is not considered complete until all recipients
// have been accounted for
retVal.add(status.getRecipient());
} else {
TxDetail detail = originalMessage.getDetail(TxDetailType.MSG_ID);
if (detail != null)
addMessageToDuplicateStore(detail.getDetailValue(), status.getRecipient());
}
}
return retVal;
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated.
@Test
public void testGenerateDSNFailureMessage_assertMessageCreated() 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);
// 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);
assertTrue(newSubject.contains(MailStandard.getHeader(mimeMessage, MailStandard.Headers.Subject)));
// check for the original message id in the in-reply-to
String originalMessageId = MailStandard.getHeader(dsnMessage, MailStandard.Headers.InReplyTo);
assertEquals(MailStandard.getHeader(mimeMessage, MailStandard.Headers.MessageID), originalMessageId);
} finally {
IOUtils.closeQuietly(str);
}
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_IMFMessage_msgIdExists_assertMessageIdEvaluated.
@Test
public void testEvaluate_IMFMessage_msgIdExists_assertMessageIdEvaluated() {
MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
String msgId = UUID.randomUUID().toString();
Map<String, TxDetail> details = new HashMap<String, TxDetail>();
details.put(TxDetailType.MSG_ID.getType(), new TxDetail(TxDetailType.MSG_ID, msgId));
Tx tx = new Tx(TxMessageType.IMF, details);
CamelContext context = mock(CamelContext.class);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(tx);
assertEquals(msgId, exp.evaluate(exchange, String.class));
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class TestUtils method makeReliableMessage.
public static Tx makeReliableMessage(TxMessageType type, String msgId, String parentId, String from, String recip, String finalRecip, String action, String disposition) {
Map<String, TxDetail> details = new HashMap<String, TxDetail>();
if (msgId != null && !msgId.isEmpty())
details.put(TxDetailType.MSG_ID.getType(), new TxDetail(TxDetailType.MSG_ID, msgId));
if (parentId != null && !parentId.isEmpty())
details.put(TxDetailType.PARENT_MSG_ID.getType(), new TxDetail(TxDetailType.PARENT_MSG_ID, parentId));
if (from != null && !from.isEmpty())
details.put(TxDetailType.FROM.getType(), new TxDetail(TxDetailType.FROM, from));
if (recip != null && !recip.isEmpty())
details.put(TxDetailType.RECIPIENTS.getType(), new TxDetail(TxDetailType.RECIPIENTS, recip));
if (finalRecip != null && !finalRecip.isEmpty())
details.put(TxDetailType.FINAL_RECIPIENTS.getType(), new TxDetail(TxDetailType.FINAL_RECIPIENTS, finalRecip));
if (action != null && !action.isEmpty())
details.put(TxDetailType.DSN_ACTION.getType(), new TxDetail(TxDetailType.DSN_ACTION, action));
if (disposition != null && !disposition.isEmpty())
details.put(TxDetailType.DISPOSITION.getType(), new TxDetail(TxDetailType.DISPOSITION, disposition));
details.put(TxDetailType.DISPOSITION_OPTIONS.getType(), new TxDetail(TxDetailType.DISPOSITION_OPTIONS, "X-DIRECT-FINAL-DESTINATION-DELIVERY"));
return new Tx(type, details);
}
Aggregations