Skip to content

v0.2.54..v0.2.55 changeset PullApiCommand.java

Garret Voltz edited this page Aug 14, 2020 · 1 revision
diff --git a/hoot-services/src/main/java/hoot/services/controllers/grail/PullApiCommand.java b/hoot-services/src/main/java/hoot/services/controllers/grail/PullApiCommand.java
index bb5b259..ae202b1 100644
--- a/hoot-services/src/main/java/hoot/services/controllers/grail/PullApiCommand.java
+++ b/hoot-services/src/main/java/hoot/services/controllers/grail/PullApiCommand.java
@@ -26,6 +26,8 @@
  */
 package hoot.services.controllers.grail;
 
+import static hoot.services.HootProperties.GRAIL_CONNECTED_WAYS_QUERY;
+import static hoot.services.HootProperties.HOME_FOLDER;
 import static hoot.services.HootProperties.PRIVATE_OVERPASS_CERT_PATH;
 import static hoot.services.HootProperties.PRIVATE_OVERPASS_CERT_PHRASE;
 import static hoot.services.HootProperties.PRIVATE_OVERPASS_URL;
@@ -96,19 +98,16 @@ class PullApiCommand implements InternalCommand {
         String url = "";
         try {
             BoundingBox boundingBox = new BoundingBox(params.getBounds());
-            //buffer the reference data bounding box
-            //to include neighboring data that may be snapped to
-// Disable this for now as pulling a buffered extent does not guarantee that
-// connected ways will be present in the output
-//            boundingBox.adjust(Double.parseDouble(CHANGESET_DERIVE_BUFFER));
+            // buffer the reference data bounding box to include neighboring data that may be snapped to
+            // Disable this for now as pulling a buffered extent does not guarantee that connected ways will be present in the output
+            // boundingBox.adjust(Double.parseDouble(CHANGESET_DERIVE_BUFFER));
 
             double bboxArea = boundingBox.getArea();
 
             double maxBboxArea = params.getMaxBBoxSize();
 
             if (bboxArea > maxBboxArea) {
-                throw new IllegalArgumentException("The bounding box area (" + bboxArea +
-                        ") is too large. It must be less than " + maxBboxArea + " degrees");
+                throw new IllegalArgumentException("The bounding box area (" + bboxArea + ") is too large. It must be less than " + maxBboxArea + " degrees");
             }
 
             InputStream responseStream = null;
@@ -163,4 +162,40 @@ class PullApiCommand implements InternalCommand {
 
         return entity.getContent();
     }
+
+    /**
+     * String query that will retrieve the connected ways.
+     *
+     * @param query if query is provided then we append the pull connected ways query to the end.
+     *              else we get the default overpass query and append the pull connected ways query to that.
+     *
+     * @return String query that will retrieve the connected ways.
+     */
+    static String connectedWaysQuery(String query) {
+        String newQuery;
+
+        // if no query provided then use default overpass query
+        if (query == null || query.equals("")) {
+            newQuery = PullOverpassCommand.getDefaultOverpassQuery();
+        } else {
+            newQuery = query;
+        }
+
+        // connected ways query
+        String connectedWaysQuery;
+        File connectedWaysQueryFile = new File(HOME_FOLDER, GRAIL_CONNECTED_WAYS_QUERY);
+        try {
+            connectedWaysQuery = FileUtils.readFileToString(connectedWaysQueryFile, "UTF-8");
+        } catch(Exception exc) {
+            throw new IllegalArgumentException("Grail pull connected ways error. Couldn't read connected ways overpass query file: " + connectedWaysQueryFile.getName());
+        }
+
+        if (newQuery.lastIndexOf("out meta;") != -1) {
+            newQuery = newQuery.substring(0, newQuery.lastIndexOf("out meta;")) + connectedWaysQuery;
+        } else if (newQuery.lastIndexOf("out count;") != -1) {
+            newQuery = newQuery.substring(0, newQuery.lastIndexOf("out count;")) + connectedWaysQuery;
+        }
+
+        return newQuery;
+    }
 }
Clone this wiki locally