diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.scan/src/com/raytheon/uf/common/dataplugin/scan/ScanException.java b/edexOsgi/com.raytheon.uf.common.dataplugin.scan/src/com/raytheon/uf/common/dataplugin/scan/ScanException.java new file mode 100644 index 0000000000..c092852362 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.scan/src/com/raytheon/uf/common/dataplugin/scan/ScanException.java @@ -0,0 +1,73 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.dataplugin.scan; + +/** + * Exception specific to SCAN + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Apr 24, 2014            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +public class ScanException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * Default Constructor + * + */ + public ScanException() { + super(); + } + + /** + * @param message + */ + public ScanException(String message) { + super(message); + } + + /** + * @param message + * @param cause + */ + public ScanException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param cause + */ + public ScanException(Throwable cause) { + super(cause); + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/DATUtils.java b/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/DATUtils.java index 0b64cbd375..3143b8f76a 100644 --- a/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/DATUtils.java +++ b/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/DATUtils.java @@ -52,6 +52,7 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 06/22/09 2152 D. Hladky Initial release + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -69,8 +70,7 @@ public class DATUtils { * @param uri * @return */ - public static PluginDataObject getPDORecord(String uri, SourceXML xml) - throws PluginException { + public static PluginDataObject getPDORecord(String uri, SourceXML xml) { PluginDataObject rec = null; try { Class clazz = Class.forName(xml.getPluginClass()); @@ -104,19 +104,7 @@ public class DATUtils { gr = (GridRecord) gd.getMetadata(uri); if (gr != null) { - - IDataStore dataStore = gd.getDataStore(gr); - - try { - IDataRecord[] dataRec = dataStore.retrieve(uri); - for (int i = 0; i < dataRec.length; i++) { - if (dataRec[i] instanceof FloatDataRecord) { - gr.setMessageData(dataRec[i]); - } - } - } catch (Exception se) { - logger.error("No Grib record found....."); - } + populateGridRecord(gr); } else { logger.error("URI: " + uri + " Not in Database..."); } @@ -125,31 +113,27 @@ public class DATUtils { } /** - * Make a DB request + * Fills a GridRecord with the raw data retrieved from IDataStore * - * @param sql - * @return + * @param gr + * @throws PluginException */ - public static Object[] dbRequest(String sql) { - - logger.debug("SQL to run: " + sql); - CoreDao cdao = null; - Object[] results = null; - try { - if (cdao == null) { - try { - cdao = new CoreDao(DaoConfig.DEFAULT); - } catch (Exception ed1) { - logger.error("Core DAO access failed. " + ed1); + public static void populateGridRecord(GridRecord gr) throws PluginException { + if (gr != null) { + PluginDao gd = PluginFactory.getInstance().getPluginDao( + gr.getPluginName()); + IDataStore dataStore = gd.getDataStore(gr); + try { + IDataRecord[] dataRec = dataStore.retrieve(gr.getDataURI()); + for (int i = 0; i < dataRec.length; i++) { + if (dataRec[i] instanceof FloatDataRecord) { + gr.setMessageData(dataRec[i]); + } } + } catch (Exception e) { + logger.error("Error retrieving grid data for " + gr, e); } - results = cdao.executeSQLQuery(sql); - - } catch (Exception ed2) { - logger.error("SQL Query Failed to process. SQL=" + sql + " : " - + ed2); } - return results; } /** @@ -159,7 +143,9 @@ public class DATUtils { * @param startTime * @param endTime * @return + * @deprecated Nothing seems to be calling this.... */ + @Deprecated public static FFMPVirtualGageBasin getVirtualBasinData(String lid, FFMPVirtualGageBasin vgb, String endTime, String startTime) { @@ -229,13 +215,6 @@ public class DATUtils { } } - int totalDurations = 0; - for (int dur : durations) { - totalDurations += dur; - } - - int avDuration = totalDurations / durations.size(); - float totalVals = 0.0f; for (float val : values) { totalVals += val; @@ -263,20 +242,18 @@ public class DATUtils { * @param param * @return */ - public static GridRecord getMostRecentGridRecord(int interval, String sql, - SCANModelParameterXML param) { - + public static GridRecord getMostRecentGridRecord(int interval, + GridRecord newRec, SCANModelParameterXML param) { GridRecord rec = null; try { ScanDataCache cache = ScanDataCache.getInstance(); - Object[] obs = dbRequest(sql); - GridRecord newRec = null; - - if (obs != null && obs.length > 0) { - String uri = (String) obs[0]; - newRec = getGridRecord(uri); - } + /* + * TODO njensen: we should only spend time populating if the new rec + * replaces the old rec. Delaying that change as at present as I'm + * just trying to make it work the same as before. + */ + populateGridRecord(newRec); if (cache.getModelData().isType(param.getModelName(), param.getParameterName())) { @@ -304,9 +281,8 @@ public class DATUtils { } } } catch (Exception e) { - logger.error("DatUtils: " + param.getModelName() + ": " - + param.getParameterName() + " SQL: " + sql - + " error in retrieval.."); + logger.error("Error in retrieval: " + param.getModelName() + ": " + + param.getParameterName() + " record: " + newRec); } return rec; diff --git a/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/FreezingLevel.java b/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/FreezingLevel.java index 1415a59ff2..535f2d11f0 100644 --- a/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/FreezingLevel.java +++ b/edexOsgi/com.raytheon.uf.edex.dat.utils/src/com/raytheon/uf/edex/dat/utils/FreezingLevel.java @@ -19,21 +19,21 @@ package com.raytheon.uf.edex.dat.utils; * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map.Entry; import java.util.TreeSet; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.geometry.DirectPosition2D; import org.opengis.referencing.crs.CoordinateReferenceSystem; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; @@ -41,6 +41,9 @@ import com.raytheon.uf.common.geospatial.ISpatialObject; import com.raytheon.uf.common.geospatial.MapUtil; import com.raytheon.uf.common.geospatial.PointUtil; import com.raytheon.uf.common.monitor.xml.SCANModelParameterXML; +import com.raytheon.uf.edex.database.plugin.PluginDao; +import com.raytheon.uf.edex.database.plugin.PluginFactory; +import com.raytheon.uf.edex.database.query.DatabaseQuery; import com.vividsolutions.jts.geom.Coordinate; /** @@ -56,6 +59,7 @@ import com.vividsolutions.jts.geom.Coordinate; * 19Nov 2011 dhladky Initial creation * 29 Jan 2013 15729 wkwock fix the algorithm * Jan 07, 2013 njensen Change some logs to debug + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -86,8 +90,9 @@ public class FreezingLevel { // reference time Calendar refTime = null; + private transient final Log logger = LogFactory.getLog(getClass()); - + public FreezingLevel(String modelName) { this.modelName = modelName; times = new HashMap(); @@ -112,72 +117,80 @@ public class FreezingLevel { /** * find (x,y) coordinate for lat,lon(coor) + * * @param coors */ - public DirectPosition2D findXYloc(Coordinate coor, String type){ + public DirectPosition2D findXYloc(Coordinate coor, String type) { ScanDataCache cache = ScanDataCache.getInstance(); - ISpatialObject iso = cache.getModelData().getGridRecord(modelName, type).getSpatialObject(); - CoordinateReferenceSystem crs=iso.getCrs(); + ISpatialObject iso = cache.getModelData() + .getGridRecord(modelName, type).getSpatialObject(); + CoordinateReferenceSystem crs = iso.getCrs(); GridGeometry2D mapGeometry = MapUtil.getGridGeometry(iso); DirectPosition2D resultPoint; try { - resultPoint = PointUtil.determineExactIndex( - coor, crs, mapGeometry); - return resultPoint; - } catch (Exception e) { - logger.error("Error: Freezing level -- unable to find x,y coordinate for lat,lon:"+coor); + resultPoint = PointUtil.determineExactIndex(coor, crs, mapGeometry); + return resultPoint; + } catch (Exception e) { + logger.error("Error: Freezing level -- unable to find x,y coordinate for lat,lon:" + + coor); } - return null; + return null; } - + /** * get the bi-linear interpolation value amount the nearest 4 points * - * @param modelName, prodType, coor + * @param modelName + * , prodType, coor * @return bi-linear interpolation amount the nearest 4 points * @throws VizException */ public Double getValue(String modelName, String prodType, Coordinate coor) { double value = -99999.0; try { - //xyLoc is the location in x,y - DirectPosition2D xyLoc = findXYloc(coor, prodType); + // xyLoc is the location in x,y + DirectPosition2D xyLoc = findXYloc(coor, prodType); - //data from hdf5 - ScanDataCache cache = ScanDataCache.getInstance(); - GridRecord gribRec = cache.getModelData().getGridRecord(modelName, prodType); + // data from hdf5 + ScanDataCache cache = ScanDataCache.getInstance(); + GridRecord gribRec = cache.getModelData().getGridRecord(modelName, + prodType); FloatDataRecord rec = (FloatDataRecord) gribRec.getMessageData(); - - //dimension of the record from hdf5, recNx =151 and recNy=113 during development + + // dimension of the record from hdf5, recNx =151 and recNy=113 + // during development int recNx = gribRec.getSpatialObject().getNx(); - - //get four nearest points/values form the record around xyLoc - xyLoc.y=xyLoc.y * 0.9941; //A special adjustment due to PointUtil.determineExactIndex - xyLoc.x=xyLoc.x * 0.9983; // is not as accurate as A1 - int x0=(int)(xyLoc.x); - int x1=x0+1; - int y0=(int)(xyLoc.y); - int y1=y0+1; + // get four nearest points/values form the record around xyLoc + xyLoc.y = xyLoc.y * 0.9941; // A special adjustment due to + // PointUtil.determineExactIndex + xyLoc.x = xyLoc.x * 0.9983; // is not as accurate as A1 + + int x0 = (int) (xyLoc.x); + int x1 = x0 + 1; + int y0 = (int) (xyLoc.y); + int y1 = y0 + 1; + + double p1 = xyLoc.x - x0; + double p2 = 1 - p1; + double p3 = xyLoc.y - y0; + double p4 = 1 - p3; - double p1=xyLoc.x-x0; - double p2=1-p1; - double p3=xyLoc.y-y0; - double p4=1-p3; - double value0 = rec.getFloatData()[(recNx * y0) + x0]; double value1 = rec.getFloatData()[(recNx * y0) + x1]; double value2 = rec.getFloatData()[(recNx * y1) + x0]; double value3 = rec.getFloatData()[(recNx * y1) + x1]; - //do a bi-linear interpolation amount the nearest 4 points - value = (p1*p4*value1)+(p2*p4*value0)+(p1*p3*value3)+(p2*p3*value2); - logger.debug("bi-linear interpolation: "+value+"-->("+value0+","+value1+ - ","+value2+","+value3+") at "+xyLoc); + // do a bi-linear interpolation amount the nearest 4 points + value = (p1 * p4 * value1) + (p2 * p4 * value0) + + (p1 * p3 * value3) + (p2 * p3 * value2); + logger.debug("bi-linear interpolation: " + value + "-->(" + value0 + + "," + value1 + "," + value2 + "," + value3 + ") at " + + xyLoc); } catch (Exception e) { logger.error("No Grib value available....." + modelName + " " - + prodType+" lat,lon:"+coor); + + prodType + " lat,lon:" + coor); return null; } return value; @@ -194,7 +207,7 @@ public class FreezingLevel { HashMap freezingMap = new HashMap(); ScanDataCache cache = ScanDataCache.getInstance(); - //get data from hdf5 files + // get data from hdf5 files for (Coordinate coor : coors) { HashMap ghValues = new HashMap(); @@ -202,37 +215,43 @@ public class FreezingLevel { for (Entry entry : getGHLevelMap().entrySet()) { if (cache.getModelData().isType(modelName, entry.getKey())) { - ghValues.put(entry.getValue(), getValue(modelName, entry.getKey(), coor)); + ghValues.put(entry.getValue(), + getValue(modelName, entry.getKey(), coor)); } else { - ghValues.put(entry.getValue(),null); + ghValues.put(entry.getValue(), null); } } for (Entry entry : getTLevelMap().entrySet()) { if (cache.getModelData().isType(modelName, entry.getKey())) { - tValues.put(entry.getValue(), getValue(modelName, entry.getKey(), coor)); + tValues.put(entry.getValue(), + getValue(modelName, entry.getKey(), coor)); } } - - //here's the calculation + + // here's the calculation Double fLevel = 0.0; Integer jtopLevel = null; Integer ktopLevel = null; - int foundValFlag=-1;//-1=all ghValue and tValue are null, - //0=all ghValue<=-9000 and tValue<=273.16, 1=found a fLevel + int foundValFlag = -1;// -1=all ghValue and tValue are null, + // 0=all ghValue<=-9000 and tValue<=273.16, 1=found a fLevel - TreeSet ts= new TreeSet(ghValues.keySet());//want an asc sorted list + TreeSet ts = new TreeSet(ghValues.keySet());// want + // an + // asc + // sorted + // list Iterator it = ts.iterator(); - //for (Integer level : ghValues.keySet()) { + // for (Integer level : ghValues.keySet()) { while (it.hasNext()) { - Integer level = (Integer) it.next(); + Integer level = it.next(); Double tValue = tValues.get(level); Double ghValue = ghValues.get(level); - if (ghValue != null && tValue != null && foundValFlag ==-1){ - foundValFlag=0; + if (ghValue != null && tValue != null && foundValFlag == -1) { + foundValFlag = 0; } if (ghValue != null && ghValue.doubleValue() > -9000) { @@ -242,14 +261,13 @@ public class FreezingLevel { .get(ktopLevel) - ghValue) * ((273.16 - tValues .get(jtopLevel)) / (tValue - tValues .get(jtopLevel))))) * .00328; - logger.debug("***Freezing level: "+fLevel+"=" - + "(" + ghValues.get(ktopLevel) - + " - ((" + ghValues.get(ktopLevel) + " - " - + ghValue + ") * ((273.16 - " - + tValues.get(jtopLevel) + ") / (" + tValue - + " - " + tValues.get(jtopLevel) - + ")))) * .00328"); - foundValFlag=1; + logger.debug("***Freezing level: " + fLevel + "=" + "(" + + ghValues.get(ktopLevel) + " - ((" + + ghValues.get(ktopLevel) + " - " + ghValue + + ") * ((273.16 - " + tValues.get(jtopLevel) + + ") / (" + tValue + " - " + + tValues.get(jtopLevel) + ")))) * .00328"); + foundValFlag = 1; freezingMap.put(coor, fLevel.floatValue()); break; } else { @@ -258,10 +276,10 @@ public class FreezingLevel { } } } - - if (foundValFlag==0) {//this means all tValue are <= 273.16 - freezingMap.put(coor, 0.0f); - logger.debug("*** FreezingLevel = 0.0"); + + if (foundValFlag == 0) {// this means all tValue are <= 273.16 + freezingMap.put(coor, 0.0f); + logger.debug("*** FreezingLevel = 0.0"); } } @@ -343,15 +361,21 @@ public class FreezingLevel { * @param param * @return */ - private GridRecord populateRecord(String model, String param, Date refTime) { + private void populateRecord(String model, String param, Date refTime) { int interval = 1440; SCANModelParameterXML paramXML = new SCANModelParameterXML(); paramXML.setModelName(model); paramXML.setParameterName(param); - String sql = getSQL(interval, model, param, refTime); - logger.debug("Freezing level sql="+sql); - GridRecord modelRec = DATUtils.getMostRecentGridRecord(interval, sql, + GridRecord modelRec = null; + try { + modelRec = getGridRecord(interval, model, param, refTime); + } catch (Exception e) { + logger.error("Error retrieving grid record " + model + " " + param + + " " + refTime, e); + } + logger.debug("Freezing level rec=" + modelRec); + modelRec = DATUtils.getMostRecentGridRecord(interval, modelRec, paramXML); if (modelRec != null) { @@ -359,8 +383,6 @@ public class FreezingLevel { addForecastTime(fcHour); times.put(fcHour, modelRec.getDataTime().getRefTime()); } - - return modelRec; } /** @@ -432,17 +454,11 @@ public class FreezingLevel { return times; } - /** - * The SQL - * - * @return - */ - private String getSQL(int interval, String model, String param, Date refTime) { + private GridRecord getGridRecord(int interval, String model, String param, + Date refTime) throws Exception { String paramName = null; String level = null; - SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd HH:00:00"); - String refTimeStr = sdt.format(refTime); if (param.startsWith("GH")) { paramName = "GH"; level = param.substring(2, param.length()); @@ -451,13 +467,29 @@ public class FreezingLevel { level = param.substring(1, param.length()); } - // Gets the most recent record of it's type - String sql = "select grid.datauri from grid, grid_info, level where grid.info_id = grid_info.id and grid_info.level_id = level.id and grid_info.parameter_abbreviation = \'" - + paramName - + "\' and grid_info.datasetId = \'" - + model - + "\' and level.masterlevel_name = 'MB' and level.levelonevalue = '" - + level + "\' and grid.reftime=\'" + refTimeStr + "\' and grid.forecasttime=0 order by grid.reftime desc limit 1"; - return sql; + DatabaseQuery dbQuery = new DatabaseQuery(GridRecord.class); + dbQuery.addQueryParam("info.datasetId", model); + dbQuery.addQueryParam("info.parameter.abbreviation", paramName); + dbQuery.addQueryParam("info.level.masterLevel.name", "MB"); + dbQuery.addQueryParam("info.level.levelonevalue", level); + dbQuery.addQueryParam("dataTime.refTime", refTime); + dbQuery.addQueryParam("dataTime.fcstTime", 0); + dbQuery.addOrder("dataTime.refTime", false); + dbQuery.setMaxResults(1); + + try { + PluginDao dao = PluginFactory.getInstance().getPluginDao("grid"); + List list = dao.queryByCriteria(dbQuery); + GridRecord result = null; + if (list != null && !list.isEmpty()) { + result = (GridRecord) list.get(0); + } + return result; + } catch (Exception e) { + throw new Exception("Error querying database for grid record " + + dbQuery, e); + } + } + } diff --git a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/query/DatabaseQuery.java b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/query/DatabaseQuery.java index 2e195101c6..3eb2eef310 100644 --- a/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/query/DatabaseQuery.java +++ b/edexOsgi/com.raytheon.uf.edex.database/src/com/raytheon/uf/edex/database/query/DatabaseQuery.java @@ -54,6 +54,7 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; * 05/29/08 #875 bphillip Initial Creation * 06/03/08 #875 bphillip Added returned fields * 09/19/08 #1531 bphillip Refactored to include join capability + * Apr 24, 2014 2060 njensen Added toString() * * * @author bphillip @@ -675,12 +676,12 @@ public class DatabaseQuery { } } } else if (parameters.get(i).getValue() instanceof List) { - for (int j = 0; j < ((List) parameters.get(i) + for (int j = 0; j < ((List) parameters.get(i) .getValue()).size(); j++) { queryString.append(QueryUtil.COLON); queryString.append(QueryUtil.QUERY_CONSTRAINT + constraintIndex++); - if (j != ((List) parameters.get(i).getValue()) + if (j != ((List) parameters.get(i).getValue()) .size() - 1) { queryString.append(QueryUtil.COMMA); } @@ -951,10 +952,12 @@ public class DatabaseQuery { } } else if (value instanceof List) { - for (int j = 0; j < ((List) value).size(); j++) { - if (((List) value).get(0) instanceof String) { - ((List) value).add(ConvertUtil.convertObject( - (String) ((List) value).remove(0), returnedClass)); + for (int j = 0; j < ((List) value).size(); j++) { + if (((List) value).get(0) instanceof String) { + ((List) value) + .add(ConvertUtil.convertObject( + (String) ((List) value).remove(0), + returnedClass)); } } } @@ -1039,4 +1042,15 @@ public class DatabaseQuery { public void setEntityName(String entityName) { this.entityName = entityName; } + + @Override + public String toString() { + return "DatabaseQuery [maxResults=" + maxResults + ", parameters=" + + parameters + ", distinctParameter=" + distinctParameter + + ", returnedFields=" + returnedFields + ", orderFields=" + + orderFields + ", joinedClasses=" + joinedClasses + + ", joinFields=" + joinFields + ", entityName=" + entityName + + "]"; + } + } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.cwat/src/com/raytheon/uf/edex/plugin/cwat/common/CWATConfig.java b/edexOsgi/com.raytheon.uf.edex.plugin.cwat/src/com/raytheon/uf/edex/plugin/cwat/common/CWATConfig.java index b93edcfbfd..265137639e 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.cwat/src/com/raytheon/uf/edex/plugin/cwat/common/CWATConfig.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.cwat/src/com/raytheon/uf/edex/plugin/cwat/common/CWATConfig.java @@ -42,6 +42,7 @@ import com.raytheon.uf.common.monitor.xml.SCANModelParameterXML; import com.raytheon.uf.common.monitor.xml.SCANSiteXML; import com.raytheon.uf.common.serialization.SerializationException; import com.raytheon.uf.common.sounding.VerticalSounding; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.edex.dat.utils.DATUtils; import com.raytheon.uf.edex.dat.utils.ScanDataCache; import com.raytheon.uf.edex.plugin.cwat.CWATGenerator; @@ -55,13 +56,14 @@ import com.vividsolutions.jts.geom.Coordinate; /** * CWATConfig object * - * Hold config for CWAT Generator + * Config for CWAT Generator * *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * 06/02/2009   2037       dhladky    Initial Creation.
+ * 06/02/2009   2037       dhladky     Initial Creation.
+ * Apr 24, 2014  2060      njensen     Updates for removal of grid dataURI column
  * 
  * 
* @@ -560,19 +562,29 @@ public class CWATConfig { SCANModelParameterXML param500U = siteXML .getModelParameter("U500"); - // check back for a couple hours - int interval = 1440; + int interval = TimeUtil.MINUTES_PER_DAY; + /* + * FIXME the inner calls to ####Product.getGridProduct below + * will always return null. The second parameter is supposed to + * be the model (e.g. RUC130) but is passing in the parameter. + * + * Despite this problem, the code continues to function without + * exceptions because the call to + * DATUtils.getMostRecentGridRecord() will see the null record + * and then return the cached record, which was retrieved + * correctly. + */ u700 = DATUtils.getMostRecentGridRecord(interval, - U700Product.getSQL(interval, U700Product.U700), + U700Product.getGridRecord(interval, U700Product.U700), param700U); v700 = DATUtils.getMostRecentGridRecord(interval, - V700Product.getSQL(interval, V700Product.V700), + V700Product.getGridRecord(interval, V700Product.V700), param700V); u500 = DATUtils.getMostRecentGridRecord(interval, - U500Product.getSQL(interval, U500Product.U500), + U500Product.getGridRecord(interval, U500Product.U500), param500U); if (u700 != null && v700 != null && u500 != null) { diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.ffmp/src/com/raytheon/uf/edex/plugin/ffmp/common/FFMPConfig.java b/edexOsgi/com.raytheon.uf.edex.plugin.ffmp/src/com/raytheon/uf/edex/plugin/ffmp/common/FFMPConfig.java index 68459bae77..44031e4278 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.ffmp/src/com/raytheon/uf/edex/plugin/ffmp/common/FFMPConfig.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.ffmp/src/com/raytheon/uf/edex/plugin/ffmp/common/FFMPConfig.java @@ -56,7 +56,8 @@ import com.vividsolutions.jts.geom.GeometryFactory; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * 06/30/2009 2521 dhladky Initial Creation. + * 06/30/2009 2521 dhladky Initial Creation. + * Apr 24, 2014 2060 njensen Removed unnecessary catch * * * @@ -244,13 +245,7 @@ public class FFMPConfig { * @return */ private IMonitorProcessing getPDOFile(SourceXML xml, String uri) { - IMonitorProcessing obj = null; - try { - obj = (IMonitorProcessing) DATUtils.getPDORecord(uri, xml); - } catch (PluginException e) { - e.printStackTrace(); - } - return obj; + return (IMonitorProcessing) DATUtils.getPDORecord(uri, xml); } /** diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.qpf/src/com/raytheon/uf/edex/plugin/qpf/common/QPFConfig.java b/edexOsgi/com.raytheon.uf.edex.plugin.qpf/src/com/raytheon/uf/edex/plugin/qpf/common/QPFConfig.java index bb46f7f36a..1a35481e33 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.qpf/src/com/raytheon/uf/edex/plugin/qpf/common/QPFConfig.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.qpf/src/com/raytheon/uf/edex/plugin/qpf/common/QPFConfig.java @@ -40,6 +40,7 @@ import com.raytheon.uf.common.monitor.xml.SCANSiteXML; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.edex.dat.utils.DATUtils; import com.raytheon.uf.edex.dat.utils.ScanDataCache; import com.raytheon.uf.edex.plugin.qpf.QPFGenerator; @@ -59,9 +60,10 @@ import com.vividsolutions.jts.geom.Coordinate; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * 02/17/2009 1981 dhladky Initial Creation. - * 01/07/2013 DR 15647 gzhang Use logger.warn for null earlyVilURI/earlyCZURI. - * 11/11/2013 2377 bclement setRadarRecords returns bool for success + * 02/17/2009 1981 dhladky Initial Creation. + * 01/07/2013 DR 15647 gzhang Use logger.warn for null earlyVilURI/earlyCZURI. + * 11/11/2013 2377 bclement setRadarRecords returns bool for success + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @author dhladky @@ -357,11 +359,11 @@ public class QPFConfig { Set vilKeys = vilmap.keySet(); Iterator iter1 = vilKeys.iterator(); while (iter1.hasNext()) { - Date vilcal = (Date) iter1.next(); + Date vilcal = iter1.next(); Set czKeys = czMap.keySet(); Iterator iter2 = czKeys.iterator(); while (iter2.hasNext()) { - Date czcal = (Date) iter2.next(); + Date czcal = iter2.next(); if (czcal.equals(vilcal)) { earlyVilURI = vilmap.get(vilcal); earlyCZURI = czMap.get(czcal); @@ -375,7 +377,9 @@ public class QPFConfig { } if (earlyVilURI == null || earlyCZURI == null) { - qpfgen.logger.warn("QPFConfig: No previous data for QPF. Check the RADAR OP Mode.");// DR 15647 + qpfgen.logger + .warn("QPFConfig: No previous data for QPF. Check the RADAR OP Mode.");// DR + // 15647 return false; } @@ -542,13 +546,25 @@ public class QPFConfig { SCANModelParameterXML paramXMLU = siteXML.getModelParameter("U700"); SCANModelParameterXML paramXMLV = siteXML.getModelParameter("V700"); - int interval = 1440; + int interval = TimeUtil.MINUTES_PER_DAY; + /* + * FIXME the inner calls to ####Product.getGridProduct below will + * always return null. The second parameter is supposed to be the + * model (e.g. RUC130) but is passing in the parameter. + * + * Despite this problem, the code continues to function without + * exceptions because the call to DATUtils.getMostRecentGridRecord() + * will see the null record and then return the cached record, which + * was retrieved correctly. + */ GridRecord modelURec = DATUtils.getMostRecentGridRecord(interval, - U700Product.getSQL(interval, U700Product.U700), paramXMLU); + U700Product.getGridRecord(interval, U700Product.U700), + paramXMLU); GridRecord modelVRec = DATUtils.getMostRecentGridRecord(interval, - V700Product.getSQL(interval, V700Product.V700), paramXMLV); + V700Product.getGridRecord(interval, V700Product.V700), + paramXMLV); if (modelURec != null && modelVRec != null) { useModel = true; diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanGridRecordSet.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanGridRecordSet.java new file mode 100644 index 0000000000..7f705ecbdb --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanGridRecordSet.java @@ -0,0 +1,113 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.plugin.scan; + +import com.raytheon.uf.common.dataplugin.grid.GridRecord; + +/** + * Container for grid records that are potentially used by SCAN + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Apr 24, 2014            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +public class ScanGridRecordSet { + + private GridRecord cape; + + private GridRecord heli; + + private GridRecord u500; + + private GridRecord u700; + + private GridRecord v700; + + private GridRecord gh500; + + private GridRecord gh1000; + + public GridRecord getCape() { + return cape; + } + + public void setCape(GridRecord cape) { + this.cape = cape; + } + + public GridRecord getHeli() { + return heli; + } + + public void setHeli(GridRecord heli) { + this.heli = heli; + } + + public GridRecord getU500() { + return u500; + } + + public void setU500(GridRecord u500) { + this.u500 = u500; + } + + public GridRecord getU700() { + return u700; + } + + public void setU700(GridRecord u700) { + this.u700 = u700; + } + + public GridRecord getV700() { + return v700; + } + + public void setV700(GridRecord v700) { + this.v700 = v700; + } + + public GridRecord getGh500() { + return gh500; + } + + public void setGh500(GridRecord gh500) { + this.gh500 = gh500; + } + + public GridRecord getGh1000() { + return gh1000; + } + + public void setGh1000(GridRecord gh1000) { + this.gh1000 = gh1000; + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanURIFilter.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanURIFilter.java index 312744d120..e700292a86 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanURIFilter.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/ScanURIFilter.java @@ -33,7 +33,6 @@ import org.geotools.coverage.grid.GridGeometry2D; import com.raytheon.edex.urifilter.URIFilter; import com.raytheon.edex.urifilter.URIGenerateMessage; -import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.binlightning.BinLightningRecord; import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.message.DataURINotificationMessage; @@ -58,6 +57,7 @@ import com.raytheon.uf.common.monitor.xml.SCANSiteXML; import com.raytheon.uf.common.serialization.SingleTypeJAXBManager; import com.raytheon.uf.common.sounding.VerticalSounding; import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.edex.dat.utils.DATUtils; import com.raytheon.uf.edex.plugin.scan.common.ScanCommonUtils; import com.raytheon.uf.edex.plugin.scan.process.CAPEProduct; @@ -91,6 +91,7 @@ import com.vividsolutions.jts.geom.Coordinate; * Mar 23, 2010 dhladky Initial creation * Jun 21, 2013 7613 zhao Modified setGridRecords() etc. * Oct 15, 2013 2361 njensen Use JAXBManager for XML + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -885,76 +886,74 @@ public class ScanURIFilter extends URIFilter { /** * Set Grib Record in Model Data */ - public void setGridRecords() { + public void initializeGridRecords() { try { - GridRecord[] records = { null, null, null, null, null, null, null }; - records = getGridRecords(); + ScanGridRecordSet records = getGridData(); - if (records[0] != null) { + if (records.getCape() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(CAPEProduct.cape) .getModelName(), CAPEProduct.cape, - records[0]); + records.getCape()); } - if (records[1] != null) { + if (records.getHeli() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(HELIProduct.heli) .getModelName(), HELIProduct.heli, - records[1]); + records.getHeli()); } - if (records[2] != null) { + if (records.getU500() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(U500Product.U500) .getModelName(), U500Product.U500, - records[2]); + records.getU500()); } - if (records[3] != null) { + if (records.getU700() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(U700Product.U700) .getModelName(), U700Product.U700, - records[3]); + records.getU700()); } - if (records[4] != null) { + if (records.getV700() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(V700Product.V700) .getModelName(), V700Product.V700, - records[4]); + records.getV700()); } - if (records[5] != null) { + if (records.getGh500() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(GH500Product.GH500) .getModelName(), GH500Product.GH500, - records[5]); + records.getGh500()); } - if (records[6] != null) { + if (records.getGh1000() != null) { scan.getCache() .getModelData() .setGridRecord( site.getModelParameter(GH1000Product.GH1000) .getModelName(), GH1000Product.GH1000, - records[6]); + records.getGh1000()); } } catch (Exception e) { - logger.debug("Grib record setter failed....."); - e.printStackTrace(); + logger.error("Grib record initialization failed", e); } } @@ -1062,7 +1061,7 @@ public class ScanURIFilter extends URIFilter { * to retrieve the data from a database. */ public void init() { - setGridRecords(); + initializeGridRecords(); setSoundingRecord(ScanProduct.UA, ""); } @@ -1136,127 +1135,67 @@ public class ScanURIFilter extends URIFilter { } /** - * get Populated grib records for CAPE and HELI - * - * @return - */ - public GridRecord[] getGridRecords() throws PluginException { - - GridRecord[] records = { null, null, null, null, null, null, null }; - try { - String[] modelUris = getModelSQL(); - for (String uri : modelUris) { - logger.info(" model uri = " + uri); - } - for (int i = 0; i < modelUris.length; i++) { - if (!modelUris[i].isEmpty()) { - records[i] = DATUtils.getGridRecord(modelUris[i]); - } else { - logger.info(" modelUris[" + i + "] is empty"); - } - } - // // CAPE - // records[0] = DATUtils.getGridRecord(modelUris[0]); - // // HELI - // records[1] = DATUtils.getGridRecord(modelUris[1]); - // // U500 - // records[2] = DATUtils.getGridRecord(modelUris[2]); - // // U700 - // records[3] = DATUtils.getGridRecord(modelUris[3]); - // // V700 - // records[4] = DATUtils.getGridRecord(modelUris[4]); - // // GH500 - // records[5] = DATUtils.getGridRecord(modelUris[5]); - // // GH1000 - // records[6] = DATUtils.getGridRecord(modelUris[6]); - } catch (Exception e) { - logger.error("No Grib record(s) found....."); - logger.error(e.toString()); - e.printStackTrace(); - } - return records; - } - - /** - * Get the Model SQL Uses the environmental data backup for the + * Get the grid data. Uses the environmental data backup for the * "pull strategy" for All model params. */ - private String[] getModelSQL() throws Exception { + protected ScanGridRecordSet getGridData() throws Exception { SCANSiteXML site = scan.getRunConfig().getSiteConfig(getIcao()); logger.info(" site = " + site.getScanSite()); - int interval = 1440 * 3; - // Set interval to 1 day, 1440 minutes + int interval = TimeUtil.MINUTES_PER_DAY; + ScanGridRecordSet result = new ScanGridRecordSet(); String modelCape = site.getModelParameter(CAPEProduct.cape) .getModelName(); - String sqlCapeUri = CAPEProduct.getSQL(interval, modelCape); - logger.info("modelCape = " + modelCape + "; sqlCapeUri = " + sqlCapeUri); - Object[] objectsCapeUri = scan.dbRequest(sqlCapeUri); + GridRecord cape = CAPEProduct.getGridRecord(interval, modelCape); + logger.info("modelCape = " + modelCape + "; record = " + cape); + DATUtils.populateGridRecord(cape); + result.setCape(cape); String modelHeli = site.getModelParameter(HELIProduct.heli) .getModelName(); - String sqlHeliUri = HELIProduct.getSQL(interval, modelHeli); - logger.info("modelHeli = " + modelHeli + "; sqlHeliUri = " + sqlHeliUri); - Object[] objectsHeliUri = scan.dbRequest(sqlHeliUri); + GridRecord heli = HELIProduct.getGridRecord(interval, modelHeli); + logger.info("modelHeli = " + modelHeli + "; record = " + heli); + DATUtils.populateGridRecord(heli); + result.setHeli(heli); String modelU500 = site.getModelParameter(U500Product.U500) .getModelName(); - String sqlU500Uri = U500Product.getSQL(interval, modelU500); - logger.info("modelU500 = " + modelU500 + "; sqlU500Uri = " + sqlU500Uri); - Object[] objectsU500Uri = scan.dbRequest(sqlU500Uri); + GridRecord u500 = U500Product.getGridRecord(interval, modelU500); + logger.info("modelU500 = " + modelU500 + "; record = " + u500); + DATUtils.populateGridRecord(u500); + result.setU500(u500); String modelU700 = site.getModelParameter(U700Product.U700) .getModelName(); - String sqlU700Uri = U700Product.getSQL(interval, modelU700); - logger.info("modelU700 = " + modelU700 + "; sqlU700Uri = " + sqlU700Uri); - Object[] objectsU700Uri = scan.dbRequest(sqlU700Uri); + GridRecord u700 = U700Product.getGridRecord(interval, modelU700); + logger.info("modelU700 = " + modelU700 + "; record = " + u700); + DATUtils.populateGridRecord(u700); + result.setU700(u700); String modelV700 = site.getModelParameter(V700Product.V700) .getModelName(); - String sqlV700Uri = V700Product.getSQL(interval, modelV700); - logger.info("modelV700 = " + modelV700 + "; sqlV700Uri = " + sqlV700Uri); - Object[] objectsV700Uri = scan.dbRequest(sqlV700Uri); + GridRecord v700 = V700Product.getGridRecord(interval, modelV700); + logger.info("modelV700 = " + modelV700 + "; record = " + v700); + DATUtils.populateGridRecord(v700); + result.setV700(v700); String modelGH500 = site.getModelParameter(GH500Product.GH500) .getModelName(); - String sqlGH500Uri = GH500Product.getSQL(interval, modelGH500); - logger.info("modelGH500 = " + modelGH500 + "; sqlGH500Uri = " - + sqlGH500Uri); - Object[] objectsGH500Uri = scan.dbRequest(sqlGH500Uri); + GridRecord gh500 = GH500Product.getGridRecord(interval, modelGH500); + logger.info("modelGH500 = " + modelGH500 + "; record = " + gh500); + DATUtils.populateGridRecord(gh500); + result.setGh500(gh500); String modelGH1000 = site.getModelParameter(GH1000Product.GH1000) .getModelName(); - String sqlGH1000Uri = GH1000Product.getSQL(interval, modelGH1000); - logger.info("modelGH1000 = " + modelGH1000 + "; sqlGH1000Uri = " - + sqlGH1000Uri); - Object[] objectsGH1000Uri = scan.dbRequest(sqlGH1000Uri); + GridRecord gh1000 = GH1000Product.getGridRecord(interval, modelGH1000); + logger.info("modelGH1000 = " + modelGH1000 + "; record = " + gh1000); + DATUtils.populateGridRecord(gh1000); + result.setGh1000(gh1000); - // always grab the most recent time data - String[] results = { "", "", "", "", "", "", "" }; + return result; - if (objectsCapeUri.length > 0) { - results[0] = (String) objectsCapeUri[0]; - } - if (objectsHeliUri.length > 0) { - results[1] = (String) objectsHeliUri[0]; - } - if (objectsU500Uri.length > 0) { - results[2] = (String) objectsU500Uri[0]; - } - if (objectsU700Uri.length > 0) { - results[3] = (String) objectsU700Uri[0]; - } - if (objectsV700Uri.length > 0) { - results[4] = (String) objectsV700Uri[0]; - } - if (objectsGH500Uri.length > 0) { - results[5] = (String) objectsGH500Uri[0]; - } - if (objectsGH1000Uri.length > 0) { - results[6] = (String) objectsGH1000Uri[0]; - } - return results; } /** diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/CAPEProduct.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/CAPEProduct.java index 47810616ea..96dbc29785 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/CAPEProduct.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/CAPEProduct.java @@ -26,11 +26,27 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; +/** + * CAPE Product + * + *
+ * 
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ *                                     Initial creation
+ * Apr 24, 2014 2060       njensen     Updates for removal of grid dataURI column
+ * 
+ * 
+ * + * @version 1.0 + */ public class CAPEProduct extends GridProduct { /** @@ -113,13 +129,15 @@ public class CAPEProduct extends GridProduct { } /** - * The SQL for CAPE + * Retrieves the record for CAPE * * @param wmo * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, cape, "SFC", "0.0", + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, cape, "SFC", "0.0", Level.getInvalidLevelValueAsString()); } } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH1000Product.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH1000Product.java index 4d7ad4a5cc..7e5e81d098 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH1000Product.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH1000Product.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; @@ -40,6 +41,7 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 27, 2010 5098 grichard Initial creation + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -134,12 +136,14 @@ public class GH1000Product extends GridProduct { } /** - * The SQL + * Retrieves the record for gh1000 * * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, "GH", "MB", "1000.0", + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, "GH", "MB", "1000.0", Level.getInvalidLevelValueAsString()); } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH500Product.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH500Product.java index ac41d746db..62adc7566b 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH500Product.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GH500Product.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; @@ -40,6 +41,7 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 27, 2010 5098 grichard Initial creation + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -134,12 +136,14 @@ public class GH500Product extends GridProduct { } /** - * The SQL for MODEL 500 thickness + * Retrieves the record for gh500 * * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, "GH", "MB", "500.0", + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, "GH", "MB", "500.0", Level.getInvalidLevelValueAsString()); } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GridProduct.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GridProduct.java index 37ae0ff582..2e85e20ab0 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GridProduct.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/GridProduct.java @@ -19,14 +19,23 @@ **/ package com.raytheon.uf.edex.plugin.scan.process; +import java.util.Date; +import java.util.List; import java.util.regex.Pattern; +import com.raytheon.uf.common.dataplugin.grid.GridRecord; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; +import com.raytheon.uf.common.time.SimulatedTime; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.edex.database.plugin.PluginDao; +import com.raytheon.uf.edex.database.plugin.PluginFactory; +import com.raytheon.uf.edex.database.query.DatabaseQuery; import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; /** * - * TODO Add Description + * Abstract grid product for SCAN * *
  * 
@@ -34,8 +43,9 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter;
  * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Mar 2, 2012             bsteffen     Initial creation
- * Jun 21, 2013 7613       zhao         Modified getGrigSQL()
+ * Mar 2, 2012             bsteffen    Initial creation
+ * Jun 21, 2013 7613       zhao        Modified getGridSQL()
+ * Apr 24, 2014 2060       njensen     Updates for removal of grid dataURI column
  * 
  * 
* @@ -52,6 +62,21 @@ public abstract class GridProduct extends ScanProduct { super(uri, tableType, filter); } + /** + * Gets a pattern for matching a URI with the specified parameters. + * + * @param dataset + * @param parameter + * @param levelName + * @param levelOne + * @param levelTwo + * @return + * @deprecated This entire method should be removed and/or replaced, + * possibly by using the PluginNotifier or methods in + * DataURIUtil. At present the method is coupled too tightly to + * the grid dataURI format. + */ + @Deprecated protected static Pattern getGridPattern(String dataset, String parameter, String levelName, String levelOne, String levelTwo) { // Format = @@ -92,34 +117,52 @@ public abstract class GridProduct extends ScanProduct { } /** - * The SQL for MODEL 500 thickness + * Gets the newest grid record that has a reftime newer than the interval + * back in time * - * @return + * @param interval + * the number of minutes back from the current time to check for + * a matching record + * @param dataset + * the grid dataset + * @param parameter + * the grid parameter + * @param levelName + * the grid level name + * @param levelOne + * the grid level one value + * @param levelTwo + * the grid level two value + * @return the newest grid record that matches, or null if none are found + * @throws ScanException */ - public static String getGridSQL(int interval, String dataset, - String parameter, String levelName, String levelOne, String levelTwo) { - StringBuilder sql = new StringBuilder( - "select grid.datauri from grid, grid_info, level where"); - sql.append(" grid.info_id = grid_info.id"); - sql.append(" and"); - // datasetId - sql.append(" grid_info.datasetId = \'" + dataset + "\'"); - sql.append(" and"); - // parameterAbbreviation - sql.append(" grid_info.parameter_abbreviation = \'" + parameter + "\'"); - sql.append(" and"); - // level - sql.append(" level.id = grid_info.level_id"); - sql.append(" and"); - sql.append(" level.masterlevel_name = \'" + levelName + "\'"); - sql.append(" and"); - sql.append(" level.levelonevalue = \'" + levelOne + "\'"); - sql.append(" and"); - sql.append(" level.leveltwovalue = \'" + levelTwo + "\'"); - // interval - sql.append("and reftime > (now()- interval \'" + interval - + " minutes\')"); - sql.append(" order by reftime desc, forecasttime desc" + " limit 1"); - return sql.toString(); + public static GridRecord getGridRecord(int interval, String dataset, + String parameter, String levelName, String levelOne, String levelTwo) + throws ScanException { + DatabaseQuery dbQuery = new DatabaseQuery(GridRecord.class); + dbQuery.addQueryParam("info.datasetId", dataset); + dbQuery.addQueryParam("info.parameter.abbreviation", parameter); + dbQuery.addQueryParam("info.level.masterLevel.name", levelName); + dbQuery.addQueryParam("info.level.levelonevalue", levelOne); + dbQuery.addQueryParam("info.level.leveltwovalue", levelTwo); + dbQuery.addQueryParam("dataTime.refTime", new Date(SimulatedTime + .getSystemTime().getMillis() + - (interval * TimeUtil.MILLIS_PER_MINUTE)), ">"); + dbQuery.addOrder("dataTime.refTime", false); + dbQuery.addOrder("dataTime.fcstTime", false); + dbQuery.setMaxResults(1); + + try { + PluginDao dao = PluginFactory.getInstance().getPluginDao("grid"); + List list = dao.queryByCriteria(dbQuery); + GridRecord result = null; + if (list != null && !list.isEmpty()) { + result = (GridRecord) list.get(0); + } + return result; + } catch (Exception e) { + throw new ScanException("Error querying database for grid record " + + dbQuery, e); + } } } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/HELIProduct.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/HELIProduct.java index 24fde781d8..23d6510088 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/HELIProduct.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/HELIProduct.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; @@ -41,6 +42,7 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; * ------------ ---------- ----------- -------------------------- * May 18, 2010 5098 grichard Initial creation * Jun 20, 2013 7613 zhao Modified getSQL() + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -131,13 +133,14 @@ public class HELIProduct extends GridProduct { } /** - * The SQL HELI + * Retrieves the record for heli * * @param interval * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, "Heli", "FHAG", "0.0", - "3000.0"); + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, "Heli", "FHAG", "0.0", "3000.0"); } } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U500Product.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U500Product.java index 64249d530e..3c4cf22640 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U500Product.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U500Product.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; @@ -40,6 +41,7 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 27, 2010 5098 grichard Initial creation + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -134,13 +136,15 @@ public class U500Product extends GridProduct { } /** - * The SQL for RUC13 CAPE + * Retrieves the record for u500 * * @param wmo * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, "uW", "MB", "500.0", + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, "uW", "MB", "500.0", Level.getInvalidLevelValueAsString()); } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U700Product.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U700Product.java index ef2cb01b6e..834ec9d4b2 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U700Product.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/U700Product.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; @@ -40,6 +41,7 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 27, 2010 5098 grichard Initial creation + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -134,12 +136,14 @@ public class U700Product extends GridProduct { } /** - * The SQL + * Retrieves the record for u700 * * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, "uW", "MB", "700.0", + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, "uW", "MB", "700.0", Level.getInvalidLevelValueAsString()); } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/V700Product.java b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/V700Product.java index 6ac5e2709a..f880155577 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/V700Product.java +++ b/edexOsgi/com.raytheon.uf.edex.plugin.scan/src/com/raytheon/uf/edex/plugin/scan/process/V700Product.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.dataplugin.persist.PersistablePluginDataObject; +import com.raytheon.uf.common.dataplugin.scan.ScanException; import com.raytheon.uf.common.dataplugin.scan.data.ScanTableDataRow; import com.raytheon.uf.common.monitor.config.SCANRunSiteConfigurationManager; import com.raytheon.uf.common.monitor.scan.config.SCANConfigEnums.ScanTables; @@ -40,6 +41,7 @@ import com.raytheon.uf.edex.plugin.scan.ScanURIFilter; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 27, 2010 5098 grichard Initial creation + * Apr 24, 2014 2060 njensen Updates for removal of grid dataURI column * * * @@ -134,13 +136,15 @@ public class V700Product extends GridProduct { } /** - * The SQL for RUC13 CAPE + * Retrieves the record for v700 * * @param wmo * @return + * @throws ScanException */ - public static String getSQL(int interval, String model) { - return getGridSQL(interval, model, "vW", "MB", "700.0", + public static GridRecord getGridRecord(int interval, String model) + throws ScanException { + return getGridRecord(interval, model, "vW", "MB", "700.0", Level.getInvalidLevelValueAsString()); }