Issue #2121 add weather and discrete grid support to data access framework and add remove identifier ability for python interpreter requests
Change-Id: I8ede8f8149be84e58d10d30066e08d3c80d543e5 Former-commit-id:22a6ac6460
[formerly0fe30ac2fb
] [formerly54a114d789
] [formerly99e9194921
[formerly54a114d789
[formerly 95ec6db9b349890a29bd13860193ada39b43c294]]] Former-commit-id:99e9194921
Former-commit-id: 3285d64a25c4b063cb7870f164e60f088e108622 [formerly4fa399c710
] Former-commit-id:6486801d2c
This commit is contained in:
parent
6faf91da7d
commit
389c518d07
4 changed files with 70 additions and 16 deletions
|
@ -50,6 +50,9 @@ class JDataRequest(IDataRequest, JUtil.JavaWrapperClass):
|
||||||
def addIdentifier(self, key, value):
|
def addIdentifier(self, key, value):
|
||||||
self.jobj.addIdentifier(key, JUtil.pyValToJavaObj(value))
|
self.jobj.addIdentifier(key, JUtil.pyValToJavaObj(value))
|
||||||
|
|
||||||
|
def removeIdentifier(self, key):
|
||||||
|
self.jobj.removeIdentifier(key)
|
||||||
|
|
||||||
def setParameters(self, *args):
|
def setParameters(self, *args):
|
||||||
from java.lang import String as JavaString
|
from java.lang import String as JavaString
|
||||||
params = jep.jarray(len(args), JavaString)
|
params = jep.jarray(len(args), JavaString)
|
||||||
|
|
|
@ -97,6 +97,12 @@ public class DefaultDataRequest implements IDataRequest {
|
||||||
identifiers.put(key, value);
|
identifiers.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeIdentifier(String key) {
|
||||||
|
if (identifiers != null) {
|
||||||
|
identifiers.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setIdentifiers(Map<String, Object> identifiers) {
|
public void setIdentifiers(Map<String, Object> identifiers) {
|
||||||
this.identifiers = identifiers;
|
this.identifiers = identifiers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,18 +36,26 @@ import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord;
|
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
|
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo;
|
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo;
|
||||||
|
import com.raytheon.uf.common.dataplugin.gfe.discrete.DiscreteKey;
|
||||||
|
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DByte;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat;
|
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat;
|
||||||
|
import com.raytheon.uf.common.dataplugin.gfe.grid.IGrid2D;
|
||||||
|
import com.raytheon.uf.common.dataplugin.gfe.slice.DiscreteGridSlice;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice;
|
import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice;
|
||||||
import com.raytheon.uf.common.dataplugin.gfe.slice.ScalarGridSlice;
|
import com.raytheon.uf.common.dataplugin.gfe.slice.ScalarGridSlice;
|
||||||
|
import com.raytheon.uf.common.dataplugin.gfe.slice.WeatherGridSlice;
|
||||||
|
import com.raytheon.uf.common.dataplugin.gfe.weather.WeatherKey;
|
||||||
import com.raytheon.uf.common.dataplugin.level.Level;
|
import com.raytheon.uf.common.dataplugin.level.Level;
|
||||||
import com.raytheon.uf.common.dataplugin.level.MasterLevel;
|
import com.raytheon.uf.common.dataplugin.level.MasterLevel;
|
||||||
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
|
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
|
||||||
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
|
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
|
||||||
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
|
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
|
||||||
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
|
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
|
||||||
|
import com.raytheon.uf.common.datastorage.records.ByteDataRecord;
|
||||||
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
|
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
|
||||||
import com.raytheon.uf.common.datastorage.records.IDataRecord;
|
import com.raytheon.uf.common.datastorage.records.IDataRecord;
|
||||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||||
|
import com.raytheon.uf.common.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A data factory for getting gfe data from the metadata database. There are
|
* A data factory for getting gfe data from the metadata database. There are
|
||||||
|
@ -81,6 +89,8 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
|
||||||
|
|
||||||
private static final String SITE_ID = "siteId";
|
private static final String SITE_ID = "siteId";
|
||||||
|
|
||||||
|
private static final String KEYS = "keys";
|
||||||
|
|
||||||
// The more full version from GFEDataAccessUtil is prefered but the smaller
|
// The more full version from GFEDataAccessUtil is prefered but the smaller
|
||||||
// keys are needed for backwards compatibility.
|
// keys are needed for backwards compatibility.
|
||||||
private static final String[] VALID_IDENTIFIERS = { MODEL_NAME, MODEL_TIME,
|
private static final String[] VALID_IDENTIFIERS = { MODEL_NAME, MODEL_TIME,
|
||||||
|
@ -107,14 +117,14 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
|
||||||
defaultGridData.setLevel(level);
|
defaultGridData.setLevel(level);
|
||||||
defaultGridData.setUnit(gfeRecord.getGridInfo().getUnitObject());
|
defaultGridData.setUnit(gfeRecord.getGridInfo().getUnitObject());
|
||||||
defaultGridData.setLocationName(gfeRecord.getDbId().getSiteId());
|
defaultGridData.setLocationName(gfeRecord.getDbId().getSiteId());
|
||||||
|
|
||||||
Map<String, Object> attrs = new HashMap<String, Object>();
|
Map<String, Object> attrs = new HashMap<String, Object>();
|
||||||
attrs.put(MODEL_NAME, gfeRecord.getDbId()
|
attrs.put(MODEL_NAME, gfeRecord.getDbId().getModelName());
|
||||||
.getModelName());
|
attrs.put(MODEL_TIME, gfeRecord.getDbId().getModelTime());
|
||||||
attrs.put(MODEL_TIME, gfeRecord.getDbId()
|
|
||||||
.getModelTime());
|
|
||||||
attrs.put(SITE_ID, gfeRecord.getDbId().getSiteId());
|
attrs.put(SITE_ID, gfeRecord.getDbId().getSiteId());
|
||||||
|
if (dataRecord.getDataAttributes().containsKey(KEYS)) {
|
||||||
|
attrs.put(KEYS, StringUtil.join((String[]) dataRecord
|
||||||
|
.getDataAttributes().get(KEYS), ','));
|
||||||
|
}
|
||||||
defaultGridData.setAttributes(attrs);
|
defaultGridData.setAttributes(attrs);
|
||||||
|
|
||||||
return defaultGridData;
|
return defaultGridData;
|
||||||
|
@ -130,8 +140,7 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
|
||||||
for (Entry<String, Object> entry : identifiers.entrySet()) {
|
for (Entry<String, Object> entry : identifiers.entrySet()) {
|
||||||
if (entry.getKey().equals(MODEL_NAME)) {
|
if (entry.getKey().equals(MODEL_NAME)) {
|
||||||
constraints.put(GFEDataAccessUtil.MODEL_NAME,
|
constraints.put(GFEDataAccessUtil.MODEL_NAME,
|
||||||
new RequestConstraint(entry
|
new RequestConstraint(entry.getValue().toString()));
|
||||||
.getValue().toString()));
|
|
||||||
} else if (entry.getKey().equals(SITE_ID)) {
|
} else if (entry.getKey().equals(SITE_ID)) {
|
||||||
constraints.put(GFEDataAccessUtil.SITE_ID,
|
constraints.put(GFEDataAccessUtil.SITE_ID,
|
||||||
new RequestConstraint(entry.getValue().toString()));
|
new RequestConstraint(entry.getValue().toString()));
|
||||||
|
@ -154,7 +163,8 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
|
||||||
RequestConstraint paramNameConstraint = new RequestConstraint(
|
RequestConstraint paramNameConstraint = new RequestConstraint(
|
||||||
null, ConstraintType.IN);
|
null, ConstraintType.IN);
|
||||||
paramNameConstraint.setConstraintValueList(parameters);
|
paramNameConstraint.setConstraintValueList(parameters);
|
||||||
constraints.put(GFEDataAccessUtil.PARM_NAME, paramNameConstraint);
|
constraints.put(GFEDataAccessUtil.PARM_NAME,
|
||||||
|
paramNameConstraint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +181,8 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
|
||||||
paramLevelConstraint.addToConstraintValueList(level
|
paramLevelConstraint.addToConstraintValueList(level
|
||||||
.getMasterLevel().getName());
|
.getMasterLevel().getName());
|
||||||
}
|
}
|
||||||
constraints.put(GFEDataAccessUtil.PARM_LEVEL, paramLevelConstraint);
|
constraints.put(GFEDataAccessUtil.PARM_LEVEL,
|
||||||
|
paramLevelConstraint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,20 +207,51 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
|
||||||
GFERecord gfeRecord = asGFERecord(pdo);
|
GFERecord gfeRecord = asGFERecord(pdo);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IGridSlice slice = GFEDataAccessUtil
|
IGridSlice slice = GFEDataAccessUtil.getSlice(gfeRecord);
|
||||||
.getSlice(gfeRecord);
|
|
||||||
GridLocation loc = slice.getGridInfo().getGridLoc();
|
GridLocation loc = slice.getGridInfo().getGridLoc();
|
||||||
gfeRecord.setGridInfo(slice.getGridInfo());
|
gfeRecord.setGridInfo(slice.getGridInfo());
|
||||||
Grid2DFloat data = null;
|
IGrid2D data = null;
|
||||||
if(slice instanceof ScalarGridSlice){
|
Map<String, Object> attrs = new HashMap<String, Object>();
|
||||||
|
if (slice instanceof ScalarGridSlice) {
|
||||||
// This also grabs vector data.
|
// This also grabs vector data.
|
||||||
data = ((ScalarGridSlice) slice).getScalarGrid();
|
data = ((ScalarGridSlice) slice).getScalarGrid();
|
||||||
|
return new FloatDataRecord("Data", gfeRecord.getDataURI(),
|
||||||
|
((Grid2DFloat) data).getFloats(), 2, new long[] {
|
||||||
|
loc.getNx(), loc.getNy() });
|
||||||
|
} else if (slice instanceof DiscreteGridSlice) {
|
||||||
|
DiscreteGridSlice castedSlice = (DiscreteGridSlice) slice;
|
||||||
|
data = castedSlice.getDiscreteGrid();
|
||||||
|
DiscreteKey[] dKeys = castedSlice.getKey();
|
||||||
|
String[] keys = new String[dKeys.length];
|
||||||
|
for (int i = 0; i < dKeys.length; i++) {
|
||||||
|
keys[i] = dKeys[i].toString();
|
||||||
|
}
|
||||||
|
byte[] bytes = ((Grid2DByte) data).getBytes();
|
||||||
|
ByteDataRecord record = new ByteDataRecord("Data",
|
||||||
|
gfeRecord.getDataURI(), bytes, 2, new long[] {
|
||||||
|
loc.getNx(), loc.getNy() });
|
||||||
|
attrs.put(KEYS, keys);
|
||||||
|
record.setDataAttributes(attrs);
|
||||||
|
return record;
|
||||||
|
} else if (slice instanceof WeatherGridSlice) {
|
||||||
|
WeatherGridSlice castedSlice = (WeatherGridSlice) slice;
|
||||||
|
data = castedSlice.getWeatherGrid();
|
||||||
|
WeatherKey[] wKeys = castedSlice.getKeys();
|
||||||
|
String[] keys = new String[wKeys.length];
|
||||||
|
for (int i = 0; i < wKeys.length; i++) {
|
||||||
|
keys[i] = wKeys[i].toString();
|
||||||
|
}
|
||||||
|
byte[] bytes = ((Grid2DByte) data).getBytes();
|
||||||
|
ByteDataRecord record = new ByteDataRecord("Data",
|
||||||
|
gfeRecord.getDataURI(), bytes, 2, new long[] {
|
||||||
|
loc.getNx(), loc.getNy() });
|
||||||
|
attrs.put(KEYS, keys);
|
||||||
|
record.setDataAttributes(attrs);
|
||||||
|
return record;
|
||||||
} else {
|
} else {
|
||||||
throw new DataRetrievalException("Unknown slice of type "
|
throw new DataRetrievalException("Unknown slice of type "
|
||||||
+ slice.getClass().getSimpleName());
|
+ slice.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
return new FloatDataRecord("Data", gfeRecord.getDataURI(), data.getFloats(), 2, new long[] {
|
|
||||||
loc.getNx(), loc.getNy() });
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DataRetrievalException(e);
|
throw new DataRetrievalException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,9 @@ class DefaultDataRequest(IDataRequest):
|
||||||
def addIdentifier(self, key, value):
|
def addIdentifier(self, key, value):
|
||||||
self.identifiers[key] = value
|
self.identifiers[key] = value
|
||||||
|
|
||||||
|
def removeIdentifier(self, key):
|
||||||
|
del self.identifiers[key]
|
||||||
|
|
||||||
def setParameters(self, *params):
|
def setParameters(self, *params):
|
||||||
self.parameters = map(str, params)
|
self.parameters = map(str, params)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue