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: 99e9194921 [formerly 0fe30ac2fb [formerly 54a114d789] [formerly 99e9194921 [formerly 95ec6db9b349890a29bd13860193ada39b43c294]]]
Former-commit-id: 0fe30ac2fb [formerly 54a114d789]
Former-commit-id: 0fe30ac2fb
Former-commit-id: 22a6ac6460
This commit is contained in:
Matt Nash 2013-06-19 10:11:27 -05:00
parent da223ab443
commit 565bfe64e3
4 changed files with 70 additions and 16 deletions

View file

@ -50,6 +50,9 @@ class JDataRequest(IDataRequest, JUtil.JavaWrapperClass):
def addIdentifier(self, key, value):
self.jobj.addIdentifier(key, JUtil.pyValToJavaObj(value))
def removeIdentifier(self, key):
self.jobj.removeIdentifier(key)
def setParameters(self, *args):
from java.lang import String as JavaString
params = jep.jarray(len(args), JavaString)

View file

@ -97,6 +97,12 @@ public class DefaultDataRequest implements IDataRequest {
identifiers.put(key, value);
}
public void removeIdentifier(String key) {
if (identifiers != null) {
identifiers.remove(key);
}
}
public void setIdentifiers(Map<String, Object> identifiers) {
this.identifiers = identifiers;
}

View file

@ -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.GridLocation;
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.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.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.MasterLevel;
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
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.IDataRecord;
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
@ -81,6 +89,8 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
private static final String SITE_ID = "siteId";
private static final String KEYS = "keys";
// The more full version from GFEDataAccessUtil is prefered but the smaller
// keys are needed for backwards compatibility.
private static final String[] VALID_IDENTIFIERS = { MODEL_NAME, MODEL_TIME,
@ -107,14 +117,14 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
defaultGridData.setLevel(level);
defaultGridData.setUnit(gfeRecord.getGridInfo().getUnitObject());
defaultGridData.setLocationName(gfeRecord.getDbId().getSiteId());
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(MODEL_NAME, gfeRecord.getDbId()
.getModelName());
attrs.put(MODEL_TIME, gfeRecord.getDbId()
.getModelTime());
attrs.put(MODEL_NAME, gfeRecord.getDbId().getModelName());
attrs.put(MODEL_TIME, gfeRecord.getDbId().getModelTime());
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);
return defaultGridData;
@ -130,8 +140,7 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
for (Entry<String, Object> entry : identifiers.entrySet()) {
if (entry.getKey().equals(MODEL_NAME)) {
constraints.put(GFEDataAccessUtil.MODEL_NAME,
new RequestConstraint(entry
.getValue().toString()));
new RequestConstraint(entry.getValue().toString()));
} else if (entry.getKey().equals(SITE_ID)) {
constraints.put(GFEDataAccessUtil.SITE_ID,
new RequestConstraint(entry.getValue().toString()));
@ -154,7 +163,8 @@ public class GFEGridFactory extends AbstractGridDataPluginFactory implements
RequestConstraint paramNameConstraint = new RequestConstraint(
null, ConstraintType.IN);
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
.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);
try {
IGridSlice slice = GFEDataAccessUtil
.getSlice(gfeRecord);
IGridSlice slice = GFEDataAccessUtil.getSlice(gfeRecord);
GridLocation loc = slice.getGridInfo().getGridLoc();
gfeRecord.setGridInfo(slice.getGridInfo());
Grid2DFloat data = null;
if(slice instanceof ScalarGridSlice){
IGrid2D data = null;
Map<String, Object> attrs = new HashMap<String, Object>();
if (slice instanceof ScalarGridSlice) {
// This also grabs vector data.
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 {
throw new DataRetrievalException("Unknown slice of type "
+ slice.getClass().getSimpleName());
}
return new FloatDataRecord("Data", gfeRecord.getDataURI(), data.getFloats(), 2, new long[] {
loc.getNx(), loc.getNy() });
} catch (Exception e) {
throw new DataRetrievalException(e);
}

View file

@ -52,6 +52,9 @@ class DefaultDataRequest(IDataRequest):
def addIdentifier(self, key, value):
self.identifiers[key] = value
def removeIdentifier(self, key):
del self.identifiers[key]
def setParameters(self, *params):
self.parameters = map(str, params)