Updates to NDM

User was having problems with EDEX Ingest starting on a new build (https://github.com/Unidata/awips2/issues/412), and we were able to replicate on a brand new Linux Server.

-Removed the ingest files from the com.raytheon.uf.edex.ndm.dataplugin since they are now in the com.raytheon.uf.edex.ndm plugin
    -IDataSetIngester.java
    -INationalDatasetSubscriber.java
    -NationalDatasetIngester.java
-Added a few new entries in ndm-dataplugin-ingst.xml
-Removed a key line that was setting the ndmProc as the dataplugin NationalDatasetIngester (since it's no longer used here)
-Added in a new java class referenced in the ndm-data-plugin.xml (Import88DLocationsUtil.java)
-I also updated the source JRE System Library from JavaSE 1.6 --> 1.8 for the com.raytheon.uf.edex.plugin.loctables plugin
This commit is contained in:
Tiffany Meyer 2022-01-10 13:33:29 -05:00
parent 37b7ef9373
commit e3e65148cf
8 changed files with 395 additions and 272 deletions

View file

@ -28,4 +28,3 @@ Require-Bundle: com.raytheon.uf.common.localization;bundle-version="1.15.1",
com.raytheon.uf.edex.ndm;bundle-version="1.14.0"
Import-Package: com.raytheon.uf.edex.plugin.text,
com.raytheon.uf.common.geospatial.spi
Export-Package: com.raytheon.uf.edex.ndm.dataplugin.ingest

View file

@ -4,8 +4,6 @@
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="ndmProc" class="com.raytheon.uf.edex.ndm.dataplugin.ingest.NationalDatasetIngester"/>
<!-- redbook -->
<bean id="redbookNdmMenuListener"
@ -119,6 +117,7 @@
<!-- radar -->
<bean id="radarMenuCreator" class="com.raytheon.uf.edex.ndm.dataplugin.subscriber.RadarMenuUtil"/>
<bean id="import88dLocations" class="com.raytheon.uf.edex.ndm.dataplugin.subscriber.Import88DLocationsUtil"/>
<bean factory-bean="ndmProc" factory-method="registerListener">
<constructor-arg value="elevationLists.txt" />
@ -132,6 +131,18 @@
<constructor-arg value="ssssElevationLists.txt" />
<constructor-arg ref="radarMenuCreator" />
</bean>
<bean factory-bean="ndmProc" factory-method="registerListener">
<constructor-arg value="fsl-w88d.shp" />
<constructor-arg ref="import88dLocations" />
</bean>
<bean factory-bean="ndmProc" factory-method="registerListener">
<constructor-arg value="fsl-w88d.shx" />
<constructor-arg ref="import88dLocations" />
</bean>
<bean factory-bean="ndmProc" factory-method="registerListener">
<constructor-arg value="fsl-w88d.dbf" />
<constructor-arg ref="import88dLocations" />
</bean>
<!-- obs -->
<bean id="mtrListener" class="com.raytheon.uf.edex.ndm.dataplugin.subscriber.MTRSubscriber" />
@ -172,4 +183,5 @@
<constructor-arg value="icao_lookup_table.dat" />
<constructor-arg ref="icaoListener" />
</bean>
</beans>

View file

@ -1,64 +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.ndm.dataplugin.ingest;
/**
* NDM Dataset ingester interface.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 22, 2011 jkorman Initial creation
* Mar 06, 2014 2876 mpduff New NDM plugin.
*
* </pre>
*
* @author jkorman
* @version 1.0
*/
public interface IDataSetIngester {
/**
* Register a filename to be processed and the subscription listener that
* will process the file.
*
* @param filename
* @param listener
* @return
*/
INationalDatasetSubscriber registerListener(String filename,
INationalDatasetSubscriber listener);
/**
* Remove a subscription listener for a given file.
*
* @param filename
* @param listener
* @return
*/
INationalDatasetSubscriber removeListener(String filename,
INationalDatasetSubscriber listener);
}

View file

@ -1,53 +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.ndm.dataplugin.ingest;
import java.io.File;
/**
* National Dataset Subscriber Interface.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 05, 2011 bfarmer Initial creation
* Mar 06, 2014 2876 mpduff New NDM plugin.
* Mar 11, 2014 2858 mpduff javadoc update.
*
* </pre>
*
* @author bfarmer
* @version 1.0
*/
public interface INationalDatasetSubscriber {
/**
* Called when a new file is found in NDM.
*
* @param fileName
* The filename
* @param file
* The file object
*/
public void notify(String fileName, File file);
}

View file

@ -1,151 +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.ndm.dataplugin.ingest;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
/**
* National Dataset Maintenance ingester.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 4, 2011 bfarmer Initial creation
* Aug 11,2011 9965 rferrel Added logging to processEvent
* Aug 24,2011 10775 rferrel Fixed error in processEvent and added
* check on statusHandler messages.
* Mar 06, 2014 2876 mpduff New NDM plugin.
* Jun 25, 2015 4512 mapeters Removed unnecessary Exception throw.
*
* </pre>
*
* @author bfarmer
* @version 1.0
*/
public class NationalDatasetIngester implements IDataSetIngester {
private final Map<String, List<INationalDatasetSubscriber>> listeners = new HashMap<String, List<INationalDatasetSubscriber>>();
/**
* Register a filename to be processed and the subscription listener that
* will process the file.
*
* @param filename
* @param listener
* @return the registered listener
*/
@Override
public INationalDatasetSubscriber registerListener(String filename,
INationalDatasetSubscriber listener) {
if (listeners.get(filename) == null) {
listeners
.put(filename, new ArrayList<INationalDatasetSubscriber>());
}
listeners.get(filename).add(listener);
return listener;
}
/**
* Remove a subscription listener for a given file.
*
* @param filename
* @param listener
* @return Returns the listener reference that was removed, otherwise a null
* reference is returned.
*/
@Override
public INationalDatasetSubscriber removeListener(String filename,
INationalDatasetSubscriber listener) {
INationalDatasetSubscriber storedListener = null;
if (filename != null) {
if (listeners.containsKey(filename)) {
List<INationalDatasetSubscriber> list = listeners.get(filename);
for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(listener)) {
storedListener = list.get(i);
list.remove(i);
break;
}
}
}
}
return storedListener;
}
/*
* (non-Javadoc)
*
* @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
*/
public void processEvent(File file) {
String fileName = file.getName();
IUFStatusHandler statusHandler = UFStatus
.getHandler(NationalDatasetIngester.class);
if (listeners.get(fileName) != null) {
if (statusHandler.isPriorityEnabled(Priority.INFO)) {
statusHandler.handle(
Priority.INFO,
String.format("Start processing file \"%1$s\".",
file.getAbsoluteFile()));
}
for (INationalDatasetSubscriber listener : listeners.get(fileName)) {
try {
listener.notify(fileName, file);
} catch (Throwable ex) {
if (statusHandler.isPriorityEnabled(Priority.ERROR)) {
statusHandler.handle(Priority.ERROR, String.format(
"Problem notifying listener for \"%1$s\".",
file.getAbsoluteFile()), ex);
}
}
}
if (statusHandler.isPriorityEnabled(Priority.INFO)) {
statusHandler.handle(Priority.INFO, String.format(
"Finished processing file \"%1$s\".",
file.getAbsoluteFile()));
}
} else {
if (statusHandler.isPriorityEnabled(Priority.WARN)) {
statusHandler.handle(
Priority.WARN,
String.format("No listeners for file: \"%1$s\".",
file.getAbsoluteFile()));
}
}
}
}

