Issue #1869 Get plots working without dataURI

Former-commit-id: 7267acf078 [formerly 2ce2fc8a17] [formerly 79139629a6] [formerly a84c975426 [formerly 79139629a6 [formerly 855d95e8563c47e5601c80c9efe5006280bda76e]]]
Former-commit-id: a84c975426
Former-commit-id: 9e224448a5b9a9f4dba22a128d1db00c81a90c9d [formerly 2dfb65b594]
Former-commit-id: 9ebbfb262d
This commit is contained in:
Ben Steffensmeier 2013-05-14 14:29:30 -05:00
parent c233a43561
commit 05c7617fae
6 changed files with 221 additions and 81 deletions

View file

@ -37,6 +37,8 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.commons.lang.Validate;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.dataplugin.annotations.DataURIUtil;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.RequestableMetadataMarshaller;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -75,11 +77,13 @@ import com.raytheon.uf.viz.core.rsc.IResourceDataChanged.ChangeType;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 10, 2009 chammack Initial creation
* Feb 26, 2009 2032 jsanchez Added loadWithNoData condition.
* April 6, 2011 njensen Moved binning times to edex
* April 13, 2011 njensen Caching available times
* Mar 29, 2013 1638 mschenke Switched to create PDO from dataURI mapping instead of dataURI string
* Feb 10, 2009 chammack Initial creation
* Feb 26, 2009 2032 jsanchez Added loadWithNoData condition.
* Apr 06, 2011 njensen Moved binning times to edex
* Apr 13, 2011 njensen Caching available times
* Mar 29, 2013 1638 mschenke Switched to create PDO from dataURI
* mapping instead of dataURI string
* May 14, 2013 1869 bsteffen Get dataURI map directly from PDO.
*
* </pre>
*
@ -240,10 +244,8 @@ public abstract class AbstractRequestableResourceData extends
public static void checkMetadataMap(Map<String, RequestConstraint> map,
PluginDataObject pdo) {
String dataURI = pdo.getDataURI();
RecordFactory factory = RecordFactory.getInstance();
try {
Map<String, Object> dataURIMap = factory.loadMapFromUri(dataURI);
Map<String, Object> dataURIMap = DataURIUtil.createDataURIMap(pdo);
for (String key : map.keySet()) {
if (dataURIMap.containsKey(key) == false) {
statusHandler
@ -257,7 +259,7 @@ public abstract class AbstractRequestableResourceData extends
+ " is not in datauri, updates may not properly work for resource");
}
}
} catch (VizException e) {
} catch (PluginException e) {
statusHandler.handle(Priority.PROBLEM,
"Error parsing datauri into map", e);
}
@ -289,9 +291,8 @@ public abstract class AbstractRequestableResourceData extends
}
}
}
this.fireChangeListeners(ChangeType.DATA_UPDATE, updateData);
}
this.fireChangeListeners(ChangeType.DATA_UPDATE, updateData);
}
protected void update(AlertMessage... messages) {

View file

@ -37,12 +37,14 @@ import com.raytheon.uf.common.pointdata.PointDataView;
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.DataTime;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.IGraphicsTarget.LineStyle;
import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.map.IMapDescriptor;
import com.raytheon.viz.pointdata.PlotModelFactory2.PlotModelElement;
import com.raytheon.viz.pointdata.rsc.PlotResourceData;
import com.raytheon.viz.pointdata.thread.GetDataTask;
import com.raytheon.viz.pointdata.thread.PlotSampleGeneratorJob;
@ -57,6 +59,7 @@ import com.raytheon.viz.pointdata.thread.PlotSampleGeneratorJob;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 22, 2011 njensen Initial creation
* May 14, 2013 1869 bsteffen Get plots working without dataURI
*
* </pre>
*
@ -193,22 +196,62 @@ public class PlotModelDataRequestJob extends Job {
}
}
if (!params.contains("dataURI")) {
params.add("dataURI");
}
boolean hasDistinctStationId = PlotResourceData
.getPluginProperties(plugin).hasDistinctStationId;
String uniquePointDataKey = "stationId";
String uniqueQueryKey = "location.stationId";
if(!hasDistinctStationId){
uniquePointDataKey = "dataURI";
uniqueQueryKey = uniquePointDataKey;
}
if (!params.contains(uniquePointDataKey)) {
params.add(uniquePointDataKey);
}
Map<String, RequestConstraint> map = new HashMap<String, RequestConstraint>();
map.putAll(this.constraintMap);
RequestConstraint rc = new RequestConstraint();
rc.setConstraintType(ConstraintType.IN);
List<String> str = new ArrayList<String>(stationQuery.size());
DataTime start = null;
DataTime end = null;
for (PlotInfo[] infos : stationQuery) {
for (PlotInfo info : infos) {
str.add(info.dataURI);
plotMap.put(info.dataURI, info);
String key = null;
if (hasDistinctStationId) {
key = info.stationId;
}else{
key = info.dataURI;
}
str.add(key);
if (!plotMap.containsKey(key)) {
plotMap.put(key, info);
}
if (start == null
|| start.getValidTime().after(
info.dataTime.getValidTime())) {
start = info.dataTime;
}
if (end == null
|| end.getValidTime().before(
info.dataTime.getValidTime())) {
end = info.dataTime;
}
}
}
if (start.equals(end)) {
map.put("dataTime", new RequestConstraint(start.toString()));
} else {
RequestConstraint r = new RequestConstraint(null,
ConstraintType.BETWEEN);
r.setBetweenValueList(new String[] { start.toString(),
end.toString() });
map.put("dataTime.refTime", r);
}
int index = 0;
int j = 0;
int numOfValues = 500;
@ -219,7 +262,7 @@ public class PlotModelDataRequestJob extends Job {
index++;
j++;
}
map.put("dataURI", rc);
map.put(uniqueQueryKey, rc);
try {
// Try and get data from datacube
long t0 = System.currentTimeMillis();
@ -243,8 +286,8 @@ public class PlotModelDataRequestJob extends Job {
for (int uriCounter = 0; uriCounter < pdc.getAllocatedSz(); uriCounter++) {
PointDataView pdv = pdc.readRandom(uriCounter);
if (pdv != null) {
String dataURI = pdv.getString("dataURI");
PlotInfo info = plotMap.get(dataURI);
String unique = pdv.getString(uniquePointDataKey);
PlotInfo info = plotMap.get(unique);
// If the id doesn't match, try to match by
// location
if (info == null) {

View file

@ -82,15 +82,16 @@ import com.vividsolutions.jts.geom.Coordinate;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 11/20/2006 brockwoo Initial creation.
* 02/17/2009 njensen Refactored to new rsc architecture.
* 03/17/2009 2105 jsanchez Plot goessounding/poessounding availability.
* 03/30/2009 2169 jsanchez Updated initNewFrame.
* 04/09/2009 952 jsanchez Plot acars.
* 04/13/2009 2251 jsanchez Plot profilers.
* 04/21/2009 chammack Refactor to common pointData model
* 02/01/2013 1567 njensen Refactor handling of updates
*
* Nov 20, 2006 brockwoo Initial creation.
* Feb 17, 2009 njensen Refactored to new rsc architecture.
* Mar 17, 2009 2105 jsanchez Plot goessounding/poessounding
* availability.
* Mar 30, 2009 2169 jsanchez Updated initNewFrame.
* Apr 09, 2009 952 jsanchez Plot acars.
* Apr 13, 2009 2251 jsanchez Plot profilers.
* Apr 21, 2009 chammack Refactor to common pointData model
* Feb 01, 2013 1567 njensen Refactor handling of updates
* May 14, 2013 1869 bsteffen Get plots working without dataURI
*
* </pre>
*
@ -378,7 +379,9 @@ public class PlotResource2 extends
}
boolean dup = false;
for (int i = 0; i < existingStation.info.length; i++) {
if (existingStation.info[i].dataURI.equals(plot.dataURI)) {
String curUri = existingStation.info[i].dataURI;
String newUri = plot.dataURI;
if (curUri == null || curUri.equals(newUri)) {
dup = true;
break;
}

View file

@ -21,9 +21,7 @@ package com.raytheon.viz.pointdata.rsc;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -35,6 +33,7 @@ import org.apache.batik.util.ParsedURL;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
import com.raytheon.uf.common.dataquery.requests.RequestableMetadataMarshaller;
import com.raytheon.uf.common.time.BinOffset;
import com.raytheon.uf.common.time.DataTime;
@ -55,7 +54,8 @@ import com.raytheon.viz.pointdata.rsc.retrieve.PointDataPlotInfoRetriever;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 17, 2009 njensen Initial creation
* Jun 29, 2009 2538 jsanchez Implemented Metars.
* Jun 29, 2009 2538 jsanchez Implemented Metars.
* May 14, 2013 1869 bsteffen Get plots working without dataURI
*
* </pre>
*
@ -68,6 +68,39 @@ public class PlotResourceData extends AbstractRequestableResourceData {
public static final String PLOT_DIR = "plotModels" + File.separator;
public static class PluginPlotProperties {
/**
* Plugins that use the point data api will be instantiated using
* PlotResource2, otherwise PlotResource will be used which requires
* that the PDO of the plugin implement IDecoderGettable
*/
public final boolean usesPointDataApi;
/**
* When this is true all plots will be correlated based on the
* stationId, otherwise each dataURI is mapped to a specific set of
* data.
*/
public final boolean hasDistinctStationId;
public PluginPlotProperties(boolean usesPointDataApi,
boolean hasDistinctStationId) {
this.usesPointDataApi = usesPointDataApi;
this.hasDistinctStationId = hasDistinctStationId;
}
/**
* This is the goal for all plugins, they should use the new api and
* they should have distinct stationIds.
*/
public PluginPlotProperties() {
this.usesPointDataApi = true;
this.hasDistinctStationId = true;
}
}
@XmlAttribute
int pixelSampleDistance = 32;
@ -107,40 +140,56 @@ public class PlotResourceData extends AbstractRequestableResourceData {
@XmlJavaTypeAdapter(value = RequestableMetadataMarshaller.class)
protected HashMap<String, RequestConstraint> timeQueryMetadataMap;
private static Set<String> pluginNames = new HashSet<String>();
private static final Map<String, PluginPlotProperties> pluginProps = new HashMap<String, PluginPlotProperties>();
static {
pluginNames.add("goessounding");
pluginNames.add("poessounding");
pluginNames.add("obs");
pluginNames.add("bufrssmi");
pluginNames.add("bufrquikscat");
pluginNames.add("bufrascat");
pluginNames.add("radar");
pluginNames.add("bufrhdw");
pluginNames.add("bufrmthdw");
pluginNames.add("bufrua");
pluginNames.add("lsr");
pluginNames.add("sfcobs");
pluginNames.add("tcg");
pluginNames.add("svrwx");
pluginNames.add("ldadmesonet");
pluginNames.add("ldadhydro");
pluginNames.add("qc");
pluginNames.add("profiler");
pluginNames.add("fssobs");
pluginNames.add("modelsounding");
pluginNames.add("textPoints");
pluginNames.add("bufrmosAVN");
pluginNames.add("bufrmosETA");
pluginNames.add("bufrmosGFS");
pluginNames.add("bufrmosHPC");
pluginNames.add("bufrmosLAMP");
pluginNames.add("bufrmosMRF");
pluginNames.add("bufrmosNGM");
}
/*
* These use the original PlotResource, whoever can convert these gets
* to delete thousands of lines of code, it will be amazing.
*/
pluginProps.put("pirep", new PluginPlotProperties(false, false));
pluginProps.put("airep", new PluginPlotProperties(false, false));
/*
* These have a dependency on dataURI because they don't set stationId,
* In the future if stationId can be set to anything that is even a
* little unique we can get rid of this
*/
pluginProps.put("bufrssmi", new PluginPlotProperties(true, false));
pluginProps.put("bufrquikscat", new PluginPlotProperties(true, false));
pluginProps.put("bufrascat", new PluginPlotProperties(true, false));
pluginProps.put("radar", new PluginPlotProperties(true, false));
pluginProps.put("bufrhdw", new PluginPlotProperties(true, false));
pluginProps.put("bufrmthdw", new PluginPlotProperties(true, false));
pluginProps.put("lsr", new PluginPlotProperties(true, false));
pluginProps.put("tcg", new PluginPlotProperties(true, false));
pluginProps.put("svrwx", new PluginPlotProperties(true, false));
pluginProps.put("ldadmesonet", new PluginPlotProperties(true, false));
pluginProps.put("ldadhydro", new PluginPlotProperties(true, false));
pluginProps.put("qc", new PluginPlotProperties(true, false));
pluginProps.put("textPoints", new PluginPlotProperties(true, false));
/*
* The good ones, these don't even need to be here because this is the
* default behavior, but for now they are included so we have a
* comprehensive list of which plugins use certain behaviors.
*/
pluginProps.put("obs", new PluginPlotProperties());
pluginProps.put("goessounding", new PluginPlotProperties());
pluginProps.put("poessounding", new PluginPlotProperties());
pluginProps.put("bufrua", new PluginPlotProperties());
pluginProps.put("sfcobs", new PluginPlotProperties());
pluginProps.put("profiler", new PluginPlotProperties());
pluginProps.put("fssobs", new PluginPlotProperties());
pluginProps.put("modelsounding", new PluginPlotProperties());
pluginProps.put("bufrmosAVN", new PluginPlotProperties());
pluginProps.put("bufrmosETA", new PluginPlotProperties());
pluginProps.put("bufrmosGFS", new PluginPlotProperties());
pluginProps.put("bufrmosHPC", new PluginPlotProperties());
pluginProps.put("bufrmosLAMP", new PluginPlotProperties());
pluginProps.put("bufrmosMRF", new PluginPlotProperties());
pluginProps.put("bufrmosNGM", new PluginPlotProperties());
static {
ParsedURL.registerHandler(new LocalizationParsedURLHandler());
}
@ -161,8 +210,8 @@ public class PlotResourceData extends AbstractRequestableResourceData {
@Override
protected AbstractVizResource<?, ?> constructResource(
LoadProperties loadProperties, PluginDataObject[] objects) {
if (pluginNames.contains(this.metadataMap.get("pluginName")
.getConstraintValue())) {
if (getPluginProperties().usesPointDataApi) {
return new PlotResource2(this, loadProperties);
}
@ -418,4 +467,24 @@ public class PlotResourceData extends AbstractRequestableResourceData {
return false;
}
public PluginPlotProperties getPluginProperties() {
return getPluginProperties(this.metadataMap);
}
public static PluginPlotProperties getPluginProperties(String pluginName) {
PluginPlotProperties result = pluginProps.get(pluginName);
if (result == null) {
result = new PluginPlotProperties();
}
return result;
}
public static PluginPlotProperties getPluginProperties(Map<String,RequestConstraint> metadataMap){
RequestConstraint rc = metadataMap.get("pluginName");
if (rc == null || rc.getConstraintType() != ConstraintType.EQUALS) {
throw new IllegalArgumentException("Cannot find plugin properties because metadataMap does not specify a plugin.");
}
return getPluginProperties(rc.getConstraintValue());
}
}

View file

@ -37,6 +37,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.IResourceDataChanged;
import com.raytheon.uf.viz.core.rsc.IResourceDataChanged.ChangeType;
import com.raytheon.viz.pointdata.PlotInfo;
import com.raytheon.viz.pointdata.rsc.PlotResourceData;
/**
*
@ -47,7 +48,8 @@ import com.raytheon.viz.pointdata.PlotInfo;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 9, 2009 bsteffen Initial creation
* Oct 09, 2009 bsteffen Initial creation
* May 14, 2013 1869 bsteffen Get plots working without dataURI
*
* </pre>
*
@ -64,9 +66,10 @@ public class PointDataPlotInfoRetriever extends AbstractDbPlotInfoRetriever {
protected boolean onlyRefTime = false;
protected boolean needsDataUri = true;
@Override
protected void addColumns(DbQuery dq) {
dq.addColumn("dataURI");
dq.addColumn("location.latitude");
dq.addColumn("location.longitude");
dq.addColumn("location.stationId");
@ -76,23 +79,26 @@ public class PointDataPlotInfoRetriever extends AbstractDbPlotInfoRetriever {
} else {
dq.addColumn("dataTime");
}
if (needsDataUri) {
dq.addColumn("dataURI");
}
}
@Override
protected PlotInfo getPlotInfo(Object[] data) {
PlotInfo stationInfo = new PlotInfo();
stationInfo.dataURI = (String) data[0];
stationInfo.latitude = (Double) data[1];
stationInfo.longitude = (Double) data[2];
stationInfo.stationId = (String) data[3];
stationInfo.latitude = (Double) data[0];
stationInfo.longitude = (Double) data[1];
stationInfo.stationId = (String) data[2];
if (stationInfo.stationId == null) {
stationInfo.stationId = "" + data[1] + "#" + data[2];
stationInfo.stationId = "" + stationInfo.latitude + "#"
+ stationInfo.longitude;
}
if (data[4] instanceof DataTime) {
stationInfo.dataTime = (DataTime) data[4];
} else if (data[4] instanceof Timestamp) {
stationInfo.dataTime = new DataTime((Timestamp) data[4]);
if (data[3] instanceof DataTime) {
stationInfo.dataTime = (DataTime) data[3];
} else if (data[3] instanceof Timestamp) {
stationInfo.dataTime = new DataTime((Timestamp) data[3]);
} else {
String message = "Incorrect dataTime class type from database, expected "
+ DataTime.class.getName()
@ -103,7 +109,9 @@ public class PointDataPlotInfoRetriever extends AbstractDbPlotInfoRetriever {
statusHandler.handle(Priority.CRITICAL, message, new Exception(
message));
}
if (data.length == 5) {
stationInfo.dataURI = (String) data[4];
}
return stationInfo;
}
@ -113,6 +121,7 @@ public class PointDataPlotInfoRetriever extends AbstractDbPlotInfoRetriever {
DbQuery dq = null;
synchronized (onlyRefTimeFlagLock) {
onlyRefTime = !time.getUtilityFlags().contains(FLAG.FCST_USED);
needsDataUri = !PlotResourceData.getPluginProperties(metadataMap).hasDistinctStationId;
dq = getQueryObject(metadataMap);
}
List<PlotInfo> info = runStationQuery(dq);

View file

@ -28,6 +28,7 @@ import java.util.Set;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.pointdata.PointDataConstants;
import com.raytheon.uf.common.pointdata.PointDataContainer;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData;
@ -46,7 +47,8 @@ import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableNode;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 13, 2012 bsteffen Initial creation
* Apr 13, 2012 bsteffen Initial creation
* May 14, 2013 1869 bsteffen Get plots working without dataURI
*
* </pre>
*
@ -56,6 +58,15 @@ import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableNode;
public class PointMetadataContainer extends MetadataContainer {
/**
* Parameters which should be requested for all levels.
*/
private static final List<String> constantParameters = Arrays.asList("id",
"latitude", "longitude", "dataURI",
PointDataConstants.DATASET_STATIONID,
PointDataConstants.DATASET_REFTIME,
PointDataConstants.DATASET_FORECASTHR);
private final PointDataCubeAdapter pdca;
private final List<String> requestedParameters;
@ -97,9 +108,13 @@ public class PointMetadataContainer extends MetadataContainer {
if (baseParams.isEmpty()) {
return;
}
if (requestedParameters.contains("dataURI")) {
baseParams.add("dataURI");
for (String parameter : requestedParameters) {
if (constantParameters.contains(parameter)
&& !baseParams.contains(parameter)) {
baseParams.add(parameter);
}
}
pdc = pdca.getBaseRecords(baseParams, originalConstraints);
for (PointDataLevelNode node : nodes) {
Set<AbstractRequestableData> cacheSet = new HashSet<AbstractRequestableData>();
@ -107,7 +122,7 @@ public class PointMetadataContainer extends MetadataContainer {
IDataRecord rec = pdc.getParameterRecord(node.getParameter());
cacheSet.add(new PointRequestableData(rec, pdc.getDescription(
node.getParameter()).getUnitObject()));
if (!Arrays.asList("id", "latitude", "longitude", "dataURI")
if (!constantParameters
.contains(rec.getName())) {
pdc.remove(rec.getName());
}