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 2023/01/05 21:14:27 UTC

[streampipes] 05/07: [STREAMPIPES-584] add connection and processor

This is an automated email from the ASF dual-hosted git repository.

micklich pushed a commit to branch SP-584
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit c8d2a2de67b209b6e6de08f10fa7f37eed49e6dc
Author: micklich <mi...@apache.org>
AuthorDate: Sun Jan 1 17:33:57 2023 +0100

    [STREAMPIPES-584] add connection and processor
---
 .../streampipes/processors/geo/jvm/GeoJvmInit.java | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java
index ae79eea55..b4e4e3466 100644
--- a/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java
+++ b/streampipes-extensions/streampipes-processors-geo-jvm/src/main/java/org/apache/streampipes/processors/geo/jvm/GeoJvmInit.java
@@ -30,6 +30,7 @@ import org.apache.streampipes.messaging.mqtt.SpMqttProtocolFactory;
 import org.apache.streampipes.processors.geo.jvm.config.ConfigKeys;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.epsg.EpsgProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.latlngtojtspoint.LatLngToJtsPointProcessor;
+import org.apache.streampipes.processors.geo.jvm.jts.processor.reprojection.ReprojectionProcessor;
 import org.apache.streampipes.processors.geo.jvm.jts.processor.trajectory.TrajectoryFromPointsProcessor;
 import org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.haversine.HaversineDistanceCalculatorProcessor;
 import org.apache.streampipes.processors.geo.jvm.latlong.processor.distancecalculator.haversinestatic.HaversineStaticDistanceCalculatorProcessor;
@@ -39,10 +40,21 @@ import org.apache.streampipes.processors.geo.jvm.latlong.processor.revgeocoder.g
 import org.apache.streampipes.processors.geo.jvm.latlong.processor.speedcalculator.SpeedCalculatorProcessor;
 import org.apache.streampipes.service.extensions.ExtensionsModelSubmitter;
 
+import org.apache.sis.setup.Configuration;
+import org.postgresql.ds.PGSimpleDataSource;
+
 public class GeoJvmInit extends ExtensionsModelSubmitter {
 
   @Override
   public SpServiceDefinition provideServiceDefinition() {
+
+
+    try {
+      Configuration.current().setDatabase(GeoJvmInit::createDataSource);
+    } catch (IllegalStateException e) {
+      // catch the exceptions due connection is already initialized.
+    }
+
     return SpServiceDefinitionBuilder.create("org.apache.streampipes.processors.geo.jvm",
             "Processors Geo JVM",
             "",
@@ -56,7 +68,8 @@ public class GeoJvmInit extends ExtensionsModelSubmitter {
             new EpsgProcessor(),
             new LatLngToJtsPointProcessor(),
             new TrajectoryFromPointsProcessor(),
-            new SpeedCalculatorProcessor())
+            new SpeedCalculatorProcessor(),
+            new ReprojectionProcessor())
         .registerMessagingFormats(
             new JsonDataFormatFactory(),
             new CborDataFormatFactory(),
@@ -69,4 +82,18 @@ public class GeoJvmInit extends ExtensionsModelSubmitter {
         .addConfig(ConfigKeys.GOOGLE_API_KEY, "", "Google Maps API key")
         .build();
   }
+
+  // https://sis.apache.org/apidocs/org/apache/sis/setup/Configuration.html#setDatabase(java.util.function.Supplier)
+  protected static PGSimpleDataSource createDataSource() {
+    PGSimpleDataSource ds = new PGSimpleDataSource();
+    String[] serverAddresses = {"epsg"};
+    ds.setServerNames(serverAddresses);
+    ds.setDatabaseName("EPSG");
+    ds.setUser("streampipes");
+    ds.setPassword("streampipes");
+    ds.setReadOnly(true);
+
+    return ds;
+  }
+
 }