diff --git a/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java b/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java index d4bb663924..a1378d8954 100644 --- a/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java +++ b/cave/com.raytheon.uf.viz.product.alertviz/src/com/raytheon/uf/viz/product/alertviz/AlertVizApplication.java @@ -44,6 +44,7 @@ import com.raytheon.uf.viz.core.localization.CAVELocalizationNotificationObserve import com.raytheon.uf.viz.core.localization.LocalizationConstants; import com.raytheon.uf.viz.core.localization.LocalizationInitializer; import com.raytheon.uf.viz.core.localization.LocalizationManager; +import com.raytheon.uf.viz.core.notification.jobs.NotificationManagerJob; /** * @@ -55,6 +56,7 @@ import com.raytheon.uf.viz.core.localization.LocalizationManager; * ------------ ---------- ----------- -------------------------- * Sep 29, 2008 #1433 chammack Initial creation * Jan 12, 2012 #27 rferrel Added createAlertVisualization + * May 08, 2013 1939 rjpeter Updated to start NotificationManagerJob. * * * @author chammack @@ -128,6 +130,10 @@ public class AlertVizApplication implements IStandaloneComponent { // Job is not running on port, launch UI. AlertVisualization av = createAlertVisualization(true, display); + + // open JMS connection to allow alerts to be received + NotificationManagerJob.connect(); + Throwable t = null; try { while (!display.isDisposed()) { @@ -153,17 +159,18 @@ public class AlertVizApplication implements IStandaloneComponent { display.dispose(); if (t != null) { // Killed because of error, set exit status to non zero value - return IApplication.EXIT_RELAUNCH; + return IApplication.EXIT_RELAUNCH; } } return av.getExitStatus(); } - + protected AlertVisualization createAlertVisualization( - boolean runningStandalone, final Display display) { - return new AlertVisualization(runningStandalone, display); + boolean runningStandalone, final Display display) { + return new AlertVisualization(runningStandalone, display); } + protected void initializeObservers() { CAVELocalizationNotificationObserver.register(); } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java index 3f4ac1869a..75c9c60c19 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java @@ -997,23 +997,29 @@ public class GFEDao extends DefaultPluginDao { sess = getHibernateTemplate().getSessionFactory() .openStatelessSession(); tx = sess.beginTransaction(); + // use intersection of time range, UPDATE statement don't auto join + // table so have to manually select the id Query query = sess .createQuery("UPDATE GridDataHistory SET lastSentTime = ?" - + " WHERE parent.parmId = ? AND parent.dataTime.validPeriod.start >= ?" - + " AND parent.dataTime.validPeriod.end >= ?"); - query.setParameter(0, parmId); - query.setTimestamp(1, tr.getStart()); + + " WHERE parent.id in (SELECT id FROM GFERecord " + + " WHERE parmId = ?" + + " AND dataTime.validPeriod.start < ?" + + " AND dataTime.validPeriod.end > ?)"); + query.setTimestamp(0, sentTime); + query.setParameter(1, parmId); query.setTimestamp(2, tr.getEnd()); + query.setTimestamp(3, tr.getStart()); query.executeUpdate(); + // use intersection of time range query = sess .createQuery("SELECT hist.parent.dataTime.validPeriod, hist " + "FROM GridDataHistory hist" - + " WHERE hist.parent.parmId = ? AND hist.parent.dataTime.validPeriod.start >= ?" - + " AND hist.parent.dataTime.validPeriod.end >= ?"); + + " WHERE hist.parent.parmId = ? AND hist.parent.dataTime.validPeriod.start < ?" + + " AND hist.parent.dataTime.validPeriod.end > ?"); query.setParameter(0, parmId); - query.setTimestamp(1, tr.getStart()); - query.setTimestamp(2, tr.getEnd()); + query.setTimestamp(1, tr.getEnd()); + query.setTimestamp(2, tr.getStart()); rows = query.list(); tx.commit(); } catch (Exception e) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFELockDao.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFELockDao.java index 884b7ffe9c..eabd41a41c 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFELockDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFELockDao.java @@ -75,8 +75,8 @@ public class GFELockDao extends CoreDao { * If errors occur during database interaction */ @SuppressWarnings("unchecked") - public Map getLocks(final List parmIds, WsId wsId) - throws DataAccessLayerException { + public Map getLocks(final Collection parmIds, + WsId wsId) throws DataAccessLayerException { // Return if no parmIDs are provided if (parmIds.isEmpty()) { return Collections.emptyMap(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java index d14101ffab..6e8c94dd2f 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java @@ -34,11 +34,10 @@ import jep.JepException; import com.raytheon.edex.plugin.gfe.config.GFESiteActivation; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.db.dao.GFEDao; import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.database.GridDatabase; import com.raytheon.edex.plugin.gfe.util.SendNotifications; -import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -48,7 +47,6 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.edex.core.EDEXUtil; -import com.raytheon.uf.edex.database.plugin.PluginFactory; /** * Class to for running the isc scripts @@ -200,28 +198,25 @@ public class IscSendJob implements Runnable { } try { - // TODO: Interact with IFPGridDatabase - GFEDao dao = (GFEDao) PluginFactory.getInstance().getPluginDao( - "gfe"); - - ServerResponse> sr = GridParmManager - .getGridInventory(id); - if (!sr.isOkay()) { - statusHandler.error("Error getting inventory for " + id); - return; - } - - WsId wsId = new WsId(InetAddress.getLocalHost(), "ISC", "ISC"); - - List notifications = new ArrayList( - 1); - Map> histories = dao + GridDatabase gridDb = GridParmManager.getDb(id.getDbId()); + ServerResponse>> sr = gridDb .updateSentTime(id, tr, new Date()); - notifications.add(new GridHistoryUpdateNotification(id, - histories, wsId, siteId)); - SendNotifications.send(notifications); - } catch (PluginException e) { - statusHandler.error("Error creating GFE dao!", e); + if (sr.isOkay()) { + WsId wsId = new WsId(InetAddress.getLocalHost(), "ISC", + "ISC"); + List notifications = new ArrayList( + 1); + Map> histories = sr + .getPayload(); + notifications.add(new GridHistoryUpdateNotification(id, + histories, wsId, siteId)); + SendNotifications.send(notifications); + + } else { + statusHandler + .error("Error updating last sent times in GFERecords: " + + sr.getMessages()); + } } catch (Exception e) { statusHandler.error( "Error updating last sent times in GFERecords.", e); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java index 9abe650305..f1542f98da 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java @@ -479,6 +479,24 @@ public abstract class GridDatabase { + this.getClass().getName()); } + /** + * Updates the sent time for all histories of passed parmId during the + * timeRange. The histories are then returned in a map by timeRange. + * + * @param parmId + * the parmId to use + * @param tr + * the time range to update sent time for + * @param sentTime + * the sent time to update to + * @return + */ + public ServerResponse>> updateSentTime( + final ParmID parmId, TimeRange tr, Date sentTime) { + throw new UnsupportedOperationException("Not implemented for class " + + this.getClass().getName()); + } + public ServerResponse saveGridSlices(ParmID parmId, TimeRange tr, List sliceData, WsId requestor, List skipDelete) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java index 6ac5804b42..0759db12f7 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java @@ -2555,6 +2555,7 @@ public class IFPGridDatabase extends GridDatabase { public ServerResponse updatePublishTime(List history, Date publishTime) { ServerResponse sr = new ServerResponse(); + GFEDao dao = null; try { dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); @@ -2566,6 +2567,7 @@ public class IFPGridDatabase extends GridDatabase { "Unable to update grid history!", e); sr.addMessage("Error updating history"); } + return sr; } @@ -2592,4 +2594,35 @@ public class IFPGridDatabase extends GridDatabase { return rval; } + + /** + * Updates the sent time for all histories of passed parmId during the + * timeRange. The histories are then returned in a map by timeRange. + * + * @param parmId + * the parmId to use + * @param tr + * the time range to update sent time for + * @param sentTime + * the sent time to update to + * @return + */ + @Override + public ServerResponse>> updateSentTime( + final ParmID parmId, TimeRange tr, Date sentTime) { + ServerResponse>> sr = new ServerResponse>>(); + try { + ParmID dbParmId = getCachedParmID(parmId); + GFEDao dao = new GFEDao(); + sr.setPayload(dao.updateSentTime(dbParmId, tr, sentTime)); + } catch (UnknownParmIdException e) { + sr.addMessage(e.getLocalizedMessage()); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "Unable to update grid history last sent time", e); + sr.addMessage("Unable to update grid history last sent time"); + } + + return sr; + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java index 6d9e91cbc0..60cb3fbaaf 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java @@ -119,12 +119,41 @@ public class LockManager { } // extract the ParmIds from the request list - List parmIds = new ArrayList(); + Set parmIds = new HashSet(); try { sr.addMessages(extractParmIds(request, parmIds, siteID)); + List nonIfpParmIds = new LinkedList(); - sr.setPayload(new ArrayList(dao.getLocks(parmIds, - requestor).values())); + // remove parm IDs that are not persisted to database + Iterator iter = parmIds.iterator(); + while (iter.hasNext()) { + ParmID id = iter.next(); + if (id.getId() == 0) { + nonIfpParmIds.add(id); + iter.remove(); + } + } + + List payLoad = null; + + if (!parmIds.isEmpty()) { + Map lockMap = dao.getLocks(parmIds, + requestor); + payLoad = new ArrayList(lockMap.size() + + nonIfpParmIds.size()); + payLoad.addAll(lockMap.values()); + } else { + payLoad = new ArrayList(nonIfpParmIds.size()); + } + + if (!nonIfpParmIds.isEmpty()) { + for (ParmID id : nonIfpParmIds) { + payLoad.add(new LockTable(id, new ArrayList(0), + requestor)); + } + } + + sr.setPayload(payLoad); } catch (Exception e) { logger.error("Error getting lock tables for " + parmIds, e); sr.addMessage("Error getting lock tables for " + parmIds); @@ -214,12 +243,22 @@ public class LockManager { return sr; } - List parmIds = new LinkedList(); + Set parmIds = new HashSet(); Map lockTableMap; try { // extract the ParmIds from the requests sr.addMessages(extractParmIdsFromLockReq(req, parmIds, siteID)); + Iterator iter = parmIds.iterator(); + while (iter.hasNext()) { + ParmID id = iter.next(); + // non persisted parm IDs cannot be locked + if (id.getId() == 0) { + sr.addMessage("ParmID " + id + " is not a lockable parm"); + iter.remove(); + } + } + // get the lock tables specific to the extracted parmIds lockTableMap = dao.getLocks(parmIds, requestor); } catch (Exception e) { @@ -681,14 +720,14 @@ public class LockManager { * @throws GfeException */ private ServerResponse extractParmIds(List ltrList, - List parmIds, String siteID) throws GfeException { + Set parmIds, String siteID) throws GfeException { ServerResponse sr = new ServerResponse(); // process each request for (LockTableRequest ltr : ltrList) { if (ltr.isParmRequest()) { ParmID parmId = ltr.getParmId(); - // append parm (if not already in the list) + // append parm (if not already in the set) if (!parmIds.contains(parmId)) { parmIds.add(GridParmManager.getDb(parmId.getDbId()) .getCachedParmID(parmId)); @@ -697,11 +736,7 @@ public class LockManager { // get all the parmIds for that databaseId List pids = GridParmManager.getParmList(ltr.getDbId()) .getPayload(); - for (ParmID id : pids) { - if (!parmIds.contains(id)) { - parmIds.add(id); - } - } + parmIds.addAll(pids); } else { // get all the parms for all the databases List dbids = GridParmManager.getDbInventory(siteID) @@ -709,11 +744,7 @@ public class LockManager { for (int j = 0; j < dbids.size(); j++) { List pids = GridParmManager.getParmList( dbids.get(j)).getPayload(); - for (ParmID id : pids) { - if (!parmIds.contains(id)) { - parmIds.add(id); - } - } + parmIds.addAll(pids); } } } @@ -738,7 +769,7 @@ public class LockManager { * If errors occur */ private ServerResponse extractParmIdsFromLockReq(List lrs, - List parmIds, String siteID) throws GfeException { + Set parmIds, String siteID) throws GfeException { ServerResponse sr = new ServerResponse(); // process each request