Issue #1394: Reduce GFE Grid Database calls
Change-Id: I7462cca18b1b46169b25611dddbad844895be0cd Former-commit-id:ac41861f0b
[formerly3c3c695f24
] [formerly0670ac79fa
[formerly bc127f06236cb1e09dc0c87fee578e4a0cb60063]] Former-commit-id:0670ac79fa
Former-commit-id:0cdb86b6ac
This commit is contained in:
parent
17b9e0077c
commit
912b2ec928
5 changed files with 325 additions and 244 deletions
|
@ -90,12 +90,12 @@ public class IFPServerConfigManager {
|
||||||
*/
|
*/
|
||||||
public static IFPServerConfig getServerConfig(String siteID)
|
public static IFPServerConfig getServerConfig(String siteID)
|
||||||
throws GfeConfigurationException {
|
throws GfeConfigurationException {
|
||||||
if (configMap.containsKey(siteID)) {
|
IFPServerConfig config = configMap.get(siteID);
|
||||||
return configMap.get(siteID);
|
if (config == null) {
|
||||||
} else {
|
|
||||||
throw new GfeConfigurationException("Site " + siteID
|
throw new GfeConfigurationException("Site " + siteID
|
||||||
+ " has no active GFE configuration.");
|
+ " has no active GFE configuration.");
|
||||||
}
|
}
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,18 +31,16 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.criterion.Criterion;
|
|
||||||
import org.hibernate.criterion.DetachedCriteria;
|
import org.hibernate.criterion.DetachedCriteria;
|
||||||
import org.hibernate.criterion.Order;
|
|
||||||
import org.hibernate.criterion.Property;
|
import org.hibernate.criterion.Property;
|
||||||
import org.hibernate.criterion.Restrictions;
|
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
import org.springframework.transaction.support.TransactionCallback;
|
||||||
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||||
|
@ -74,7 +72,6 @@ import com.raytheon.uf.common.dataplugin.gfe.type.Pair;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil;
|
import com.raytheon.uf.common.dataplugin.gfe.util.GfeUtil;
|
||||||
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
|
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
|
||||||
import com.raytheon.uf.common.dataplugin.grid.GridInfoConstants;
|
import com.raytheon.uf.common.dataplugin.grid.GridInfoConstants;
|
||||||
import com.raytheon.uf.common.dataplugin.grid.GridInfoRecord;
|
|
||||||
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
|
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
|
||||||
import com.raytheon.uf.common.dataplugin.level.Level;
|
import com.raytheon.uf.common.dataplugin.level.Level;
|
||||||
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
||||||
|
@ -106,14 +103,27 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery;
|
||||||
* 08/07/09 #2763 njensen Refactored queryByD2DParmId
|
* 08/07/09 #2763 njensen Refactored queryByD2DParmId
|
||||||
* 09/10/12 DR15137 ryu Changed for MOSGuide D2D mxt/mnt grids for consistency
|
* 09/10/12 DR15137 ryu Changed for MOSGuide D2D mxt/mnt grids for consistency
|
||||||
* with A1.
|
* with A1.
|
||||||
* 10/10/12 #1260 randerso Added check to ensure db can be created before
|
* 10/10/12 #1260 randerso Added check to ensure db can be created before
|
||||||
* adding it to the inventory
|
* adding it to the inventory
|
||||||
|
* 12/06/12 #1394 rjpeter Optimized D2D grid access.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author bphillip
|
* @author bphillip
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class GFEDao extends DefaultPluginDao {
|
public class GFEDao extends DefaultPluginDao {
|
||||||
|
// hibernate query to find grid info record for the given datasetId and
|
||||||
|
// parameter
|
||||||
|
private static final String HQL_D2D_GRID_PARM_QUERY = "select parameter.abbreviation, id from GridInfoRecord "
|
||||||
|
+ "where datasetId = :datasetId AND (lower(parameter.abbreviation) = :abbrev OR lower(parameter_abbreviation) like :hourAbbrev)";
|
||||||
|
|
||||||
|
// hibernate query to find the times for the GridRecord for the given
|
||||||
|
// info.id, id returned to allow easy lookup of the record associated with
|
||||||
|
// the time
|
||||||
|
private static final String HQL_D2D_GRID_TIME_QUERY = "select dataTime, id from GridRecord "
|
||||||
|
+ "where info.id = :info_id AND dataTime.refTime = :refTime order by dataTime.fcstTime";
|
||||||
|
|
||||||
|
private static final Pattern WIND_PATTERN = Pattern.compile("wind");
|
||||||
|
|
||||||
public GFEDao() throws PluginException {
|
public GFEDao() throws PluginException {
|
||||||
super("gfe");
|
super("gfe");
|
||||||
|
@ -300,7 +310,12 @@ public class GFEDao extends DefaultPluginDao {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sess != null) {
|
if (sess != null) {
|
||||||
sess.close();
|
try {
|
||||||
|
sess.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
statusHandler.error(
|
||||||
|
"Error occurred closing database session", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,53 +626,75 @@ public class GFEDao extends DefaultPluginDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a GridRecord from the grib metadata database based on a ParmID
|
* Retrieves a GridRecord from the grib metadata database based on a ParmID,
|
||||||
* and a TimeRange
|
* TimeRange, and GridParmInfo.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* The parmID of the desired GridRecord
|
* The parmID of the desired GridRecord
|
||||||
* @param timeRange
|
* @param timeRange
|
||||||
* The timeRange of the desired GridRecord
|
* The timeRange of the desired GridRecord
|
||||||
|
* @param info
|
||||||
|
* The GridParmInfo for the requested d2d grid.
|
||||||
* @return The GridRecord from the grib metadata database
|
* @return The GridRecord from the grib metadata database
|
||||||
* @throws DataAccessLayerException
|
* @throws DataAccessLayerException
|
||||||
* If errors occur while querying the metadata database
|
* If errors occur while querying the metadata database
|
||||||
*/
|
*/
|
||||||
public GridRecord getD2DGrid(ParmID id, TimeRange timeRange,
|
public GridRecord getD2DGrid(ParmID id, TimeRange timeRange,
|
||||||
GridParmInfo info) throws DataAccessLayerException {
|
GridParmInfo info) throws DataAccessLayerException {
|
||||||
List<GridRecord> records = queryByD2DParmId(id);
|
Session s = null;
|
||||||
List<TimeRange> gribTimes = new ArrayList<TimeRange>();
|
|
||||||
for (GridRecord record : records) {
|
try {
|
||||||
gribTimes.add(record.getDataTime().getValidPeriod());
|
s = getHibernateTemplate().getSessionFactory().openSession();
|
||||||
}
|
// TODO: clean up so we only make one db query
|
||||||
|
SortedMap<DataTime, Integer> rawTimes = queryByD2DParmId(id, s);
|
||||||
|
List<TimeRange> gribTimes = new ArrayList<TimeRange>();
|
||||||
|
for (DataTime dt : rawTimes.keySet()) {
|
||||||
|
gribTimes.add(dt.getValidPeriod());
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < records.size(); i++) {
|
|
||||||
TimeRange gribTime = records.get(i).getDataTime().getValidPeriod();
|
|
||||||
try {
|
try {
|
||||||
if (isMos(id)) {
|
if (isMos(id)) {
|
||||||
TimeRange time = info.getTimeConstraints().constraintTime(
|
for (Map.Entry<DataTime, Integer> timeEntry : rawTimes
|
||||||
gribTime.getEnd());
|
.entrySet()) {
|
||||||
if (timeRange.getEnd().equals(time.getEnd())
|
TimeRange gribTime = timeEntry.getKey()
|
||||||
|| !info.getTimeConstraints().anyConstraints()) {
|
.getValidPeriod();
|
||||||
GridRecord retVal = records.get(i);
|
TimeRange time = info.getTimeConstraints()
|
||||||
retVal.setPluginName(GridConstants.GRID);
|
.constraintTime(gribTime.getEnd());
|
||||||
return retVal;
|
if (timeRange.getEnd().equals(time.getEnd())
|
||||||
|
|| !info.getTimeConstraints().anyConstraints()) {
|
||||||
|
GridRecord retVal = (GridRecord) s.get(
|
||||||
|
GridRecord.class, timeEntry.getValue());
|
||||||
|
retVal.setPluginName(GridConstants.GRID);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (D2DGridDatabase.isNonAccumDuration(id, gribTimes)) {
|
} else if (D2DGridDatabase.isNonAccumDuration(id, gribTimes)) {
|
||||||
if (timeRange.getStart().equals(gribTime.getEnd())
|
for (Map.Entry<DataTime, Integer> timeEntry : rawTimes
|
||||||
|| timeRange.equals(gribTime)) {
|
.entrySet()) {
|
||||||
GridRecord retVal = records.get(i);
|
TimeRange gribTime = timeEntry.getKey()
|
||||||
retVal.setPluginName(GridConstants.GRID);
|
.getValidPeriod();
|
||||||
return retVal;
|
if (timeRange.getStart().equals(gribTime.getEnd())
|
||||||
|
|| timeRange.equals(gribTime)) {
|
||||||
|
GridRecord retVal = (GridRecord) s.get(
|
||||||
|
GridRecord.class, timeEntry.getValue());
|
||||||
|
retVal.setPluginName(GridConstants.GRID);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
TimeRange time = info.getTimeConstraints().constraintTime(
|
for (Map.Entry<DataTime, Integer> timeEntry : rawTimes
|
||||||
gribTime.getStart());
|
.entrySet()) {
|
||||||
if ((timeRange.getStart().equals(time.getStart()) || !info
|
TimeRange gribTime = timeEntry.getKey()
|
||||||
.getTimeConstraints().anyConstraints())) {
|
.getValidPeriod();
|
||||||
GridRecord retVal = records.get(i);
|
TimeRange time = info.getTimeConstraints()
|
||||||
retVal.setPluginName(GridConstants.GRID);
|
.constraintTime(gribTime.getStart());
|
||||||
return retVal;
|
if ((timeRange.getStart().equals(time.getStart()) || !info
|
||||||
|
.getTimeConstraints().anyConstraints())) {
|
||||||
|
GridRecord retVal = (GridRecord) s.get(
|
||||||
|
GridRecord.class, timeEntry.getValue());
|
||||||
|
retVal.setPluginName(GridConstants.GRID);
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (GfeConfigurationException e) {
|
} catch (GfeConfigurationException e) {
|
||||||
|
@ -665,219 +702,219 @@ public class GFEDao extends DefaultPluginDao {
|
||||||
"Error getting configuration for "
|
"Error getting configuration for "
|
||||||
+ id.getDbId().getSiteId(), e);
|
+ id.getDbId().getSiteId(), e);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (s != null) {
|
||||||
|
try {
|
||||||
|
s.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
statusHandler.error(
|
||||||
|
"Error occurred closing database session", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of GridRecords from the grib metadata database which match
|
* Gets a SortedMap of DataTime and GridRecord ids from the grib metadata
|
||||||
* the given ParmID
|
* database which match the given ParmID. Session passed to allow reuse
|
||||||
|
* across multiple calls.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* The ParmID to search with
|
* The ParmID to search with
|
||||||
|
* @param s
|
||||||
|
* The database session to use
|
||||||
* @return The list of GridRecords from the grib metadata database which
|
* @return The list of GridRecords from the grib metadata database which
|
||||||
* match the given ParmID
|
* match the given ParmID
|
||||||
* @throws DataAccessLayerException
|
* @throws DataAccessLayerException
|
||||||
* If errors occur while querying the metadata database
|
* If errors occur while querying the metadata database
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<GridRecord> queryByD2DParmId(ParmID id)
|
public SortedMap<DataTime, Integer> queryByD2DParmId(ParmID id, Session s)
|
||||||
throws DataAccessLayerException {
|
throws DataAccessLayerException {
|
||||||
Session s = null;
|
String levelName = GridTranslator.getLevelName(id.getParmLevel());
|
||||||
|
|
||||||
|
double[] levelValues = GridTranslator.getLevelValue(id.getParmLevel());
|
||||||
|
boolean levelOnePresent = (levelValues[0] != Level
|
||||||
|
.getInvalidLevelValue());
|
||||||
|
boolean levelTwoPresent = (levelValues[1] != Level
|
||||||
|
.getInvalidLevelValue());
|
||||||
|
Level level = null;
|
||||||
|
|
||||||
|
// to have a level 2, must have a level one
|
||||||
try {
|
try {
|
||||||
String levelName = GridTranslator.getLevelName(id.getParmLevel());
|
if (levelOnePresent && levelTwoPresent) {
|
||||||
|
level = LevelFactory.getInstance().getLevel(levelName,
|
||||||
|
levelValues[0], levelValues[1]);
|
||||||
|
} else if (levelOnePresent) {
|
||||||
|
level = LevelFactory.getInstance().getLevel(levelName,
|
||||||
|
levelValues[0]);
|
||||||
|
} else {
|
||||||
|
level = LevelFactory.getInstance().getLevel(levelName, 0.0);
|
||||||
|
}
|
||||||
|
} catch (CommunicationException e) {
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
if (level == null) {
|
||||||
|
logger.warn("Unable to query D2D parms, ParmID " + id
|
||||||
|
+ " does not map to a level");
|
||||||
|
return new TreeMap<DataTime, Integer>();
|
||||||
|
}
|
||||||
|
|
||||||
double[] levelValues = GridTranslator.getLevelValue(id
|
Query modelQuery = s.createQuery(HQL_D2D_GRID_PARM_QUERY);
|
||||||
.getParmLevel());
|
|
||||||
boolean levelOnePresent = (levelValues[0] != Level
|
|
||||||
.getInvalidLevelValue());
|
|
||||||
boolean levelTwoPresent = (levelValues[1] != Level
|
|
||||||
.getInvalidLevelValue());
|
|
||||||
Level level = null;
|
|
||||||
|
|
||||||
// to have a level 2, must have a level one
|
DatabaseID dbId = id.getDbId();
|
||||||
try {
|
try {
|
||||||
if (levelOnePresent && levelTwoPresent) {
|
IFPServerConfig config = IFPServerConfigManager
|
||||||
level = LevelFactory.getInstance().getLevel(levelName,
|
.getServerConfig(dbId.getSiteId());
|
||||||
levelValues[0], levelValues[1]);
|
modelQuery.setString(GridInfoConstants.DATASET_ID,
|
||||||
} else if (levelOnePresent) {
|
config.d2dModelNameMapping(dbId.getModelName()));
|
||||||
level = LevelFactory.getInstance().getLevel(levelName,
|
} catch (GfeConfigurationException e) {
|
||||||
levelValues[0]);
|
throw new DataAccessLayerException(
|
||||||
|
"Error occurred looking up model name mapping", e);
|
||||||
|
}
|
||||||
|
String abbreviation = DataFieldTableLookup.getInstance()
|
||||||
|
.lookupDataName(id.getParmName());
|
||||||
|
if (abbreviation == null) {
|
||||||
|
abbreviation = id.getParmName();
|
||||||
|
}
|
||||||
|
abbreviation = abbreviation.toLowerCase();
|
||||||
|
modelQuery.setString("abbrev", abbreviation);
|
||||||
|
modelQuery.setString("hourAbbrev", abbreviation + "%hr");
|
||||||
|
List<?> results = modelQuery.list();
|
||||||
|
Integer modelId = null;
|
||||||
|
if (results.size() == 0) {
|
||||||
|
return new TreeMap<DataTime, Integer>();
|
||||||
|
} else if (results.size() > 1) {
|
||||||
|
// hours matched, take hour with least number that matches exact
|
||||||
|
// param
|
||||||
|
Pattern p = Pattern.compile("^" + abbreviation + "(\\d+)hr$");
|
||||||
|
int lowestHr = -1;
|
||||||
|
for (Object[] rows : (List<Object[]>) results) {
|
||||||
|
String param = ((String) rows[0]).toLowerCase();
|
||||||
|
if (param.equals(abbreviation) && (lowestHr < 0)) {
|
||||||
|
modelId = (Integer) rows[1];
|
||||||
} else {
|
} else {
|
||||||
level = LevelFactory.getInstance().getLevel(levelName, 0.0);
|
Matcher matcher = p.matcher(param);
|
||||||
}
|
if (matcher.matches()) {
|
||||||
} catch (CommunicationException e) {
|
int hr = Integer.parseInt(matcher.group(1));
|
||||||
logger.error(e.getLocalizedMessage(), e);
|
if ((lowestHr < 0) || (hr < lowestHr)) {
|
||||||
}
|
modelId = (Integer) rows[1];
|
||||||
if (level == null) {
|
lowestHr = hr;
|
||||||
logger.warn("Unable to query D2D parms, ParmID " + id
|
|
||||||
+ " does not map to a level");
|
|
||||||
return new ArrayList<GridRecord>();
|
|
||||||
}
|
|
||||||
|
|
||||||
s = getHibernateTemplate().getSessionFactory().openSession();
|
|
||||||
|
|
||||||
Criteria modelCrit = s.createCriteria(GridInfoRecord.class);
|
|
||||||
Criterion baseCrit = Restrictions
|
|
||||||
.eq(GridInfoConstants.LEVEL, level);
|
|
||||||
|
|
||||||
DatabaseID dbId = id.getDbId();
|
|
||||||
try {
|
|
||||||
IFPServerConfig config = IFPServerConfigManager
|
|
||||||
.getServerConfig(dbId.getSiteId());
|
|
||||||
baseCrit = Restrictions.and(baseCrit, Restrictions.eq(
|
|
||||||
GridInfoConstants.DATASET_ID,
|
|
||||||
config.d2dModelNameMapping(dbId.getModelName())));
|
|
||||||
} catch (GfeConfigurationException e) {
|
|
||||||
throw new DataAccessLayerException(
|
|
||||||
"Error occurred looking up model name mapping", e);
|
|
||||||
}
|
|
||||||
String abbreviation = DataFieldTableLookup.getInstance()
|
|
||||||
.lookupDataName(id.getParmName());
|
|
||||||
if (abbreviation == null) {
|
|
||||||
abbreviation = id.getParmName();
|
|
||||||
}
|
|
||||||
abbreviation = abbreviation.toLowerCase();
|
|
||||||
Criterion abbrevCrit = Restrictions
|
|
||||||
.and(baseCrit,
|
|
||||||
Restrictions.or(
|
|
||||||
Restrictions
|
|
||||||
.sqlRestriction("lower(parameter_abbreviation) = '"
|
|
||||||
+ abbreviation + "'"),
|
|
||||||
Restrictions
|
|
||||||
.sqlRestriction("lower(parameter_abbreviation) like '"
|
|
||||||
+ abbreviation + "%hr'")));
|
|
||||||
|
|
||||||
modelCrit.add(abbrevCrit);
|
|
||||||
List<?> results = modelCrit.list();
|
|
||||||
GridInfoRecord model = null;
|
|
||||||
if (results.size() == 0) {
|
|
||||||
return new ArrayList<GridRecord>(0);
|
|
||||||
} else if (results.size() > 1) {
|
|
||||||
// hours matched, take hour with least number that matches exact
|
|
||||||
// param
|
|
||||||
Pattern p = Pattern.compile("^" + abbreviation + "(\\d+)hr$");
|
|
||||||
int lowestHr = -1;
|
|
||||||
for (GridInfoRecord m : (List<GridInfoRecord>) results) {
|
|
||||||
String param = m.getParameter().getAbbreviation()
|
|
||||||
.toLowerCase();
|
|
||||||
if (param.equals(abbreviation) && (lowestHr < 0)) {
|
|
||||||
model = m;
|
|
||||||
} else {
|
|
||||||
Matcher matcher = p.matcher(param);
|
|
||||||
if (matcher.matches()) {
|
|
||||||
int hr = Integer.parseInt(matcher.group(1));
|
|
||||||
if ((lowestHr < 0) || (hr < lowestHr)) {
|
|
||||||
model = m;
|
|
||||||
lowestHr = hr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
model = (GridInfoRecord) results.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Criteria recordCrit = s.createCriteria(GridRecord.class);
|
|
||||||
baseCrit = Restrictions.eq("info", model);
|
|
||||||
baseCrit = Restrictions.and(
|
|
||||||
baseCrit,
|
|
||||||
Restrictions.eq("dataTime.refTime",
|
|
||||||
dbId.getModelTimeAsDate()));
|
|
||||||
recordCrit.add(baseCrit);
|
|
||||||
recordCrit.addOrder(Order.asc("dataTime.fcstTime"));
|
|
||||||
return recordCrit.list();
|
|
||||||
} finally {
|
|
||||||
if (s != null) {
|
|
||||||
s.flush();
|
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
modelId = (Integer) ((Object[]) results.get(0))[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Query timeQuery = s.createQuery(HQL_D2D_GRID_TIME_QUERY);
|
||||||
|
timeQuery.setInteger("info_id", modelId);
|
||||||
|
timeQuery.setParameter("refTime", dbId.getModelTimeAsDate());
|
||||||
|
List<Object[]> timeResults = timeQuery.list();
|
||||||
|
if (timeResults.isEmpty()) {
|
||||||
|
return new TreeMap<DataTime, Integer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
SortedMap<DataTime, Integer> dataTimes = new TreeMap<DataTime, Integer>();
|
||||||
|
for (Object[] rows : timeResults) {
|
||||||
|
dataTimes.put((DataTime) rows[0], (Integer) rows[1]);
|
||||||
|
}
|
||||||
|
return dataTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TimeRange> queryTimeByD2DParmId(ParmID id)
|
public List<TimeRange> queryTimeByD2DParmId(ParmID id)
|
||||||
throws DataAccessLayerException {
|
throws DataAccessLayerException {
|
||||||
List<TimeRange> timeList = new ArrayList<TimeRange>();
|
List<TimeRange> timeList = new ArrayList<TimeRange>();
|
||||||
if (id.getParmName().equalsIgnoreCase("wind")) {
|
Session s = null;
|
||||||
ParmID uWindId = new ParmID(id.toString().replace("wind", "uW"));
|
try {
|
||||||
List<TimeRange> uTimeList = new ArrayList<TimeRange>();
|
s = getHibernateTemplate().getSessionFactory().openSession();
|
||||||
List<DataTime> results = executeD2DParmQuery(uWindId);
|
|
||||||
for (DataTime o : results) {
|
|
||||||
uTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
|
||||||
3600 * 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
ParmID vWindId = new ParmID(id.toString().replace("wind", "vW"));
|
if (id.getParmName().equalsIgnoreCase("wind")) {
|
||||||
List<TimeRange> vTimeList = new ArrayList<TimeRange>();
|
String idString = id.toString();
|
||||||
results = executeD2DParmQuery(vWindId);
|
Matcher idWindMatcher = WIND_PATTERN.matcher(idString);
|
||||||
for (DataTime o : results) {
|
|
||||||
vTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
|
||||||
3600 * 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TimeRange tr : uTimeList) {
|
ParmID uWindId = new ParmID(idWindMatcher.replaceAll("uW"));
|
||||||
if (vTimeList.contains(tr)) {
|
SortedMap<DataTime, Integer> results = queryByD2DParmId(
|
||||||
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
|
uWindId, s);
|
||||||
|
List<TimeRange> uTimeList = new ArrayList<TimeRange>(
|
||||||
|
results.size());
|
||||||
|
for (DataTime o : results.keySet()) {
|
||||||
|
uTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
||||||
|
3600 * 1000));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!timeList.isEmpty()) {
|
ParmID vWindId = new ParmID(idWindMatcher.replaceAll("vW"));
|
||||||
return timeList;
|
results = queryByD2DParmId(vWindId, s);
|
||||||
}
|
Set<TimeRange> vTimeList = new HashSet<TimeRange>(
|
||||||
|
results.size(), 1);
|
||||||
ParmID sWindId = new ParmID(id.toString().replace("wind", "ws"));
|
for (DataTime o : results.keySet()) {
|
||||||
List<TimeRange> sTimeList = new ArrayList<TimeRange>();
|
vTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
||||||
results = executeD2DParmQuery(sWindId);
|
3600 * 1000));
|
||||||
for (DataTime o : results) {
|
|
||||||
sTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
|
||||||
3600 * 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
ParmID dWindId = new ParmID(id.toString().replace("wind", "wd"));
|
|
||||||
List<TimeRange> dTimeList = new ArrayList<TimeRange>();
|
|
||||||
results = executeD2DParmQuery(dWindId);
|
|
||||||
for (DataTime o : results) {
|
|
||||||
dTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
|
||||||
3600 * 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TimeRange tr : sTimeList) {
|
|
||||||
if (dTimeList.contains(tr)) {
|
|
||||||
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!timeList.isEmpty()) {
|
for (TimeRange tr : uTimeList) {
|
||||||
return timeList;
|
if (vTimeList.contains(tr)) {
|
||||||
}
|
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
|
||||||
} else {
|
}
|
||||||
List<DataTime> results = executeD2DParmQuery(id);
|
}
|
||||||
for (DataTime o : results) {
|
|
||||||
|
if (!timeList.isEmpty()) {
|
||||||
|
return timeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParmID sWindId = new ParmID(idWindMatcher.replaceAll("ws"));
|
||||||
|
results = queryByD2DParmId(sWindId, s);
|
||||||
|
List<TimeRange> sTimeList = new ArrayList<TimeRange>(
|
||||||
|
results.size());
|
||||||
|
for (DataTime o : results.keySet()) {
|
||||||
|
sTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
||||||
|
3600 * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
ParmID dWindId = new ParmID(idWindMatcher.replaceAll("wd"));
|
||||||
|
results = queryByD2DParmId(dWindId, s);
|
||||||
|
Set<TimeRange> dTimeList = new HashSet<TimeRange>(
|
||||||
|
results.size(), 1);
|
||||||
|
for (DataTime o : results.keySet()) {
|
||||||
|
dTimeList.add(new TimeRange(o.getValidPeriod().getStart(),
|
||||||
|
3600 * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TimeRange tr : sTimeList) {
|
||||||
|
if (dTimeList.contains(tr)) {
|
||||||
|
timeList.add(new TimeRange(tr.getStart(), tr.getStart()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SortedMap<DataTime, Integer> results = queryByD2DParmId(id, s);
|
||||||
if (isMos(id)) {
|
if (isMos(id)) {
|
||||||
timeList.add(new TimeRange(o.getValidPeriod().getEnd(), o
|
for (DataTime o : results.keySet()) {
|
||||||
.getValidPeriod().getDuration()));
|
timeList.add(new TimeRange(o.getValidPeriod().getEnd(),
|
||||||
|
o.getValidPeriod().getDuration()));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
timeList.add(o.getValidPeriod());
|
for (DataTime o : results.keySet()) {
|
||||||
|
timeList.add(o.getValidPeriod());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (s != null) {
|
||||||
|
try {
|
||||||
|
s.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
statusHandler.error(
|
||||||
|
"Error occurred closing database session", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeList;
|
return timeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DataTime> executeD2DParmQuery(ParmID id)
|
|
||||||
throws DataAccessLayerException {
|
|
||||||
List<DataTime> times = new ArrayList<DataTime>();
|
|
||||||
List<GridRecord> records = queryByD2DParmId(id);
|
|
||||||
for (GridRecord record : records) {
|
|
||||||
times.add(record.getDataTime());
|
|
||||||
}
|
|
||||||
return times;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void purgeGFEGrids(final DatabaseID dbId) {
|
public void purgeGFEGrids(final DatabaseID dbId) {
|
||||||
txTemplate.execute(new TransactionCallbackWithoutResult() {
|
txTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -108,12 +108,12 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
.getNamedHandler("GFEPerformanceLogger");
|
.getNamedHandler("GFEPerformanceLogger");
|
||||||
|
|
||||||
/** The remap object used for resampling grids */
|
/** The remap object used for resampling grids */
|
||||||
private Map<Integer, RemapGrid> remap = new HashMap<Integer, RemapGrid>();
|
private final Map<Integer, RemapGrid> remap = new HashMap<Integer, RemapGrid>();
|
||||||
|
|
||||||
/** The destination GridLocation (The local GFE grid coverage) */
|
/** The destination GridLocation (The local GFE grid coverage) */
|
||||||
private GridLocation outputLoc;
|
private GridLocation outputLoc;
|
||||||
|
|
||||||
private List<ParmID> parms;
|
private final List<ParmID> parms;
|
||||||
|
|
||||||
public static final String GRID_LOCATION_CACHE_KEY = "GfeLocations";
|
public static final String GRID_LOCATION_CACHE_KEY = "GfeLocations";
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
public ServerResponse<List<IGridSlice>> getGridData(ParmID id,
|
public ServerResponse<List<IGridSlice>> getGridData(ParmID id,
|
||||||
List<TimeRange> timeRanges) {
|
List<TimeRange> timeRanges) {
|
||||||
|
|
||||||
List<IGridSlice> data = new ArrayList<IGridSlice>();
|
List<IGridSlice> data = new ArrayList<IGridSlice>(timeRanges.size());
|
||||||
ServerResponse<List<IGridSlice>> sr = new ServerResponse<List<IGridSlice>>();
|
ServerResponse<List<IGridSlice>> sr = new ServerResponse<List<IGridSlice>>();
|
||||||
for (TimeRange tr : timeRanges) {
|
for (TimeRange tr : timeRanges) {
|
||||||
GridParmInfo gpi = getGridParmInfo(id).getPayload();
|
GridParmInfo gpi = getGridParmInfo(id).getPayload();
|
||||||
|
@ -415,7 +415,7 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
public ServerResponse<List<IGridSlice>> getGridData(ParmID id,
|
public ServerResponse<List<IGridSlice>> getGridData(ParmID id,
|
||||||
List<TimeRange> timeRanges, boolean convertUnit) {
|
List<TimeRange> timeRanges, boolean convertUnit) {
|
||||||
|
|
||||||
List<IGridSlice> data = new ArrayList<IGridSlice>();
|
List<IGridSlice> data = new ArrayList<IGridSlice>(timeRanges.size());
|
||||||
ServerResponse<List<IGridSlice>> sr = new ServerResponse<List<IGridSlice>>();
|
ServerResponse<List<IGridSlice>> sr = new ServerResponse<List<IGridSlice>>();
|
||||||
for (TimeRange tr : timeRanges) {
|
for (TimeRange tr : timeRanges) {
|
||||||
GridParmInfo gpi = getGridParmInfo(id).getPayload();
|
GridParmInfo gpi = getGridParmInfo(id).getPayload();
|
||||||
|
@ -429,6 +429,7 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
+ " TimeRange: " + tr, e);
|
+ " TimeRange: " + tr, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sr.setPayload(data);
|
sr.setPayload(data);
|
||||||
return sr;
|
return sr;
|
||||||
}
|
}
|
||||||
|
@ -550,7 +551,7 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
RemapGrid remap = getOrCreateRemap(d2dRecord.getLocation());
|
RemapGrid remap = getOrCreateRemap(d2dRecord.getLocation());
|
||||||
retVal = remap.remap(bdata, fillV, gpi.getMaxValue(),
|
retVal = remap.remap(bdata, fillV, gpi.getMaxValue(),
|
||||||
gpi.getMinValue(), gpi.getMinValue());
|
gpi.getMinValue(), gpi.getMinValue());
|
||||||
if (convertUnit && d2dRecord != null) {
|
if (convertUnit && (d2dRecord != null)) {
|
||||||
convertUnits(d2dRecord, retVal, gpi.getUnitObject());
|
convertUnits(d2dRecord, retVal, gpi.getUnitObject());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -651,7 +652,7 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
|
|
||||||
String mappedModel = config.d2dModelNameMapping(dbId.getModelName());
|
String mappedModel = config.d2dModelNameMapping(dbId.getModelName());
|
||||||
|
|
||||||
if (uRecord != null && vRecord != null) {
|
if ((uRecord != null) && (vRecord != null)) {
|
||||||
// Gets the raw grid data from the D2D grib HDF5 files
|
// Gets the raw grid data from the D2D grib HDF5 files
|
||||||
Grid2DFloat uData = getRawGridData(uRecord);
|
Grid2DFloat uData = getRawGridData(uRecord);
|
||||||
Grid2DFloat vData = getRawGridData(vRecord);
|
Grid2DFloat vData = getRawGridData(vRecord);
|
||||||
|
@ -688,7 +689,7 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
"Unable to retrieve wind grids from D2D database", e);
|
"Unable to retrieve wind grids from D2D database", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sRecord != null && dRecord != null) {
|
if ((sRecord != null) && (dRecord != null)) {
|
||||||
// Gets the raw grid data from the D2D grib HDF5 files
|
// Gets the raw grid data from the D2D grib HDF5 files
|
||||||
Grid2DFloat sData = getRawGridData(sRecord);
|
Grid2DFloat sData = getRawGridData(sRecord);
|
||||||
Grid2DFloat dData = getRawGridData(dRecord);
|
Grid2DFloat dData = getRawGridData(dRecord);
|
||||||
|
@ -914,8 +915,8 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNonAccumDuration(ParmID id, List<TimeRange> times)
|
public static boolean isNonAccumDuration(ParmID id,
|
||||||
throws GfeConfigurationException {
|
Collection<TimeRange> times) throws GfeConfigurationException {
|
||||||
boolean isAccum = false;
|
boolean isAccum = false;
|
||||||
try {
|
try {
|
||||||
isAccum = IFPServerConfigManager
|
isAccum = IFPServerConfigManager
|
||||||
|
@ -925,14 +926,19 @@ public class D2DGridDatabase extends VGridDatabase {
|
||||||
} catch (GfeConfigurationException e) {
|
} catch (GfeConfigurationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
boolean isDuration = false;
|
|
||||||
for (TimeRange time : times) {
|
if (!isAccum) {
|
||||||
if (time.getDuration() > 0) {
|
boolean isDuration = false;
|
||||||
isDuration = true;
|
for (TimeRange time : times) {
|
||||||
break;
|
if (time.getDuration() > 0) {
|
||||||
|
isDuration = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return !isAccum && isDuration;
|
||||||
}
|
}
|
||||||
return !isAccum && isDuration;
|
|
||||||
|
return !isAccum;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package com.raytheon.edex.plugin.gfe.util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.raytheon.uf.common.dataplugin.level.Level;
|
import com.raytheon.uf.common.dataplugin.level.Level;
|
||||||
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
||||||
|
@ -34,7 +35,7 @@ import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* May 5, 2008 njensen Initial creation
|
* May 5, 2008 njensen Initial creation
|
||||||
* Aug 22, 2008 1502 dglazesk Changed to JAXB unmarshalling
|
* Aug 22, 2008 1502 dglazesk Changed to JAXB unmarshalling
|
||||||
*
|
* Dec 06, 2012 1394 rjpeter Attend static compiled patterns.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author njensen
|
* @author njensen
|
||||||
|
@ -45,15 +46,19 @@ public class GridTranslator {
|
||||||
|
|
||||||
private static final List<String> NEEDS_ZERO = Arrays.asList("BLD", "WBZ");
|
private static final List<String> NEEDS_ZERO = Arrays.asList("BLD", "WBZ");
|
||||||
|
|
||||||
|
private static final Pattern ANY_NUMBER = Pattern.compile("[0-9]");
|
||||||
|
|
||||||
|
private static final Pattern NOT_NUMBER = Pattern.compile("[^0-9]");
|
||||||
|
|
||||||
private GridTranslator() {
|
private GridTranslator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLevelName(String shorthand) {
|
public static String getLevelName(String shorthand) {
|
||||||
return shorthand.replaceAll("[0-9]*", "");
|
return ANY_NUMBER.matcher(shorthand).replaceAll("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double[] getLevelValue(String shorthand) {
|
public static double[] getLevelValue(String shorthand) {
|
||||||
String levelString = shorthand.replaceAll("[^0-9]", "");
|
String levelString = NOT_NUMBER.matcher(shorthand).replaceAll("");
|
||||||
int length = levelString.length();
|
int length = levelString.length();
|
||||||
double[] retVal = new double[2];
|
double[] retVal = new double[2];
|
||||||
retVal[0] = Level.getInvalidLevelValue();
|
retVal[0] = Level.getInvalidLevelValue();
|
||||||
|
@ -126,9 +131,9 @@ public class GridTranslator {
|
||||||
} else {
|
} else {
|
||||||
tmp.append(name);
|
tmp.append(name);
|
||||||
|
|
||||||
if (levelOne != Level.getInvalidLevelValue()
|
if ((levelOne != Level.getInvalidLevelValue())
|
||||||
&& (levelOne != 0
|
&& ((levelOne != 0)
|
||||||
|| levelTwo != Level.getInvalidLevelValue() || NEEDS_ZERO
|
|| (levelTwo != Level.getInvalidLevelValue()) || NEEDS_ZERO
|
||||||
.contains(name))) {
|
.contains(name))) {
|
||||||
tmp.append(String.valueOf(Math.round(levelOne)));
|
tmp.append(String.valueOf(Math.round(levelOne)));
|
||||||
}
|
}
|
||||||
|
@ -166,7 +171,7 @@ public class GridTranslator {
|
||||||
+ level
|
+ level
|
||||||
+ " "
|
+ " "
|
||||||
+ Arrays.toString(levels)
|
+ Arrays.toString(levels)
|
||||||
+ (l1 == levels[0] && l2 == levels[1] ? " passed"
|
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
|
||||||
: " failed"));
|
: " failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +192,7 @@ public class GridTranslator {
|
||||||
+ level
|
+ level
|
||||||
+ " "
|
+ " "
|
||||||
+ Arrays.toString(levels)
|
+ Arrays.toString(levels)
|
||||||
+ (l1 == levels[0] && l2 == levels[1] ? " passed"
|
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
|
||||||
: " failed"));
|
: " failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,26 +202,50 @@ public class GridTranslator {
|
||||||
l2 = -999999;
|
l2 = -999999;
|
||||||
level = GridTranslator.getShortLevelName(levelName, l1, l2);
|
level = GridTranslator.getShortLevelName(levelName, l1, l2);
|
||||||
levels = GridTranslator.getLevelValue(level);
|
levels = GridTranslator.getLevelValue(level);
|
||||||
System.out.println(levelName + " " + l1 + " " + l2 + ": " + level + " "
|
System.out.println(levelName
|
||||||
|
+ " "
|
||||||
|
+ l1
|
||||||
|
+ " "
|
||||||
|
+ l2
|
||||||
|
+ ": "
|
||||||
|
+ level
|
||||||
|
+ " "
|
||||||
+ Arrays.toString(levels)
|
+ Arrays.toString(levels)
|
||||||
+ (l1 == levels[0] && l2 == levels[1] ? " passed" : " failed"));
|
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
|
||||||
|
: " failed"));
|
||||||
|
|
||||||
levelName = "BLD";
|
levelName = "BLD";
|
||||||
l1 = 0;
|
l1 = 0;
|
||||||
l2 = -999999;
|
l2 = -999999;
|
||||||
level = GridTranslator.getShortLevelName(levelName, l1, l2);
|
level = GridTranslator.getShortLevelName(levelName, l1, l2);
|
||||||
levels = GridTranslator.getLevelValue(level);
|
levels = GridTranslator.getLevelValue(level);
|
||||||
System.out.println(levelName + " " + l1 + " " + l2 + ": " + level + " "
|
System.out.println(levelName
|
||||||
|
+ " "
|
||||||
|
+ l1
|
||||||
|
+ " "
|
||||||
|
+ l2
|
||||||
|
+ ": "
|
||||||
|
+ level
|
||||||
|
+ " "
|
||||||
+ Arrays.toString(levels)
|
+ Arrays.toString(levels)
|
||||||
+ (l1 == levels[0] && l2 == levels[1] ? " passed" : " failed"));
|
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
|
||||||
|
: " failed"));
|
||||||
|
|
||||||
levelName = "WBZ";
|
levelName = "WBZ";
|
||||||
l1 = 0;
|
l1 = 0;
|
||||||
l2 = -999999;
|
l2 = -999999;
|
||||||
level = GridTranslator.getShortLevelName(levelName, l1, l2);
|
level = GridTranslator.getShortLevelName(levelName, l1, l2);
|
||||||
levels = GridTranslator.getLevelValue(level);
|
levels = GridTranslator.getLevelValue(level);
|
||||||
System.out.println(levelName + " " + l1 + " " + l2 + ": " + level + " "
|
System.out.println(levelName
|
||||||
|
+ " "
|
||||||
|
+ l1
|
||||||
|
+ " "
|
||||||
|
+ l2
|
||||||
|
+ ": "
|
||||||
|
+ level
|
||||||
|
+ " "
|
||||||
+ Arrays.toString(levels)
|
+ Arrays.toString(levels)
|
||||||
+ (l1 == levels[0] && l2 == levels[1] ? " passed" : " failed"));
|
+ ((l1 == levels[0]) && (l2 == levels[1]) ? " passed"
|
||||||
|
: " failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||||
|
@ -56,11 +57,19 @@ public class DataFieldTableLookup {
|
||||||
|
|
||||||
private static DataFieldTableLookup instance;
|
private static DataFieldTableLookup instance;
|
||||||
|
|
||||||
private Map<String, String> data2cdl = new HashMap<String, String>();
|
private final Pattern DASH = Pattern.compile("-");
|
||||||
|
|
||||||
private Map<String, String> cdl2data = new HashMap<String, String>();
|
private final Pattern UNDERSCORE = Pattern.compile("_");
|
||||||
|
|
||||||
private Map<String, String> data2name = new HashMap<String, String>();
|
private final Pattern NEWLINE = Pattern.compile("\n");
|
||||||
|
|
||||||
|
private final Pattern PIPE = Pattern.compile("\\|");
|
||||||
|
|
||||||
|
private final Map<String, String> data2cdl = new HashMap<String, String>();
|
||||||
|
|
||||||
|
private final Map<String, String> cdl2data = new HashMap<String, String>();
|
||||||
|
|
||||||
|
private final Map<String, String> data2name = new HashMap<String, String>();
|
||||||
|
|
||||||
public static synchronized DataFieldTableLookup getInstance() {
|
public static synchronized DataFieldTableLookup getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
|
@ -87,13 +96,13 @@ public class DataFieldTableLookup {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
|
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
for (String line : contents.split("\n")) {
|
for (String line : NEWLINE.split(contents)) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.startsWith("//") || line.startsWith("#")) {
|
if (line.startsWith("//") || line.startsWith("#")) {
|
||||||
// ignore comments
|
// ignore comments
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String[] parts = line.split("\\|");
|
String[] parts = PIPE.split(line);
|
||||||
if (parts.length < 2) {
|
if (parts.length < 2) {
|
||||||
// invalid line
|
// invalid line
|
||||||
continue;
|
continue;
|
||||||
|
@ -121,7 +130,7 @@ public class DataFieldTableLookup {
|
||||||
public String lookupCdlName(String dataField) {
|
public String lookupCdlName(String dataField) {
|
||||||
String retVal = data2cdl.get(dataField);
|
String retVal = data2cdl.get(dataField);
|
||||||
if (retVal == null) {
|
if (retVal == null) {
|
||||||
retVal = data2cdl.get(dataField.replace("-", "_"));
|
retVal = data2cdl.get(DASH.matcher(dataField).replaceAll("_"));
|
||||||
if (retVal == null) {
|
if (retVal == null) {
|
||||||
retVal = dataField;
|
retVal = dataField;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +141,7 @@ public class DataFieldTableLookup {
|
||||||
public String lookupDataName(String cdlField) {
|
public String lookupDataName(String cdlField) {
|
||||||
String retVal = cdl2data.get(cdlField);
|
String retVal = cdl2data.get(cdlField);
|
||||||
if (retVal != null) {
|
if (retVal != null) {
|
||||||
retVal = retVal.replace("_", "-");
|
retVal = UNDERSCORE.matcher(retVal).replaceAll("-");
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +149,7 @@ public class DataFieldTableLookup {
|
||||||
public String lookupName(String dataField) {
|
public String lookupName(String dataField) {
|
||||||
String retVal = data2name.get(dataField);
|
String retVal = data2name.get(dataField);
|
||||||
if (retVal == null) {
|
if (retVal == null) {
|
||||||
retVal = data2name.get(dataField.replace("-", "_"));
|
retVal = data2name.get(DASH.matcher(dataField).replaceAll("_"));
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue