Search in sources :

Example 11 with NotificationDAOException

use of org.nhindirect.monitor.dao.NotificationDAOException 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)

Example 12 with NotificationDAOException

use of org.nhindirect.monitor.dao.NotificationDAOException in project nhin-d by DirectProject.

the class DefaultDuplicateNotificationStateManager_addNotificationTest method testAddNotification_daoError_assertException.

@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).addNotification((String) any(), (String) any());
    mgr.setDao(spyDao);
    try {
        Tx tx = TestUtils.makeMessage(TxMessageType.DSN, "1234", "5678", "", "", "gm2552@cerner.com,ah4626@cerner.com");
        mgr.addNotification(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)

Aggregations

NotificationDAOException (org.nhindirect.monitor.dao.NotificationDAOException)12 TxDetail (org.nhindirect.common.tx.model.TxDetail)5 DuplicateNotificationStateManagerException (org.nhindirect.monitor.processor.DuplicateNotificationStateManagerException)5 Test (org.junit.Test)3 Tx (org.nhindirect.common.tx.model.Tx)3 TxMessageType (org.nhindirect.common.tx.model.TxMessageType)3 NotificationDuplicationDAO (org.nhindirect.monitor.dao.NotificationDuplicationDAO)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Query (javax.persistence.Query)2 Calendar (java.util.Calendar)1 ReceivedNotification (org.nhindirect.monitor.dao.entity.ReceivedNotification)1