From 08bc45d599ffb51de7511a461df28fdbadb91cb1 Mon Sep 17 00:00:00 2001 From: Mike Duff Date: Thu, 5 Sep 2013 12:01:25 -0500 Subject: [PATCH] Issue #2314 - Fix for notification center's filtering. Change-Id: I404c5c79f642908ff8c48cba23b269af9a4dc3f6 Former-commit-id: 0ad77d7f3cb13728ba8efb45c3f7f794379c28d4 [formerly 307c3cbca9732a534448eb40c4bff03573e4a975] Former-commit-id: 37896c4b81224518ffc664d6b5a2bacf6303a6e5 --- .../utils/NotificationHandler.java | 5 +- .../notification/GetNotificationRequest.java | 21 ++++++- .../event/handler/GetNotificationHandler.java | 3 +- .../event/notification/NotificationDao.java | 62 ++++++++++++------- 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NotificationHandler.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NotificationHandler.java index 2e1d7a5bfd..92834e748e 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NotificationHandler.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NotificationHandler.java @@ -30,6 +30,7 @@ import com.raytheon.uf.viz.datadelivery.notification.xml.MessageLoadXML; * ------------ ---------- ----------- -------------------------- * Mar 12, 2012 jsanchez Initial creation * Jan 22, 2013 1501 djohnson Route requests to datadelivery. + * Sep 05, 2013 2314 mpduff support the load all messages option. * * * @@ -86,9 +87,10 @@ public class NotificationHandler implements INotificationObserver { String username = null; Integer hours = null; Integer maxResults = null; - + Boolean loadAll = false; // Retrieve the message load configuration if (messageLoad != null) { + loadAll = messageLoad.isLoadAllMessages(); loadAmount = messageLoad.getLoadLast(); if (messageLoad.isNumHours()) { @@ -116,6 +118,7 @@ public class NotificationHandler implements INotificationObserver { request.setUsername(username); request.setHours(hours); request.setMaxResults(maxResults); + request.setLoadAll(loadAll); ArrayList response = (ArrayList) RequestRouter .route(request, DataDeliveryConstants.DATA_DELIVERY_SERVER); return response; diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.event/src/com/raytheon/uf/common/datadelivery/event/notification/GetNotificationRequest.java b/edexOsgi/com.raytheon.uf.common.datadelivery.event/src/com/raytheon/uf/common/datadelivery/event/notification/GetNotificationRequest.java index 595aad3367..ae707d7850 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.event/src/com/raytheon/uf/common/datadelivery/event/notification/GetNotificationRequest.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.event/src/com/raytheon/uf/common/datadelivery/event/notification/GetNotificationRequest.java @@ -14,7 +14,8 @@ import com.raytheon.uf.common.serialization.comm.IServerRequest; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Mar 1, 2012 jsanchez Initial creation + * Mar 1, 2012 jsanchez Initial creation. + * Sep 05, 2013 2314 mpduff Add loadAll. * * * @@ -33,6 +34,9 @@ public class GetNotificationRequest implements IServerRequest { @DynamicSerializeElement private Integer maxResults; + @DynamicSerializeElement + private Boolean loadAll; + /** * * @return The username(s) of the records to be retrieved @@ -92,4 +96,19 @@ public class GetNotificationRequest implements IServerRequest { this.maxResults = maxResults; } + /** + * @return the loadAll + */ + public Boolean getLoadAll() { + return loadAll; + } + + /** + * @param loadAll + * the loadAll to set + */ + public void setLoadAll(Boolean loadAll) { + this.loadAll = loadAll; + } + } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/GetNotificationHandler.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/GetNotificationHandler.java index ff2af4af24..87cb3eec80 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/GetNotificationHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/handler/GetNotificationHandler.java @@ -18,6 +18,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * Mar 7, 2012 jsanchez Initial creation * 3/18/2013 1802 bphillip Modified to use transactional boundaries and spring injection of daos + * 9/05/2013 2314 mpduff Handle Load All flag. * * * @@ -39,7 +40,7 @@ public class GetNotificationHandler extends AbstractHandler implements throws Exception { List notifications = notificationDao .lookupNotifications(request.getUsername(), request.getHours(), - request.getMaxResults()); + request.getMaxResults(), request.getLoadAll()); return notifications; } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/notification/NotificationDao.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/notification/NotificationDao.java index 2b1ad641f1..ad9e09fe52 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/notification/NotificationDao.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.event/src/com/raytheon/uf/edex/datadelivery/event/notification/NotificationDao.java @@ -1,8 +1,10 @@ package com.raytheon.uf.edex.datadelivery.event.notification; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.List; +import java.util.regex.Pattern; import com.raytheon.uf.common.datadelivery.event.notification.NotificationRecord; import com.raytheon.uf.edex.database.DataAccessLayerException; @@ -21,6 +23,7 @@ import com.raytheon.uf.edex.database.dao.SessionManagedDao; * Mar 1, 2012 jsanchez Initial creation * 3/18/2013 1802 bphillip Modified to use transactional boundaries and spring injection of daos * 4/9/2013 1802 bphillip Changed to use new query method signatures in SessionManagedDao + * 09/05/2013 2314 mpduff Change query to an "in" query for user names. * * * @@ -29,6 +32,7 @@ import com.raytheon.uf.edex.database.dao.SessionManagedDao; */ public class NotificationDao extends SessionManagedDao { + private static final Pattern SPLIT_PATTERN = Pattern.compile(","); /** * Creates a new data access object @@ -47,42 +51,56 @@ public class NotificationDao extends * can be to be retrieved * @param maxResults * The max result of records to retrieve - * @return the Notificaion records based on passed contraints. The records + * @param loadAll + * Load all messages flag + * @return the Notification records based on passed constraints. The records * are in descending order based on date */ public List lookupNotifications(String username, - Integer hours, Integer maxResults) { - String hql = "from NotificationRecord rec"; - String nameClause = " rec.username=:userName "; + Integer hours, Integer maxResults, Boolean loadAll) { + StringBuilder hql = new StringBuilder("from NotificationRecord rec"); + String nameClause = " rec.username in (:userNames) "; String dateClause = " rec.date >= :date "; Calendar latestTime = null; + List userNames = null; + if (hours != null) { latestTime = Calendar.getInstance(); latestTime.add(Calendar.HOUR, -hours); } - List params = new ArrayList(); - if (username == null && hours != null) { - hql += " where " + dateClause; - params.add("date"); - params.add(latestTime); - } else if (username != null && hours == null) { - hql += " where " + nameClause; - params.add("userName"); - params.add(username); - } else if (username != null && hours != null) { - hql += " where " + nameClause + " and " + dateClause; - params.add("date"); - params.add(latestTime); - params.add("userName"); - params.add(username); + if (username != null) { + String[] users = SPLIT_PATTERN.split(username); + userNames = Arrays.asList(users); } - hql += " order by rec.date desc"; + List params = new ArrayList(); + if (userNames == null && hours != null) { + if (!loadAll) { + hql.append(" where ").append(dateClause); + params.add("date"); + params.add(latestTime); + } + } else if (userNames != null && hours == null) { + hql.append(" where ").append(nameClause); + params.add("userNames"); + params.add(userNames); + } else if (userNames != null && hours != null) { + hql.append(" where ").append(nameClause); + if (!loadAll) { + hql.append(" and ").append(dateClause); + params.add("date"); + params.add(latestTime); + } + params.add("userNames"); + params.add(userNames); + } + hql.append(" order by rec.date desc"); if (maxResults == null) { - return this.query(hql, params.toArray(new Object[params.size()])); + return this.query(hql.toString(), + params.toArray(new Object[params.size()])); } else { - return this.query(hql, maxResults, + return this.query(hql.toString(), maxResults, params.toArray(new Object[params.size()])); } }