View file

@ -0,0 +1,373 @@
package com.raytheon.uf.edex.ndm.dataplugin.subscriber;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import com.raytheon.edex.plugin.radar.dao.RadarStationDao;
import com.raytheon.uf.common.dataplugin.radar.RadarStation;
import com.raytheon.uf.common.localization.ILocalizationFile;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.exception.LocalizationException;
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.edex.ndm.dataplugin.util.Shapefile;
import com.raytheon.uf.edex.ndm.ingest.INationalDatasetSubscriber;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
/**
* Decoder implementation for radar shape files plugin
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 10Oct2011 10520 JWork Initial check-in.
* 09/11/2012 DR 15366 D. Friedman Set SRID on radar stations.
* Mar 06, 2014 2876 mpduff Moved NationalDatasetSubscriber.
* Jul 09, 2015 4500 rjpeter Fix SQL Injection concern.
* Jan 27, 2016 5237 tgurney Replace deprecated LocalizationFile
* method call
* Mar 02, 2016 5434 bkowal Relocated to ndm dataplugin. Eliminated
* deprecation warnings.
* Jul 18, 2016 5744 mapeters Use common_static instead of edex_static
* for saving/retrieving shape files
* Apr 09, 2019 21223 jdynina Removed 15366 (Redmine 13350) changes.
* GeoTools has been updated and the fix
* is no longer necessary and throws an error
* </pre>
*/
public class Import88DLocationsUtil implements INationalDatasetSubscriber {
private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(Import88DLocationsUtil.class);
private static final String SHAPEFILE = "fsl-w88d.shp";
private static final String NDM_DIR_NAME = "ndm" + IPathManager.SEPARATOR;
private static final int WGS84_SRID = 4326;
/** The list of the required files comprising a Shapefile set */
private static final String[] SHAPE_FILES = new String[] { "fsl-w88d.shp",
"fsl-w88d.shx", "fsl-w88d.dbf" };
/**
* The collection of feature attribute names this code needs from the
* shapefile
*/
private enum databaseColumns {
LAT, EQP_ELV, NAME, LON, IMMUTABLEX, RDA_ID, ELEVMETER, THE_GEOM, WFO_ID, RPG_ID_DEC
}
private final long theTimeRange = 3600000l;
/** The file name of the file currently being processed. */
private String fileName = null;
/** The date, in millis, of the file currently being processed. */
private long theCurrentFileDateMillis = 0;
/**
* The list of RDA_ID's from the shapefile used to determine if an ID has
* been removed from the database
*/
private ArrayList<String> theRDAList = null;
private IPathManager pathMgr = null;
private LocalizationContext commonConfiguredCtx = null;
@Override
public void notify(String aFileName, File aFile) {
pathMgr = PathManagerFactory.getPathManager();
commonConfiguredCtx = pathMgr.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED);
fileName = aFileName;
// Read file from NDM directory and move to Common directory
ILocalizationFile ndmDirFile = getPathInfoWrite();
saveFile(aFile, ndmDirFile);
if (allFilesAvailable()) {
// Start the ShapeFile update
updateRadarFromShapeFiles();
}
}
/**
* Adaptor method to use theFileName attribute.
*
* @return LocalizationFile
*/
private ILocalizationFile getPathInfoWrite() {
ILocalizationFile ndmDir = pathMgr.getLocalizationFile(
commonConfiguredCtx, NDM_DIR_NAME + fileName);
return ndmDir;
}
/**
* Returns the localization path information for the NDM filename passed in.
*
* @return LocalizationFile
*/
private File getPathInfoRead(String aFileName) {
File file = pathMgr.getFile(commonConfiguredCtx, NDM_DIR_NAME
+ aFileName);
return file;
}
/**
* Copies the file from NDM ingest directory to the landing zone
*
* @param file
* @param outFile
*/
private void saveFile(File file, ILocalizationFile outFile) {
if ((file != null) && file.exists()) {
try {
byte[] fileByteArray = Files.readAllBytes(Paths.get(file
.getAbsolutePath()));
try (OutputStream os = outFile.openOutputStream()) {
os.write(fileByteArray);
}
// / Add the outFile's time stamp to check later on.
theCurrentFileDateMillis = System.currentTimeMillis();
} catch (FileNotFoundException e) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler.handle(Priority.PROBLEM,
"Failed to find file: " + file.getName(), e);
}
} catch (IOException e) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler.handle(
Priority.PROBLEM,
"Could not create output file: "
+ outFile.getPath(), e);
}
} catch (LocalizationException e) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler.handle(
Priority.PROBLEM,
"Failed to write localization file: "
+ outFile.getPath(), e);
}
}
}
}
/**
* Determines if all the files required for a Shapefile are present and
* within a given time threshold. For this method the files are
* "fsl-w88d(.shp,.shx,.dbf)"
*
* @return
*/
private boolean allFilesAvailable() {
File tempFile = null;
long timeStampMillis = 0;
long differenceMillis = 0;
boolean rVal = false;
ArrayList<String> badList = new ArrayList<>();
ArrayList<String> goodList = new ArrayList<>();
// Determine if the two other files are available or if the time
// threshold has been crossed and are too old to process
for (String key : SHAPE_FILES) {
if (!key.equals(fileName)) {
tempFile = getPathInfoRead(key);
timeStampMillis = tempFile.lastModified();
differenceMillis = theCurrentFileDateMillis - timeStampMillis;
if ((timeStampMillis != 0L)
&& (differenceMillis <= theTimeRange)) {
goodList.add(key);
} else {
badList.add(key);
}
}
}
if (goodList.size() == 2) {
rVal = true;
} else {
// Log what files are "missing"
String logMessage = null;
String header = "Received file [" + fileName
+ "] still require file(s) [" + badList.get(0);
if (badList.size() == 2) {
logMessage = header + ", " + badList.get(1) + "]";
} else {
logMessage = header + "]";
}
if (statusHandler.isPriorityEnabled(Priority.INFO)) {
statusHandler.handle(Priority.INFO, logMessage);
}
}
return rVal;
}
private void updateRadarFromShapeFiles() {
SimpleFeature simpleFeature = null;
List<HashMap<String, String>> dataRows = new ArrayList<>();
HashMap<String, String> nameValuePair = null;
Collection<Property> propCollection = null;
String name = null;
String value = null;
List<RadarStation> stationList = new ArrayList<>();
File tempFile = getPathInfoRead(SHAPEFILE);
Shapefile shapefile = new Shapefile(tempFile);
if (shapefile.readShapefile()) {
Set<String> featureIDs = shapefile.getFeatureIDs();
for (String id : featureIDs) {
simpleFeature = shapefile.getFeature(id);
propCollection = simpleFeature.getProperties();
nameValuePair = new HashMap<>();
for (Property property : propCollection) {
name = property.getDescriptor().getName().getLocalPart();
value = property.getValue().toString();
nameValuePair.put(name, value);
}
dataRows.add(nameValuePair);
}
stationList = buildStations(dataRows);
updateDatabase(stationList);
checkForMissingStations();
} else {
/**
* TODO: Add code to handle when file could not be read.
*/
}
}
private void updateDatabase(List<RadarStation> aStationList) {
RadarStationDao radarStationDAO = new RadarStationDao();
for (RadarStation station : aStationList) {
radarStationDAO.saveOrUpdate(station);
}
if (statusHandler.isPriorityEnabled(Priority.INFO)) {
statusHandler
.handle(Priority.INFO,
"The NDM update of database table RADAR_SPATIAL has been completed successfully");
}
}
/**
* Using the list of RDA IDs from the shapefile determine if one or more
* stations are missing and log a warning message for the missing stations
*/
private void checkForMissingStations() {
RadarStationDao dao = new RadarStationDao();
List<String> currentList = dao.getRDA_IDs();
currentList.removeAll(theRDAList);
if (currentList.size() > 0) {
for (String rda_id : currentList) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler
.handle(Priority.PROBLEM,
"The RADAR_SPATIAL database table for the row with a RDA_ID of ["
+ rda_id
+ "] needs to be removed per latest NDM update");
}
}
}
}
private List<RadarStation> buildStations(
List<HashMap<String, String>> aDataList) {
List<RadarStation> rVal = new ArrayList<>();
theRDAList = new ArrayList<>();
String rda_id = null;
RadarStation tempStation = null;
Set<String> keySet = null;
GeometryFactory gf = new GeometryFactory(new PrecisionModel(),
WGS84_SRID);
WKTReader wkt = new WKTReader(gf);
for (HashMap<String, String> aHashMap : aDataList) {
keySet = aHashMap.keySet();
tempStation = new RadarStation();
for (String key : keySet) {
switch (databaseColumns.valueOf(key.toUpperCase())) {
case LAT:
tempStation.setLat(Float.valueOf(aHashMap.get(key)));
break;
case EQP_ELV:
tempStation.setEqpElv(Float.valueOf(aHashMap.get(key)));
break;
case NAME:
tempStation.setName(aHashMap.get(key));
break;
case LON:
tempStation.setLon(Float.valueOf(aHashMap.get(key)));
break;
case IMMUTABLEX:
tempStation.setImmutablEx(Float.valueOf(aHashMap.get(key)));
break;
case RDA_ID:
rda_id = aHashMap.get(key);
tempStation.setRdaId(rda_id);
// Add the rda_id to a list in order to determine if a
// rda_id has been removed from the database
theRDAList.add(rda_id);
break;
case ELEVMETER:
tempStation.setElevMeter(Float.valueOf(aHashMap.get(key)));
break;
case THE_GEOM:
try {
tempStation.setStation((Point) wkt.read(aHashMap
.get(key)));
} catch (ParseException e) {
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage() + e);
}
}
break;
case WFO_ID:
tempStation.setWfoId(aHashMap.get(key));
break;
case RPG_ID_DEC:
tempStation.setRpgIdDec(aHashMap.get(key));
break;
default:
if (statusHandler.isPriorityEnabled(Priority.PROBLEM)) {
statusHandler.handle(Priority.PROBLEM,
"Unknown token [" + key + "}");
}
break;
}
rVal.add(tempStation);
}
}
return rVal;
}
}

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8