Merge "Issue #2391 - Add Data Delivery to product browser. Peer review comments" into development

Former-commit-id: 8d3e7e1ace [formerly 8d3e7e1ace [formerly 683c87e0bfa87c9b7d8ad72e29ba72f581acf92d]]
Former-commit-id: 2c9c5e3597
Former-commit-id: 78d939dbca
This commit is contained in:
Richard Peter 2013-09-20 12:19:34 -05:00 committed by Gerrit Code Review
commit 1523f3cd05
7 changed files with 922 additions and 211 deletions

View file

@ -32,7 +32,11 @@ Require-Bundle: org.eclipse.ui,
com.raytheon.uf.common.units;bundle-version="1.0.0",
com.raytheon.uf.common.site;bundle-version="1.12.1174",
com.raytheon.uf.common.event;bundle-version="1.0.0",
com.raytheon.uf.common.plugin.nwsauth;bundle-version="1.12.1174"
com.raytheon.uf.common.plugin.nwsauth;bundle-version="1.12.1174",
com.raytheon.uf.viz.productbrowser;bundle-version="1.12.1174",
com.raytheon.viz.pointdata;bundle-version="1.12.1174",
com.raytheon.viz.alerts;bundle-version="1.12.1174",
com.raytheon.viz.grid;bundle-version="1.12.1174"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.uf.viz.datadelivery;uses:="org.eclipse.ui.plugin,org.osgi.framework",

View file

@ -121,4 +121,11 @@
</menu>
</menuContribution>
</extension>
<extension
point="com.raytheon.uf.viz.productbrowser.dataDefinition">
<dataDefinition
class="com.raytheon.uf.viz.datadelivery.DataDeliveryProductBrowserDataDefinition"
name="dataDeliveryProductBrowserDataDefinition">
</dataDefinition>
</extension>
</plugin>

View file

