use of org.nhindirect.monitor.dao.NotificationDAOException in project nhin-d by DirectProject.
the class NotificationDuplicationDAOImpl method getReceivedAddresses.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public Set<String> getReceivedAddresses(String messageId, Collection<String> addresses) throws NotificationDAOException {
validateState();
if (addresses == null || addresses.size() == 0)
return Collections.emptySet();
if (messageId == null || messageId.isEmpty())
return Collections.emptySet();
Collection<String> rs;
Set<String> retVal;
final StringBuffer ids = new StringBuffer("(");
for (String tp : addresses) {
if (ids.length() > 1) {
ids.append(", ");
}
ids.append("'").append(tp.toLowerCase(Locale.getDefault())).append("'");
}
ids.append(")");
try {
final String query = "SELECT address from ReceivedNotification rn WHERE rn.messageid = ?1 and rn.address IN " + ids.toString();
final Query select = entityManager.createQuery(query);
select.setParameter(1, messageId.toLowerCase(Locale.getDefault()));
rs = (Collection<String>) select.getResultList();
if (rs == null || rs.size() == 0)
return Collections.emptySet();
retVal = new HashSet<String>(rs);
}///CLOVER:OFF
catch (Exception e) {
throw new NotificationDAOException("Failed to execute received notification DAO query.", e);
}
///CLOVER:ON
return retVal;
}
use of org.nhindirect.monitor.dao.NotificationDAOException 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.dao.NotificationDAOException in project nhin-d by DirectProject.
the class DefaultDuplicateNotificationStateManager method purge.
/**
* {@inheritDoc}
*/
@Override
public void purge() {
if (dao == null)
throw new IllegalArgumentException("Dao cannot be null");
try {
final Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.add(Calendar.HOUR, -(24 * messageRetention));
dao.purgeNotifications(cal);
} catch (NotificationDAOException e) {
LOGGER.warn("Message duplication state purge failed.", e);
}
}
use of org.nhindirect.monitor.dao.NotificationDAOException in project nhin-d by DirectProject.
the class TimeoutDupStateManager method addNotificationForOriginalRecips.
/**
* Adds a duplication state entry for each recipient of the original message
* @param txs Collection of message transactions. The original message must be present in the collection
* @throws DuplicateNotificationStateManagerException
*/
public void addNotificationForOriginalRecips(Collection<Tx> txs) throws DuplicateNotificationStateManagerException {
if (dao == null)
throw new IllegalArgumentException("Dao cannot be null");
if (txs == null)
throw new IllegalArgumentException("Txs cannot be null");
final Tx tx = AbstractCompletionCondition.getMessageToTrack(txs);
if (tx != null && TxUtil.isReliableAndTimelyRequested(tx)) {
final TxDetail recipDetail = tx.getDetail(TxDetailType.RECIPIENTS);
final TxDetail msgId = tx.getDetail(TxDetailType.MSG_ID);
if (recipDetail != null && msgId != null) {
final String[] recips = recipDetail.getDetailValue().split(",");
for (String recip : recips) {
try {
final String normalizedFinalRecip = AbstractCompletionCondition.normalizeFinalRecip(recip);
dao.addNotification(msgId.getDetailValue(), normalizedFinalRecip);
}///CLOVER:OFF
catch (NotificationDAOException e) {
LOGGER.warn("Can't add recipient " + recip + " for message id " + msgId.getDetailValue() + " to dup store. Possibly already exists in dup store.");
}
///CLOVER:ON
}
}
}
}
use of org.nhindirect.monitor.dao.NotificationDAOException in project nhin-d by DirectProject.
the class NotificationDuplicationDAOImpl method purgeNotifications.
/**
* {@inheritDoc}
*/
@Override
@Transactional(readOnly = false)
public void purgeNotifications(Calendar purgeTime) throws NotificationDAOException {
validateState();
try {
final Query delete = entityManager.createQuery("DELETE FROM ReceivedNotification rn where rn.receivedTime < ?1");
delete.setParameter(1, purgeTime);
delete.executeUpdate();
entityManager.flush();
}///CLOVER:OFF
catch (Exception rt) {
throw new NotificationDAOException("Failed to execute delete.", rt);
}
///CLOVER:ON
}
Aggregations