use of org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException 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.monitor.processor.DuplicateNotificationStateManagerException in project nhin-d by DirectProject.
the class DefaultDuplicateNotificationStateManager_suppressNotificationTest method testAddNotification_daoError_assertException.
@SuppressWarnings("unchecked")
@Test
public void testAddNotification_daoError_assertException() throws Exception {
DefaultDuplicateNotificationStateManager mgr = new DefaultDuplicateNotificationStateManager();
boolean execptionOccured = false;
NotificationDuplicationDAO spyDao = mock(NotificationDuplicationDAO.class);
doThrow(new NotificationDAOException("")).when(spyDao).getReceivedAddresses((String) any(), (Collection<String>) any());
mgr.setDao(spyDao);
try {
Tx tx = TestUtils.makeMessage(TxMessageType.DSN, "1234", "5678", "", "", "gm2552@cerner.com,ah4626@cerner.com");
mgr.suppressNotification(tx);
} catch (DuplicateNotificationStateManagerException e) {
execptionOccured = true;
}
assertTrue(execptionOccured);
}
use of org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException in project nhin-d by DirectProject.
the class TxResource_suppressNotificationTest method testSuppressNotification_mgrException_assert500StatusCode.
@Test
public void testSuppressNotification_mgrException_assert500StatusCode() throws Exception {
Tx tx = mock(Tx.class);
DuplicateNotificationStateManager dupMgr = mock(DuplicateNotificationStateManager.class);
when(dupMgr.suppressNotification(tx)).thenThrow(new DuplicateNotificationStateManagerException());
TxsResource resource = new TxsResource(null, dupMgr);
Response res = resource.supressNotification(tx);
assertEquals(500, res.getStatus());
}
use of org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException 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.monitor.processor.DuplicateNotificationStateManagerException in project nhin-d by DirectProject.
the class DefaultDuplicateNotificationStateManager method addNotification.
/**
* {@inheritDoc}
*/
@Override
public void addNotification(Tx notificationMessage) throws DuplicateNotificationStateManagerException {
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 originalMessageIdDetail = notificationMessage.getDetail(TxDetailType.PARENT_MSG_ID);
final TxDetail origRecips = notificationMessage.getDetail(TxDetailType.FINAL_RECIPIENTS);
if (originalMessageIdDetail != null && origRecips != null) {
for (String recipAddress : origRecips.getDetailValue().split(",")) {
try {
dao.addNotification(originalMessageIdDetail.getDetailValue(), recipAddress);
} catch (NotificationDAOException e) {
throw new DuplicateNotificationStateManagerException(e);
}
}
}
}
}
Aggregations