From 3cc44584e450b6d45e2ad1d6565e5d3f7588a116 Mon Sep 17 00:00:00 2001 From: EHJ-52n Date: Fri, 22 Feb 2019 12:49:08 +0100 Subject: [PATCH 1/6] Make java source and target version configurable --- feeder/pom.xml | 4 ++-- pom.xml | 2 ++ wizard/pom.xml | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/feeder/pom.xml b/feeder/pom.xml index e86ccb18..507fc588 100644 --- a/feeder/pom.xml +++ b/feeder/pom.xml @@ -93,8 +93,8 @@ maven-compiler-plugin 2.5.1 - 1.7 - 1.7 + ${java.source.version} + ${java.target.version} -Xlint:all true true diff --git a/pom.xml b/pom.xml index 8b0dc436..17a3ecc5 100644 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,8 @@ 0.2 9.5 https://github.com/52North/sos-importer + 1.8 + 1.8 diff --git a/wizard/pom.xml b/wizard/pom.xml index db9134ca..a09162ff 100644 --- a/wizard/pom.xml +++ b/wizard/pom.xml @@ -80,8 +80,8 @@ maven-compiler-plugin 2.5.1 - 1.7 - 1.7 + ${java.source.version} + ${java.target.version} -Xlint:all true true From 17756fd81f9660e5d135e9701984616b83f62400 Mon Sep 17 00:00:00 2001 From: EHJ-52n Date: Mon, 25 Feb 2019 16:42:05 +0100 Subject: [PATCH 2/6] Minor code layout fixing --- .../sos/importer/feeder/Configuration.java | 33 ++++++-------- .../org/n52/sos/importer/feeder/DataFile.java | 10 ++--- .../org/n52/sos/importer/feeder/Feeder.java | 2 +- .../feeder/SensorObservationService.java | 44 ++++++++++--------- 4 files changed, 43 insertions(+), 46 deletions(-) diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java b/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java index ff594f2d..ae88f18c 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java @@ -125,7 +125,7 @@ public final class Configuration { public static HashMap EPSG_EASTING_FIRST_MAP = null; static { - EPSG_EASTING_FIRST_MAP = new HashMap(); + EPSG_EASTING_FIRST_MAP = new HashMap<>(); EPSG_EASTING_FIRST_MAP.put("default", false); EPSG_EASTING_FIRST_MAP.put("4326",false); EPSG_EASTING_FIRST_MAP.put("4979",false); @@ -159,7 +159,7 @@ public Configuration(final String pathToFile) throws XmlException, IOException { SosImportConfigurationDocument.Factory.parse(configFile); // Create an XmlOptions instance and set the error listener. final XmlOptions validateOptions = new XmlOptions(); - final ArrayList errorList = new ArrayList(); + final ArrayList errorList = new ArrayList<>(); validateOptions.setErrorListener(errorList); // Validate the XML. @@ -222,7 +222,7 @@ public File getDataFile() { importConf.getDataFile().isSetLocalFile() && !importConf.getDataFile().getLocalFile().getPath().equalsIgnoreCase("") ) { // Path for LocalFile set to something, so return a new File using is - return new File(importConf.getDataFile().getLocalFile().getPath()); + return new File(importConf.getDataFile().getLocalFile().getPath().trim()); } LOG.error("DataFile.LocalFile.Path not set!"); return null; @@ -357,7 +357,7 @@ public char getCsvEscape() { public int[] getMeasureValueColumnIds() { LOG.trace("getMeasureValueColumnIds()"); final Column[] cols = importConf.getCsvMetadata().getColumnAssignments().getColumnArray(); - final ArrayList ids = new ArrayList(); + final ArrayList ids = new ArrayList<>(); for (final Column column : cols) { if (column.getType().equals(Type.MEASURED_VALUE)){ LOG.debug("Found measured value column: {}", column.getNumber()); @@ -378,7 +378,7 @@ public int[] getMeasureValueColumnIds() { public int[] getIgnoredColumnIds() { LOG.trace("getIgnoredColumnIds()"); final Column[] cols = importConf.getCsvMetadata().getColumnAssignments().getColumnArray(); - final ArrayList ids = new ArrayList(); + final ArrayList ids = new ArrayList<>(); for (final Column column : cols) { if (column.getType().equals(Type.DO_NOT_EXPORT)){ LOG.debug("Found ignored column: {}", column.getNumber()); @@ -441,25 +441,20 @@ public int getColumnIdForSensor(final int mvColumnId) { return -1; } - /** - * - * @param mvColumnId - * @return - */ - public Column getColumnById(final int mvColumnId) { - LOG.trace(String.format("getColumnById(%d)",mvColumnId)); + public Column getColumnById(final int columnId) { + LOG.trace(String.format("getColumnById(%d)", columnId)); final Column[] cols = importConf.getCsvMetadata().getColumnAssignments().getColumnArray(); for (final Column column : cols) { - if (column.getNumber() == mvColumnId) { + if (column.getNumber() == columnId) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Column found for id %d", - mvColumnId)); + columnId)); } return column; } } LOG.error(String.format("CsvMetadat.ColumnAssignments not set properly. Could not find Column for id %d.", - mvColumnId)); + columnId)); return null; } @@ -854,14 +849,14 @@ private char getDecimalSeparator() { * @return a Column[] having all the group id * group or
*/ - public Column[] getAllColumnsForGroup(final String group, final Enum t) { + public Column[] getAllColumnsForGroup(final String group, final Enum type) { LOG.trace("getAllColumnsForGroup()"); if (group == null) { return null; } final Column[] allCols = importConf.getCsvMetadata().getColumnAssignments().getColumnArray(); - final ArrayList tmpResultSet = new ArrayList(allCols.length); + final ArrayList tmpResultSet = new ArrayList<>(allCols.length); for (final Column col : allCols) { if (col.getType() != null && - col.getType().equals(t) ) { + col.getType().equals(type) ) { // we have a position or dateTime // check the Metadata kvps if (col.getMetadataArray() != null && col.getMetadataArray().length > 0) { @@ -1028,7 +1023,7 @@ public SensorType getSensorFromAdditionalMetadata() { } public boolean isOneMvColumn() { - return (getMeasureValueColumnIds().length == 1); + return getMeasureValueColumnIds().length == 1; } public String getSosVersion() { diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java b/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java index e0df44e3..459a6275 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java @@ -266,7 +266,7 @@ public FeatureOfInterest getFoiForColumn(final int mvColumnId, final String[] va mvColumnId, Arrays.toString(values))); // check for foi column and return new sensor - FeatureOfInterest foi = getFoiColumn(mvColumnId,values); + FeatureOfInterest foi = getFoiColumn(mvColumnId, values); if (foi == null) { LOG.debug(String.format("Could not find foi column for column id %d", mvColumnId)); @@ -850,7 +850,7 @@ private short parseTimestampComponent(final String timestampPart, private int[] getGregorianCalendarFields(final String pattern) { LOG.trace(String.format("getGregorianCalendarFields(%s)", pattern)); - final ArrayList fields = new ArrayList(); + final ArrayList fields = new ArrayList<>(); if (pattern.indexOf("y") != -1) { fields.add(GregorianCalendar.YEAR); } @@ -860,13 +860,13 @@ private int[] getGregorianCalendarFields(final String pattern) { fields.add(GregorianCalendar.MONTH); } if (pattern.indexOf("d") != -1 || - (pattern.indexOf("W") != -1 && pattern.indexOf("d") != -1)) { + pattern.indexOf("W") != -1 && pattern.indexOf("d") != -1) { fields.add(GregorianCalendar.DAY_OF_MONTH); } if (pattern.indexOf("H") != -1 || pattern.indexOf("k") != -1 || - ((pattern.indexOf("K") != -1 || - (pattern.indexOf("h") != -1) && pattern.indexOf("a") != -1))) { + pattern.indexOf("K") != -1 || + pattern.indexOf("h") != -1 && pattern.indexOf("a") != -1) { fields.add(GregorianCalendar.HOUR_OF_DAY); } if (pattern.indexOf("m") != -1) { diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/Feeder.java b/feeder/src/main/java/org/n52/sos/importer/feeder/Feeder.java index aa8f3bbe..cc1ae017 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/Feeder.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/Feeder.java @@ -68,7 +68,7 @@ public static void main(final String[] args) { // data file if (args.length == 2) { // Case: one time feeding with defined configuration - new Thread(new OneTimeFeeder(c),OneTimeFeeder.class.getSimpleName()).start(); + new Thread(new OneTimeFeeder(c), OneTimeFeeder.class.getSimpleName()).start(); } else if (args.length == 4) { // Case: one time feeding with file override or period with file from configuration diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java b/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java index eefb06ab..2678c021 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java @@ -28,7 +28,9 @@ */ package org.n52.sos.importer.feeder; -import static org.n52.sos.importer.feeder.Configuration.*; +import static org.n52.sos.importer.feeder.Configuration.SOS_OBSERVATION_TYPE_BOOLEAN; +import static org.n52.sos.importer.feeder.Configuration.SOS_OBSERVATION_TYPE_COUNT; +import static org.n52.sos.importer.feeder.Configuration.SOS_OBSERVATION_TYPE_TEXT; import java.io.BufferedReader; import java.io.FileInputStream; @@ -55,11 +57,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.opengis.sos.x10.InsertObservationResponseDocument; -import net.opengis.sos.x10.InsertObservationResponseDocument.InsertObservationResponse; -import net.opengis.sos.x10.RegisterSensorResponseDocument; -import net.opengis.swes.x20.InsertSensorResponseDocument; - import org.apache.xmlbeans.XmlException; import org.n52.oxf.OXFException; import org.n52.oxf.adapter.OperationResult; @@ -101,6 +98,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import net.opengis.sos.x10.InsertObservationResponseDocument; +import net.opengis.sos.x10.InsertObservationResponseDocument.InsertObservationResponse; +import net.opengis.sos.x10.RegisterSensorResponseDocument; +import net.opengis.swes.x20.InsertSensorResponseDocument; + /** * Handles connection to SOS and provides an easy to use interface.
* Now this class supports only OGC SOS 1.0.0 @@ -170,7 +172,7 @@ public final class SensorObservationService { private int sweArrayObservationTimeOutBuffer = 25000; private int sampleSizeDivisor; - + private String skipReason = ""; public SensorObservationService(final Configuration config) throws ExceptionReport, OXFException, MalformedURLException { @@ -201,10 +203,10 @@ public SensorObservationService(final Configuration config) throws ExceptionRepo } else { sensorDescBuilder = new DescriptionBuilder(); } - failedInsertObservations = new LinkedList(); - registeredSensors = new LinkedList(); + failedInsertObservations = new LinkedList<>(); + registeredSensors = new LinkedList<>(); if (sosVersion.equals("2.0.0")) { - offerings = new HashMap(); + offerings = new HashMap<>(); } if (config.getHunkSize() > 0) { hunkSize = config.getHunkSize(); @@ -305,7 +307,7 @@ public List importData(final DataFile dataFile) throws IOExce LOG.debug(Feeder.heapSizeInformation()); } else { LOG.trace(String.format("\t\tSkip CSV line #%d; %s; Raw data: '%s'", - (lineCounter+1), + lineCounter+1, !skipReason.isEmpty()?String.format("Reason: %s", skipReason):"", Arrays.toString(values))); skipReason = ""; @@ -353,7 +355,7 @@ public List importData(final DataFile dataFile) throws IOExce } } else { LOG.trace(String.format("\t\tSkip CSV line #%d; %s; Raw data: '%s'", - (lineCounter+1), + lineCounter+1, !skipReason.isEmpty()?String.format("Reason: %s", skipReason):"", Arrays.toString(values))); skipReason = ""; @@ -365,7 +367,7 @@ public List importData(final DataFile dataFile) throws IOExce if (isSampleBasedDataFile) { LOG.debug("SampleFile: {}; isInSample: {}; lineCounter: {}; sampleStartLine: {}; sampleSize: {}; sampleDataOffset: {}", isSampleBasedDataFile, isInSample, lineCounter, sampleStartLine, sampleSize, sampleDataOffset); - + if (isInSample && isSampleEndReached(sampleStartLine)) { isInSample = false; LOG.debug("Current sample left"); @@ -475,7 +477,7 @@ private void skipLines(final CsvParser cr, int skipLimit = cr.getSkipLimit(); while (skipCount > skipLimit) { values = cr.readNext(); - LOG.trace(String.format("\t\tSkip CSV line #%d: %s",(lineCounter+1),restoreLine(values))); + LOG.trace(String.format("\t\tSkip CSV line #%d: %s",lineCounter+1,restoreLine(values))); skipCount--; lineCounter++; } @@ -550,9 +552,9 @@ private InsertObservation[] getInsertObservations(final String[] values, LOG.error("Method called with bad arguments: values: {}, mVColumns: {}", Arrays.toString(values), Arrays.toString(mVColumns)); return null; } - final ArrayList result = new ArrayList(mVColumns.length); + final ArrayList result = new ArrayList<>(mVColumns.length); for (final int mVColumn : mVColumns) { - LOG.debug("Parsing measured value column {}",mVColumn); + LOG.debug("Parsing measured value column {}", mVColumn); try { final InsertObservation io = getInsertObservationForColumnIdFromValues(mVColumn,values,df); if (io != null) { @@ -697,7 +699,7 @@ private void insertObservationsForOneLine(final InsertObservation[] ios, final S private Map getUnitsOfMeasurement(final String sensorURI, final InsertObservation[] ios) { - final Map unitsOfMeasurement = new HashMap(ios.length); + final Map unitsOfMeasurement = new HashMap<>(ios.length); for (final InsertObservation insertObservation : ios) { if (insertObservation.getSensorURI().equalsIgnoreCase(sensorURI)) { @@ -710,7 +712,7 @@ private Map getUnitsOfMeasurement(final String sensorU } private Map getMeasuredValueTypes(final String sensorURI, final InsertObservation[] ios) { - final Map measuredValueTypes = new HashMap(ios.length); + final Map measuredValueTypes = new HashMap<>(ios.length); for (final InsertObservation insertObservation : ios) { if (insertObservation.getSensorURI().equalsIgnoreCase(sensorURI)) { @@ -723,7 +725,7 @@ private Map getMeasuredValueTypes(final String sensorU } private Collection getObservedProperties(final String sensorURI, final InsertObservation[] ios) { - final Set observedProperties = new HashSet(ios.length); + final Set observedProperties = new HashSet<>(ios.length); for (final InsertObservation insertObservation : ios) { if (insertObservation.getSensorURI().equalsIgnoreCase(sensorURI)) { @@ -1026,7 +1028,7 @@ private Collection getObservationTypeURIs(final RegisterSensor rs) { if (rs == null || rs.getObservedProperties() == null || rs.getObservedProperties().size() < 1) { return Collections.emptyList(); } - final Set tmp = new HashSet(rs.getObservedProperties().size()); + final Set tmp = new HashSet<>(rs.getObservedProperties().size()); for (final ObservedProperty obsProp : rs.getObservedProperties()) { final String measuredValueType = rs.getMeasuredValueType(obsProp); if (measuredValueType != null) { @@ -1058,7 +1060,7 @@ private Collection getObservedPropertyURIs(final Collection result = new ArrayList(observedProperties.size()); + final Collection result = new ArrayList<>(observedProperties.size()); for (final ObservedProperty observedProperty : observedProperties) { result.add(observedProperty.getUri()); } From 1f76fe4c4550d97dda16dfa90b9eda97c56974da Mon Sep 17 00:00:00 2001 From: EHJ-52n Date: Mon, 25 Feb 2019 16:46:57 +0100 Subject: [PATCH 3/6] Update dependencies fixes #99 --- .../n52/sos/importer/feeder/Issue099Test.java | 49 ++++ .../src/test/resources/issue-099/config-2.xml | 126 ++++++++++ .../src/test/resources/issue-099/config.xml | 237 ++++++++++++++++++ feeder/src/test/resources/issue-099/data.csv | 4 + pom.xml | 14 +- 5 files changed, 423 insertions(+), 7 deletions(-) create mode 100644 feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java create mode 100644 feeder/src/test/resources/issue-099/config-2.xml create mode 100644 feeder/src/test/resources/issue-099/config.xml create mode 100644 feeder/src/test/resources/issue-099/data.csv diff --git a/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java b/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java new file mode 100644 index 00000000..af744ac9 --- /dev/null +++ b/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2011-2015 52°North Initiative for Geospatial Open Source + * Software GmbH + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * If the program is linked with libraries which are licensed under one of + * the following licenses, the combination of the program with the linked + * library is not considered a "derivative work" of the program: + * + * - Apache License, version 2.0 + * - Apache Software License, version 1.0 + * - GNU Lesser General Public License, version 3 + * - Mozilla Public License, versions 1.0, 1.1 and 2.0 + * - Common Development and Distribution License (CDDL), version 1.0 + * + * Therefore the distribution of the program linked with libraries licensed + * under the aforementioned licenses, is permitted by the copyright holders + * if the distribution is compliant with both the GNU General Public + * License version 2 and the aforementioned licenses. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + */ +package org.n52.sos.importer.feeder; + +import org.junit.Assert; +import org.junit.Test; +import org.n52.oxf.OXFException; +import org.n52.oxf.ows.ExceptionReport; +import org.n52.oxf.sos.adapter.ISOSRequestBuilder.Binding; +import org.n52.oxf.sos.adapter.wrapper.SosWrapperFactory; + +public class Issue099Test { + + @Test(expected = OXFException.class) + public void issue099TestForNoSuchMethodExceptionDuringSosWrapperInit() throws ExceptionReport, OXFException { + try { + SosWrapperFactory.newInstance("http://example.com:52/not/available", "2.0.0", Binding.POX); + } catch (NoSuchMethodError e) { + Assert.fail("NoSuchMethodError still happening: " + e.getLocalizedMessage()); + } + } + +} diff --git a/feeder/src/test/resources/issue-099/config-2.xml b/feeder/src/test/resources/issue-099/config-2.xml new file mode 100644 index 00000000..99a45a8e --- /dev/null +++ b/feeder/src/test/resources/issue-099/config-2.xml @@ -0,0 +1,126 @@ + + + + + src/test/resources/issue-099/data.csv + UTF-8 + + + + http://localhost:8080/52n-sos-webapp/service + + 2.0.0 + POX + + + + + 0 + POSITION + + TYPE + COMBINATION + + + PARSE_PATTERN + EPSG + + + GROUP + A + + + POSITION_ALTITUDE + 60m + + + + 1 + POSITION + + TYPE + COMBINATION + + + PARSE_PATTERN + LAT + + + GROUP + A + + + + 2 + POSITION + + TYPE + COMBINATION + + + PARSE_PATTERN + LON + + + GROUP + A + + + + 3 + MEASURED_VALUE + + TYPE + NUMERIC + + + + 4 + OBSERVED_PROPERTY + + + 5 + UOM + + + 6 + DATE_TIME + + GROUP + 1 + + + PARSE_PATTERN + yyyy-MM-dd'T'HH:mm:ss + + + TYPE + COMBINATION + + + TIME_ZONE + 0 + + + + 7 + FOI + + + 8 + SENSOR + + + . + 1 + + # + , + " + + false + + \ No newline at end of file diff --git a/feeder/src/test/resources/issue-099/config.xml b/feeder/src/test/resources/issue-099/config.xml new file mode 100644 index 00000000..2d9a9f73 --- /dev/null +++ b/feeder/src/test/resources/issue-099/config.xml @@ -0,0 +1,237 @@ + + + + + src/test/resources/issue-099/no-data-file.csv + UTF-8 + + + + http://localhost:8080/52n-sos-webapp/service + + 2.0.0 + POX + + + + + 0 + DATE_TIME + + GROUP + 1 + + + TYPE + COMBINATION + + + PARSE_PATTERN + yyyyMMdd_hhmmss + + + + 1 + FOI + + + 2 + POSITION + + TYPE + COMBINATION + + + PARSE_PATTERN + LAT + + + GROUP + A + + + + 3 + POSITION + + TYPE + COMBINATION + + + PARSE_PATTERN + LON + + + GROUP + A + + + POSITION_ALTITUDE + 60.0 m + + + POSITION_EPSG_CODE + 4326 + + + + 4 + MEASURED_VALUE + + TYPE + NUMERIC + + + obsprop-1021812780 + + + sensor980306765 + + + uom-451987561 + + + + 5 + MEASURED_VALUE + + TYPE + NUMERIC + + + obsprop1699005028 + + + sensor-408582831 + + + uom-241239927 + + + + 6 + MEASURED_VALUE + + TYPE + NUMERIC + + + obsprop-43923438 + + + sensor5386699 + + + uom-241239927 + + + + 7 + MEASURED_VALUE + + TYPE + NUMERIC + + + obsprop-487945612 + + + sensor800036162 + + + uom-284659718 + + + + . + 1 + + # + , + " + + false + + + + + sensor980306765 + 1 + measured-value-1-sensor- + + + + + sensor-408582831 + 1 + measured-value-2-sensor- + + + + + sensor5386699 + 1 + measured-value-3-sensor- + + + + + sensor800036162 + 1 + measured-value-4-sensor- + + + + + obsprop-1021812780 + http://www.example.com/properties/1 + Property 1 Name + + + + + obsprop1699005028 + http://www.example.com/properties/2 + Property 2 Name + + + + + obsprop-43923438 + http://www.example.com/properties/3 + Property 3 Name + + + + + obsprop-487945612 + http://www.example.com/properties/4 + Property 4 Name + + + + + uom-451987561 + http://www.example.com/units/1 + Unit-1-Name + + + + + uom-241239927 + http://www.example.com/units/2 + Unit-2-Name + + + + + uom-284659718 + http://www.example.com/units/3 + Unit-3-Name + + + + diff --git a/feeder/src/test/resources/issue-099/data.csv b/feeder/src/test/resources/issue-099/data.csv new file mode 100644 index 00000000..858a8873 --- /dev/null +++ b/feeder/src/test/resources/issue-099/data.csv @@ -0,0 +1,4 @@ +"epsg-code","lat","lon","measured-value","property","uom","timestamp","feature-id","sensor-id" +4326,51.141977,7.369473,805,"property","uom",1970-01-01T11:00:00,1,sensor-1 +4326,51.141942,7.369396,790,"property","uom",1970-01-01T11:01:00,2,sensor-1 +4326,51.141954,7.369358,794,"property","uom",1970-01-01T11:02:00,3,sensor-1 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 17a3ecc5..e8fbc7ef 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,7 @@ ${maven.build.timestamp} UTF-8 yyyy-MM-dd_HH-mm - 2.0.0-alpha.4 + 2.2.0 0.2 9.5 https://github.com/52North/sos-importer @@ -106,17 +106,17 @@ commons-logging commons-logging - 1.1.1 + 1.2 org.apache.httpcomponents httpclient - 4.5.6 + 4.5.7 org.apache.httpcomponents httpcore - 4.2.3 + 4.4.11 net.sf.opencsv @@ -126,7 +126,7 @@ org.apache.xmlbeans xmlbeans - 2.5.0 + 3.0.2 ${project.groupId} @@ -161,7 +161,7 @@ commons-net commons-net - 3.1 + 3.6 org.slf4j @@ -181,7 +181,7 @@ joda-time joda-time - 2.2 + 2.10.1 org.geotools From 6faa216991b1e2a85f517b4409df39dfaec39419 Mon Sep 17 00:00:00 2001 From: EHJ-52n Date: Mon, 25 Feb 2019 16:50:32 +0100 Subject: [PATCH 4/6] Fix bug in position retrieval from columns --- .../sos/importer/feeder/Configuration.java | 17 +++++++-- .../org/n52/sos/importer/feeder/DataFile.java | 25 +++++++++---- .../n52/sos/importer/feeder/Issue099Test.java | 35 +++++++++++++++++++ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java b/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java index ae88f18c..456021fe 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java @@ -877,16 +877,29 @@ public Column[] getAllColumnsForGroup(final String group, final Enum type) { return result; } + /** + * Returns the group id of the first position group found in + * CsvMetadata.ColumnAssignments.Column[] + * @return a {@link java.lang.String String} + */ + public String getFirstPositionGroup() { + return getFirstGroup(Type.POSITION); + } + /** * Returns the group id of the first date time group found in * CsvMetadata.ColumnAssignments.Column[] * @return a {@link java.lang.String String} */ public String getFirstDateTimeGroup() { - LOG.trace("getFirstDateTimeGroup()"); + return getFirstGroup(Type.DATE_TIME); + } + + public String getFirstGroup(Enum type) { + LOG.trace("getFirstGroup()"); final Column[] cols = importConf.getCsvMetadata().getColumnAssignments().getColumnArray(); for (final Column col : cols) { - if (col.getType().equals(Type.DATE_TIME)){ + if (col.getType().equals(type)){ // it's DATE_TIME -> get group id from metadata[] if (col.getMetadataArray() != null && col.getMetadataArray().length > 0) { for (final Metadata m : col.getMetadataArray()) { diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java b/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java index 459a6275..22553ff6 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/DataFile.java @@ -125,10 +125,11 @@ public boolean isAvailable() { return false; } - private boolean checkWindowsJavaApiBugJDK6203387(final File file) { + private boolean checkWindowsJavaApiBugJDK6203387(File file) { if (isWindows()) { + FileReader fr = null; try { - new FileReader(file); + fr = new FileReader(file); } catch (final FileNotFoundException fnfe) { // TODO add more language specific versions of this error message @@ -143,6 +144,14 @@ private boolean checkWindowsJavaApiBugJDK6203387(final File file) { { return true; } + } finally { + if (fr != null) { + try { + fr.close(); + } catch (IOException e) { + LOG.error("Exception thrown", e); + } + } } } return false; @@ -784,17 +793,21 @@ private Sensor getSensorFromColumn(final int mvColumnId, final String[] values) } } - private FeatureOfInterest getFoiColumn(final int mvColumnId, final String[] values) { + private FeatureOfInterest getFoiColumn(int mvColumnId, String[] values) throws ParseException { LOG.trace(String.format("getFoiColumn(%d,%s)", mvColumnId, Arrays.toString(values))); - final int i = configuration.getColumnIdForFoi(mvColumnId); + int i = configuration.getColumnIdForFoi(mvColumnId); if (i < 0) { // foi is not in the data file -> return null return null; } else { - final Position p = configuration.getFoiPosition(values[i]); - final FeatureOfInterest s = new FeatureOfInterest(values[i], + Position p = configuration.getFoiPosition(values[i]); + if (p == null) { + String group = configuration.getFirstPositionGroup(); + p = configuration.getPosition(group, values); + } + FeatureOfInterest s = new FeatureOfInterest(values[i], values[i], p); LOG.debug(String.format("Feature of Interst found in datafile: %s", s)); diff --git a/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java b/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java index af744ac9..ffd471b6 100644 --- a/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java +++ b/feeder/src/test/java/org/n52/sos/importer/feeder/Issue099Test.java @@ -28,12 +28,22 @@ */ package org.n52.sos.importer.feeder; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.io.File; +import java.io.IOException; +import java.text.ParseException; + +import org.apache.xmlbeans.XmlException; import org.junit.Assert; import org.junit.Test; import org.n52.oxf.OXFException; import org.n52.oxf.ows.ExceptionReport; import org.n52.oxf.sos.adapter.ISOSRequestBuilder.Binding; import org.n52.oxf.sos.adapter.wrapper.SosWrapperFactory; +import org.n52.sos.importer.feeder.model.Position; public class Issue099Test { @@ -46,4 +56,29 @@ public void issue099TestForNoSuchMethodExceptionDuringSosWrapperInit() throws Ex } } + + @Test + public void getPositionShouldReturnValidPosition() throws XmlException, IOException, ParseException { + Configuration configuration = new Configuration("src/test/resources/issue-099/config-2.xml"); + Position position = configuration.getPosition("A", + new String[] { "4326", "52.0", "42.0", "timestamp", "value"}); + assertThat(position, notNullValue()); + assertThat(position.getEpsgCode(), is(4326)); + assertThat(position.getLatitude(), is(52.0)); + assertThat(position.getLongitude(), is(42.0)); + } + + @Test + public void getFoiForColumnShouldReturnValidFoiWithPosition() throws XmlException, IOException, ParseException { + Configuration configuration = new Configuration("src/test/resources/issue-099/config-2.xml"); + DataFile dataFile = new DataFile(configuration, new File("src/test/resources/issue-099/data.csv")); + Position position = dataFile.getFoiForColumn(3, + new String[] { "4326", "51.141977", "7.369473", "805", "property", "uom", "1970-01-01T11:00:00", "1"}) + .getPosition(); + assertThat(position, notNullValue()); + assertThat(position.getEpsgCode(), is(4326)); + assertThat(position.getLatitude(), is(51.141977)); + assertThat(position.getLongitude(), is(7.369473)); + } + } From f883c63a13b4625da0368d72236273c495573a98 Mon Sep 17 00:00:00 2001 From: EHJ-52n Date: Mon, 25 Feb 2019 16:56:42 +0100 Subject: [PATCH 5/6] Update RELEASE_NOTES --- RELEASE_NOTES | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 753c8083..9479aabf 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -2,6 +2,12 @@ For a complete Release Notes overview visit https://wiki.52north.org/bin/view/SensorWeb/SosImporter#Road_map +Release Notes for SOS-Importer 0.4.2 +==================================== + Bugfixes: +--------- + * https://github.com/52North/sos-importer/issues/99 + Release Notes for SOS-Importer 0.4.1 ==================================== Bugfixes: From 0e4a715f2dadce6901d3c541a0b447363b398de2 Mon Sep 17 00:00:00 2001 From: EHJ-52n Date: Mon, 25 Feb 2019 17:00:09 +0100 Subject: [PATCH 6/6] Update travis configuration: java 7 -> 8 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6eda7805..f8294d24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: java #notifications: # email: false jdk: - - openjdk7 - - oraclejdk7 + - openjdk8 + - oraclejdk8 # - oraclejdk8 install: true script: mvn clean install