You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by mi...@apache.org on 2022/11/18 19:10:43 UTC
[streampipes] 05/06: implement checks against the DB if valid and correct version is used
This is an automated email from the ASF dual-hosted git repository.
micklich pushed a commit to branch STREAMPIPES-584
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit e2f07c16dc723cae17ae799cd85b982a65416d31
Author: micklich <mi...@apache.org>
AuthorDate: Fri Nov 18 20:05:10 2022 +0100
implement checks against the DB if valid and correct version is used
---
.../geo/jvm/jts/helper/SpReprojectionBuilder.java | 55 ++++++++++++++++++++++
.../processor/reprojection/ProjTransformation.java | 42 ++++++++++++++---
2 files changed, 90 insertions(+), 7 deletions(-)
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpReprojectionBuilder.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpReprojectionBuilder.java
index 28ae4bff3..4ebffbdac 100755
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpReprojectionBuilder.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/helper/SpReprojectionBuilder.java
@@ -5,6 +5,7 @@ import org.locationtech.jts.geom.CoordinateList;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.impl.CoordinateArraySequence;
+
import org.apache.streampipes.processors.geo.jvm.jts.exceptions.*;
import java.util.List;
@@ -15,12 +16,16 @@ import org.apache.sis.referencing.CRS;
import org.apache.sis.referencing.crs.AbstractCRS;
import org.apache.sis.referencing.cs.AxesConvention;
import org.locationtech.jts.geom.*;
+
+import org.opengis.metadata.citation.Citation;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.CoordinateSystemAxis;
import org.opengis.referencing.operation.CoordinateOperation;
import org.opengis.referencing.operation.TransformException;
import org.opengis.util.FactoryException;
+
public class SpReprojectionBuilder {
public static Geometry reprojectSpGeometry(Geometry geom, Integer targetEPSG) throws SpNotSupportedGeometryException {
@@ -223,4 +228,54 @@ public class SpReprojectionBuilder {
return unit;
}
}
+
+ public static boolean isSisEpsgValid(Integer targetEPSG){
+ boolean check = true;
+
+ try {
+ CRS.forCode("EPSG::" + targetEPSG);
+ } catch (FactoryException ex) {
+ check = false;
+ }
+ return check;
+ }
+
+
+
+ private static CRSAuthorityFactory getFactory() throws FactoryException {
+ CRSAuthorityFactory factory;
+ try {
+ factory = CRS.getAuthorityFactory("EPSG");
+ } catch (FactoryException e) {
+ throw new FactoryException (e);
+ }
+ return factory;
+ }
+
+ public static boolean isSisConfigurationValid() throws FactoryException {
+ boolean check = true;
+ CRSAuthorityFactory factory = SpReprojectionBuilder.getFactory();
+ Citation authority = factory.getAuthority();
+ if (authority == null) {
+ check = false;
+ }
+ return check;
+ }
+
+ public static boolean isSisDbCorrectVersion() throws FactoryException {
+ boolean check = true;
+ CRSAuthorityFactory factory = SpReprojectionBuilder.getFactory();
+ Citation authority = factory.getAuthority();
+ if (!authority.getEdition().toString().equals("9.9.1")){
+ check = false;
+ }
+ return check;
+ }
+
+ public static String getSisDbVersion() throws FactoryException {
+ CRSAuthorityFactory factory = SpReprojectionBuilder.getFactory();
+ Citation authority = factory.getAuthority();
+ String version = authority.getEdition().toString();
+ return version;
+ }
}
diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/reprojection/ProjTransformation.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/reprojection/ProjTransformation.java
index b4c309af5..daeb60aef 100755
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/reprojection/ProjTransformation.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/jts/processor/reprojection/ProjTransformation.java
@@ -27,7 +27,6 @@ import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
import org.apache.streampipes.wrapper.routing.SpOutputCollector;
import org.apache.streampipes.wrapper.runtime.EventProcessor;
-import org.apache.sis.referencing.CRS;
import org.apache.sis.setup.Configuration;
import org.locationtech.jts.geom.Geometry;
import org.opengis.util.FactoryException;
@@ -50,13 +49,42 @@ public class ProjTransformation implements EventProcessor<ProjTransformationPara
//TODO: this has to move to a central place in the streampipes backend
// otherwise Connection to SpatialMetadata database is already initialized occur
- Configuration.current().setDatabase(ProjTransformation::createDataSource);
- // checks invalid input field. SIS got a cache system but if it is in the cache already it is also vallid
try {
- System.out.println(CRS.forCode("EPSG::" + targetEPSG));
+ Configuration.current().setDatabase(ProjTransformation::createDataSource);
+ } catch (IllegalStateException e) {
+ logger.info("Setup was already established");
+ // catch the exceptions due connection is already initialized.
+ }
+
+
+ // check if SIS DB is set up with imported data or is null
+ try {
+ if (SpReprojectionBuilder.isSisConfigurationValid()){
+ logger.info("SIS DB Settings successful checked ");
+ } else {
+ logger.warn("The required EPSG database is not imported");
+ //TODO implement fallback option with proj4j
+ throw new SpRuntimeException("Database not set and ready for fallback ");
+ }
+ } catch (FactoryException e) {
+ throw new SpRuntimeException("Something unexpected happened " + e);
+ }
+
+ // check if SIS DB has the supported 9.9.1 Version.
+ try {
+ if (!SpReprojectionBuilder.isSisDbCorrectVersion()) {
+ logger.warn("Not supported EPSG DB used.");
+ throw new SpRuntimeException("Your current EPSG DB version " + SpReprojectionBuilder.getSisDbVersion()
+ + " is not the supported 9.9.1 version. ");
+ }
} catch (FactoryException e) {
- throw new SpRuntimeException("Your chosen EPSG Code " + targetEPSG + " is not valid. "
+ throw new SpRuntimeException("Something unexpected happened " + e);
+ }
+
+ // checks if Input EPSG in valid and exists in EPSG DB
+ if (!SpReprojectionBuilder.isSisEpsgValid(targetEPSG)) {
+ throw new SpRuntimeException("Your chosen EPSG Code " + targetEPSG + " is not valid or supported. "
+ "Check EPSG on https://spatialreference.org");
}
}
@@ -81,8 +109,8 @@ public class ProjTransformation implements EventProcessor<ProjTransformationPara
out.collect(in);
} else {
- logger.warn("An empty point geometry is created in " + ProjTransformationController.EPA_NAME + " "
- + "due invalid input values. Check used epsg Code:" + epsgCode);
+ logger.warn("An empty point geometry is created in " + ProjTransformationController.EPA_NAME + " " +
+ "due invalid input values. Check used epsg Code:" + epsgCode);
}
}