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

bchapuis pushed a commit to branch 745-daylight
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit 9fde553f421bc0c16ec93255fa80377f6170bcd4
Author: Bertil Chapuis <[email protected]>
AuthorDate: Mon Sep 18 21:35:33 2023 +0200

    Fix tileset setter
---
 .../main/java/org/apache/baremaps/cli/map/Dev.java | 143 +++++++++++----------
 1 file changed, 76 insertions(+), 67 deletions(-)

diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java 
b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
index 14c21fd0..4c572b1f 100644
--- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
+++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/map/Dev.java
@@ -66,72 +66,81 @@ public class Dev implements Callable<Integer> {
 
   @Override
   public Integer call() throws Exception {
-    var configReader = new ConfigReader();
-    var objectMapper = objectMapper();
-    var tileset = objectMapper.readValue(configReader.read(this.tilesetPath), 
Tileset.class);
-    var datasource = 
PostgresUtils.createDataSourceFromObject(tileset.getDatabase());
-
-    var tileStoreType = new TypeLiteral<Supplier<TileStore>>() {};
-    var tileStoreSupplier = (Supplier<TileStore>) () -> {
-      try {
-        var config = configReader.read(this.tilesetPath);
-        var tilesetObject =
-            objectMapper.readValue(config, Tileset.class);
-        return new PostgresTileStore(datasource, tilesetObject);
-      } catch (IOException e) {
-        e.printStackTrace();
-        throw new RuntimeException(e);
-      }
-    };
-
-    var styleSupplierType = new TypeLiteral<Supplier<Style>>() {};
-    var styleSupplier = (Supplier<Style>) () -> {
-      try {
-        var config = configReader.read(stylePath);
-        return objectMapper.readValue(config, Style.class);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    };
-
-    var tileJSONSupplierType = new TypeLiteral<Supplier<Tileset>>() {};
-    var tileJSONSupplier = (Supplier<Tileset>) () -> {
-      try {
-        var config = configReader.read(tilesetPath);
-        return objectMapper.readValue(config, Tileset.class);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      }
-    };
-
-    var application = new ResourceConfig()
-        .register(CorsFilter.class)
-        .register(ChangeResource.class)
-        .register(TileResource.class)
-        .register(StyleResource.class)
-        .register(TilesetResource.class)
-        .register(ChangeResource.class)
-        .register(ClassPathResource.class)
-        .register(newContextResolver(objectMapper))
-        .register(new AbstractBinder() {
-          @Override
-          protected void configure() {
-            bind("assets").to(String.class).named("directory");
-            bind("viewer.html").to(String.class).named("index");
-            bind(tilesetPath).to(Path.class).named("tileset");
-            bind(stylePath).to(Path.class).named("style");
-            bind(tileStoreSupplier).to(tileStoreType);
-            bind(styleSupplier).to(styleSupplierType);
-            bind(tileJSONSupplier).to(tileJSONSupplierType);
-          }
-        });
-
-    var httpService = new 
HttpJerseyRouterBuilder().buildBlockingStreaming(application);
-    var serverContext = 
HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
-
-    logger.info("Listening on {}", serverContext.listenAddress());
-    serverContext.awaitShutdown();
-
-    return 0;
+    try {
+      var configReader = new ConfigReader();
+      var objectMapper = objectMapper();
+      var tileset = 
objectMapper.readValue(configReader.read(this.tilesetPath), Tileset.class);
+      var datasource = 
PostgresUtils.createDataSourceFromObject(tileset.getDatabase());
+
+      var tileStoreType = new TypeLiteral<Supplier<TileStore>>() {
+      };
+      var tileStoreSupplier = (Supplier<TileStore>) () -> {
+        try {
+          var config = configReader.read(this.tilesetPath);
+          var tilesetObject =
+                  objectMapper.readValue(config, Tileset.class);
+          return new PostgresTileStore(datasource, tilesetObject);
+        } catch (IOException e) {
+          e.printStackTrace();
+          throw new RuntimeException(e);
+        }
+      };
+
+      var styleSupplierType = new TypeLiteral<Supplier<Style>>() {
+      };
+      var styleSupplier = (Supplier<Style>) () -> {
+        try {
+          var config = configReader.read(stylePath);
+          return objectMapper.readValue(config, Style.class);
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        }
+      };
+
+      var tileJSONSupplierType = new TypeLiteral<Supplier<Tileset>>() {
+      };
+      var tileJSONSupplier = (Supplier<Tileset>) () -> {
+        try {
+          var config = configReader.read(tilesetPath);
+          return objectMapper.readValue(config, Tileset.class);
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        }
+      };
+
+      var application = new ResourceConfig()
+              .register(CorsFilter.class)
+              .register(ChangeResource.class)
+              .register(TileResource.class)
+              .register(StyleResource.class)
+              .register(TilesetResource.class)
+              .register(ChangeResource.class)
+              .register(ClassPathResource.class)
+              .register(newContextResolver(objectMapper))
+              .register(new AbstractBinder() {
+                @Override
+                protected void configure() {
+                  bind("assets").to(String.class).named("directory");
+                  bind("viewer.html").to(String.class).named("index");
+                  bind(tilesetPath).to(Path.class).named("tileset");
+                  bind(stylePath).to(Path.class).named("style");
+                  bind(tileStoreSupplier).to(tileStoreType);
+                  bind(styleSupplier).to(styleSupplierType);
+                  bind(tileJSONSupplier).to(tileJSONSupplierType);
+                }
+              });
+
+      var httpService = new 
HttpJerseyRouterBuilder().buildBlockingStreaming(application);
+      var serverContext = 
HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
+
+      logger.info("Listening on {}", serverContext.listenAddress());
+      serverContext.awaitShutdown();
+
+      return 0;
+    } catch (Exception e) {
+      e.printStackTrace();
+      return 1;
+
+    }
   }
 }

Reply via email to