use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class TimeoutDupStateManager 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) {
final String[] recipsArray = origRecips.getDetailValue().split(",");
for (int idx = 0; idx < recipsArray.length; ++idx) recipsArray[idx] = AbstractCompletionCondition.normalizeFinalRecip(recipsArray[idx]);
final Collection<String> recips = Arrays.asList(recipsArray);
try {
// try by tabbular concatenation first... we need to make sure DSN messages
// generated by the message monitor are not supressed... these messages
// should be the only ones that use the tabbular format
final String queryMsgId = originalMessageIdDetail.getDetailValue() + "\t" + notificationMessage.getDetail(TxDetailType.MSG_ID).getDetailValue();
Set<String> alreadyReceivedNotifs = dao.getReceivedAddresses(queryMsgId, recips);
if (!alreadyReceivedNotifs.isEmpty())
// this is from a DSN message generated by the monitor... don't suppress it
retVal = false;
else {
// ok, so it's not in the tabular list... so just do the normal suppression test
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 TimeoutDupStateManager method addNotificationForMonitorGeneratedDSN.
/**
* Adds a duplication state entry for each final recipient in a DSN message that was generated by the message monitor
* @param dsnMessage The DSN message
* @param ex The aggregation exchange. The property "ORGI_IS_TIMELY" is checked to see if this DSN is part of a timely and reliable
* exchange
* @throws DuplicateNotificationStateManagerException
*/
public void addNotificationForMonitorGeneratedDSN(MimeMessage dsnMessage, Exchange ex) throws DuplicateNotificationStateManagerException {
if (dao == null)
throw new IllegalArgumentException("Dao cannot be null");
if (dsnMessage == null)
throw new IllegalArgumentException("DSN message cannot be null");
if (TxUtil.getMessageType(dsnMessage).equals(TxMessageType.DSN) && ex.getProperty("ORIG_IS_TIMELY") != null) {
final Map<String, TxDetail> details = parser.getMessageDetails(dsnMessage);
final TxDetail origMsgId = details.get(TxDetailType.PARENT_MSG_ID.getType());
final TxDetail finalRecipDetail = details.get(TxDetailType.FINAL_RECIPIENTS.getType());
final TxDetail msgId = details.get(TxDetailType.MSG_ID.getType());
if (origMsgId != null && finalRecipDetail != null && msgId != null) {
final String[] finalRecips = finalRecipDetail.getDetailValue().split(",");
for (String finalRecip : finalRecips) {
try {
final String normalizedFinalRecip = AbstractCompletionCondition.normalizeFinalRecip(finalRecip);
final String addMsgId = origMsgId.getDetailValue() + "\t" + msgId.getDetailValue();
dao.addNotification(addMsgId, normalizedFinalRecip);
// also write it out with just the orig message id
// this is needed for DSN messages that are not generated by the message monitor
// so we can ensure that later messages are properly suppressed
dao.addNotification(origMsgId.getDetailValue(), normalizedFinalRecip);
}///CLOVER:OFF
catch (NotificationDAOException e) {
LOGGER.warn("Can't add recipient " + finalRecip + " for message id " + msgId.getDetailValue() + " to dup store. Possibly already exists in dup store.");
}
///CLOVER:ON
}
}
}
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class AbstractCompletionCondition_getMessageToTrackTest method testGetMessageToTrack_assertMessageFound.
@Test
public void testGetMessageToTrack_assertMessageFound() {
ConditionAdapter condition = new ConditionAdapter();
Tx tx = new Tx(TxMessageType.IMF, new HashMap<String, TxDetail>());
List<Tx> txs = Arrays.asList(tx);
Tx foundTx = condition.getMessageToTrackInternal(txs);
assertEquals(tx, foundTx);
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject.
@Test
public void testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject() 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);
mimeMessage.setHeader(MailStandard.Headers.Subject, "");
// 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);
assertEquals("Not Delivered:", newSubject);
} finally {
IOUtils.closeQuietly(str);
}
}
use of org.nhindirect.common.tx.model.TxDetail in project nhin-d by DirectProject.
the class MessageIdCorrelationExpression_evaluateTest method testEvaluate_emptyDetails_assertNullId.
@Test
public void testEvaluate_emptyDetails_assertNullId() {
MessageIdCorrelationExpression exp = new MessageIdCorrelationExpression();
Tx tx = new Tx(TxMessageType.IMF, new HashMap<String, TxDetail>());
CamelContext context = mock(CamelContext.class);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(tx);
assertNull(exp.evaluate(exchange, String.class));
}
Aggregations