Search in sources :

Example 1 with DuplicateNotificationStateManagerException

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;
}
Also used : TxDetail(org.nhindirect.common.tx.model.TxDetail) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) TxMessageType(org.nhindirect.common.tx.model.TxMessageType)

Example 2 with DuplicateNotificationStateManagerException

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);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) Test(org.junit.Test)

Example 3 with DuplicateNotificationStateManagerException

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());
}
Also used : Response(javax.ws.rs.core.Response) DuplicateNotificationStateManager(org.nhindirect.monitor.processor.DuplicateNotificationStateManager) Tx(org.nhindirect.common.tx.model.Tx) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) Test(org.junit.Test)

Example 4 with DuplicateNotificationStateManagerException

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;
}
Also used : TxDetail(org.nhindirect.common.tx.model.TxDetail) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) TxMessageType(org.nhindirect.common.tx.model.TxMessageType)

Example 5 with DuplicateNotificationStateManagerException

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);
                }
            }
        }
    }
}
Also used : TxDetail(org.nhindirect.common.tx.model.TxDetail) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) DuplicateNotificationStateManagerException(org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException) TxMessageType(org.nhindirect.common.tx.model.TxMessageType)

Aggregations

DuplicateNotificationStateManagerException (org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException)6 NotificationDAOException (org.nhindirect.monitor.dao.NotificationDAOException)5 Test (org.junit.Test)3 Tx (org.nhindirect.common.tx.model.Tx)3 TxDetail (org.nhindirect.common.tx.model.TxDetail)3 TxMessageType (org.nhindirect.common.tx.model.TxMessageType)3 NotificationDuplicationDAO (org.nhindirect.monitor.dao.NotificationDuplicationDAO)2 Response (javax.ws.rs.core.Response)1 DuplicateNotificationStateManager (org.nhindirect.monitor.processor.DuplicateNotificationStateManager)1