Merge "Issue #189 changes to mappings and ncep merge from code review Change-Id: Ia44b66535dbbf36a6e0b99cd547f0dc161af6a47" into development

Former-commit-id: 219d5cd37e412c47cf12eebb6849c5c233163f16
This commit is contained in:
Nate Jensen 2012-11-14 16:09:00 -06:00 committed by Gerrit Code Review
commit 49c2079963
8 changed files with 52 additions and 80 deletions

View file

@ -22,7 +22,6 @@ package com.raytheon.uf.common.dataplugin.grid.mapping;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManager; import com.raytheon.uf.common.localization.PathManager;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
@ -55,17 +54,8 @@ public class DatasetIdMapper extends Mapper {
private DatasetIdMapper() { private DatasetIdMapper() {
IPathManager pathMgr = PathManagerFactory.getPathManager(); IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext commonStaticBase = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.BASE);
LocalizationContext commonStaticSite = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.SITE);
// read in the namespace map // read in the namespace map
LocalizationFile[] files = pathMgr.listFiles(new LocalizationContext[] { LocalizationFile[] files = pathMgr.listStaticFiles("grid"
commonStaticSite, commonStaticBase }, "grid"
+ PathManager.SEPARATOR + "dataset" + IPathManager.SEPARATOR + PathManager.SEPARATOR + "dataset" + IPathManager.SEPARATOR
+ "alias", new String[] { ".xml" }, true, true); + "alias", new String[] { ".xml" }, true, true);
for (LocalizationFile file : files) { for (LocalizationFile file : files) {
@ -79,12 +69,9 @@ public class DatasetIdMapper extends Mapper {
} }
} }
private static DatasetIdMapper instance; private static final DatasetIdMapper instance = new DatasetIdMapper();
public static synchronized DatasetIdMapper getInstance() { public static DatasetIdMapper getInstance() {
if (instance == null) {
instance = new DatasetIdMapper();
}
return instance; return instance;
} }
} }

View file

@ -31,7 +31,6 @@ import com.raytheon.uf.common.dataplugin.level.Level;
import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataplugin.level.LevelFactory;
import com.raytheon.uf.common.dataplugin.level.MasterLevel; import com.raytheon.uf.common.dataplugin.level.MasterLevel;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
@ -68,17 +67,8 @@ public class LevelMapper extends Mapper {
private LevelMapper() { private LevelMapper() {
IPathManager pathMgr = PathManagerFactory.getPathManager(); IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext commonStaticBase = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.BASE);
LocalizationContext commonStaticSite = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.SITE);
// read in the namespace map // read in the namespace map
LocalizationFile[] files = pathMgr.listFiles(new LocalizationContext[] { LocalizationFile[] files = pathMgr.listStaticFiles("level"
commonStaticSite, commonStaticBase }, "level"
+ IPathManager.SEPARATOR + "alias", new String[] { ".xml" }, + IPathManager.SEPARATOR + "alias", new String[] { ".xml" },
true, true); true, true);
for (LocalizationFile file : files) { for (LocalizationFile file : files) {
@ -193,12 +183,9 @@ public class LevelMapper extends Mapper {
return result; return result;
} }
private static LevelMapper instance; private static final LevelMapper instance = new LevelMapper();
public static synchronized LevelMapper getInstance() { public static LevelMapper getInstance() {
if (instance == null) {
instance = new LevelMapper();
}
return instance; return instance;
} }

View file

@ -33,7 +33,6 @@ 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.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.parameter.Parameter; import com.raytheon.uf.common.parameter.Parameter;
@ -65,12 +64,9 @@ public class ParameterLookup {
private static final transient IUFStatusHandler statusHandler = UFStatus private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ParameterLookup.class); .getHandler(ParameterLookup.class);
private static ParameterLookup instance; private static final ParameterLookup instance = new ParameterLookup();
public static ParameterLookup getInstance() { public static ParameterLookup getInstance() {
if (instance == null) {
instance = new ParameterLookup();
}
return instance; return instance;
} }
@ -106,18 +102,9 @@ public class ParameterLookup {
} }
if (unmarshaller != null) { if (unmarshaller != null) {
IPathManager pathMgr = PathManagerFactory.getPathManager(); IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext commonStaticBase = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.BASE);
LocalizationContext commonStaticSite = pathMgr.getContext( LocalizationFile[] files = pathMgr.listStaticFiles("parameter"
LocalizationContext.LocalizationType.COMMON_STATIC, + IPathManager.SEPARATOR + "definition",
LocalizationContext.LocalizationLevel.SITE);
LocalizationFile[] files = pathMgr.listFiles(
new LocalizationContext[] { commonStaticSite,
commonStaticBase }, "parameter"
+ IPathManager.SEPARATOR + "definition",
new String[] { ".xml" }, true, true); new String[] { ".xml" }, true, true);
for (LocalizationFile file : files) { for (LocalizationFile file : files) {
@ -141,9 +128,11 @@ public class ParameterLookup {
} }
} }
} else { } else {
statusHandler.error("Error reading parameter defintions: " statusHandler.error("Error reading parameter definitions: "
+ file.getName() + " was a " + file.getName() + " was a "
+ obj.getClass().getSimpleName()); + obj.getClass().getSimpleName()
+ " but was expecting "
+ ParameterList.class.getSimpleName());
} }
} }
} }

