Issue #2314 - Fix for notification center's filtering.

Change-Id: I404c5c79f642908ff8c48cba23b269af9a4dc3f6

Former-commit-id: 0ad77d7f3c [formerly 307c3cbca9732a534448eb40c4bff03573e4a975]
Former-commit-id: 37896c4b81
This commit is contained in:
Mike Duff 2013-09-05 12:01:25 -05:00
parent 2e38a75945
commit 08bc45d599
4 changed files with 66 additions and 25 deletions

View file

@ -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.
*
* </pre>
*
@ -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<NotificationRecord> response = (ArrayList<NotificationRecord>) RequestRouter
.route(request, DataDeliveryConstants.DATA_DELIVERY_SERVER);
return response;

View file

@ -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.
*
* </pre>
*
@ -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;
}
}

View file

@ -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.
*
* </pre>
*
@ -39,7 +40,7 @@ public class GetNotificationHandler extends AbstractHandler implements
throws Exception {
List<NotificationRecord> notifications = notificationDao
.lookupNotifications(request.getUsername(), request.getHours(),
request.getMaxResults());
request.getMaxResults(), request.getLoadAll());
return notifications;
}

View file

@ -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.
*
* </pre>
*
@ -29,6 +32,7 @@ import com.raytheon.uf.edex.database.dao.SessionManagedDao;
*/
public class NotificationDao extends
SessionManagedDao<Integer, NotificationRecord> {
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<NotificationRecord> 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<String> userNames = null;
if (hours != null) {
latestTime = Calendar.getInstance();
latestTime.add(Calendar.HOUR, -hours);
}
List<Object> params = new ArrayList<Object>();
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<Object> params = new ArrayList<Object>();
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()]));
}
}