Search in sources :

Example 1 with NotificationDAOException

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

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

Example 3 with NotificationDAOException

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

the class DefaultDuplicateNotificationStateManager_purgeTest method testPurgeNotification_daoError_assertException.

@Test
public void testPurgeNotification_daoError_assertException() throws Exception {
    DefaultDuplicateNotificationStateManager mgr = new DefaultDuplicateNotificationStateManager();
    NotificationDuplicationDAO spyDao = mock(NotificationDuplicationDAO.class);
    doThrow(new NotificationDAOException("")).when(spyDao).purgeNotifications((Calendar) any());
    mgr.setDao(spyDao);
    mgr.purge();
}
Also used : NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) NotificationDuplicationDAO(org.nhindirect.monitor.dao.NotificationDuplicationDAO) Test(org.junit.Test)

Example 4 with NotificationDAOException

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

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

the class NotificationDuplicationDAOImpl method addNotification.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void addNotification(String messageId, String address) throws NotificationDAOException {
    validateState();
    try {
        final Collection<String> notification = this.getReceivedAddresses(messageId, Arrays.asList(address));
        if (!notification.isEmpty()) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Notification for message id " + messageId + " and address " + address + " already received.  Not adding to received notification store.");
            return;
        }
        final ReceivedNotification notif = new ReceivedNotification();
        notif.setMessageid(messageId);
        notif.setAddress(address);
        notif.setReceivedTime(Calendar.getInstance(Locale.getDefault()));
        entityManager.persist(notif);
        entityManager.flush();
    }///CLOVER:OFF
     catch (Exception e) {
        throw new NotificationDAOException("Failed to add notification to the store.", e);
    }
///CLOVER:ON
}
Also used : ReceivedNotification(org.nhindirect.monitor.dao.entity.ReceivedNotification) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) NotificationDAOException(org.nhindirect.monitor.dao.NotificationDAOException) Transactional(org.springframework.transaction.annotation.Transactional)

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