View file

@ -25,7 +25,6 @@ import java.util.Set;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.parameter.Parameter; import com.raytheon.uf.common.parameter.Parameter;
@ -62,17 +61,8 @@ public class ParameterMapper extends Mapper {
private ParameterMapper() { private ParameterMapper() {
IPathManager pathMgr = PathManagerFactory.getPathManager(); IPathManager pathMgr = PathManagerFactory.getPathManager();
LocalizationContext commonStaticBase = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.BASE);
LocalizationContext commonStaticSite = pathMgr.getContext(
LocalizationContext.LocalizationType.COMMON_STATIC,
LocalizationContext.LocalizationLevel.SITE);
// read in the namespace map // read in the namespace map
LocalizationFile[] files = pathMgr.listFiles(new LocalizationContext[] { LocalizationFile[] files = pathMgr.listStaticFiles("parameter"
commonStaticSite, commonStaticBase }, "parameter"
+ IPathManager.SEPARATOR + "alias", new String[] { ".xml" }, + IPathManager.SEPARATOR + "alias", new String[] { ".xml" },
true, true); true, true);
for (LocalizationFile file : files) { for (LocalizationFile file : files) {
@ -135,12 +125,9 @@ public class ParameterMapper extends Mapper {
return ParameterLookup.getInstance().getParameter(baseName); return ParameterLookup.getInstance().getParameter(baseName);
} }
private static ParameterMapper instance; private static final ParameterMapper instance = new ParameterMapper();
public static synchronized ParameterMapper getInstance() { public static ParameterMapper getInstance() {
if (instance == null) {
instance = new ParameterMapper();
}
return instance; return instance;
} }

View file

@ -25,16 +25,13 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/** /**
* *
* A AliasNamespace represents a set of alternative names for a base name. This * Represents a bidirectional map for going between base names and aliases.
* list defines the alternatives within a namespace so that it is possible to * Allows for caseInsensitive aliases since some naming conventions are ambigous
* match aliases for only a specific group. Parent namespaces can be used to * on case. The base names cannot be treated case insensitive because this would
* bring all aliases from another list into this namespace. * cause ambiguity and require case insensitive handling of base names in all
* namespaces.
* *
* <pre> * <pre>
* *
@ -49,8 +46,6 @@ import javax.xml.bind.annotation.XmlRootElement;
* @author bsteffen * @author bsteffen
* @version 1.0 * @version 1.0
*/ */
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement
public class AliasNamespace { public class AliasNamespace {
protected final boolean caseSensitive; protected final boolean caseSensitive;

View file

@ -81,7 +81,9 @@ public abstract class Mapper {
Unmarshaller unmarshaller = Mapper.unmarshaller; Unmarshaller unmarshaller = Mapper.unmarshaller;
if (unmarshaller == null) { if (unmarshaller == null) {
// This will be safe if multiple threads get in before the sync // This will be safe if multiple threads get in before the sync
// block. // block. This is not in a static block or ThreadLocal because this
// class is deliberately not handling any exceptions but instead
// propagates all problems to the concrete implementation.
JAXBContext context = JAXBContext.newInstance(AliasList.class, JAXBContext context = JAXBContext.newInstance(AliasList.class,
Alias.class); Alias.class);
unmarshaller = context.createUnmarshaller(); unmarshaller = context.createUnmarshaller();

View file

@ -4,13 +4,17 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
// TODO this logic could probably be included in the ncgribFileNameProcessor rather than in a singleton
public class GridLookupFileName { public class GridLookupFileName {
/** The singleton instance of GridLookupFileName **/ /** The singleton instance of GridLookupFileName **/
private static GridLookupFileName instance; private static GridLookupFileName instance;
// TODO modelname needs to be infered from filename since the file name
// processing happens before decode.
private String[] modelNames = { "cmce", "gefs", "gww", "naefsBC", private String[] modelNames = { "cmce", "gefs", "gww", "naefsBC",
"naefsUS", "naefsAK", "sref" }; "naefsUS", "naefsAK", "sref" };
// TODO this should be read from a configureable xml file, not hardcoded
private String[] template = { private String[] template = {
"cmc_gep.*|cmce;cmc_gec.*|cmcec;cmc_geavg.*|cmceMean;cmc_gespr.*|cmceSpread", "cmc_gep.*|cmce;cmc_gec.*|cmcec;cmc_geavg.*|cmceMean;cmc_gespr.*|cmceSpread",
"gec00.*bc.*|gefscBC;gec00.*anl|gefscAnal;gec00.*[0-9]|gefsc;gep.*anl|gefsAnal;gep.*bc.*|gefsBC;geavg.*bc.*|gefsMeanBC;gespr.*bc.*|gefsSpreadBC;gespr.*|gefsSpread", "gec00.*bc.*|gefscBC;gec00.*anl|gefscAnal;gec00.*[0-9]|gefsc;gep.*anl|gefsAnal;gep.*bc.*|gefsBC;geavg.*bc.*|gefsMeanBC;gespr.*bc.*|gefsSpreadBC;gespr.*|gefsSpread",
@ -36,6 +40,9 @@ public class GridLookupFileName {
} }
private void initModels() { private void initModels() {
// TODO instead of just building this map, all parsing should be
// happening here and regexes should be built into Pattern object so
// that we aren'y constantly reprocessing regexes
for (int i = 0; i < modelNames.length; i++) { for (int i = 0; i < modelNames.length; i++) {
models.put(modelNames[i].toUpperCase(), template[i]); models.put(modelNames[i].toUpperCase(), template[i]);
} }
@ -44,18 +51,24 @@ public class GridLookupFileName {
public String getModelName(String filename) { public String getModelName(String filename) {
String modelname = null; String modelname = null;
// this was commented out because file name processing should happen
// before decode so there is no pre-existing model name.
// if (model.equalsIgnoreCase("gww") && gridId.equalsIgnoreCase("229")) // if (model.equalsIgnoreCase("gww") && gridId.equalsIgnoreCase("229"))
// { // {
// return modelname; // return modelname;
// } // }
// //
// String template = models.get(model.toUpperCase()); // String template = models.get(model.toUpperCase());
// since we don't know the model name, we must process all templates.
for (String template : this.template) { for (String template : this.template) {
// TODO do not split this for every filename, split in init
String[] tokens = template.split(";"); String[] tokens = template.split(";");
// System.out.println ( " CMC ensemble " + "!!!\n"); // System.out.println ( " CMC ensemble " + "!!!\n");
for (String token : tokens) { for (String token : tokens) {
// TODO do not split this for every filename, split in init
String[] alias = token.split("\\|"); String[] alias = token.split("\\|");
// TODO compile and reuse patterns.
if (Pattern.matches(alias[0], filename)) { if (Pattern.matches(alias[0], filename)) {
modelname = alias[1]; modelname = alias[1];
@ -68,6 +81,9 @@ public class GridLookupFileName {
break; break;
} }
} }
if (modelname != null) {
break;
}
} }
return modelname; return modelname;
} }

View file

@ -27,9 +27,11 @@ import org.apache.camel.Processor;
/** /**
* *
* Processor for ncep grib files, this processor has lots of hard coded * Based off a file name for a grib file, determine the modelName, secondaryId,
* assumptions about file naming that need to be more generic based off ncep * and ensembleId. It is ok not to set any headers because the decoder can find
* file names. * the modelName and ensembleId. Those fields should only be set if the filename
* has information beyond what is in the actual grib file.The grib decoder will
* not set a secondary id so if it isn't set here it will be null.
* *
* <pre> * <pre>
* *
@ -46,20 +48,25 @@ import org.apache.camel.Processor;
*/ */
public class NcgribFileNameProcessor implements Processor { public class NcgribFileNameProcessor implements Processor {
// TODO does this actually match all ensemble patterns?
// grab all known ensemble ids // grab all known ensemble ids
private static final Pattern ENSEMBLE_ID_PATTERN = Pattern private static final Pattern ENSEMBLE_ID_PATTERN = Pattern
.compile("^(p|n|ctl)\\d{0,2}$"); .compile("^(p|n|ctl)\\d{0,2}$");
// TODO merge this pattern in with the patterns in GridLookupFileName
// anything that ends in nest is assumed to be a nested grid identifier // anything that ends in nest is assumed to be a nested grid identifier
private static final Pattern FIREWXNEST_ID_PATTERN = Pattern private static final Pattern FIREWXNEST_ID_PATTERN = Pattern
.compile("^firewxnest$"); .compile("^firewxnest$");
// TODO merge this pattern in with the patterns in GridLookupFileName
// anything that ends in nest is assumed to be a nested grid identifier // anything that ends in nest is assumed to be a nested grid identifier
private static final Pattern NEST_ID_PATTERN = Pattern.compile("^.*nest$"); private static final Pattern NEST_ID_PATTERN = Pattern.compile("^.*nest$");
// TODO merge this pattern in with the patterns in GridLookupFileName
// SREF gets special handling, does this apply to other models? // SREF gets special handling, does this apply to other models?
private static final Pattern SREF_PATTERN = Pattern.compile("^sref_.*$"); private static final Pattern SREF_PATTERN = Pattern.compile("^sref_.*$");
// TODO merge this pattern in with the patterns in GridLookupFileName
// This is the least generic pattern ever, are there any constraints on // This is the least generic pattern ever, are there any constraints on
// event names, who knows? // event names, who knows?
private static final Pattern HURRICANE_PATTERN = Pattern private static final Pattern HURRICANE_PATTERN = Pattern
@ -106,6 +113,8 @@ public class NcgribFileNameProcessor implements Processor {
exchange.getIn().setHeader("datasetid", datasetid); exchange.getIn().setHeader("datasetid", datasetid);
} }
if (secondaryid == null) { if (secondaryid == null) {
// TODO does everything really need secondaryid or should this only
// be set for events?
secondaryid = nameTokens[0]; secondaryid = nameTokens[0];
} }
exchange.getIn().setHeader("secondaryid", secondaryid); exchange.getIn().setHeader("secondaryid", secondaryid);