@ -0,0 +1,476 @@
/**
* 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.viz.datadelivery;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.datadelivery.registry.Coverage;
import com.raytheon.uf.common.datadelivery.registry.DataType;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.registry.handler.RegistryObjectHandlers;
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.BinOffset;
import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData;
import com.raytheon.uf.viz.core.rsc.DisplayType;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.ResourceType;
import com.raytheon.uf.viz.productbrowser.AbstractRequestableProductBrowserDataDefinition;
import com.raytheon.uf.viz.productbrowser.ProductBrowserLabel;
import com.raytheon.uf.viz.productbrowser.ProductBrowserPreference;
import com.raytheon.uf.viz.productbrowser.ProductBrowserPreference.PreferenceType;
import com.raytheon.viz.grid.GridProductBrowserDataFormatter;
import com.raytheon.viz.grid.inv.GridInventory;
import com.raytheon.viz.grid.rsc.GridResourceData;
import com.raytheon.viz.pointdata.PlotModels;
import com.raytheon.viz.pointdata.rsc.PlotResourceData;
import com.raytheon.viz.pointdata.util.PointDataInventory;
/**
* Product browser implementation for data delivery data
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 17, 2013 2391 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class DataDeliveryProductBrowserDataDefinition
extends
AbstractRequestableProductBrowserDataDefinition<AbstractRequestableResourceData> {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(DataDeliveryProductBrowserDataDefinition.class);
/** Constant */
private final String MADIS = "madis";
/** Plot model file */
private final String SVG = "madisObsDesign.svg";
/** Constant */
private final String PLUGIN_NAME = "pluginName";
/** Constant */
private final String DATA_DELIVERY = "Data Delivery";
/** Constant */
private final String SHOW_DERIVED_PARAMS = "Show Derived Parameters";
/** Active subscription list */
private final List<Subscription> activeSubList = new ArrayList<Subscription>();
/** Selected subscription name */
private String selectedSubscriptionName;
/** Selected data type */
private String selectedDataType;
/** Point order */
private final String[] POINT_ORDER = new String[] { "type", "subscription",
"level" };
private final String[] GRID_ORDER = new String[] {
GridInventory.MODEL_NAME_QUERY, GridInventory.PARAMETER_QUERY,
GridInventory.MASTER_LEVEL_QUERY, GridInventory.LEVEL_ID_QUERY };
/**
* Constructor.
*/
public DataDeliveryProductBrowserDataDefinition() {
this.productName = DATA_DELIVERY;
this.displayName = DATA_DELIVERY;
loadProperties = new LoadProperties();
order = POINT_ORDER;
}
/**
* {@inheritDoc}
*/
@Override
public void constructResource(String[] selection, ResourceType type) {
selectedSubscriptionName = selection[2];
selectedDataType = selection[1];
super.constructResource(selection, type);
if (selection[1].equalsIgnoreCase("Point")) {
((PlotResourceData) resourceData)
.setPlotSource(selection[selection.length - 3] + " "
+ selection[selection.length - 2] + " "
+ selection[selection.length - 1]);
((PlotResourceData) resourceData).setPlotModelFile(SVG);
((PlotResourceData) resourceData)
.setLevelKey(selection[selection.length - 1]);
}
constructResource();
}
/**
* {@inheritDoc}
*/
@Override
public List<ProductBrowserLabel> populateData(String[] selection) {
// Set the order based on data type
if (selection.length > 2) {
if (selection[1].equalsIgnoreCase(DataType.GRID.name())) {
order = GRID_ORDER;
productName = DataType.GRID.name().toLowerCase();
selectedDataType = DataType.GRID.name();
} else if (selection[1].equalsIgnoreCase(DataType.POINT.name())) {
order = POINT_ORDER;
productName = DataType.POINT.name().toLowerCase();
selectedDataType = DataType.POINT.name();
}
}
if (selection.length == 1) {
// Get provider names
String[] dataTypes = getDataTypes();
return formatData("Data Type", dataTypes);
}
if (selection.length == 2) {
String source = selection[1];
String[] subs = getSubscriptions(source);
return formatData("SubscriptionName", subs);
}
if (selection.length == 3) {
if (selectedDataType.equalsIgnoreCase(DataType.POINT.name())) {
String[] results = PlotModels.getInstance().getLevels(MADIS,
SVG);
String param = order[2];
return formatData(param, results);
} else if (selectedDataType.equalsIgnoreCase(DataType.GRID.name())) {
this.productName = DataType.GRID.name().toLowerCase();
// Must remove the first selection so this matches with the grid
// version
String[] usedSelection = realignSelection(selection);
return super.populateData(usedSelection);
}
}
if (selection.length >= 4) {
if (selection[1].equalsIgnoreCase(DataType.GRID.name())) {
// Must remove the first selection so this matches with the grid
// version
String[] usedSelection = realignSelection(selection);
return super.populateData(usedSelection);
}
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String populateInitial() {
return DATA_DELIVERY;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.productbrowser.AbstractProductBrowserDataDefinition
* #formatData(java.lang.String, java.lang.String[])
*/
@Override
public List<ProductBrowserLabel> formatData(String param,
String[] parameters) {
if (selectedDataType == null
|| selectedDataType.equalsIgnoreCase(DataType.POINT.name())) {
List<ProductBrowserLabel> temp = new ArrayList<ProductBrowserLabel>();
for (int i = 0; i < parameters.length; i++) {
ProductBrowserLabel label = new ProductBrowserLabel(
parameters[i], parameters[i]);
temp.add(label);
label.setProduct(param == order[2]);
label.setData(parameters[i]);
}
Collections.sort(temp);
return temp;
} else if (selectedDataType.equalsIgnoreCase(DataType.GRID.name())) {
try {
return GridProductBrowserDataFormatter.formatGridData(param,
parameters);
} catch (CommunicationException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
return Collections.emptyList();
}
/**
* {@inheritDoc}
*/
@Override
public AbstractRequestableResourceData getResourceData() {
if (selectedDataType.equalsIgnoreCase(DataType.POINT.name())) {
resourceData = new PlotResourceData();
resourceData.setBinOffset(new BinOffset(900, 900));
resourceData.setRetrieveData(false);
resourceData.setUpdatingOnMetadataOnly(true);
((PlotResourceData) resourceData).setTopOfTheHour(false);
} else if (selectedDataType.equalsIgnoreCase(DataType.GRID.name())) {
resourceData = new GridResourceData();
}
return resourceData;
}
/**
* {@inheritDoc}
*/
@Override
public HashMap<String, RequestConstraint> getProductParameters(
String[] selection, String[] order) {
if (selection[1].equalsIgnoreCase(DataType.POINT.name())) {
return getPointProductParameters(selection, order);
} else if (selection[0].equalsIgnoreCase(DataType.GRID.name())
|| selection[1].equalsIgnoreCase(DataType.GRID.name())) {
return getGridProductParameters(selection, order);
} else {
throw new IllegalArgumentException("Invalid data type: "
+ selection[1]);
}
}
/**
* Get the grid parameters.
*
* @param selection
* The selected node
*
* @param order
* The order
* @return The constraint map
*/
private HashMap<String, RequestConstraint> getGridProductParameters(
String[] selection, String[] order) {
if (selection.length > 5) {
// Must remove the first selection so this matches with the grid
// version
String[] tmpSelection = realignSelection(selection);
return super.getProductParameters(tmpSelection, order);
} else {
return super.getProductParameters(selection, order);
}
}
/**
* Get the point parameters.
*
* @param selection
* The selected node
*
* @param order
* The order
* @return The constraint map
*/
private HashMap<String, RequestConstraint> getPointProductParameters(
String[] selection, String[] order) {
HashMap<String, RequestConstraint> queryList = new HashMap<String, RequestConstraint>();
queryList.put(PLUGIN_NAME, new RequestConstraint(MADIS));
PointDataInventory inv = PlotModels.getInstance().getInventory();
if (!inv.getTypeKey(selection[1])
.equals(PointDataInventory.PLUGIN_NAME)) {
queryList.put(inv.getTypeKey(selection[1]), new RequestConstraint(
selection[2]));
}
List<RequestConstraint> spatialCons = getSpatialConstraint();
if (spatialCons != null && !spatialCons.isEmpty()) {
queryList.put("location.longitude", spatialCons.get(0));
queryList.put("location.latitude", spatialCons.get(1));
}
return queryList;
}
/**
* Get the spatial constraints.
*
* @return List of spatial constraints, or empty list if none
*/
private List<RequestConstraint> getSpatialConstraint() {
if (activeSubList == null || activeSubList.isEmpty()) {
getSubscriptions(selectedDataType);
}
List<RequestConstraint> cons = new ArrayList<RequestConstraint>();
Coverage cov = null;
for (Subscription s : activeSubList) {
if (s.getName().equals(this.selectedSubscriptionName)) {
cov = s.getCoverage();
break;
}
}
if (cov != null) {
RequestConstraint lonConstraint = new RequestConstraint(
cov.getRequestUpperLeft().x + "--"
+ cov.getRequestLowerRight().x,
ConstraintType.BETWEEN);
RequestConstraint latConstraint = new RequestConstraint(
cov.getRequestLowerRight().y + "--"
+ cov.getRequestUpperLeft().y,
ConstraintType.BETWEEN);
cons.add(lonConstraint);
cons.add(latConstraint);
}
return cons;
}
/**
* Get the subscriptions for the specified data type.
*
* @param dataType
* The data type
*
* @return Array of subscription names for the specified data type
*/
private String[] getSubscriptions(String dataType) {
DataType dt = DataType.valueOf(dataType.toUpperCase());
List<String> subscriptionList = getSubscriptions(dt);
return subscriptionList.toArray(new String[subscriptionList.size()]);
}
/**
* Get the subscriptions for the specified data type.
*
* @param dataType
* The data type
* @return
*/
private List<String> getSubscriptions(DataType dataType) {
activeSubList.clear();
final List<String> subNames = new ArrayList<String>();
List<Subscription> activeSubs = getSubscriptions();
for (Subscription s : activeSubs) {
if (s.getDataSetType() == dataType) {
activeSubList.add(s);
subNames.add(s.getName());
}
}
return subNames;
}
private String[] getDataTypes() {
List<Subscription> subList = getSubscriptions();
List<String> dataTypes = new ArrayList<String>();
for (Subscription s : subList) {
String dt = StringUtils.capitalize(s.getDataSetType().name()
.toLowerCase());
if (!dataTypes.contains(dt)) {
dataTypes.add(dt);
}
}
return dataTypes.toArray(new String[dataTypes.size()]);
}
/**
* Get a list of subscriptions from the registry.
*
* @return List of subscriptions
*/
private List<Subscription> getSubscriptions() {
List<Subscription> subList = new ArrayList<Subscription>();
final ISubscriptionHandler handler = RegistryObjectHandlers
.get(ISubscriptionHandler.class);
try {
subList = handler.getActive();
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
return subList;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.productbrowser.AbstractProductBrowserDataDefinition
* #getDisplayTypes()
*/
@Override
public Map<ResourceType, List<DisplayType>> getDisplayTypes() {
if (selectedDataType.equalsIgnoreCase(DataType.GRID.name())) {
Map<ResourceType, List<DisplayType>> type = new HashMap<ResourceType, List<DisplayType>>();
List<DisplayType> types = new ArrayList<DisplayType>();
types.add(DisplayType.CONTOUR);
types.add(DisplayType.IMAGE);
type.put(ResourceType.PLAN_VIEW, types);
return type;
}
return super.getDisplayTypes();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.productbrowser.
* AbstractRequestableProductBrowserDataDefinition#configurePreferences()
*/
@Override
protected List<ProductBrowserPreference> configurePreferences() {
if (selectedDataType.equalsIgnoreCase(DataType.GRID.name())) {
List<ProductBrowserPreference> widgets = super
.configurePreferences();
ProductBrowserPreference derivedParameterPref = new ProductBrowserPreference();
derivedParameterPref.setLabel(SHOW_DERIVED_PARAMS);
derivedParameterPref.setPreferenceType(PreferenceType.BOOLEAN);
derivedParameterPref
.setTooltip("Show derived parameters in the Product Browser");
derivedParameterPref.setValue(true);
widgets.add(derivedParameterPref);
return widgets;
}
return super.configurePreferences();
}
}

View file

@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -37,11 +36,8 @@ import java.util.concurrent.LinkedBlockingQueue;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
import com.raytheon.uf.common.dataplugin.grid.dataset.DatasetInfo;
import com.raytheon.uf.common.dataplugin.grid.dataset.DatasetInfoLookup;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
import com.raytheon.uf.common.dataplugin.level.MasterLevel;
import com.raytheon.uf.common.dataplugin.level.mapping.LevelMappingFactory;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -53,8 +49,6 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.DisplayType;
import com.raytheon.uf.viz.core.rsc.ResourceProperties;
import com.raytheon.uf.viz.core.rsc.ResourceType;
import com.raytheon.uf.viz.derivparam.library.DerivParamDesc;
import com.raytheon.uf.viz.derivparam.library.DerivedParameterGenerator;
import com.raytheon.uf.viz.productbrowser.AbstractRequestableProductBrowserDataDefinition;
import com.raytheon.uf.viz.productbrowser.ProductBrowserLabel;
import com.raytheon.uf.viz.productbrowser.ProductBrowserPreference;
@ -75,6 +69,7 @@ import com.raytheon.viz.grid.rsc.GridResourceData;
* May 26, 2010 mnash Used ProductBrowserLabel implementation instead of requery
* May 02, 2013 1949 bsteffen Switch Product Browser from uengine to
* DbQueryRequest.
* Sep 19, 2013 2391 mpduff refactored some methods to common class.
*
* </pre>
*
@ -83,33 +78,14 @@ import com.raytheon.viz.grid.rsc.GridResourceData;
*/
public class GridProductBrowserDataDefinition extends
AbstractRequestableProductBrowserDataDefinition<GridResourceData> {
private static final transient IUFStatusHandler statusHandler = UFStatus
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(GridProductBrowserDataDefinition.class);
private static final String SHOW_DERIVED_PARAMS = "Show Derived Parameters";
private static final Comparator<Level> levelComparator = new Comparator<Level>() {
@Override
public int compare(Level o1, Level o2) {
if (o1.isRangeLevel() == o2.isRangeLevel()) {
int val = Double.compare(o1.getLevelonevalue(),
o2.getLevelonevalue());
if (val == 0) {
val = Double.compare(o1.getLeveltwovalue(),
o2.getLeveltwovalue());
}
return val;
}
if (o1.isRangeLevel()) {
return 1;
} else {
return -1;
}
}
};
private final String SHOW_DERIVED_PARAMS = "Show Derived Parameters";
/**
* Constructor.
*/
public GridProductBrowserDataDefinition() {
productName = GridInventory.PLUGIN_NAME;
displayName = "Grid";
@ -307,70 +283,17 @@ public class GridProductBrowserDataDefinition extends
@Override
public List<ProductBrowserLabel> formatData(String param,
String[] parameters) {
List<ProductBrowserLabel> labels = new ArrayList<ProductBrowserLabel>();
try {
if (GridInventory.MODEL_NAME_QUERY.equals(param)) {
DatasetInfoLookup lookup = DatasetInfoLookup.getInstance();
for (int i = 0; i < parameters.length; i++) {
DatasetInfo info = lookup.getInfo(parameters[i]);
if (info == null) {
labels.add(new ProductBrowserLabel(parameters[i],
parameters[i]));
} else {
labels.add(new ProductBrowserLabel(info.getTitle()
+ " (" + parameters[i] + ")", parameters[i]));
}
}
Collections.sort(labels);
return labels;
} else if (GridInventory.PARAMETER_QUERY.equals(param)) {
Map<String, DerivParamDesc> library = DerivedParameterGenerator
.getDerParLibrary();
for (int i = 0; i < parameters.length; i++) {
DerivParamDesc desc = library.get(parameters[i]);
if (desc == null || desc.getName().isEmpty()) {
labels.add(new ProductBrowserLabel(parameters[i],
parameters[i]));
} else {
labels.add(new ProductBrowserLabel(desc.getName()
+ " (" + parameters[i] + ")", parameters[i]));
}
}
Collections.sort(labels);
return labels;
} else if (GridInventory.LEVEL_ID_QUERY.equals(param)) {
Level[] levels = new Level[parameters.length];
LevelFactory lf = LevelFactory.getInstance();
for (int i = 0; i < levels.length; i++) {
levels[i] = lf.getLevel(parameters[i]);
}
Arrays.sort(levels, levelComparator);
for (int i = 0; i < parameters.length; i++) {
String levelName = levels[i].toString().replace("_", "-");
levelName = levelName.replace(levels[i].getMasterLevel()
.getName(), " "
+ levels[i].getMasterLevel().getName());
labels.add(new ProductBrowserLabel(levelName, Long
.toString(levels[i].getId())));
}
return labels;
} else if (GridInventory.MASTER_LEVEL_QUERY.equals(param)) {
LevelFactory lf = LevelFactory.getInstance();
for (int i = 0; i < parameters.length; i++) {
MasterLevel masterLevel = lf.getMasterLevel(parameters[i]);
labels.add(new ProductBrowserLabel(masterLevel
.getDescription()
+ " ("
+ masterLevel.getName()
+ ")", masterLevel.getName()));
}
Collections.sort(labels);
List<ProductBrowserLabel> labels = GridProductBrowserDataFormatter
.formatGridData(param, parameters);
if (labels != null && !labels.isEmpty()) {
return labels;
}
} catch (CommunicationException e) {
statusHandler.handle(Priority.ERROR, "Unable to format data for "
+ productName, e);
}
return super.formatData(param, parameters);
}

View file

@ -0,0 +1,149 @@
/**
* 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.viz.grid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.dataplugin.grid.dataset.DatasetInfo;
import com.raytheon.uf.common.dataplugin.grid.dataset.DatasetInfoLookup;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
import com.raytheon.uf.common.dataplugin.level.MasterLevel;
import com.raytheon.uf.viz.derivparam.library.DerivParamDesc;
import com.raytheon.uf.viz.derivparam.library.DerivedParameterGenerator;
import com.raytheon.uf.viz.productbrowser.ProductBrowserLabel;
import com.raytheon.viz.grid.inv.GridInventory;
/**
* Grid product formatter. Refactored out of GridProductBrowserDataDefinition.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 19, 2013 2391 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class GridProductBrowserDataFormatter {
/**
* Format the info for the product browser display
*
* @param param
* Parameter
* @param parameters
* List of parameters
* @return List of ProductBrowserLabel objects
* @throws CommunicationException
*/
public static List<ProductBrowserLabel> formatGridData(String param,
String[] parameters) throws CommunicationException {
List<ProductBrowserLabel> labels = new ArrayList<ProductBrowserLabel>();
if (GridInventory.MODEL_NAME_QUERY.equals(param)) {
DatasetInfoLookup lookup = DatasetInfoLookup.getInstance();
for (int i = 0; i < parameters.length; i++) {
DatasetInfo info = lookup.getInfo(parameters[i]);
if (info == null) {
labels.add(new ProductBrowserLabel(parameters[i],
parameters[i]));
} else {
labels.add(new ProductBrowserLabel(info.getTitle() + " ("
+ parameters[i] + ")", parameters[i]));
}
}
Collections.sort(labels);
return labels;
} else if (GridInventory.PARAMETER_QUERY.equals(param)) {
Map<String, DerivParamDesc> library = DerivedParameterGenerator
.getDerParLibrary();
for (int i = 0; i < parameters.length; i++) {
DerivParamDesc desc = library.get(parameters[i]);
if (desc == null || desc.getName().isEmpty()) {
labels.add(new ProductBrowserLabel(parameters[i],
parameters[i]));
} else {
labels.add(new ProductBrowserLabel(desc.getName() + " ("
+ parameters[i] + ")", parameters[i]));
}
}
Collections.sort(labels);
return labels;
} else if (GridInventory.LEVEL_ID_QUERY.equals(param)) {
Level[] levels = new Level[parameters.length];
LevelFactory lf = LevelFactory.getInstance();
for (int i = 0; i < levels.length; i++) {
levels[i] = lf.getLevel(parameters[i]);
}
Arrays.sort(levels, levelComparator);
for (int i = 0; i < parameters.length; i++) {
String levelName = levels[i].toString().replace("_", "-");
levelName = levelName.replace(levels[i].getMasterLevel()
.getName(), " " + levels[i].getMasterLevel().getName());
labels.add(new ProductBrowserLabel(levelName, Long
.toString(levels[i].getId())));
}
return labels;
} else if (GridInventory.MASTER_LEVEL_QUERY.equals(param)) {
LevelFactory lf = LevelFactory.getInstance();
for (int i = 0; i < parameters.length; i++) {
MasterLevel masterLevel = lf.getMasterLevel(parameters[i]);
labels.add(new ProductBrowserLabel(masterLevel.getDescription()
+ " (" + masterLevel.getName() + ")", masterLevel
.getName()));
}
Collections.sort(labels);
return labels;
}
return Collections.emptyList();
}
private static final Comparator<Level> levelComparator = new Comparator<Level>() {
@Override
public int compare(Level o1, Level o2) {
if (o1.isRangeLevel() == o2.isRangeLevel()) {
int val = Double.compare(o1.getLevelonevalue(),
o2.getLevelonevalue());
if (val == 0) {
val = Double.compare(o1.getLeveltwovalue(),
o2.getLeveltwovalue());
}
return val;
}
if (o1.isRangeLevel()) {
return 1;
} else {
return -1;
}
}
};
}

View file

@ -5,48 +5,40 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
import com.raytheon.uf.common.dataplugin.level.mapping.LevelMappingFactory;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
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.BinOffset;
import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.map.MapDescriptor;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.ResourceType;
import com.raytheon.uf.viz.productbrowser.AbstractRequestableProductBrowserDataDefinition;
import com.raytheon.uf.viz.productbrowser.ProductBrowserLabel;
import com.raytheon.uf.viz.productbrowser.ProductBrowserPreference;
import com.raytheon.viz.pointdata.PlotModelFactory2.PlotModelElement;
import com.raytheon.viz.pointdata.rsc.PlotResourceData;
import com.raytheon.viz.pointdata.util.PointDataInventory;
/**
* Product browser implementation for grid
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 19, 2013 2391 mpduff refactored some methods to common class.
*
* </pre>
*/
public class PlotModelDataDefinition extends
AbstractRequestableProductBrowserDataDefinition<PlotResourceData> {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PlotModelDataDefinition.class);
private static final String PLOTLOCATION = "plotModels";
private static Map<String, List<String>> models;
/**
* Constructor.
*/
public PlotModelDataDefinition() {
productName = "plotModels";
displayName = "Plot Models";
@ -72,6 +64,9 @@ public class PlotModelDataDefinition extends
resourceData.setLevelKey(selection[selection.length - 1]);
}
/**
* {@inheritDoc}
*/
@Override
public PlotResourceData getResourceData() {
resourceData = new PlotResourceData();
@ -81,12 +76,15 @@ public class PlotModelDataDefinition extends
return resourceData;
}
/**
* {@inheritDoc}
*/
@Override
public HashMap<String, RequestConstraint> getProductParameters(
String[] selection, String[] order) {
HashMap<String, RequestConstraint> queryList = new HashMap<String, RequestConstraint>();
queryList.put(PLUGIN_NAME, new RequestConstraint(selection[1]));
PointDataInventory inv = getInventory();
PointDataInventory inv = PlotModels.getInstance().getInventory();
if (!inv.getTypeKey(selection[1])
.equals(PointDataInventory.PLUGIN_NAME)) {
queryList.put(inv.getTypeKey(selection[1]), new RequestConstraint(
@ -96,19 +94,27 @@ public class PlotModelDataDefinition extends
return queryList;
}
/**
* {@inheritDoc}
*/
@Override
public List<String> buildProductList(List<String> historyList) {
// TODO something here
return Collections.emptyList();
}
/**
* {@inheritDoc}
*/
@Override
public String populateInitial() {
if (!isEnabled()) {
return null;
}
PointDataInventory inv = PlotModels.getInstance().getInventory();
try {
if (getInventory() == null || getInventory().getPlugins() == null) {
if (inv == null || inv.getPlugins() == null) {
return null;
}
} catch (Exception e) {
@ -118,10 +124,14 @@ public class PlotModelDataDefinition extends
}
/**
* {@inheritDoc}
*/
@Override
public List<ProductBrowserLabel> populateData(String[] selection) {
String[] results = null;
PointDataInventory inv = getInventory();
PlotModels plotModels = PlotModels.getInstance();
PointDataInventory inv = plotModels.getInventory();
String param = null;
if (selection.length == 1) {
results = inv.getPlugins().toArray(new String[0]);
@ -152,13 +162,17 @@ public class PlotModelDataDefinition extends
}
if ((hasType && selection.length == 4) || selection.length == 3) {
results = getLevels(source, selection[selection.length - 1]);
results = plotModels.getLevels(source,
selection[selection.length - 1]);
param = order[2];
return formatData(param, results);
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public List<ProductBrowserLabel> formatData(String param,
String[] parameters) {
@ -176,66 +190,22 @@ public class PlotModelDataDefinition extends
return labels;
}
private void populateModels() {
if (models == null) {
Map<String, List<String>> models = new HashMap<String, List<String>>();
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationFile[] files = pm.listFiles(
pm.getLocalSearchHierarchy(LocalizationType.CAVE_STATIC),
PLOTLOCATION, new String[] { ".svg" }, true, true);
MapDescriptor fakeDescriptor = null;
try {
fakeDescriptor = new MapDescriptor();
} catch (VizException e) {
throw new RuntimeException(e);
}
for (LocalizationFile file : files) {
String fileName = file.getName();
fileName = fileName.substring(PLOTLOCATION.length() + 1);
try {
if (models.containsKey(fileName) == false) {
List<String> params = new ArrayList<String>();
List<PlotModelElement> fields = new PlotModelFactory2(
fakeDescriptor, fileName).getPlotFields();
for (PlotModelElement p : fields) {
if (!p.parameter.equals("")
&& !p.parameter.contains(",")) {
params.add(p.parameter);
} else if (p.parameter.contains(",")) {
String[] individualParams = p.parameter
.split(",");
for (String param : individualParams) {
params.add(param);
}
}
}
models.put(fileName, params);
}
} catch (Throwable t) {
// Ignore as some svg files are fonts and not plot models
// and the only way to tell is by catching exceptions thrown
// from PlotModelFactory2 when constructed with the non-plot
// model svg
}
}
PlotModelDataDefinition.models = models;
}
}
private String[] getModels(String source) {
populateModels();
PlotModels models = PlotModels.getInstance();
List<String> validModels = new ArrayList<String>();
BlockingQueue<String> returnQueue = new LinkedBlockingQueue<String>();
Collection<String> sourcesToProcess = Arrays.asList(source);
try {
getInventory().checkParameters(sourcesToProcess, null, null, true,
returnQueue);
PlotModels
.getInstance()
.getInventory()
.checkParameters(sourcesToProcess, null, null, true,
returnQueue);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for (Entry<String, List<String>> entry : models.entrySet()) {
for (Entry<String, List<String>> entry : models.getModels().entrySet()) {
if (returnQueue.containsAll(entry.getValue())) {
validModels.add(entry.getKey());
}
@ -244,50 +214,9 @@ public class PlotModelDataDefinition extends
return validModels.toArray(new String[0]);
}
private String[] getLevels(String source, String model) {
populateModels();
Set<String> possibleLevels = null;
for (String parameter : models.get(model)) {
BlockingQueue<String> returnQueue = new LinkedBlockingQueue<String>();
Collection<String> sourcesToProcess = Arrays.asList(source);
try {
getInventory().checkLevels(sourcesToProcess,
Arrays.asList(parameter), null, returnQueue);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (possibleLevels == null) {
possibleLevels = new HashSet<String>(returnQueue);
} else {
possibleLevels.retainAll(returnQueue);
}
}
List<String> validLevels = new ArrayList<String>();
if (possibleLevels != null) {
for (String levelid : possibleLevels) {
try {
Level level = LevelFactory.getInstance().getLevel(
Long.parseLong(levelid));
validLevels
.add(LevelMappingFactory
.getInstance(
LevelMappingFactory.VOLUMEBROWSER_LEVEL_MAPPING_FILE)
.getLevelMappingForLevel(level)
.getDisplayName());
} catch (CommunicationException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
}
return validLevels.toArray(new String[0]);
}
private PointDataInventory getInventory() {
return (PointDataInventory) DataCubeContainer.getInventory("obs");
}
/**
* {@inheritDoc}
*/
@Override
public List<ProductBrowserPreference> configurePreferences() {
List<ProductBrowserPreference> prefs = super.configurePreferences();

View file

@ -0,0 +1,223 @@
/**
* 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.viz.pointdata;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import com.raytheon.uf.common.comm.CommunicationException;
import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
import com.raytheon.uf.common.dataplugin.level.mapping.LevelMappingFactory;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
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.viz.core.datastructure.DataCubeContainer;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.map.MapDescriptor;
import com.raytheon.viz.pointdata.PlotModelFactory2.PlotModelElement;
import com.raytheon.viz.pointdata.util.PointDataInventory;
/**
* Plot Model Utility class.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 18, 2013 2391 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class PlotModels {
/** The only instance */
private static final PlotModels instance = new PlotModels();
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(PlotModels.class);
/** Constant */
private final String PLOTLOCATION = "plotModels";
/** Models */
private Map<String, List<String>> models;
/**
* Private constructor.
*/
private PlotModels() {
populateModels();
}
/**
* Get the instance.
*
* @return The instance
*/
public static PlotModels getInstance() {
return instance;
}
/**
* Get the parameters for the provided model.
*
* @param model
* The model
* @return List of parameters
*/
public List<String> getParameters(String model) {
return models.get(model);
}
/**
* Get the models
*
* @return The models
*/
public Map<String, List<String>> getModels() {
return models;
}
/**
* Populate the models.
*/
private void populateModels() {
if (models == null) {
models = new HashMap<String, List<String>>();
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationFile[] files = pm.listFiles(
pm.getLocalSearchHierarchy(LocalizationType.CAVE_STATIC),
PLOTLOCATION, new String[] { ".svg" }, true, true);
MapDescriptor fakeDescriptor = null;
try {
fakeDescriptor = new MapDescriptor();
} catch (VizException e) {
throw new RuntimeException(e);
}
for (LocalizationFile file : files) {
String fileName = file.getName();
fileName = fileName.substring(PLOTLOCATION.length() + 1);
try {
if (!models.containsKey(fileName)) {
List<String> params = new ArrayList<String>();
List<PlotModelElement> fields = new PlotModelFactory2(
fakeDescriptor, fileName).getPlotFields();
for (PlotModelElement p : fields) {
if (!p.parameter.equals("")
&& !p.parameter.contains(",")) {
params.add(p.parameter);
} else if (p.parameter.contains(",")) {
String[] individualParams = p.parameter
.split(",");
for (String param : individualParams) {
params.add(param);
}
}
}
models.put(fileName, params);
}
} catch (Throwable t) {
// Ignore as some svg files are fonts and not plot models
// and the only way to tell is by catching exceptions thrown
// from PlotModelFactory2 when constructed with the non-plot
// model svg
}
}
}
}
/**
* Get the available levels.
*
* @param source
* The source
* @param model
* The model
* @return Array of levels
*/
public String[] getLevels(String source, String model) {
PlotModels models = PlotModels.getInstance();
Set<String> possibleLevels = null;
for (String parameter : models.getParameters(model)) {
BlockingQueue<String> returnQueue = new LinkedBlockingQueue<String>();
Collection<String> sourcesToProcess = Arrays.asList(source);
try {
getInventory().checkLevels(sourcesToProcess,
Arrays.asList(parameter), null, returnQueue);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (possibleLevels == null) {
possibleLevels = new HashSet<String>(returnQueue);
} else {
possibleLevels.retainAll(returnQueue);
}
}
List<String> validLevels = new ArrayList<String>();
if (possibleLevels != null) {
for (String levelid : possibleLevels) {
try {
Level level = LevelFactory.getInstance().getLevel(
Long.parseLong(levelid));
validLevels
.add(LevelMappingFactory
.getInstance(
LevelMappingFactory.VOLUMEBROWSER_LEVEL_MAPPING_FILE)
.getLevelMappingForLevel(level)
.getDisplayName());
} catch (CommunicationException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
}
return validLevels.toArray(new String[0]);
}
/**
* Get the PointDataInventory.
*
* @return the PointDataInventory
*/
public PointDataInventory getInventory() {
return (PointDataInventory) DataCubeContainer.getInventory("obs");
}
}