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));
}
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;
}
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);
}
}
}
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;
}
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();
}
Aggregations