Issue #1108 initial implementation of mappings
Change-Id: I05a3643e288778dbb97e80f881f2e71f6373067d Conflicts: edexOsgi/com.raytheon.uf.common.dataplugin.grid/META-INF/MANIFEST.MF Former-commit-id:693090cb36
[formerly 8db340a796df354059f3d4142db92dfd5fa527f5] Former-commit-id:535c73051d
This commit is contained in:
parent
7f49c5fe04
commit
20e618eb4f
46 changed files with 2113 additions and 1381 deletions
|
@ -24,7 +24,8 @@ Require-Bundle: org.eclipse.ui,
|
|||
com.raytheon.uf.common.dataplugin.radar;bundle-version="1.0.0",
|
||||
com.raytheon.uf.viz.points;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.gridcoverage,
|
||||
org.apache.commons.beanutils;bundle-version="1.8.3"
|
||||
org.apache.commons.beanutils;bundle-version="1.8.3",
|
||||
com.raytheon.uf.common.dataplugin.grid;bundle-version="1.0.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: com.raytheon.viz.grid,
|
||||
com.raytheon.viz.grid.inv,
|
||||
|
@ -35,19 +36,8 @@ Export-Package: com.raytheon.viz.grid,
|
|||
Import-Package: com.raytheon.edex.scriptfactory,
|
||||
com.raytheon.uf.common.colormap,
|
||||
com.raytheon.uf.common.comm,
|
||||
com.raytheon.uf.common.dataplugin.grib.request,
|
||||
com.raytheon.uf.common.dataplugin.grid,
|
||||
com.raytheon.uf.common.dataplugin.grid.dataset,
|
||||
com.raytheon.uf.common.dataplugin.grid.request,
|
||||
com.raytheon.uf.common.dataplugin.grid.units,
|
||||
com.raytheon.uf.common.dataplugin.grid.util,
|
||||
com.raytheon.uf.common.dataplugin.level,
|
||||
com.raytheon.uf.common.derivparam.tree,
|
||||
com.raytheon.uf.common.gridcoverage,
|
||||
com.raytheon.uf.common.gridcoverage.convert,
|
||||
com.raytheon.uf.common.gridcoverage.lookup,
|
||||
com.raytheon.uf.common.gridcoverage.request,
|
||||
com.raytheon.uf.common.gridcoverage.subgrid,
|
||||
com.raytheon.uf.common.localization,
|
||||
com.raytheon.uf.common.message,
|
||||
com.raytheon.uf.common.message.response,
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<ns2:groupList xmlns:ns2="group">
|
||||
<!-- TODO: Use D2D/src/localization/nationalData/gridPlaneTable.txt
|
||||
to fill in rest of standard, composite, and binary groups -->
|
||||
<group id="S" description="Standard">
|
||||
<level id="MB">
|
||||
<levelValue valueOne="1000" />
|
||||
<levelValue valueOne="900" />
|
||||
<levelValue valueOne="800" />
|
||||
<levelValue valueOne="700" />
|
||||
<levelValue valueOne="600" />
|
||||
<levelValue valueOne="500" />
|
||||
<levelValue valueOne="400" />
|
||||
<levelValue valueOne="300" />
|
||||
<levelValue valueOne="200" />
|
||||
<levelValue valueOne="100" />
|
||||
</level>
|
||||
<level id="BL">
|
||||
<levelValue valueOne="120" valueTwo="90" />
|
||||
</level>
|
||||
</group>
|
||||
<group description="Composite" id="C">
|
||||
<level id="LYRMB">
|
||||
<levelValue valueOne="300.0" valueTwo="200.0" />
|
||||
<levelValue valueOne="400.0" valueTwo="300.0" />
|
||||
<levelValue valueOne="500.0" valueTwo="400.0" />
|
||||
<levelValue valueOne="700.0" valueTwo="600.0" />
|
||||
<levelValue valueOne="800.0" valueTwo="700.0" />
|
||||
<levelValue valueOne="900.0" valueTwo="800.0" />
|
||||
<levelValue valueOne="1000.0" valueTwo="900.0" />
|
||||
<levelValue valueOne="1000.0" valueTwo="950.0" />
|
||||
<levelValue valueOne="950.0" valueTwo="900.0" />
|
||||
<levelValue valueOne="900.0" valueTwo="850.0" />
|
||||
<levelValue valueOne="850.0" valueTwo="800.0" />
|
||||
<levelValue valueOne="800.0" valueTwo="750.0" />
|
||||
<levelValue valueOne="750.0" valueTwo="700.0" />
|
||||
<levelValue valueOne="700.0" valueTwo="650.0" />
|
||||
<levelValue valueOne="650.0" valueTwo="600.0" />
|
||||
<levelValue valueOne="600.0" valueTwo="550.0" />
|
||||
<levelValue valueOne="550.0" valueTwo="500.0" />
|
||||
<levelValue valueOne="500.0" valueTwo="450.0" />
|
||||
<levelValue valueOne="450.0" valueTwo="400.0" />
|
||||
<levelValue valueOne="400.0" valueTwo="350.0" />
|
||||
<levelValue valueOne="350.0" valueTwo="300.0" />
|
||||
<levelValue valueOne="300.0" valueTwo="250.0" />
|
||||
<levelValue valueOne="250.0" valueTwo="200.0" />
|
||||
<levelValue valueOne="400.0" valueTwo="200.0" />
|
||||
<levelValue valueOne="500.0" valueTwo="100.0" />
|
||||
<levelValue valueOne="500.0" valueTwo="250.0" />
|
||||
<levelValue valueOne="500.0" valueTwo="300.0" />
|
||||
<levelValue valueOne="600.0" valueTwo="400.0" />
|
||||
<levelValue valueOne="700.0" valueTwo="300.0" />
|
||||
<levelValue valueOne="700.0" valueTwo="500.0" />
|
||||
<levelValue valueOne="850.0" valueTwo="250.0" />
|
||||
<levelValue valueOne="850.0" valueTwo="300.0" />
|
||||
<levelValue valueOne="850.0" valueTwo="500.0" />
|
||||
<levelValue valueOne="850.0" valueTwo="700.0" />
|
||||
<levelValue valueOne="925.0" valueTwo="700.0" />
|
||||
<levelValue valueOne="925.0" valueTwo="850.0" />
|
||||
<levelValue valueOne="1000.0" valueTwo="500.0" />
|
||||
<levelValue valueOne="1000.0" valueTwo="700.0" />
|
||||
<levelValue valueOne="1000.0" valueTwo="850.0" />
|
||||
</level>
|
||||
</group>
|
||||
<group id="Surface" description="Surface">
|
||||
<level id="FH">
|
||||
<levelValue valueOne="10" />
|
||||
</level>
|
||||
<level id="MSL">
|
||||
<levelValue valueOne="0" />
|
||||
</level>
|
||||
<level id="SFC">
|
||||
<levelValue valueOne="0" />
|
||||
</level>
|
||||
<level id="FHAG">
|
||||
<levelValue valueOne="2" />
|
||||
<levelValue valueOne="10" />
|
||||
</level>
|
||||
</group>
|
||||
</ns2:groupList>
|
|
@ -1,82 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<levelAliasList>
|
||||
<level name="MB">
|
||||
<alias>ISBL</alias>
|
||||
</level>
|
||||
<level name="K">
|
||||
<alias>THEL</alias>
|
||||
</level>
|
||||
<level name="TROP">
|
||||
<alias>TRO</alias>
|
||||
</level>
|
||||
<level name="FRZ">
|
||||
<alias>0DEG</alias>
|
||||
</level>
|
||||
<level name="MAXW">
|
||||
<alias>MWSL</alias>
|
||||
</level>
|
||||
<level name="FHAG">
|
||||
<alias>HTGL</alias>
|
||||
<alias>ZAGL</alias>
|
||||
</level>
|
||||
<level name="SIG">
|
||||
<alias>SIGL</alias>
|
||||
</level>
|
||||
<level name="FH">
|
||||
<alias>AMSL</alias>
|
||||
<alias>ZZZZ</alias>
|
||||
</level>
|
||||
<level name="BLS">
|
||||
<alias>DBLL</alias>
|
||||
</level>
|
||||
<level name="EA">
|
||||
<alias>EATM</alias>
|
||||
</level>
|
||||
<level name="BL">
|
||||
<alias>SPDL</alias>
|
||||
</level>
|
||||
<level name="PV">
|
||||
<alias>PVL</alias>
|
||||
</level>
|
||||
<level name="HYB">
|
||||
<alias>HYBL</alias>
|
||||
</level>
|
||||
<level name="ETA">
|
||||
<alias>ETAL</alias>
|
||||
</level>
|
||||
<level name="BSS">
|
||||
<alias>DBSL</alias>
|
||||
</level>
|
||||
<level name="MLD">
|
||||
<alias>MIXL</alias>
|
||||
</level>
|
||||
<level name="MEPT">
|
||||
<alias>MTHE</alias>
|
||||
</level>
|
||||
<level name="EL">
|
||||
<alias>EHLT</alias>
|
||||
</level>
|
||||
<level name="OSEQD">
|
||||
<alias>OSD</alias>
|
||||
</level>
|
||||
</levelAliasList>
|
||||
|
|
@ -54,6 +54,7 @@ from com.raytheon.uf.common.gridcoverage.lookup import GridCoverageLookup
|
|||
from com.raytheon.uf.common.gridcoverage import Corner
|
||||
from com.raytheon.edex.plugin.grib.util import GribModelLookup
|
||||
|
||||
from com.raytheon.uf.common.dataplugin.level.mapping import LevelMapper
|
||||
from com.raytheon.uf.common.dataplugin.level import Level
|
||||
from com.raytheon.uf.common.dataplugin.level import LevelFactory
|
||||
|
||||
|
@ -534,9 +535,6 @@ class GribDecoder():
|
|||
parameterAbbreviation = parameter.getD2dAbbrev()
|
||||
else:
|
||||
parameterAbbreviation = parameter.getAbbreviation()
|
||||
baseParameter = ParameterMapper.getInstance().lookupParameter("grib", parameterAbbreviation)
|
||||
if baseParameter != None:
|
||||
parameterAbbreviation = baseParameter.getAbbreviation();
|
||||
parameterUnit = parameter.getUnit()
|
||||
else:
|
||||
LogStream.logEvent("No parameter information for center[" + str(centerID) + "], subcenter[" +
|
||||
|
@ -677,6 +675,8 @@ class GribDecoder():
|
|||
|
||||
if(pdsTemplate[2] == 6 or pdsTemplate[2] == 7):
|
||||
parameterAbbreviation = parameterAbbreviation+"erranl"
|
||||
|
||||
parameterAbbreviation = ParameterMapper.getInstance().lookupBaseName(parameterAbbreviation, "grib");
|
||||
# Constructing the GribModel object
|
||||
pdsFields['centerid'] = centerID
|
||||
pdsFields['subcenterid'] = subcenterID
|
||||
|
@ -687,7 +687,7 @@ class GribDecoder():
|
|||
pdsFields['parameterUnit'] = parameterUnit
|
||||
|
||||
# Constructing the Level object
|
||||
level = LevelFactory.getInstance().getLevel(levelName, levelOneValue, levelTwoValue, levelUnit)
|
||||
level = LevelMapper.getInstance().lookupLevel(levelName, 'grib', levelOneValue, levelTwoValue, levelUnit)
|
||||
pdsFields['level'] = level
|
||||
|
||||
|
||||
|
@ -1269,12 +1269,11 @@ class GribDecoder():
|
|||
return gridModel
|
||||
|
||||
def _createModelName(self, pdsSectionValues, grid):
|
||||
gridModel = self._getGridModel(pdsSectionValues, grid)
|
||||
if gridModel is None:
|
||||
name = "UnknownModel:" + str(pdsSectionValues['centerid']) + ":" + str(pdsSectionValues['subcenterid']) + ":" + str(pdsSectionValues['genprocess']) + ":" + str(grid.getId())
|
||||
else:
|
||||
name = gridModel.getName()
|
||||
return name
|
||||
center = pdsSectionValues['centerid']
|
||||
subcenter = pdsSectionValues['subcenterid']
|
||||
|
||||
process = pdsSectionValues['genprocess']
|
||||
return GribModelLookup.getInstance().getModelName(center, subcenter, grid, process)
|
||||
|
||||
def _checkForecastFlag(self, pdsSectionValues, grid, dataTime):
|
||||
gridModel = self._getGridModel(pdsSectionValues, grid)
|
||||
|
|
|
@ -22,15 +22,14 @@ Require-Bundle: javax.measure,
|
|||
com.raytheon.uf.common.datastorage.hdf5;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.edex.awipstools;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.awipstools;bundle-version="1.12.1174",
|
||||
ucar.nc2;bundle-version="1.0.0"
|
||||
ucar.nc2;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.dataplugin.level;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.dataplugin.grid;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.dataplugin.grid
|
||||
Import-Package: com.raytheon.edex.exception,
|
||||
com.raytheon.uf.common.comm,
|
||||
com.raytheon.uf.common.dataplugin.grib,
|
||||
com.raytheon.uf.common.dataplugin.grib.request,
|
||||
com.raytheon.uf.common.dataplugin.grid,
|
||||
com.raytheon.uf.common.dataplugin.grid.dataset,
|
||||
com.raytheon.uf.common.dataplugin.grid.util,
|
||||
com.raytheon.uf.common.dataplugin.level,
|
||||
com.raytheon.uf.common.derivparam.tree,
|
||||
com.raytheon.uf.common.gridcoverage,
|
||||
com.raytheon.uf.common.gridcoverage.exception,
|
||||
|
|
|
@ -60,6 +60,8 @@ import com.raytheon.uf.common.dataplugin.PluginException;
|
|||
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
|
||||
import com.raytheon.uf.common.dataplugin.level.Level;
|
||||
import com.raytheon.uf.common.dataplugin.level.LevelFactory;
|
||||
import com.raytheon.uf.common.dataplugin.level.mapping.LevelMapper;
|
||||
import com.raytheon.uf.common.dataplugin.level.mapping.MultipleLevelMappingException;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.LambertConformalGridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.LatLonGridCoverage;
|
||||
|
@ -79,6 +81,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
import com.raytheon.uf.common.time.DataTime;
|
||||
import com.raytheon.uf.common.time.DataTime.FLAG;
|
||||
import com.raytheon.uf.common.time.TimeRange;
|
||||
import com.raytheon.uf.common.util.mapping.MultipleMappingException;
|
||||
|
||||
/**
|
||||
* Grib decoder implementation for decoding grib version 1 files.
|
||||
|
@ -250,11 +253,7 @@ public class Grib1Decoder extends AbstractDecoder {
|
|||
parameterName = param.getDescription();
|
||||
parameterAbbreviation = param.getName();
|
||||
parameterUnit = param.getUnit();
|
||||
Parameter baseParameter = ParameterMapper.getInstance()
|
||||
.lookupParameter("grib", parameterAbbreviation);
|
||||
if (baseParameter != null) {
|
||||
parameterAbbreviation = baseParameter.getAbbreviation();
|
||||
}
|
||||
|
||||
} catch (NotSupportedException e) {
|
||||
throw new GribException("Error getting grib 1 parameter", e);
|
||||
}
|
||||
|
@ -263,11 +262,6 @@ public class Grib1Decoder extends AbstractDecoder {
|
|||
parameterUnit = parameter.getUnit();
|
||||
if (parameter.getD2dAbbrev() == null) {
|
||||
parameterAbbreviation = parameter.getAbbreviation();
|
||||
Parameter baseParameter = ParameterMapper.getInstance()
|
||||
.lookupParameter("grib", parameterAbbreviation);
|
||||
if (baseParameter != null) {
|
||||
parameterAbbreviation = baseParameter.getAbbreviation();
|
||||
}
|
||||
} else {
|
||||
parameterAbbreviation = parameter.getD2dAbbrev();
|
||||
}
|
||||
|
@ -482,6 +476,13 @@ public class Grib1Decoder extends AbstractDecoder {
|
|||
parameterAbbreviation = newAbbr;
|
||||
}
|
||||
parameterAbbreviation = parameterAbbreviation.replaceAll("_", "-");
|
||||
try {
|
||||
parameterAbbreviation = ParameterMapper.getInstance()
|
||||
.lookupBaseName("grib", parameterAbbreviation);
|
||||
} catch (MultipleMappingException e) {
|
||||
statusHandler.handle(Priority.WARN, e.getLocalizedMessage(), e);
|
||||
parameterAbbreviation = e.getArbitraryMapping();
|
||||
}
|
||||
|
||||
retVal.setPluginName("grid");
|
||||
Parameter param = new Parameter(parameterAbbreviation, parameterName,
|
||||
|
@ -909,16 +910,8 @@ public class Grib1Decoder extends AbstractDecoder {
|
|||
*/
|
||||
private String createModelName(int centerId, int subcenterId, int process,
|
||||
GridCoverage grid) {
|
||||
GridModel gridModel = GribModelLookup.getInstance().getModel(centerId,
|
||||
return GribModelLookup.getInstance().getModelName(centerId,
|
||||
subcenterId, grid, process);
|
||||
if (gridModel == null || gridModel.getName() == null) {
|
||||
return "UnknownModel:" + String.valueOf(centerId) + ":"
|
||||
+ String.valueOf(subcenterId) + ":"
|
||||
+ String.valueOf(process) + ":"
|
||||
+ String.valueOf(grid.getId());
|
||||
} else {
|
||||
return gridModel.getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1269,11 +1262,13 @@ public class Grib1Decoder extends AbstractDecoder {
|
|||
levelTwoValue = Level.getInvalidLevelValue();
|
||||
}
|
||||
try {
|
||||
Level level = LevelFactory.getInstance().getLevel(levelName,
|
||||
return LevelMapper.getInstance().lookupLevel(levelName, "grib",
|
||||
levelOneValue, levelTwoValue, levelUnit);
|
||||
return level;
|
||||
} catch (CommunicationException e) {
|
||||
throw new GribException("Error requesting levels", e);
|
||||
} catch (MultipleLevelMappingException e) {
|
||||
statusHandler.handle(Priority.WARN, e.getLocalizedMessage(), e);
|
||||
return e.getArbitraryLevelMapping();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,20 @@ import com.raytheon.edex.plugin.grib.exception.GribException;
|
|||
import com.raytheon.edex.plugin.grib.spatial.GribSpatialCache;
|
||||
import com.raytheon.uf.common.dataplugin.grid.dataset.DatasetInfo;
|
||||
import com.raytheon.uf.common.dataplugin.grid.dataset.DatasetInfoSet;
|
||||
import com.raytheon.uf.common.dataplugin.grid.mapping.DatasetIdMapper;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
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.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.util.mapping.MultipleMappingException;
|
||||
|
||||
public class GribModelLookup {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(GribModelLookup.class);
|
||||
|
||||
/** The logger */
|
||||
protected transient Log logger = LogFactory.getLog(getClass());
|
||||
|
@ -87,8 +94,10 @@ public class GribModelLookup {
|
|||
|
||||
public GridModel getModel(int center, int subcenter, GridCoverage grid,
|
||||
int process) {
|
||||
GridModel model = models.get(toKey(center, subcenter, grid.getName(),
|
||||
process));
|
||||
GridModel model = null;
|
||||
if (grid.getName() != null) {
|
||||
models.get(toKey(center, subcenter, grid.getName(), process));
|
||||
}
|
||||
if (model == null) {
|
||||
for (String gribGridName : GribSpatialCache.getInstance()
|
||||
.getGribCoverageNames(grid)) {
|
||||
|
@ -123,6 +132,45 @@ public class GribModelLookup {
|
|||
return modelsByName.keySet();
|
||||
}
|
||||
|
||||
public String getModelName(int center, int subcenter, GridCoverage grid,
|
||||
int process) {
|
||||
GridModel model = getModel(center, subcenter, grid, process);
|
||||
if (model == null || model.getName() == null) {
|
||||
String cenSubProc = "GribModel:" + String.valueOf(center) + ":"
|
||||
+ String.valueOf(subcenter) + ":" + String.valueOf(process);
|
||||
String cenSubProcLoc = null;
|
||||
DatasetIdMapper mapper = DatasetIdMapper.getInstance();
|
||||
try {
|
||||
if (grid.getName() != null) {
|
||||
cenSubProcLoc = cenSubProc + ":" + grid.getName();
|
||||
String name = mapper.lookupBaseName(cenSubProcLoc, "grib");
|
||||
if (!name.equals(cenSubProcLoc)) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
for (String gribGridName : GribSpatialCache.getInstance()
|
||||
.getGribCoverageNames(grid)) {
|
||||
cenSubProcLoc = cenSubProc + ":" + gribGridName;
|
||||
String name = mapper.lookupBaseName(cenSubProcLoc, "grib");
|
||||
if (!name.equals(cenSubProcLoc)) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
String name = mapper.lookupBaseName(cenSubProc, "grib");
|
||||
if (!name.equals(cenSubProcLoc)) {
|
||||
return name;
|
||||
}
|
||||
return cenSubProcLoc;
|
||||
} catch (MultipleMappingException e) {
|
||||
statusHandler.handle(Priority.WARN, e.getLocalizedMessage(), e);
|
||||
|
||||
return e.getArbitraryMapping();
|
||||
}
|
||||
} else {
|
||||
return model.getName();
|
||||
}
|
||||
}
|
||||
|
||||
private void initModelList() throws GribException {
|
||||
logger.info("Initializing grib models");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<aliasList namespace="grib">
|
||||
<alias base="GFS212">GribModel:7:0:96:212</alias>
|
||||
<alias base="GFS212">GribModel:7:0:81:212</alias>
|
||||
<alias base="GFS212">GribModel:7:0:77:212</alias>
|
||||
</aliasList>
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<aliasList namespace="grib">
|
||||
<alias base="MB">ISBL</alias>
|
||||
<alias base="K">THEL</alias>
|
||||
<alias base="TROP">TRO</alias>
|
||||
<alias base="FRZ">0DEG</alias>
|
||||
<alias base="MAXW">MWSL</alias>
|
||||
<alias base="FHAG">HTGL</alias>
|
||||
<alias base="FHAG">ZAGL</alias>
|
||||
<alias base="SIG">SIGL</alias>
|
||||
<alias base="FH">AMSL</alias>
|
||||
<alias base="FH">ZZZZ</alias>
|
||||
<alias base="BLS">DBLL</alias>
|
||||
<alias base="EA">EATM</alias>
|
||||
<alias base="BL">SPDL</alias>
|
||||
<alias base="PV">PVL</alias>
|
||||
<alias base="HYB">HYBL</alias>
|
||||
<alias base="ETA">ETAL</alias>
|
||||
<alias base="BSS">DBSL</alias>
|
||||
<alias base="MLD">MIXL</alias>
|
||||
<alias base="MEPT">MTHE</alias>
|
||||
<alias base="EL">EHLT</alias>
|
||||
<alias base="OSEQD">OSD</alias>
|
||||
</aliasList>
|
|
@ -18,7 +18,7 @@
|
|||
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
|
||||
further_licensing_information.
|
||||
-->
|
||||
<parameterAliasList namespace="grib">
|
||||
<aliasList namespace="grib">
|
||||
<alias base="WGH">5WAVH</alias>
|
||||
<alias base="AV">ABSV</alias>
|
||||
<alias base="CRAIN">CRAIN</alias>
|
||||
|
@ -101,4 +101,4 @@
|
|||
<alias base="WD">WDIR</alias>
|
||||
<alias base="WS">WIND</alias>
|
||||
<alias base="WGS">WGS</alias>
|
||||
</parameterAliasList>
|
||||
</aliasList>
|
|
@ -9,7 +9,6 @@ Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization
|
|||
Eclipse-BuddyPolicy: registered, ext, global
|
||||
Import-Package: com.raytheon.uf.common.dataplugin,
|
||||
com.raytheon.uf.common.dataplugin.annotations,
|
||||
com.raytheon.uf.common.dataplugin.level,
|
||||
com.raytheon.uf.common.dataplugin.persist,
|
||||
com.raytheon.uf.common.datastorage.records,
|
||||
com.raytheon.uf.common.geospatial,
|
||||
|
@ -28,6 +27,12 @@ Import-Package: com.raytheon.uf.common.dataplugin,
|
|||
org.opengis.metadata.spatial
|
||||
Export-Package: com.raytheon.uf.common.dataplugin.grid,
|
||||
com.raytheon.uf.common.dataplugin.grid.dataset,
|
||||
com.raytheon.uf.common.dataplugin.grid.mapping,
|
||||
com.raytheon.uf.common.dataplugin.grid.request,
|
||||
com.raytheon.uf.common.dataplugin.grid.units,
|
||||
com.raytheon.uf.common.dataplugin.grid.util
|
||||
Require-Bundle: com.raytheon.uf.common.comm;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.dataplugin.level;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.parameter;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.util;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.dataquery;bundle-version="1.0.0"
|
||||
|
|
|
@ -0,0 +1,308 @@
|
|||
/**
|
||||
* 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.common.dataplugin.grid.dataquery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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 com.raytheon.uf.common.comm.CommunicationException;
|
||||
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
|
||||
import com.raytheon.uf.common.dataplugin.grid.mapping.DatasetIdMapper;
|
||||
import com.raytheon.uf.common.dataplugin.level.Level;
|
||||
import com.raytheon.uf.common.dataplugin.level.mapping.LevelMapper;
|
||||
import com.raytheon.uf.common.dataquery.db.QueryParam;
|
||||
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
|
||||
import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType;
|
||||
import com.raytheon.uf.common.parameter.mapping.ParameterMapper;
|
||||
import com.raytheon.uf.common.util.mapping.Mapper;
|
||||
|
||||
/**
|
||||
* Assemble a query to use when requesting grid data. To use populate query
|
||||
* fields using the various setters, then use getConstraintMap to get the
|
||||
* constraints to use in a DbQueryRequest or other query type. This
|
||||
* implementation uses the ParameterMapper, LevelMapper, and DatasetIdMapper so
|
||||
* it can accept fields using namespaces that aren't in the database and
|
||||
* transform them to valid database requests. Even if no custom namespace is
|
||||
* being used the assembler should still be used to check for deprecated names.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 9, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class GridQueryAssembler {
|
||||
|
||||
private String datasetIdNamespace;
|
||||
|
||||
private String datasetId;
|
||||
|
||||
private String secondaryId;
|
||||
|
||||
private String ensembleId;
|
||||
|
||||
private String parameterNamespace;
|
||||
|
||||
private String parameterAbbreviation;
|
||||
|
||||
private String levelNamespace;
|
||||
|
||||
private String masterLevelName;
|
||||
|
||||
private Double levelOneValue;
|
||||
|
||||
private Double levelTwoValue;
|
||||
|
||||
private String levelUnits;
|
||||
|
||||
/**
|
||||
* Construct an assembler that only checks for deprecated names.
|
||||
*/
|
||||
public GridQueryAssembler() {
|
||||
this(Mapper.DEPRECATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an assembler that uses the provided namespace for all mappings.
|
||||
*/
|
||||
public GridQueryAssembler(String namespace) {
|
||||
this(namespace, namespace, namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an assembler that will use three separate namespaces for each
|
||||
* type of mapping.
|
||||
*/
|
||||
public GridQueryAssembler(String datasetIdNamespace,
|
||||
String parameterNamespace, String levelNamespace) {
|
||||
this.datasetIdNamespace = datasetIdNamespace;
|
||||
this.parameterNamespace = parameterNamespace;
|
||||
this.levelNamespace = levelNamespace;
|
||||
}
|
||||
|
||||
private RequestConstraint buildEqualOrInRC(Set<String> names) {
|
||||
if (names.size() == 1) {
|
||||
return new RequestConstraint(names.iterator().next());
|
||||
} else {
|
||||
RequestConstraint rc = new RequestConstraint(null,
|
||||
ConstraintType.IN);
|
||||
rc.setConstraintValueList(names);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the constraints that can be used for querying whatever parameters
|
||||
* were specified.
|
||||
*
|
||||
* @return
|
||||
* @throws CommunicationException
|
||||
*/
|
||||
public Map<String, RequestConstraint> getConstraintMap()
|
||||
throws CommunicationException {
|
||||
Map<String, RequestConstraint> constraintMap = new HashMap<String, RequestConstraint>();
|
||||
constraintMap.put(GridConstants.PLUGIN_NAME, new RequestConstraint(
|
||||
GridConstants.GRID));
|
||||
if (datasetId != null) {
|
||||
Set<String> names = DatasetIdMapper.getInstance().lookupBaseNames(
|
||||
datasetId, datasetIdNamespace);
|
||||
constraintMap
|
||||
.put(GridConstants.DATASET_ID, buildEqualOrInRC(names));
|
||||
}
|
||||
if (secondaryId != null) {
|
||||
constraintMap.put(GridConstants.SECONDARY_ID,
|
||||
new RequestConstraint(secondaryId));
|
||||
}
|
||||
if (ensembleId != null) {
|
||||
constraintMap.put(GridConstants.ENSEMBLE_ID, new RequestConstraint(
|
||||
ensembleId));
|
||||
}
|
||||
if (parameterAbbreviation != null) {
|
||||
Set<String> names = ParameterMapper.getInstance().lookupBaseNames(
|
||||
parameterAbbreviation, parameterNamespace);
|
||||
constraintMap.put(GridConstants.PARAMETER_ABBREVIATION,
|
||||
buildEqualOrInRC(names));
|
||||
}
|
||||
if (masterLevelName != null) {
|
||||
if (levelOneValue != null) {
|
||||
Set<Level> levels = null;
|
||||
if (levelTwoValue != null) {
|
||||
levels = LevelMapper.getInstance().lookupLevels(
|
||||
masterLevelName, levelNamespace, levelOneValue,
|
||||
levelTwoValue, levelUnits);
|
||||
} else {
|
||||
levels = LevelMapper.getInstance().lookupLevels(
|
||||
masterLevelName, levelNamespace, levelOneValue,
|
||||
levelUnits);
|
||||
}
|
||||
Set<String> masterLevels = new HashSet<String>(
|
||||
(int) (levels.size() / 0.75) + 1, 0.75f);
|
||||
Set<String> levelOnes = new HashSet<String>(
|
||||
(int) (levels.size() / 0.75) + 1, 0.75f);
|
||||
Set<String> levelTwos = new HashSet<String>(
|
||||
(int) (levels.size() / 0.75) + 1, 0.75f);
|
||||
for (Level level : levels) {
|
||||
masterLevels.add(level.getMasterLevel().getName());
|
||||
levelOnes.add(level.getLevelOneValueAsString());
|
||||
levelTwos.add(level.getLevelTwoValueAsString());
|
||||
}
|
||||
constraintMap.put(GridConstants.MASTER_LEVEL_NAME,
|
||||
buildEqualOrInRC(masterLevels));
|
||||
constraintMap.put(GridConstants.LEVEL_ONE,
|
||||
buildEqualOrInRC(levelOnes));
|
||||
if (levelTwoValue != null) {
|
||||
constraintMap.put(GridConstants.LEVEL_TWO,
|
||||
buildEqualOrInRC(levelTwos));
|
||||
}
|
||||
} else {
|
||||
Set<String> names = LevelMapper.getInstance().lookupBaseNames(
|
||||
masterLevelName, levelNamespace);
|
||||
constraintMap.put(GridConstants.MASTER_LEVEL_NAME,
|
||||
buildEqualOrInRC(names));
|
||||
}
|
||||
}
|
||||
return new HashMap<String, RequestConstraint>(constraintMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same idea as getConstraintMap but return QueryParams instead.
|
||||
*
|
||||
* @return
|
||||
* @throws CommunicationException
|
||||
*/
|
||||
public List<QueryParam> getQueryParams() throws CommunicationException {
|
||||
Map<String, RequestConstraint> map = getConstraintMap();
|
||||
List<QueryParam> result = new ArrayList<QueryParam>(map.size());
|
||||
for (Entry<String, RequestConstraint> entry : getConstraintMap()
|
||||
.entrySet()) {
|
||||
String field = entry.getKey();
|
||||
String value = entry.getValue().getConstraintValue();
|
||||
String operand = entry.getValue().getConstraintType().getOperand();
|
||||
result.add(new QueryParam(field, value, operand));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namespace to se when looking up dataset mappings, by default deprecated
|
||||
* is used to replace deprecated names with new names.
|
||||
*
|
||||
* @param datasetIdNamespace
|
||||
*/
|
||||
public void setDatasetIdNamespace(String datasetIdNamespace) {
|
||||
this.datasetIdNamespace = datasetIdNamespace;
|
||||
}
|
||||
|
||||
public void setDatasetId(String datasetId) {
|
||||
this.datasetId = datasetId;
|
||||
}
|
||||
|
||||
public void setSecondaryId(String secondaryId) {
|
||||
this.secondaryId = secondaryId;
|
||||
}
|
||||
|
||||
public void setEnsembleId(String ensembleId) {
|
||||
this.ensembleId = ensembleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namespace to se when looking up parameter mappings, by default deprecated
|
||||
* is used to replace deprecated names with new names.
|
||||
*
|
||||
* @param parameterNamespace
|
||||
*/
|
||||
public void setParameterNamespace(String parameterNamespace) {
|
||||
this.parameterNamespace = parameterNamespace;
|
||||
}
|
||||
|
||||
public void setParameterAbbreviation(String parameterAbbreviation) {
|
||||
this.parameterAbbreviation = parameterAbbreviation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Namespace to se when looking up level mappings, by default deprecated is
|
||||
* used to replace deprecated names with new names.
|
||||
*
|
||||
* @param levelNamespace
|
||||
*/
|
||||
public void setLevelNamespace(String levelNamespace) {
|
||||
this.levelNamespace = levelNamespace;
|
||||
}
|
||||
|
||||
public void setMasterLevelName(String masterLevelName) {
|
||||
this.masterLevelName = masterLevelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the level one value, be sure to set level units if the units might
|
||||
* differ from the db.
|
||||
*
|
||||
* @param levelOneValue
|
||||
*/
|
||||
public void setLevelOneValue(Double levelOneValue) {
|
||||
this.levelOneValue = levelOneValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the level two value, only valid if levelonevalue is also set.
|
||||
*
|
||||
* @param levelOneValue
|
||||
*/
|
||||
public void setLevelTwoValue(Double levelTwoValue) {
|
||||
this.levelTwoValue = levelTwoValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the unit of the numerical values passed in for the level values. The
|
||||
* level units aren't used directly in the request constraints, but if the
|
||||
* units are different then what is in the database then the values will
|
||||
* automatically be converted to build proper constraints.
|
||||
*
|
||||
* @param levelUnits
|
||||
*/
|
||||
public void setLevelUnits(String levelUnits) {
|
||||
this.levelUnits = levelUnits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to set all three namespaces to the same thing.
|
||||
*
|
||||
* @param namespace
|
||||
*/
|
||||
public void setNamespace(String namespace) {
|
||||
setParameterNamespace(namespace);
|
||||
setDatasetIdNamespace(namespace);
|
||||
setLevelNamespace(namespace);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* 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.common.dataplugin.grid.mapping;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
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.PathManager;
|
||||
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.util.mapping.Mapper;
|
||||
|
||||
/**
|
||||
* Provide mappings of grid datasetId. The "base" namespace is not formally
|
||||
* defined and can be considered as whatever the decoders are storing in the
|
||||
* database.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 30, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class DatasetIdMapper extends Mapper {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(DatasetIdMapper.class);
|
||||
|
||||
private DatasetIdMapper() {
|
||||
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
|
||||
LocalizationFile[] files = pathMgr.listFiles(new LocalizationContext[] {
|
||||
commonStaticSite, commonStaticBase }, "grid"
|
||||
+ PathManager.SEPARATOR + "dataset" + IPathManager.SEPARATOR
|
||||
+ "alias", new String[] { ".xml" }, true, true);
|
||||
for (LocalizationFile file : files) {
|
||||
try {
|
||||
addAliasList(file.getFile());
|
||||
} catch (JAXBException e) {
|
||||
statusHandler.error(
|
||||
"Error reading datasetid aliases: " + file.getName()
|
||||
+ " has been ignored.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DatasetIdMapper instance;
|
||||
|
||||
public static synchronized DatasetIdMapper getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new DatasetIdMapper();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<aliasList namespace="d2d-title">
|
||||
<alias base="AKWAVE239">AKWAVE</alias>
|
||||
<alias base="AUTOSPE">SPE</alias>
|
||||
<alias base="AVN203">GFS190</alias>
|
||||
<alias base="AVN211">GFS80</alias>
|
||||
<alias base="AVN225">GFS75</alias>
|
||||
<alias base="AVN37">GFSGbl</alias>
|
||||
<alias base="AVN38">GFSGbl</alias>
|
||||
<alias base="AVN39">GFSGbl</alias>
|
||||
<alias base="AVN40">GFSGbl</alias>
|
||||
<alias base="AVN41">GFSGbl</alias>
|
||||
<alias base="AVN42">GFSGbl</alias>
|
||||
<alias base="AVN43">GFSGbl</alias>
|
||||
<alias base="AVN44">GFSGbl</alias>
|
||||
<alias base="AVN">GFS180</alias>
|
||||
<alias base="AVN-NorthernHemisphere">GFSGbl</alias>
|
||||
<alias base="BHPE">BiasHPE</alias>
|
||||
<alias base="CPCoutlook211">CPCoutlook-Long</alias>
|
||||
<alias base="DGEX185">DGEX</alias>
|
||||
<alias base="DGEX186">DGEX</alias>
|
||||
<alias base="ECMF10">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF11">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF12">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF1">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF2">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF3">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF4">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF5">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF6">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF7">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF8">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF9">ECMWF-LowRes</alias>
|
||||
<alias base="ECMF-MODEL0">ECMWF-MODEL0</alias>
|
||||
<alias base="ECMF-NorthernHemisphere">ECMWF-LowRes</alias>
|
||||
<alias base="ENPWAVE253">ENPwave</alias>
|
||||
<alias base="ENSEMBLE37">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE38">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE39">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE40">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE41">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE42">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE43">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE44">GFSensemble</alias>
|
||||
<alias base="ENSEMBLE">GFSensemble</alias>
|
||||
<alias base="ETA207">NAM95</alias>
|
||||
<alias base="ETA212">NAMWX</alias>
|
||||
<alias base="ETA218">NAM12</alias>
|
||||
<alias base="ETA242">AK-NAM12</alias>
|
||||
<alias base="EtaBufr">NAM Bufr</alias>
|
||||
<alias base="ETA">NAM80</alias>
|
||||
<alias base="GFS160">AK-GFS</alias>
|
||||
<alias base="GFS161">SJU-GFS</alias>
|
||||
<alias base="GFS199">Guam-GFS</alias>
|
||||
<alias base="GFS201">GFS360</alias>
|
||||
<alias base="GFS212">GFS40</alias>
|
||||
<alias base="GFS213">GFS90</alias>
|
||||
<alias base="GFS254">PR-GFS</alias>
|
||||
<alias base="GfsBufr">GFSBufr</alias>
|
||||
<alias base="GFSLAMP">GFSLAMP-Stn</alias>
|
||||
<alias base="GFSLAMPTstorm">GFSLAMP-Grid</alias>
|
||||
<alias base="GWW233">GWW</alias>
|
||||
<alias base="HPCqpfNDFD">HPC</alias>
|
||||
<alias base="HurWind175">GuamHurWind</alias>
|
||||
<alias base="HurWind226">TPC-HurWind</alias>
|
||||
<alias base="HurWind250">HawHurWind</alias>
|
||||
<alias base="MANSPE">SPE</alias>
|
||||
<alias base="mesoEta212">NAM40</alias>
|
||||
<alias base="mesoEta215">NAM20</alias>
|
||||
<alias base="mesoEta216">AK-NAM40</alias>
|
||||
<alias base="mesoEta217">AK-NAM20</alias>
|
||||
<alias base="mesoEta237">PR-NAM12</alias>
|
||||
<alias base="MOSGuide-AK">AK-GriddedMOS</alias>
|
||||
<alias base="MOSGuide">GriddedMOS</alias>
|
||||
<alias base="MPE-Local">MPE</alias>
|
||||
<alias base="MPE-Mosaic">MPE</alias>
|
||||
<alias base="MRF203">gfs190</alias>
|
||||
<alias base="MRF204">GFS150</alias>
|
||||
<alias base="MRF205">GFS150</alias>
|
||||
<alias base="MRF21">gfsLR21</alias>
|
||||
<alias base="MRF22">gfsLR22</alias>
|
||||
<alias base="MRF23">gfsLR23</alias>
|
||||
<alias base="MRF24">gfsLR24</alias>
|
||||
<alias base="MRF25">gfsLR25</alias>
|
||||
<alias base="MRF26">gfsLR26</alias>
|
||||
<alias base="MRF">gfsLR</alias>
|
||||
<alias base="mrfNH">gfsLR</alias>
|
||||
<alias base="NGM202">NGM180</alias>
|
||||
<alias base="NGM207">NGM95</alias>
|
||||
<alias base="NGM213">NGM90</alias>
|
||||
<alias base="NGM">NGM80</alias>
|
||||
<alias base="OPCWave180">OPCWave-W-ATL</alias>
|
||||
<alias base="OPCWave181">OPCWave-NE-PAC</alias>
|
||||
<alias base="OPCWave182">OPCWave-TE-PAC</alias>
|
||||
<alias base="RTGSSTHR">RTG-SST-HR-Analysis</alias>
|
||||
<alias base="RTGSST">RTG-SST-Analysis</alias>
|
||||
<alias base="RUC130">RAP13</alias>
|
||||
<alias base="RUC236">RAP40</alias>
|
||||
<alias base="SREF212">SREF</alias>
|
||||
<alias base="SREF216">AK-SREF</alias>
|
||||
<alias base="SREF243">PR-SREF</alias>
|
||||
<alias base="UKMET37">UKMET</alias>
|
||||
<alias base="UKMET38">UKMET</alias>
|
||||
<alias base="UKMET39">UKMET</alias>
|
||||
<alias base="UKMET40">UKMET</alias>
|
||||
<alias base="UKMET41">UKMET</alias>
|
||||
<alias base="UKMET42">UKMET</alias>
|
||||
<alias base="UKMET43">UKMET</alias>
|
||||
<alias base="UKMET44">UKMET</alias>
|
||||
<alias base="UKMET-NorthernHemisphere">UKMET</alias>
|
||||
<alias base="WNAWAVE238">WNAwave</alias>
|
||||
</aliasList>
|
|
@ -6,7 +6,7 @@ Bundle-Version: 1.12.1174.qualifier
|
|||
Eclipse-BuddyPolicy: registered, ext, global
|
||||
Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization
|
||||
Bundle-Vendor: Raytheon
|
||||
Require-Bundle: javax.measure,
|
||||
Require-Bundle: javax.measure,
|
||||
javax.persistence,
|
||||
org.apache.commons.lang,
|
||||
org.apache.commons.logging,
|
||||
|
@ -14,10 +14,11 @@ Require-Bundle: javax.measure,
|
|||
com.raytheon.uf.common.localization,
|
||||
com.raytheon.uf.common.serialization,
|
||||
com.raytheon.uf.common.serialization.comm,
|
||||
com.raytheon.uf.common.status
|
||||
com.raytheon.uf.common.status,
|
||||
com.raytheon.uf.common.util;bundle-version="1.12.1174"
|
||||
Export-Package: com.raytheon.uf.common.dataplugin.level,
|
||||
com.raytheon.uf.common.dataplugin.level.request,
|
||||
com.raytheon.uf.common.dataplugin.level.xml
|
||||
com.raytheon.uf.common.dataplugin.level.mapping,
|
||||
com.raytheon.uf.common.dataplugin.level.request
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Import-Package: com.raytheon.uf.common.comm,
|
||||
org.hibernate.annotations
|
||||
|
|
|
@ -1,8 +1,2 @@
|
|||
com.raytheon.uf.common.dataplugin.level.Level
|
||||
com.raytheon.uf.common.dataplugin.level.MasterLevel
|
||||
com.raytheon.uf.common.dataplugin.level.xml.Group
|
||||
com.raytheon.uf.common.dataplugin.level.xml.GroupList
|
||||
com.raytheon.uf.common.dataplugin.level.xml.Level
|
||||
com.raytheon.uf.common.dataplugin.level.xml.LevelAlias
|
||||
com.raytheon.uf.common.dataplugin.level.xml.LevelAliasList
|
||||
com.raytheon.uf.common.dataplugin.level.xml.LevelValue
|
||||
com.raytheon.uf.common.dataplugin.level.MasterLevel
|
|
@ -42,14 +42,11 @@ import com.raytheon.uf.common.dataplugin.level.request.GetLevelByIdRequest;
|
|||
import com.raytheon.uf.common.dataplugin.level.request.GetLevelRequest;
|
||||
import com.raytheon.uf.common.dataplugin.level.request.GetMasterLevelRequest;
|
||||
import com.raytheon.uf.common.dataplugin.level.request.ILevelRetrievalAdapter;
|
||||
import com.raytheon.uf.common.dataplugin.level.xml.LevelAlias;
|
||||
import com.raytheon.uf.common.dataplugin.level.xml.LevelAliasList;
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
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.serialization.SerializationUtil;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
@ -94,9 +91,6 @@ public class LevelFactory {
|
|||
// level id String to its full level
|
||||
private Map<String, Level> levelCacheByIdAsString = new HashMap<String, Level>();
|
||||
|
||||
// lists all aliases and their associated master level name
|
||||
private Map<String, String> levelAliasMap = new HashMap<String, String>();
|
||||
|
||||
private ILevelRetrievalAdapter retrievalAdapter = null;
|
||||
|
||||
private boolean hasRequestedAllLevels = false;
|
||||
|
@ -123,7 +117,6 @@ public class LevelFactory {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
loadLevelAliases();
|
||||
try {
|
||||
loadAllMasterLevels();
|
||||
} catch (CommunicationException e) {
|
||||
|
@ -229,11 +222,6 @@ public class LevelFactory {
|
|||
MasterLevel rval = null;
|
||||
String levelName = level.getName();
|
||||
|
||||
// check aliasing
|
||||
if (levelAliasMap.containsKey(levelName)) {
|
||||
levelName = levelAliasMap.get(levelName);
|
||||
}
|
||||
|
||||
if (!hasRequestedAllMasterLevels) {
|
||||
loadAllMasterLevels();
|
||||
}
|
||||
|
@ -366,59 +354,6 @@ public class LevelFactory {
|
|||
levelCacheByIdAsString.put("" + levelToCache.getId(), levelToCache);
|
||||
}
|
||||
|
||||
private void loadLevelAliases() {
|
||||
Map<String, String> aliasMap = new HashMap<String, String>();
|
||||
|
||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
||||
Map<LocalizationLevel, LocalizationFile> tieredMap = pathMgr
|
||||
.getTieredLocalizationFile(LocalizationType.COMMON_STATIC,
|
||||
LEVEL_FILENAME);
|
||||
|
||||
LocalizationLevel[] levels = pathMgr.getAvailableLevels();
|
||||
for (LocalizationLevel level : levels) {
|
||||
LocalizationFile file = tieredMap.get(level);
|
||||
if (file != null) {
|
||||
loadLevelAliasFile(file.getFile(), aliasMap);
|
||||
}
|
||||
}
|
||||
|
||||
// set to master file
|
||||
levelAliasMap = aliasMap;
|
||||
}
|
||||
|
||||
private void loadLevelAliasFile(File file, Map<String, String> aliasMap) {
|
||||
if ((file != null) && file.exists()) {
|
||||
LevelAliasList defList = null;
|
||||
|
||||
// use jaxb to deserialize file
|
||||
try {
|
||||
Object xmlObj = SerializationUtil.jaxbUnmarshalFromXmlFile(file
|
||||
.getAbsolutePath());
|
||||
|
||||
if (xmlObj instanceof LevelAliasList) {
|
||||
defList = (LevelAliasList) xmlObj;
|
||||
} else {
|
||||
logger.error("Malformed alias file, expected ["
|
||||
+ LevelAliasList.class.getName() + "], received ["
|
||||
+ xmlObj.getClass().getName() + "]");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Caught exception parsing level alias file", e);
|
||||
}
|
||||
|
||||
if ((defList != null) && (defList.getLevels() != null)) {
|
||||
for (LevelAlias level : defList.getLevels()) {
|
||||
String[] aliases = level.getAliases();
|
||||
if (aliases != null) {
|
||||
for (String alias : aliases) {
|
||||
aliasMap.put(alias, level.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadAllLevels() throws CommunicationException {
|
||||
if (retrievalAdapter != null) {
|
||||
LevelContainer container = retrievalAdapter.getAllLevels();
|
||||
|
|
|
@ -0,0 +1,205 @@
|
|||
/**
|
||||
* 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.common.dataplugin.level.mapping;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.measure.unit.Unit;
|
||||
import javax.measure.unit.UnitFormat;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
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.MasterLevel;
|
||||
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.PathManagerFactory;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.util.mapping.Mapper;
|
||||
import com.raytheon.uf.common.util.mapping.MultipleMappingException;
|
||||
|
||||
/**
|
||||
* Provide mapping of master level names. The base set is defined by what is in
|
||||
* the masterlevel database, which is initially populated from masterLevels. As
|
||||
* well as providing name mapping it is also possible to map level objects with
|
||||
* unit conversion.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 29, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class LevelMapper extends Mapper {
|
||||
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(LevelMapper.class);
|
||||
|
||||
private transient LevelFactory factory = LevelFactory.getInstance();
|
||||
|
||||
private LevelMapper() {
|
||||
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
|
||||
LocalizationFile[] files = pathMgr.listFiles(new LocalizationContext[] {
|
||||
commonStaticSite, commonStaticBase }, "level"
|
||||
+ IPathManager.SEPARATOR + "alias", new String[] { ".xml" },
|
||||
true, true);
|
||||
for (LocalizationFile file : files) {
|
||||
try {
|
||||
addAliasList(file.getFile());
|
||||
} catch (JAXBException e) {
|
||||
statusHandler.error(
|
||||
"Error reading level aliases: " + file.getName()
|
||||
+ " has been ignored.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* same functionality as lookupBaseNames but also maps those baseNames to
|
||||
* MasterLevel objects.
|
||||
*
|
||||
* @param alias
|
||||
* @param namespace
|
||||
* @return
|
||||
* @throws CommunicationException
|
||||
*/
|
||||
public Set<MasterLevel> lookupMasterLevels(String alias, String namespace)
|
||||
throws CommunicationException {
|
||||
Set<String> baseNames = super.lookupBaseNames(alias, namespace);
|
||||
Set<MasterLevel> result = new HashSet<MasterLevel>(
|
||||
(int) (baseNames.size() / 0.75) + 1, 0.75f);
|
||||
for (String baseName : baseNames) {
|
||||
result.add(factory.getMasterLevel(baseName));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* same functionality as lookupBaseName but also maps the baseName to a
|
||||
* MasterLevel object.
|
||||
*
|
||||
* @param alias
|
||||
* @param namespace
|
||||
* @return
|
||||
*/
|
||||
public MasterLevel lookupMasterLevel(String alias, String namespace)
|
||||
throws MultipleMappingException, CommunicationException {
|
||||
String baseName = super.lookupBaseName(alias, namespace);
|
||||
return factory.getMasterLevel(baseName);
|
||||
}
|
||||
|
||||
public Level lookupLevel(String masterLevelAlias, String namespace,
|
||||
double levelone, double leveltwo, Unit<?> unit)
|
||||
throws MultipleLevelMappingException, CommunicationException {
|
||||
return lookupLevel(masterLevelAlias, namespace, levelone, leveltwo,
|
||||
UnitFormat.getUCUMInstance().format(unit));
|
||||
}
|
||||
|
||||
public Level lookupLevel(String masterLevelAlias, String namespace,
|
||||
double levelone, Unit<?> unit)
|
||||
throws MultipleLevelMappingException, CommunicationException {
|
||||
return lookupLevel(masterLevelAlias, namespace, levelone, UnitFormat
|
||||
.getUCUMInstance().format(unit));
|
||||
}
|
||||
|
||||
public Level lookupLevel(String masterLevelAlias, String namespace,
|
||||
double levelone, String unit) throws MultipleLevelMappingException,
|
||||
CommunicationException {
|
||||
return lookupLevel(masterLevelAlias, namespace, levelone,
|
||||
Level.INVALID_VALUE, unit);
|
||||
}
|
||||
|
||||
public Level lookupLevel(String masterLevelAlias, String namespace,
|
||||
double levelone, double leveltwo, String unit)
|
||||
throws MultipleLevelMappingException, CommunicationException {
|
||||
Set<Level> levels = lookupLevels(masterLevelAlias, namespace, levelone,
|
||||
leveltwo, unit);
|
||||
if (levels.size() == 1) {
|
||||
return levels.iterator().next();
|
||||
} else {
|
||||
throw new MultipleLevelMappingException(masterLevelAlias,
|
||||
namespace, lookupBaseNames(masterLevelAlias, namespace),
|
||||
levels);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Level> lookupLevels(String masterLevelAlias, String namespace,
|
||||
double levelone, double leveltwo, Unit<?> unit)
|
||||
throws CommunicationException {
|
||||
return lookupLevels(masterLevelAlias, namespace, levelone, leveltwo,
|
||||
UnitFormat.getUCUMInstance().format(unit));
|
||||
}
|
||||
|
||||
public Set<Level> lookupLevels(String masterLevelAlias, String namespace,
|
||||
double levelone, Unit<?> unit) throws CommunicationException {
|
||||
return lookupLevels(masterLevelAlias, namespace, levelone, UnitFormat
|
||||
.getUCUMInstance().format(unit));
|
||||
}
|
||||
|
||||
public Set<Level> lookupLevels(String masterLevelAlias, String namespace,
|
||||
double levelone, String unit) throws CommunicationException {
|
||||
return lookupLevels(masterLevelAlias, namespace, levelone,
|
||||
Level.INVALID_VALUE, unit);
|
||||
}
|
||||
|
||||
public Set<Level> lookupLevels(String masterLevelAlias, String namespace,
|
||||
double levelone, double leveltwo, String unit)
|
||||
throws CommunicationException {
|
||||
Set<String> baseNames = super.lookupBaseNames(masterLevelAlias,
|
||||
namespace);
|
||||
Set<Level> result = new HashSet<Level>(
|
||||
(int) (baseNames.size() / 0.75) + 1, 0.75f);
|
||||
for (String baseName : baseNames) {
|
||||
result.add(factory.getLevel(baseName, levelone, leveltwo, unit));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static LevelMapper instance;
|
||||
|
||||
public static synchronized LevelMapper getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new LevelMapper();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* 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.common.dataplugin.level.mapping;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.level.Level;
|
||||
import com.raytheon.uf.common.util.mapping.MultipleMappingException;
|
||||
|
||||
/**
|
||||
* Exception indicating that multiple mappings are defined when the LevelMapper
|
||||
* is used to alias to a single level. Catching this exception gives a decoder
|
||||
* the ability to easily grab all the levels or an arbitrary level so it can
|
||||
* store the data while logging an exception.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 30, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class MultipleLevelMappingException extends MultipleMappingException {
|
||||
|
||||
private static final long serialVersionUID = -2542711470181578302L;
|
||||
|
||||
private final Set<Level> levelMappings;
|
||||
|
||||
public MultipleLevelMappingException(String name, String namespace,
|
||||
Set<String> mappings, Set<Level> levelMappings) {
|
||||
super(true, name, namespace, mappings);
|
||||
this.levelMappings = levelMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the matching levels, same as if LevelMapper.lookupLevels was
|
||||
* called to begin with.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<Level> getLevelMappings() {
|
||||
return levelMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one level that was mapped by the alias, which level specifically is
|
||||
* not well defined.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Level getArbitraryLevelMapping() {
|
||||
return levelMappings.iterator().next();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* 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.common.dataplugin.level.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
|
||||
/**
|
||||
* Group definition
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 03, 2009 rjpeter Initial creation.
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
@DynamicSerialize
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlType(namespace = "group")
|
||||
public class Group implements ISerializableObject {
|
||||
@DynamicSerializeElement
|
||||
@XmlAttribute
|
||||
private String id;
|
||||
|
||||
@DynamicSerializeElement
|
||||
@XmlAttribute
|
||||
private String description;
|
||||
|
||||
@DynamicSerializeElement
|
||||
@XmlElement(name = "level")
|
||||
private Level[] levels;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Level[] getLevels() {
|
||||
return levels;
|
||||
}
|
||||
|
||||
public void setLevels(Level[] levels) {
|
||||
this.levels = levels;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/**
|
||||
* 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.common.dataplugin.level.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
|
||||
/**
|
||||
* List of group definitions.
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 03, 2009 rjpeter Initial creation.
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
@DynamicSerialize
|
||||
@XmlRootElement(name = "groupList", namespace = "group")
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlType(namespace = "group")
|
||||
public class GroupList implements ISerializableObject {
|
||||
@DynamicSerializeElement
|
||||
@XmlElement(name = "group")
|
||||
private Group[] groups;
|
||||
|
||||
public Group[] getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void setGroups(Group[] groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* 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.common.dataplugin.level.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
|
||||
/**
|
||||
* Defines levels within a group
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 03, 2009 rjpeter Initial creation.
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
@DynamicSerialize
|
||||
@XmlRootElement(namespace = "group")
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlType(namespace = "group")
|
||||
public class Level implements ISerializableObject {
|
||||
@DynamicSerializeElement
|
||||
@XmlAttribute
|
||||
private String id;
|
||||
|
||||
@DynamicSerializeElement
|
||||
@XmlElement(name = "levelValue")
|
||||
private LevelValue[] levelValues;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LevelValue[] getLevelValues() {
|
||||
return levelValues;
|
||||
}
|
||||
|
||||
public void setLevelValues(LevelValue[] levelValues) {
|
||||
this.levelValues = levelValues;
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* 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.common.dataplugin.level.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
|
||||
/**
|
||||
* Level
|
||||
*
|
||||
* <pre>
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 03, 2009 rjpeter Initial creation.
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @version 1.0
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class LevelAlias implements ISerializableObject {
|
||||
@XmlAttribute(required = true)
|
||||
private String name;
|
||||
|
||||
@XmlElement(name = "alias")
|
||||
private String[] aliases;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public void setAliases(String[] aliases) {
|
||||
this.aliases = aliases;
|
||||
}
|
||||
}
|
|
@ -9,12 +9,18 @@ Eclipse-BuddyPolicy: registered, ext, global
|
|||
Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization
|
||||
Import-Package: com.raytheon.uf.common.dataplugin.annotations,
|
||||
com.raytheon.uf.common.dataplugin.persist,
|
||||
com.raytheon.uf.common.dataquery.requests,
|
||||
com.raytheon.uf.common.dataquery.responses,
|
||||
com.raytheon.uf.common.localization,
|
||||
com.raytheon.uf.common.serialization,
|
||||
com.raytheon.uf.common.serialization.annotations,
|
||||
com.raytheon.uf.common.serialization.comm,
|
||||
com.raytheon.uf.common.status,
|
||||
javax.measure.converter,
|
||||
javax.measure.unit,
|
||||
javax.persistence
|
||||
Export-Package: com.raytheon.uf.common.parameter,
|
||||
com.raytheon.uf.common.parameter.mapping
|
||||
com.raytheon.uf.common.parameter.lookup,
|
||||
com.raytheon.uf.common.parameter.mapping,
|
||||
com.raytheon.uf.common.parameter.request
|
||||
Require-Bundle: com.raytheon.uf.common.util;bundle-version="1.12.1174"
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/**
|
||||
* 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.common.parameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
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.PathManagerFactory;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
|
||||
/**
|
||||
* Provides utility method for accessing the set of parameters that are defined
|
||||
* in localization.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 5, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class ParameterDefinitions {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ParameterDefinitions.class);
|
||||
|
||||
private static List<Parameter> parameters;
|
||||
|
||||
public static synchronized List<Parameter> getParameters() {
|
||||
if (parameters == null) {
|
||||
parameters = new ArrayList<Parameter>();
|
||||
Unmarshaller unmarshaller = null;
|
||||
try {
|
||||
JAXBContext context = JAXBContext
|
||||
.newInstance(ParameterList.class);
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
} catch (JAXBException e) {
|
||||
statusHandler
|
||||
.error("Error creating Context for parameter defintions, no parameter defintions will be used.",
|
||||
e);
|
||||
}
|
||||
if (unmarshaller != null) {
|
||||
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);
|
||||
|
||||
LocalizationFile[] files = pathMgr.listFiles(
|
||||
new LocalizationContext[] { commonStaticSite,
|
||||
commonStaticBase }, "parameter"
|
||||
+ IPathManager.SEPARATOR + "definition",
|
||||
new String[] { ".xml" }, true, true);
|
||||
|
||||
for (LocalizationFile file : files) {
|
||||
if (file == null || !file.exists()
|
||||
|| file.getFile().length() < 0) {
|
||||
continue;
|
||||
}
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = unmarshaller.unmarshal(file.getFile());
|
||||
} catch (JAXBException e) {
|
||||
statusHandler
|
||||
.error("Error reading parameter defintions: "
|
||||
+ file.getName() + " has been ignored.",
|
||||
e);
|
||||
continue;
|
||||
}
|
||||
if (obj instanceof ParameterList) {
|
||||
ParameterList list = (ParameterList) obj;
|
||||
if (list.getParameters() != null) {
|
||||
parameters.addAll(list.getParameters());
|
||||
}
|
||||
} else {
|
||||
statusHandler
|
||||
.error("Error reading parameter defintions: "
|
||||
+ file.getName() + " was a "
|
||||
+ obj.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,250 @@
|
|||
/**
|
||||
* 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.common.parameter.lookup;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
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.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
import com.raytheon.uf.common.parameter.ParameterList;
|
||||
import com.raytheon.uf.common.parameter.request.GetParameterRequest;
|
||||
import com.raytheon.uf.common.serialization.comm.RequestRouter;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
||||
/**
|
||||
* Caching and convenience for finding parameters in the Database.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 12, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class ParameterLookup {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ParameterLookup.class);
|
||||
|
||||
private static ParameterLookup instance;
|
||||
|
||||
public static ParameterLookup getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ParameterLookup();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Maps abbreviation to parameter, this is a mirror of what is in the
|
||||
// database.
|
||||
private Map<String, Parameter> abbrevToParam;
|
||||
|
||||
private ParameterLookup() {
|
||||
initializeMaps();
|
||||
DbQueryRequest query = new DbQueryRequest();
|
||||
query.setEntityClass(Parameter.class.getName());
|
||||
try {
|
||||
DbQueryResponse resp = (DbQueryResponse) RequestRouter.route(query);
|
||||
for (Map<String, Object> map : resp.getResults()) {
|
||||
Parameter param = (Parameter) map.get(null);
|
||||
abbrevToParam.put(param.getAbbreviation(), param);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// do not rethrow, the lookup is not broken at this point so if the
|
||||
// problems persist then more exceptions will come from the actual
|
||||
// lookup methods themselves.
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Error occurred retrieving parameters from server.", e);
|
||||
}
|
||||
Unmarshaller unmarshaller = null;
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(ParameterList.class);
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
} catch (JAXBException e) {
|
||||
statusHandler
|
||||
.error("Error creating Context for parameter defintions, no parameter defintions will be used.",
|
||||
e);
|
||||
}
|
||||
if (unmarshaller != null) {
|
||||
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);
|
||||
|
||||
LocalizationFile[] files = pathMgr.listFiles(
|
||||
new LocalizationContext[] { commonStaticSite,
|
||||
commonStaticBase }, "parameter"
|
||||
+ IPathManager.SEPARATOR + "definition",
|
||||
new String[] { ".xml" }, true, true);
|
||||
|
||||
for (LocalizationFile file : files) {
|
||||
if (file == null || !file.exists()
|
||||
|| file.getFile().length() < 0) {
|
||||
continue;
|
||||
}
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = unmarshaller.unmarshal(file.getFile());
|
||||
} catch (JAXBException e) {
|
||||
statusHandler.error("Error reading parameter defintions: "
|
||||
+ file.getName() + " has been ignored.", e);
|
||||
continue;
|
||||
}
|
||||
if (obj instanceof ParameterList) {
|
||||
ParameterList list = (ParameterList) obj;
|
||||
if (list.getParameters() != null) {
|
||||
for (Parameter p : list.getParameters()) {
|
||||
getParameter(p, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
statusHandler.error("Error reading parameter defintions: "
|
||||
+ file.getName() + " was a "
|
||||
+ obj.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeMaps() {
|
||||
abbrevToParam = Collections
|
||||
.synchronizedMap(new HashMap<String, Parameter>());
|
||||
}
|
||||
|
||||
public Parameter getParameter(String abbreviation)
|
||||
throws ParameterLookupException {
|
||||
Parameter result = abbrevToParam.get(abbreviation);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
HashMap<String, RequestConstraint> constraints = new HashMap<String, RequestConstraint>();
|
||||
constraints.put("abbreviation", new RequestConstraint(abbreviation));
|
||||
DbQueryRequest query = new DbQueryRequest();
|
||||
query.setConstraints(constraints);
|
||||
query.setEntityClass(Parameter.class.getName());
|
||||
try {
|
||||
DbQueryResponse resp = (DbQueryResponse) RequestRouter.route(query);
|
||||
if (!resp.getResults().isEmpty()) {
|
||||
result = (Parameter) resp.getResults().get(0).get(null);
|
||||
if (result != null) {
|
||||
abbrevToParam.put(result.getAbbreviation(), result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ParameterLookupException(
|
||||
"Error occurred retrieving Parameter information from server.",
|
||||
e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* bulk request multiple parameters by abbreviation, for any parameters not
|
||||
* in the cache this can be significantly faster than requesting multiple
|
||||
* parameters individually.
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Parameter> getParameters(List<String> abbreviations)
|
||||
throws ParameterLookupException {
|
||||
RequestConstraint abbreviationConstraint = new RequestConstraint(null,
|
||||
ConstraintType.IN);
|
||||
Map<String, Parameter> result = new HashMap<String, Parameter>(
|
||||
abbreviations.size());
|
||||
for (String abbreviation : abbreviations) {
|
||||
Parameter param = abbrevToParam.get(abbreviation);
|
||||
if (param == null) {
|
||||
abbreviationConstraint.addToConstraintValueList(abbreviation);
|
||||
}
|
||||
result.put(abbreviation, param);
|
||||
}
|
||||
if (abbreviationConstraint.getConstraintValue() == null) {
|
||||
// everything was a cache hit.
|
||||
return result;
|
||||
}
|
||||
HashMap<String, RequestConstraint> constraints = new HashMap<String, RequestConstraint>();
|
||||
constraints.put("abbreviation", abbreviationConstraint);
|
||||
DbQueryRequest query = new DbQueryRequest();
|
||||
query.setConstraints(constraints);
|
||||
query.setEntityClass(Parameter.class.getName());
|
||||
try {
|
||||
DbQueryResponse resp = (DbQueryResponse) RequestRouter.route(query);
|
||||
for (Map<String, Object> thing : resp.getResults()) {
|
||||
Parameter respParam = (Parameter) thing.get(null);
|
||||
abbrevToParam.put(respParam.getAbbreviation(), respParam);
|
||||
result.put(respParam.getAbbreviation(), respParam);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ParameterLookupException(
|
||||
"Error occurred retrieving Parameter information from server.",
|
||||
e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Parameter getParameter(Parameter parameter, boolean create)
|
||||
throws ParameterLookupException {
|
||||
Parameter p = abbrevToParam.get(parameter.getAbbreviation());
|
||||
if (p != null) {
|
||||
return p;
|
||||
}
|
||||
try {
|
||||
Parameter result = (Parameter) RequestRouter
|
||||
.route(new GetParameterRequest(parameter, create));
|
||||
if (result != null) {
|
||||
abbrevToParam.put(result.getAbbreviation(), result);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new ParameterLookupException(
|
||||
"Error occurred retrieving Parameter information from server.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,41 +17,34 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.dataplugin.level.xml;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
package com.raytheon.uf.common.parameter.lookup;
|
||||
|
||||
/**
|
||||
* LevelAliasList
|
||||
* Exception is thrown when ParameterLookup cannot execute IServerRequest using
|
||||
* the RequestRouter. This is a RuntimeException because code that uses the
|
||||
* ParameterLookup cannot reasonably be expected to recover from connection
|
||||
* failure.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 03, 2009 rjpeter Initial creation.
|
||||
* Oct 1, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class LevelAliasList implements ISerializableObject {
|
||||
@XmlElement(name = "level")
|
||||
private LevelAlias[] levels;
|
||||
|
||||
public LevelAlias[] getLevels() {
|
||||
return levels;
|
||||
}
|
||||
public class ParameterLookupException extends RuntimeException {
|
||||
|
||||
public void setLevels(LevelAlias[] levels) {
|
||||
this.levels = levels;
|
||||
private static final long serialVersionUID = -3401893094682026053L;
|
||||
|
||||
public ParameterLookupException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,211 +0,0 @@
|
|||
/**
|
||||
* 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.common.parameter.mapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
|
||||
/**
|
||||
*
|
||||
* A ParameterAliasList represents a set of alternative abbreviations for a
|
||||
* parameter. This list defines the alternatives within a namespace so that it
|
||||
* is possible to match aliases for only a specific group. Parent namespaces can
|
||||
* be used to bring all aliases from another list into this namespace.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 22, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlRootElement
|
||||
public class ParameterAliasList {
|
||||
|
||||
/**
|
||||
* The parent namespace is used if a parameter lookup within this namespace
|
||||
* fails.
|
||||
*/
|
||||
@XmlAttribute
|
||||
private List<String> parentNamespace;
|
||||
|
||||
/**
|
||||
* A name for this group of parameter aliases
|
||||
*/
|
||||
@XmlAttribute
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
* The actual alias definitions for the list
|
||||
*/
|
||||
@XmlElement(name = "alias")
|
||||
private List<ParameterAlias> aliasList = new ArrayList<ParameterAlias>();
|
||||
|
||||
/**
|
||||
* Map an alias name to a parameter
|
||||
*/
|
||||
private Map<String, Parameter> map = new HashMap<String, Parameter>();
|
||||
|
||||
/**
|
||||
* maps a lower case alias name to a parameter for case insensitive searches
|
||||
*/
|
||||
private Map<String, Parameter> lowerCaseMap = new HashMap<String, Parameter>();
|
||||
|
||||
/**
|
||||
* maps parameters to thier alias name
|
||||
*/
|
||||
private Map<Parameter, String> reverseMap = new HashMap<Parameter, String>();
|
||||
|
||||
/**
|
||||
* a list of the parent list corresponding to the parent namespaces.
|
||||
*/
|
||||
private List<ParameterAliasList> parentList = new ArrayList<ParameterAliasList>();
|
||||
|
||||
public ParameterAliasList() {
|
||||
}
|
||||
|
||||
public ParameterAliasList(String name) {
|
||||
this.namespace = name;
|
||||
}
|
||||
|
||||
public List<String> getParentNamespace() {
|
||||
return parentNamespace;
|
||||
}
|
||||
|
||||
public void setParentNamespace(List<String> parentNamespace) {
|
||||
this.parentNamespace = parentNamespace;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public List<ParameterAlias> getAliasList() {
|
||||
return aliasList;
|
||||
}
|
||||
|
||||
public void setAliasList(List<ParameterAlias> aliasList) {
|
||||
this.aliasList = aliasList;
|
||||
}
|
||||
|
||||
public void addAlias(ParameterAlias alias) {
|
||||
this.aliasList.add(alias);
|
||||
}
|
||||
|
||||
public Parameter lookupParameter(String alias) {
|
||||
Parameter p = map.get(alias);
|
||||
if (p == null) {
|
||||
// If I don't have it then check my parents.
|
||||
for (ParameterAliasList parent : parentList) {
|
||||
p = parent.lookupParameter(alias);
|
||||
if (p != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public Parameter lookupParameterCaseInsensitive(String alias) {
|
||||
Parameter p = lowerCaseMap.get(alias.toLowerCase());
|
||||
if (p == null) {
|
||||
// If I don't have it then check my parents.
|
||||
for (ParameterAliasList parent : parentList) {
|
||||
p = parent.lookupParameterCaseInsensitive(alias);
|
||||
if (p != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public String lookupAlias(Parameter parameter) {
|
||||
String alias = reverseMap.get(parameter);
|
||||
if (alias == null) {
|
||||
for (ParameterAliasList parent : parentList) {
|
||||
alias = parent.lookupAlias(parameter);
|
||||
if (alias != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pl
|
||||
*/
|
||||
public void addParent(ParameterAliasList parent) {
|
||||
parentList.add(parent);
|
||||
}
|
||||
|
||||
public void resolve(Map<String, Parameter> globalMap) {
|
||||
for (ParameterAlias alias : aliasList) {
|
||||
Parameter parameter = globalMap.get(alias.getBase());
|
||||
if (parameter == null) {
|
||||
continue;
|
||||
}
|
||||
map.put(alias.getAlias(), parameter);
|
||||
lowerCaseMap.put(alias.getAlias().toLowerCase(), parameter);
|
||||
reverseMap.put(parameter, alias.getAlias());
|
||||
if (!globalMap.containsKey(alias.getAlias())) {
|
||||
globalMap.put(alias.getAlias(), parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void merge(ParameterAliasList list) {
|
||||
if (list.getParentNamespace() != null) {
|
||||
for (String parent : list.getParentNamespace()) {
|
||||
if (!parentNamespace.contains(parent)) {
|
||||
parentNamespace.add(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (list.getAliasList() != null) {
|
||||
for (ParameterAlias alias : list.getAliasList()) {
|
||||
aliasList.add(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,75 +19,29 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.parameter.mapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
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.PathManagerFactory;
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
import com.raytheon.uf.common.parameter.ParameterDefinitions;
|
||||
import com.raytheon.uf.common.parameter.lookup.ParameterLookup;
|
||||
import com.raytheon.uf.common.parameter.lookup.ParameterLookupException;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.util.mapping.Mapper;
|
||||
import com.raytheon.uf.common.util.mapping.MultipleMappingException;
|
||||
|
||||
/**
|
||||
* This class can be used to map parameters between different parameter naming
|
||||
* conventions. There is a system wide base naming convention defined in the
|
||||
* parameter definition file. All other naming conventions can be defined as a
|
||||
* set of abbreviations that alias these base parameters. The aliases for a
|
||||
* single naming convention are grouped within a namespace.
|
||||
*
|
||||
* For any namespace the base parameter that matches an abbreviation can be
|
||||
* found by looking up the parameter in the namespace. If the namespace is
|
||||
* unknown it is also possible to do a full search of all namespaces to find any
|
||||
* parameter that matches an abbreviation.
|
||||
*
|
||||
* Given a base parameter, it is also possible to lookup an alias within a given
|
||||
* namespace.
|
||||
*
|
||||
* There are two namespaces that recieve special treatment. The "base" namespace
|
||||
* will contain all parameter abbreviations from the parameter definition files.
|
||||
* The "deprecated" namespace should contain any parameters that were at one
|
||||
* time in base but have been replaced. If any class is doing lookups based off
|
||||
* standard parameters, they may want to check "deprecated" to determine if the
|
||||
* base set has changed.
|
||||
*
|
||||
* Here are some examples of how this class might be used:
|
||||
*
|
||||
* 1) To look up a base parameter that is defined by the TMP abbreviation in the
|
||||
* grib namespace:<br>
|
||||
* ParameterMapper.getInstance().lookupParameter("grib","TMP");
|
||||
*
|
||||
* 2) To look up a base parameter that is defined by the "TMP" abbreviation in
|
||||
* any namespace:<br>
|
||||
* ParameterMapper.getInstance().lookupParameter("TMP");
|
||||
*
|
||||
* 3) To find the parameter abbreviation in the "cf" namespace that matches the
|
||||
* "TMP" abbreviation from the grib namespace<br>
|
||||
* Parameter p = ParameterMapper.getInstance().lookupParameter("grib","TMP");<br>
|
||||
* String cfAbbrev = ParameterMapper.getInstance().lookupAlias(p,"cf");<br>
|
||||
*
|
||||
* 4) To check if the "T" is a base parameter or a deprecated parameter:<br>
|
||||
*
|
||||
* <pre>
|
||||
* Parameter p = ParameterMapper.getInstance().lookupParameter("base","T");
|
||||
* if (p != null){
|
||||
* System.out.println("T is a base parameter");
|
||||
* }else{
|
||||
* p = ParameterMapper.getInstance().lookupParameter("deprecated","T");
|
||||
* if(p != null){
|
||||
* System.out.println("T is deprecated, it has been replaced with " + p.getAbbreviation());
|
||||
* }
|
||||
* }<br>
|
||||
* </pre>
|
||||
* Provide mapping of parameter abbreviations. The base set is defined by what
|
||||
* is in the parameter database, which is initially populated from the parameter
|
||||
* definitions files. As well as providing name mapping it is also possible to
|
||||
* map from an alias to a Parameter object.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -95,205 +49,90 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 22, 2012 bsteffen Initial creation
|
||||
* Nov 2, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class ParameterMapper {
|
||||
public class ParameterMapper extends Mapper {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ParameterMapper.class);
|
||||
|
||||
private Map<String, Parameter> map = new HashMap<String, Parameter>();
|
||||
|
||||
private Map<String, ParameterAliasList> namespaceMap = new HashMap<String, ParameterAliasList>();
|
||||
|
||||
private ParameterMapper() {
|
||||
Unmarshaller unmarshaller = null;
|
||||
try {
|
||||
JAXBContext context = JAXBContext
|
||||
.newInstance(ParameterAliasList.class);
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
} catch (JAXBException e) {
|
||||
statusHandler
|
||||
.error("Error creating Context for parameter mapper, no parameter aliases will be used.",
|
||||
e);
|
||||
}
|
||||
if (unmarshaller != null) {
|
||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext commonStaticBase = pathMgr.getContext(
|
||||
LocalizationContext.LocalizationType.COMMON_STATIC,
|
||||
LocalizationContext.LocalizationLevel.BASE);
|
||||
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);
|
||||
LocalizationContext commonStaticSite = pathMgr.getContext(
|
||||
LocalizationContext.LocalizationType.COMMON_STATIC,
|
||||
LocalizationContext.LocalizationLevel.SITE);
|
||||
|
||||
// First fill the map with well defined parameters.
|
||||
ParameterAliasList baseList = new ParameterAliasList("base");
|
||||
for (Parameter p : ParameterDefinitions.getParameters()) {
|
||||
baseList.addAlias(new ParameterAlias(p.getAbbreviation(), p
|
||||
.getAbbreviation()));
|
||||
map.put(p.getAbbreviation(), p);
|
||||
}
|
||||
// read in the namespace map
|
||||
LocalizationFile[] files = pathMgr.listFiles(
|
||||
new LocalizationContext[] { commonStaticSite,
|
||||
commonStaticBase }, "parameter"
|
||||
+ IPathManager.SEPARATOR + "alias",
|
||||
new String[] { ".xml" }, true, true);
|
||||
List<ParameterAliasList> aliasLists = new ArrayList<ParameterAliasList>(
|
||||
files.length);
|
||||
for (LocalizationFile file : files) {
|
||||
if (file == null || !file.exists()
|
||||
|| file.getFile().length() < 0) {
|
||||
continue;
|
||||
}
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = unmarshaller.unmarshal(file.getFile());
|
||||
} catch (JAXBException e) {
|
||||
statusHandler.error("Error reading parameter aliases: "
|
||||
+ file.getName() + " has been ignored.", e);
|
||||
}
|
||||
if (obj instanceof ParameterAliasList) {
|
||||
ParameterAliasList list = (ParameterAliasList) obj;
|
||||
aliasLists.add(list);
|
||||
if (list.getNamespace() != null) {
|
||||
ParameterAliasList realList = namespaceMap.get(list
|
||||
.getNamespace());
|
||||
if (realList == null) {
|
||||
namespaceMap.put(list.getNamespace(), list);
|
||||
} else {
|
||||
realList.merge(list);
|
||||
aliasLists.remove(list);
|
||||
}
|
||||
}
|
||||
} else if (obj != null) {
|
||||
statusHandler.error("Error reading parameter aliases: "
|
||||
+ file.getName() + " was a "
|
||||
+ obj.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
namespaceMap.put(baseList.getNamespace(), baseList);
|
||||
aliasLists.add(baseList);
|
||||
// Fill in lower case entries for a case insensitve namespace map
|
||||
Map<String, ParameterAliasList> lowerCaseNSMap = new HashMap<String, ParameterAliasList>();
|
||||
for (Entry<String, ParameterAliasList> entry : namespaceMap
|
||||
.entrySet()) {
|
||||
String lowerCase = entry.getKey().toLowerCase();
|
||||
if (!namespaceMap.containsKey(lowerCase)
|
||||
&& !lowerCaseNSMap.containsKey(lowerCase)) {
|
||||
lowerCaseNSMap.put(lowerCase, entry.getValue());
|
||||
}
|
||||
}
|
||||
namespaceMap.putAll(lowerCaseNSMap);
|
||||
// If there is a deprecated namespace it should take priority over
|
||||
// all other.
|
||||
ParameterAliasList depList = namespaceMap.get("deprecated");
|
||||
if (depList != null) {
|
||||
resolve(depList);
|
||||
aliasLists.remove(depList);
|
||||
}
|
||||
// Add all other namespaces to the map.
|
||||
for (ParameterAliasList list : aliasLists) {
|
||||
resolve(list);
|
||||
}
|
||||
// Finally fill in lower case entries for a case insensitve search
|
||||
Map<String, Parameter> lowerCaseMap = new HashMap<String, Parameter>();
|
||||
for (Entry<String, Parameter> entry : map.entrySet()) {
|
||||
String lowerCase = entry.getKey().toLowerCase();
|
||||
if (!map.containsKey(lowerCase)
|
||||
&& !lowerCaseMap.containsKey(lowerCase)) {
|
||||
lowerCaseMap.put(lowerCase, entry.getValue());
|
||||
}
|
||||
}
|
||||
map.putAll(lowerCaseMap);
|
||||
}
|
||||
}
|
||||
|
||||
private void resolve(ParameterAliasList list) {
|
||||
if (list.getParentNamespace() != null) {
|
||||
for (String parent : list.getParentNamespace()) {
|
||||
ParameterAliasList pl = namespaceMap.get(parent);
|
||||
if (pl != null) {
|
||||
list.addParent(pl);
|
||||
}
|
||||
// read in the namespace map
|
||||
LocalizationFile[] files = pathMgr.listFiles(new LocalizationContext[] {
|
||||
commonStaticSite, commonStaticBase }, "parameter"
|
||||
+ IPathManager.SEPARATOR + "alias", new String[] { ".xml" },
|
||||
true, true);
|
||||
for (LocalizationFile file : files) {
|
||||
try {
|
||||
addAliasList(file.getFile());
|
||||
} catch (JAXBException e) {
|
||||
statusHandler.error(
|
||||
"Error reading parameter aliases: " + file.getName()
|
||||
+ " has been ignored.", e);
|
||||
}
|
||||
}
|
||||
list.resolve(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the parameter with an alias defined in the provided namespace.
|
||||
*
|
||||
* @param namespace
|
||||
* - the defined alias namespace to look for the parameter
|
||||
* @param alias
|
||||
* - the name of an alias defined in the namespace
|
||||
* @return the defined parameter or null if the namespace or alias is
|
||||
* undefined
|
||||
*/
|
||||
public Parameter lookupParameter(String namespace, String alias) {
|
||||
if (alias == null) {
|
||||
return null;
|
||||
}
|
||||
ParameterAliasList list = namespaceMap.get(namespace);
|
||||
if (list == null) {
|
||||
list = namespaceMap.get(namespace.toLowerCase());
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Parameter p = list.lookupParameter(alias);
|
||||
if (p == null) {
|
||||
p = list.lookupParameterCaseInsensitive(alias);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a parameter from an abbreviation. First the base namespace is
|
||||
* searched, then the deprecated namespace, and then all other namespaces in
|
||||
* an unspecified order. If the abbreviation is not defined in any namespace
|
||||
* a case insensitive search is performed.
|
||||
* same functionality as lookupBaseNames but maps each baseName to a
|
||||
* Parameter object.
|
||||
*
|
||||
* @param alias
|
||||
* - an abbreviation for a parameter
|
||||
* @return The parameter that matches or is aliased to the provided alias or
|
||||
* null if it is not found.
|
||||
* @param namespace
|
||||
* @return
|
||||
* @throws ParameterLookupException
|
||||
*/
|
||||
public Parameter lookupParameter(String alias) {
|
||||
Parameter p = map.get(alias);
|
||||
if (p == null) {
|
||||
p = map.get(alias.toLowerCase());
|
||||
public Set<Parameter> lookupParameters(String alias, String namespace)
|
||||
throws ParameterLookupException {
|
||||
Set<String> baseNames = super.lookupBaseNames(alias, namespace);
|
||||
Set<Parameter> result = new HashSet<Parameter>(
|
||||
(int) (baseNames.size() / 0.75) + 1, 0.75f);
|
||||
for (String baseName : baseNames) {
|
||||
result.add(getBaseParameter(baseName));
|
||||
}
|
||||
return p;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup an alias abbreviation for a parameter within a given namespace. If
|
||||
* multiple aliases for that parameter are in the given namespace, only one
|
||||
* will be returned.
|
||||
* same functionality as lookupBaseName but maps the baseName to a Parameter
|
||||
* Object.
|
||||
*
|
||||
* @param parameter
|
||||
* - The base parameter to find an alias for
|
||||
* @param alias
|
||||
* @param namespace
|
||||
* - The namespace in which to look for an alias.
|
||||
* @return an alias abbreviation or null if none is found.
|
||||
* @return
|
||||
* @throws ParameterLookupException
|
||||
* @throws MultipleMappingException
|
||||
*/
|
||||
public String lookupAlias(Parameter parameter, String namespace) {
|
||||
ParameterAliasList ns = namespaceMap.get(namespace);
|
||||
if (ns == null) {
|
||||
ns = namespaceMap.get(namespace.toLowerCase());
|
||||
if (ns == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return ns.lookupAlias(parameter);
|
||||
public Parameter lookupParameter(String alias, String namespace)
|
||||
throws ParameterLookupException, MultipleMappingException {
|
||||
String baseName = super.lookupBaseName(alias, namespace);
|
||||
return getBaseParameter(baseName);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a parameter object for a baseName, no mapping is done, this is
|
||||
* provided here for convenience.
|
||||
*
|
||||
* @param baseName
|
||||
* @return
|
||||
* @throws ParameterLookupException
|
||||
*/
|
||||
public Parameter getBaseParameter(String baseName)
|
||||
throws ParameterLookupException {
|
||||
return ParameterLookup.getInstance().getParameter(baseName);
|
||||
}
|
||||
|
||||
private static ParameterMapper instance;
|
||||
|
|
|
@ -17,59 +17,67 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.dataplugin.level.xml;
|
||||
package com.raytheon.uf.common.parameter.request;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
import com.raytheon.uf.common.serialization.comm.IServerRequest;
|
||||
|
||||
/**
|
||||
* Defines specific level values within a level.
|
||||
* Request to lookup a parameter that has the same abbreviation as the provided
|
||||
* parameter, also provides option for creating the parameter in the database if
|
||||
* it does not already exist.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 03, 2009 rjpeter Initial creation.
|
||||
* Mar 26, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rjpeter
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@DynamicSerialize
|
||||
@XmlRootElement(namespace = "group")
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlType(namespace = "group")
|
||||
public class LevelValue implements ISerializableObject {
|
||||
@DynamicSerializeElement
|
||||
@XmlAttribute
|
||||
private Double valueOne;
|
||||
public class GetParameterRequest implements IServerRequest {
|
||||
|
||||
@DynamicSerializeElement
|
||||
@XmlAttribute
|
||||
private Double valueTwo;
|
||||
private Parameter parameter;
|
||||
|
||||
public Double getValueOne() {
|
||||
return valueOne;
|
||||
@DynamicSerializeElement
|
||||
private boolean create = false;
|
||||
|
||||
public GetParameterRequest() {
|
||||
}
|
||||
|
||||
public void setValueOne(Double valueOne) {
|
||||
this.valueOne = valueOne;
|
||||
public GetParameterRequest(Parameter parameter) {
|
||||
this.parameter = parameter;
|
||||
this.create = false;
|
||||
}
|
||||
|
||||
public Double getValueTwo() {
|
||||
return valueTwo;
|
||||
public GetParameterRequest(Parameter parameter, boolean create) {
|
||||
this.parameter = parameter;
|
||||
this.create = create;
|
||||
}
|
||||
|
||||
public void setValueTwo(Double valueTwo) {
|
||||
this.valueTwo = valueTwo;
|
||||
public Parameter getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
public void setParameter(Parameter parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public boolean getCreate() {
|
||||
return create;
|
||||
}
|
||||
|
||||
public void setCreate(boolean create) {
|
||||
this.create = create;
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
|
||||
further_licensing_information.
|
||||
-->
|
||||
<parameterAliasList namespace="cf">
|
||||
<aliasList namespace="cf">
|
||||
<!-- http://cf-pcmdi.llnl.gov/ -->
|
||||
<alias base="AV">atmosphere_absolute_vorticity</alias>
|
||||
<alias base="CDCON">convective_cloud_area_fraction</alias>
|
||||
|
@ -72,4 +72,4 @@
|
|||
<alias base="WD">wind_from_direction</alias>
|
||||
<alias base="WS">wind_speed</alias>
|
||||
<alias base="WGS">wind_speed_of_gust</alias>
|
||||
</parameterAliasList>
|
||||
</aliasList>
|
|
@ -18,7 +18,7 @@
|
|||
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
|
||||
further_licensing_information.
|
||||
-->
|
||||
<parameterAliasList namespace="GEMPAK">
|
||||
<aliasList namespace="GEMPAK">
|
||||
<alias base="WGH">HGHT5</alias>
|
||||
<alias base="AV">AVOR</alias>
|
||||
<alias base="CRAIN">WXTR</alias>
|
||||
|
@ -113,4 +113,4 @@
|
|||
<alias base="WD">DRCT</alias>
|
||||
<alias base="WS">SPED</alias>
|
||||
<alias base="WGS">GUST</alias>
|
||||
</parameterAliasList>
|
||||
</aliasList>
|
|
@ -18,7 +18,7 @@
|
|||
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
|
||||
further_licensing_information.
|
||||
-->
|
||||
<parameterAliasList namespace="GrADS">
|
||||
<aliasList namespace="GrADS">
|
||||
<!-- Parameters defined for surface level -->
|
||||
<alias base="CAPE">capesfc</alias>
|
||||
<alias base="CIn">cinsfc</alias>
|
||||
|
@ -104,4 +104,4 @@
|
|||
<!-- Parameters defined at 500mb -->
|
||||
<alias base="AV">absv500mb</alias>
|
||||
<alias base="WGH">no5wavh500mb</alias>
|
||||
</parameterAliasList>
|
||||
</aliasList>
|
|
@ -18,7 +18,7 @@
|
|||
See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for
|
||||
further_licensing_information.
|
||||
-->
|
||||
<parameterAliasList namespace="sedris">
|
||||
<aliasList namespace="sedris">
|
||||
<!-- http://www.sedris.org/ -->
|
||||
<alias base="AV">WIND_ABSOLUTE_VORTICITY</alias>
|
||||
<alias base="CFRZR">FREEZING_RAIN_PRESENT</alias>
|
||||
|
@ -82,4 +82,4 @@
|
|||
<alias base="WD">WIND_DIRECTION</alias>
|
||||
<alias base="WS">WIND_SPEED</alias>
|
||||
<alias base="WGS">WIND_GUST_SPEED</alias>
|
||||
</parameterAliasList>
|
||||
</aliasList>
|
|
@ -12,5 +12,6 @@ Export-Package: com.raytheon.uf.common.util,
|
|||
com.raytheon.uf.common.util.cache,
|
||||
com.raytheon.uf.common.util.header,
|
||||
com.raytheon.uf.common.util.registry,
|
||||
com.raytheon.uf.common.util.mapping,
|
||||
com.raytheon.uf.common.util.session
|
||||
Import-Package: org.apache.commons.lang
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.parameter.mapping;
|
||||
package com.raytheon.uf.common.util.mapping;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
@ -25,9 +25,8 @@ import javax.xml.bind.annotation.XmlAttribute;
|
|||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
/**
|
||||
* Parameter Alias definition, base should be a well defined parameter
|
||||
* abbreviation in a parameter definition file and alias is an alternative
|
||||
* parameter abbreviation that can be used to describe the same parameter.
|
||||
* Alias definition, base should be a well defined name and alias is an
|
||||
* alternative name that can be used to describe the same thing.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -43,7 +42,7 @@ import javax.xml.bind.annotation.XmlValue;
|
|||
* @version 1.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
public class ParameterAlias {
|
||||
public class Alias {
|
||||
|
||||
@XmlAttribute
|
||||
private String base;
|
||||
|
@ -51,10 +50,10 @@ public class ParameterAlias {
|
|||
@XmlValue
|
||||
private String alias;
|
||||
|
||||
public ParameterAlias() {
|
||||
public Alias() {
|
||||
}
|
||||
|
||||
public ParameterAlias(String base, String alias) {
|
||||
public Alias(String base, String alias) {
|
||||
this.base = base;
|
||||
this.alias = alias;
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* 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.common.util.mapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* A AliasList represents a set of alternative names for a base name. This list
|
||||
* defines the alternatives within a namespace so that it is possible to match
|
||||
* aliases for only a specific group. Parent namespaces can be used to bring all
|
||||
* aliases from another list into this namespace.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 22, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlRootElement
|
||||
public class AliasList {
|
||||
|
||||
/**
|
||||
* A name for this group of parameter aliases
|
||||
*/
|
||||
@XmlAttribute
|
||||
private String namespace;
|
||||
|
||||
/**
|
||||
* A name for this group of parameter aliases
|
||||
*/
|
||||
@XmlAttribute
|
||||
private boolean caseSensitive = true;
|
||||
|
||||
/**
|
||||
* The actual alias definitions for the list
|
||||
*/
|
||||
@XmlElement(name = "alias")
|
||||
private List<Alias> aliasList = new ArrayList<Alias>();
|
||||
|
||||
public AliasList() {
|
||||
}
|
||||
|
||||
public AliasList(String name) {
|
||||
this.namespace = name;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public List<Alias> getAliasList() {
|
||||
return aliasList;
|
||||
}
|
||||
|
||||
public void setAliasList(List<Alias> aliasList) {
|
||||
this.aliasList = aliasList;
|
||||
}
|
||||
|
||||
public void addAlias(Alias alias) {
|
||||
this.aliasList.add(alias);
|
||||
}
|
||||
|
||||
public boolean isCaseSensitive() {
|
||||
return caseSensitive;
|
||||
}
|
||||
|
||||
public void setCaseSensitive(boolean caseSensitive) {
|
||||
this.caseSensitive = caseSensitive;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/**
|
||||
* 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.common.util.mapping;
|
||||
|
||||
import java.util.Collections;
|
||||
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;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* A AliasNamespace represents a set of alternative names for a base name. This
|
||||
* list defines the alternatives within a namespace so that it is possible to
|
||||
* match aliases for only a specific group. Parent namespaces can be used to
|
||||
* bring all aliases from another list into this namespace.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 22, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@XmlRootElement
|
||||
public class AliasNamespace {
|
||||
|
||||
protected final boolean caseSensitive;
|
||||
|
||||
/**
|
||||
* Map an alias name to base names
|
||||
*/
|
||||
protected Map<String, Set<String>> alias2base = new HashMap<String, Set<String>>();
|
||||
|
||||
/**
|
||||
* maps base names to alias names.
|
||||
*/
|
||||
protected Map<String, Set<String>> base2alias = new HashMap<String, Set<String>>();
|
||||
|
||||
public AliasNamespace(AliasList aliasList) {
|
||||
this.caseSensitive = aliasList.isCaseSensitive();
|
||||
int mapSize = (int) (aliasList.getAliasList().size() / 0.75) + 1;
|
||||
alias2base = new HashMap<String, Set<String>>(mapSize, 0.75f);
|
||||
base2alias = new HashMap<String, Set<String>>(mapSize, 0.75f);
|
||||
for (Alias def : aliasList.getAliasList()) {
|
||||
String alias = def.getAlias();
|
||||
if (!caseSensitive) {
|
||||
alias = alias.toLowerCase();
|
||||
}
|
||||
String base = def.getBase();
|
||||
Set<String> baseSet = alias2base.get(alias);
|
||||
if (baseSet == null) {
|
||||
baseSet = new HashSet<String>();
|
||||
alias2base.put(alias, baseSet);
|
||||
}
|
||||
baseSet.add(base);
|
||||
Set<String> aliasSet = base2alias.get(base);
|
||||
if (aliasSet == null) {
|
||||
aliasSet = new HashSet<String>();
|
||||
base2alias.put(base, aliasSet);
|
||||
}
|
||||
aliasSet.add(alias);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> lookupBaseNames(String alias) {
|
||||
if (!caseSensitive) {
|
||||
alias = alias.toLowerCase();
|
||||
}
|
||||
Set<String> base = alias2base.get(alias);
|
||||
if (base == null) {
|
||||
return base;
|
||||
}
|
||||
return Collections.unmodifiableSet(base);
|
||||
}
|
||||
|
||||
public Set<String> lookupAliases(String base) {
|
||||
Set<String> alias = base2alias.get(base);
|
||||
if (alias == null) {
|
||||
return alias;
|
||||
}
|
||||
return Collections.unmodifiableSet(alias);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
/**
|
||||
* 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.common.util.mapping;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
/**
|
||||
* This class can be used to map names between different naming conventions.
|
||||
*
|
||||
* Names are grouped into namespaces which allows mapping from any namespace
|
||||
* into the "base" namespace. The "base" namespace does not actually exist but
|
||||
* it is a theoretical namespace that other things map into, often defined by
|
||||
* the contents of a file or database table depending on the implementation.
|
||||
*
|
||||
* The "deprecated" namespace is handled specially. This namespace will contain
|
||||
* any names that were previously base names but have since changed. When any
|
||||
* mapping is performed, if the base name is deprecated it will map correctly to
|
||||
* the new base. Over time it is expected that all mappings and code will be
|
||||
* updated and any deprecated entries can be removed.
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 22, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
public abstract class Mapper {
|
||||
|
||||
/**
|
||||
* The name of the special deprecated namespace
|
||||
*/
|
||||
public static final String DEPRECATED = "deprecated";
|
||||
|
||||
private static Unmarshaller unmarshaller;
|
||||
|
||||
private Map<String, AliasNamespace> namespaceMap = new HashMap<String, AliasNamespace>();
|
||||
|
||||
protected void addAliasList(AliasList list) {
|
||||
namespaceMap.put(list.getNamespace(), new AliasNamespace(list));
|
||||
}
|
||||
|
||||
protected void addAliasList(File file) throws JAXBException {
|
||||
if (file == null || !file.exists() || file.length() < 0) {
|
||||
return;
|
||||
}
|
||||
Unmarshaller unmarshaller = Mapper.unmarshaller;
|
||||
if (unmarshaller == null) {
|
||||
// This will be safe if multiple threads get in before the sync
|
||||
// block.
|
||||
JAXBContext context = JAXBContext.newInstance(AliasList.class,
|
||||
Alias.class);
|
||||
unmarshaller = context.createUnmarshaller();
|
||||
}
|
||||
synchronized (unmarshaller) {
|
||||
Object obj = unmarshaller.unmarshal(file);
|
||||
if (obj instanceof AliasList) {
|
||||
addAliasList((AliasList) obj);
|
||||
}
|
||||
}
|
||||
Mapper.unmarshaller = unmarshaller;
|
||||
}
|
||||
|
||||
protected Set<String> lookupBaseNames(String alias, String namespace,
|
||||
boolean defaultUseAlias) {
|
||||
AliasNamespace list = namespaceMap.get(namespace);
|
||||
Set<String> baseNames = null;
|
||||
if (list != null) {
|
||||
baseNames = list.lookupBaseNames(alias);
|
||||
}
|
||||
if (baseNames == null) {
|
||||
if (defaultUseAlias) {
|
||||
baseNames = new HashSet<String>(Arrays.asList(alias));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
AliasNamespace deprecated = namespaceMap.get(DEPRECATED);
|
||||
if (deprecated != null) {
|
||||
Set<String> newBaseNames = new HashSet<String>(
|
||||
(int) (baseNames.size() / 0.75) + 1, 0.75f);
|
||||
for (String name : baseNames) {
|
||||
Set<String> undepNames = deprecated.lookupBaseNames(name);
|
||||
if (undepNames == null) {
|
||||
newBaseNames.add(name);
|
||||
} else {
|
||||
newBaseNames.addAll(baseNames);
|
||||
}
|
||||
}
|
||||
// We don't really need to make this unmodifiable, but if we don't
|
||||
// and people start modifying the result then everything breaks if
|
||||
// there are no deprecated names.
|
||||
baseNames = Collections.unmodifiableSet(newBaseNames);
|
||||
}
|
||||
return baseNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup all the baseNames associated with the given alias in a namespace.
|
||||
* If no baseNames are defined the alias is returned.
|
||||
*
|
||||
* @param namespace
|
||||
* - the defined alias namespace to look for the name
|
||||
* @param alias
|
||||
* - the name of an alias defined in the namespace
|
||||
* @return the base names or the alias if the namespace or alias is
|
||||
* undefined
|
||||
*/
|
||||
public Set<String> lookupBaseNames(String alias, String namespace) {
|
||||
return lookupBaseNames(alias, namespace, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup all the baseNames associated with the given alias in a namespace.
|
||||
* If no baseNames are defined null is returned.
|
||||
*
|
||||
* @param namespace
|
||||
* - the defined alias namespace to look for the name
|
||||
* @param alias
|
||||
* - the name of an alias defined in the namespace
|
||||
* @return the base names or null if the namespace or alias is undefined
|
||||
*/
|
||||
public Set<String> lookupBaseNamesOrNull(String alias, String namespace) {
|
||||
return lookupBaseNames(alias, namespace, false);
|
||||
}
|
||||
|
||||
protected Set<String> lookupAliases(String base, String namespace,
|
||||
boolean defaultUseBase) {
|
||||
AliasNamespace ns = namespaceMap.get(namespace);
|
||||
Set<String> aliases = null;
|
||||
if (ns != null) {
|
||||
aliases = ns.lookupAliases(base);
|
||||
}
|
||||
if (aliases == null) {
|
||||
AliasNamespace deprecated = namespaceMap.get(DEPRECATED);
|
||||
if (deprecated != null) {
|
||||
Set<String> depNames = deprecated.lookupAliases(base);
|
||||
if (depNames != null) {
|
||||
Set<String> newAliases = new HashSet<String>();
|
||||
for (String depName : depNames) {
|
||||
Set<String> depAliases = ns.lookupBaseNames(depName);
|
||||
if (depAliases != null) {
|
||||
newAliases.addAll(depAliases);
|
||||
}
|
||||
}
|
||||
if (!newAliases.isEmpty()) {
|
||||
aliases = newAliases;
|
||||
} else if (defaultUseBase) {
|
||||
aliases = depNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (aliases == null && defaultUseBase) {
|
||||
aliases = new HashSet<String>(Arrays.asList(base));
|
||||
}
|
||||
}
|
||||
return aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup an alias name within a given namespace for a base name. If no
|
||||
* alias is defined then the baseName is returned
|
||||
*
|
||||
* @param parameter
|
||||
* - The base name to find an alias for
|
||||
* @param namespace
|
||||
* - The namespace in which to look for an alias.
|
||||
* @return an alias abbreviation or the base name if none is found.
|
||||
*/
|
||||
public Set<String> lookupAliases(String base, String namespace) {
|
||||
return lookupAliases(base, namespace, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup an alias name within a given namespace for a base name. If no
|
||||
* alias is defined then null is returned
|
||||
*
|
||||
* @param parameter
|
||||
* - The base name to find an alias for
|
||||
* @param namespace
|
||||
* - The namespace in which to look for an alias.
|
||||
* @return an alias abbreviation or null if none is found.
|
||||
*/
|
||||
public Set<String> lookupAliasesOrNull(String base, String namespace) {
|
||||
return lookupAliases(base, namespace, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides same functionality as lookupBaseNames but is more convenient
|
||||
* when only alias is expected.
|
||||
*
|
||||
* @param alias
|
||||
* @param namespace
|
||||
* @return
|
||||
* @throws MultipleMappingException
|
||||
*/
|
||||
public String lookupBaseName(String alias, String namespace)
|
||||
throws MultipleMappingException {
|
||||
Set<String> baseNames = lookupBaseNames(alias, namespace);
|
||||
if (baseNames == null || baseNames.isEmpty()) {
|
||||
return null;
|
||||
} else if (baseNames.size() == 1) {
|
||||
return baseNames.iterator().next();
|
||||
} else {
|
||||
throw new MultipleMappingException(false, alias, namespace,
|
||||
baseNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides same functionality as lookupAliases but is more convenient when
|
||||
* only one base name is expected.
|
||||
*
|
||||
* @param base
|
||||
* @param namespace
|
||||
* @return
|
||||
* @throws MultipleMappingException
|
||||
*/
|
||||
public String lookupAlias(String base, String namespace)
|
||||
throws MultipleMappingException {
|
||||
Set<String> aliases = lookupAliases(base, namespace);
|
||||
if (aliases == null) {
|
||||
return null;
|
||||
} else if (aliases.size() == 1) {
|
||||
return aliases.iterator().next();
|
||||
} else {
|
||||
throw new MultipleMappingException(true, base, namespace, aliases);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
* 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.common.util.mapping;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Exception thrown when trying to map an alias or baseName to exactly one name
|
||||
* and multiple definitions are defined.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 26, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class MultipleMappingException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -376467583718598176L;
|
||||
|
||||
private final boolean base;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String namespace;
|
||||
|
||||
private final Set<String> mappings;
|
||||
|
||||
public MultipleMappingException(boolean base, String name,
|
||||
String namespace, Set<String> mappings) {
|
||||
super();
|
||||
this.base = base;
|
||||
this.name = name;
|
||||
this.namespace = namespace;
|
||||
this.mappings = mappings;
|
||||
}
|
||||
|
||||
public boolean isBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the defined mappings.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<String> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one of the mappings, no guarantee as to which one.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getArbitraryMapping() {
|
||||
return mappings.iterator().next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
StringBuilder message = new StringBuilder(100);
|
||||
if (base) {
|
||||
message.append("Base name(");
|
||||
} else {
|
||||
message.append("Alias name(");
|
||||
}
|
||||
message.append(name);
|
||||
message.append(") maps to multiple names(");
|
||||
boolean first = true;
|
||||
for (String name : mappings) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
message.append(", ");
|
||||
}
|
||||
message.append(name);
|
||||
}
|
||||
message.append(") in ");
|
||||
message.append(namespace);
|
||||
message.append(" when only one mapping is expected.");
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
|||
Import-Package: com.raytheon.edex.db.dao,
|
||||
com.raytheon.uf.common.dataplugin,
|
||||
com.raytheon.uf.common.datastorage,
|
||||
com.raytheon.uf.common.parameter,
|
||||
com.raytheon.uf.common.serialization.comm,
|
||||
com.raytheon.uf.common.status,
|
||||
com.raytheon.uf.edex.core,
|
||||
com.raytheon.uf.edex.database,
|
||||
|
@ -21,3 +21,5 @@ Import-Package: com.raytheon.edex.db.dao,
|
|||
org.springframework.dao.support,
|
||||
org.springframework.orm.hibernate3.support
|
||||
Export-Package: com.raytheon.uf.edex.parameter
|
||||
Require-Bundle: com.raytheon.uf.common.parameter;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.serialization;bundle-version="1.12.1174"
|
||||
|
|
|
@ -3,6 +3,16 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
|
||||
|
||||
<bean id="getParameterHandler"
|
||||
class="com.raytheon.uf.edex.parameter.GetParameterHandler" />
|
||||
|
||||
<bean id="getParameterHandlerRegistered" factory-bean="handlerRegistry"
|
||||
factory-method="register" depends-on="parameterRegistered">
|
||||
<constructor-arg
|
||||
value="com.raytheon.uf.common.parameter.request.GetParameterRequest" />
|
||||
<constructor-arg ref="getParameterHandler" />
|
||||
</bean>
|
||||
|
||||
<bean id="parameterProperties" class="com.raytheon.uf.edex.database.DatabasePluginProperties">
|
||||
<property name="pluginName" value="parameter" />
|
||||
<property name="pluginFQN" value="com.raytheon.uf.common.parameter" />
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* 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.edex.parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
import com.raytheon.uf.common.parameter.request.GetParameterRequest;
|
||||
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.edex.database.dao.CoreDao;
|
||||
import com.raytheon.uf.edex.database.dao.DaoConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* Cache the parameters defined in the database to avoid repeated lookups.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 7, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GetParameterHandler implements
|
||||
IRequestHandler<GetParameterRequest> {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(GetParameterHandler.class);
|
||||
|
||||
private final CoreDao dao;
|
||||
|
||||
public GetParameterHandler() {
|
||||
dao = new CoreDao(DaoConfig.forClass(Parameter.class));
|
||||
}
|
||||
|
||||
private Parameter checkDatabase(Parameter parameter, boolean create) {
|
||||
Parameter rval = null;
|
||||
|
||||
Session sess = null;
|
||||
Transaction trans = null;
|
||||
for (int tries = 0; tries < 2 && rval == null; tries++) {
|
||||
// If this fails the most likely cause is that another node in the
|
||||
// cluster is trying to insert at the same time. Trying again will
|
||||
// work without errors, if it turns out this was a real problem then
|
||||
// the second try will catch it and log it.
|
||||
try {
|
||||
sess = dao.getSessionFactory().openSession();
|
||||
trans = sess.beginTransaction();
|
||||
|
||||
Criteria crit = sess.createCriteria(Parameter.class);
|
||||
|
||||
Criterion nameCrit = Restrictions.eq("abbreviation",
|
||||
parameter.getAbbreviation());
|
||||
crit.add(nameCrit);
|
||||
List<?> vals = crit.list();
|
||||
|
||||
if (vals.size() > 0) {
|
||||
rval = (Parameter) vals.get(0);
|
||||
} else if (create) {
|
||||
sess.saveOrUpdate(parameter);
|
||||
rval = parameter;
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
} catch (Exception e) {
|
||||
if (tries > 0) {
|
||||
// Don't log errors on the first try.
|
||||
statusHandler.error("Error occurred looking up Parameter["
|
||||
+ parameter.getAbbreviation() + "]", e);
|
||||
}
|
||||
if (trans != null) {
|
||||
try {
|
||||
trans.rollback();
|
||||
} catch (Exception e1) {
|
||||
statusHandler.error(
|
||||
"Error occurred rolling back transaction", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (sess != null) {
|
||||
try {
|
||||
sess.close();
|
||||
} catch (Exception e) {
|
||||
statusHandler
|
||||
.error("Error occurred closing session", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameter handleRequest(GetParameterRequest request) {
|
||||
return checkDatabase(request.getParameter(), request.getCreate());
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
/**
|
||||
* 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.edex.parameter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
import com.raytheon.uf.common.parameter.ParameterDefinitions;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.edex.database.dao.CoreDao;
|
||||
import com.raytheon.uf.edex.database.dao.DaoConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* Cache the parameters defined in the database to avoid repeated lookups.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 7, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ParameterLookup {
|
||||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ParameterLookup.class);
|
||||
|
||||
private static ParameterLookup instance;
|
||||
|
||||
public static ParameterLookup getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ParameterLookup();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final CoreDao dao;
|
||||
|
||||
private final Map<String, Parameter> parameterMap = new HashMap<String, Parameter>();
|
||||
|
||||
private ParameterLookup() {
|
||||
dao = new CoreDao(DaoConfig.forClass(Parameter.class));
|
||||
for (Parameter parameter : ParameterDefinitions.getParameters()) {
|
||||
lookupParameter(parameter, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* lookup a parameter in the database and optionally add it if it does not
|
||||
* exist.
|
||||
*
|
||||
* @param parameter
|
||||
* @param create
|
||||
* @return
|
||||
*/
|
||||
public synchronized Parameter lookupParameter(Parameter parameter,
|
||||
boolean create) {
|
||||
synchronized (parameterMap) {
|
||||
Parameter result = parameterMap.get(parameter.getAbbreviation());
|
||||
if (result == null) {
|
||||
result = checkDatabase(parameter, true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private Parameter checkDatabase(Parameter parameter, boolean create) {
|
||||
Parameter rval = null;
|
||||
|
||||
Session sess = null;
|
||||
Transaction trans = null;
|
||||
try {
|
||||
sess = dao.getSessionFactory().openSession();
|
||||
trans = sess.beginTransaction();
|
||||
|
||||
Criteria crit = sess.createCriteria(Parameter.class);
|
||||
|
||||
Criterion nameCrit = Restrictions.eq("abbreviation",
|
||||
parameter.getAbbreviation());
|
||||
crit.add(nameCrit);
|
||||
List<?> vals = crit.list();
|
||||
|
||||
if (vals.size() > 0) {
|
||||
rval = (Parameter) vals.get(0);
|
||||
} else if (create) {
|
||||
sess.saveOrUpdate(parameter);
|
||||
rval = parameter;
|
||||
}
|
||||
|
||||
trans.commit();
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Error occurred looking up Parameter["
|
||||
+ parameter.getAbbreviation() + "]", e);
|
||||
|
||||
if (trans != null) {
|
||||
try {
|
||||
trans.rollback();
|
||||
} catch (Exception e1) {
|
||||
statusHandler.error(
|
||||
"Error occurred rolling back transaction", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (sess != null) {
|
||||
try {
|
||||
sess.close();
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Error occurred closing session", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
}
|
|
@ -20,8 +20,6 @@ Import-Package: com.raytheon.edex.site,
|
|||
com.raytheon.uf.common.geospatial.interpolation,
|
||||
com.raytheon.uf.common.gridcoverage,
|
||||
com.raytheon.uf.common.gridcoverage.lookup,
|
||||
com.raytheon.uf.common.parameter,
|
||||
com.raytheon.uf.common.parameter.mapping,
|
||||
com.raytheon.uf.common.serialization,
|
||||
com.raytheon.uf.common.serialization.comm,
|
||||
com.raytheon.uf.common.status,
|
||||
|
@ -64,3 +62,4 @@ Import-Package: com.raytheon.edex.site,
|
|||
Export-Package: com.raytheon.uf.edex.plugin.grid.dao,
|
||||
com.raytheon.uf.edex.plugin.grid.handler,
|
||||
com.raytheon.uf.edex.plugin.grid.topo
|
||||
Require-Bundle: com.raytheon.uf.common.parameter;bundle-version="1.0.0"
|
||||
|
|
|
@ -49,12 +49,12 @@ import com.raytheon.uf.common.datastorage.records.IDataRecord;
|
|||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.lookup.GridCoverageLookup;
|
||||
import com.raytheon.uf.common.parameter.Parameter;
|
||||
import com.raytheon.uf.common.parameter.lookup.ParameterLookup;
|
||||
import com.raytheon.uf.edex.core.EDEXUtil;
|
||||
import com.raytheon.uf.edex.core.EdexException;
|
||||
import com.raytheon.uf.edex.core.dataplugin.PluginRegistry;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.database.plugin.PluginDao;
|
||||
import com.raytheon.uf.edex.parameter.ParameterLookup;
|
||||
|
||||
/**
|
||||
* Data access object for accessing Grid records from the database
|
||||
|
@ -247,8 +247,8 @@ public class GridDao extends PluginDao {
|
|||
} else if (parameter.getName().equals("Missing")) {
|
||||
result = false;
|
||||
} else {
|
||||
Parameter dbParameter = ParameterLookup.getInstance()
|
||||
.lookupParameter(parameter, true);
|
||||
Parameter dbParameter = ParameterLookup.getInstance().getParameter(
|
||||
parameter, true);
|
||||
if (!parameter.equals(dbParameter)) {
|
||||
// This check is for debugging purposes
|
||||
// if (!parameter.getName().equals(dbParameter.getName())) {
|
||||
|
|
Loading…
Add table
Reference in a new issue