From 65a1bbf6af0445a8dfa209df2088f0edbe14586c Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Fri, 29 Mar 2019 16:42:10 +0100 Subject: [PATCH] bugfix-#424 build-fail --- CHANGELOG.md | 1 + .../conf/app.config.test | 1 + .../ors/v2/services/routing/ResultTest.java | 4 ++++ .../GPXRouteResponseObjects/GPXMetadata.java | 3 ++- .../GPXRouteElement.java | 2 +- .../geoJson/SimpleFeatureTypes.java | 23 +++---------------- .../gpx/GpxResponseWriter.java | 8 +------ .../routing/RoutingServiceSettings.java | 9 ++++++++ .../geoJson/SimpleFeatureTypesTest.java | 16 +++++++++---- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eb0375336..363a062d80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Updated documentation to reflect correct isochrone smoothing algorithm (Issue #471) - Enable > 2 waypoints when geometry_simplify=true (#457) +- Fixed the build fail bug when `routing_name` was set in the config file (#424) ### Changed - Updated pom to always build ors.war (Issue #432) - Replace usage of packages incompatible with Java >8 (#474) diff --git a/openrouteservice-api-tests/conf/app.config.test b/openrouteservice-api-tests/conf/app.config.test index b8537ed159..aab75740f9 100644 --- a/openrouteservice-api-tests/conf/app.config.test +++ b/openrouteservice-api-tests/conf/app.config.test @@ -38,6 +38,7 @@ init_threads: 1, attribution: "openrouteservice.org, OpenStreetMap contributors, tmc - BASt", distance_approximation: true, +1 routing_name: "ORSRouting", profiles: { active: ["vehicles-car", "vehicles-hgv", "bike", "bike-mtb", "bike-road", "bike-e", "pedestrian-walk", "pedestrian-hike", "wheelchair"], default_params: { diff --git a/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java b/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java index 17d4f4d489..bdb3f703d5 100644 --- a/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java +++ b/openrouteservice-api-tests/src/test/java/heigit/ors/v2/services/routing/ResultTest.java @@ -34,6 +34,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import javax.imageio.metadata.IIOMetadataNode; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -173,6 +174,7 @@ private void testGpxConsistency(Response response, boolean instructions) throws boolean gpxMetadata = false; boolean gpxRte = false; boolean gpxExtensions = false; + Node gpxMetadataNode = new IIOMetadataNode(); for (int i = 0; i < doc_length; i++) { String item = doc.getDocumentElement().getChildNodes().item(i).getNodeName(); switch (item) { @@ -191,6 +193,7 @@ private void testGpxConsistency(Response response, boolean instructions) throws switch (metadataItem.getNodeName()) { case "name": metadataName = true; + gpxMetadataNode = metadataItem; break; case "desc": metadataDescription = true; @@ -265,6 +268,7 @@ private void testGpxConsistency(Response response, boolean instructions) throws } } Assert.assertTrue(metadataName); + Assert.assertEquals("ORSRouting", gpxMetadataNode.getTextContent()); Assert.assertTrue(metadataDescription); Assert.assertTrue(metadataAuthor); Assert.assertTrue(metadataCopyright); diff --git a/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXMetadata.java b/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXMetadata.java index c70ea4838e..5cd23677d2 100644 --- a/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXMetadata.java +++ b/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXMetadata.java @@ -21,6 +21,7 @@ import heigit.ors.api.responses.common.BoundingBox.BoundingBoxFactory; import heigit.ors.exceptions.StatusCodeException; import heigit.ors.routing.RouteResult; +import heigit.ors.services.routing.RoutingServiceSettings; import heigit.ors.util.GeomUtility; import javax.xml.bind.annotation.XmlElement; @@ -45,7 +46,7 @@ public class GPXMetadata { public GPXMetadata() {} public GPXMetadata(RouteResult[] routeResults, RouteRequest request) throws StatusCodeException { - this.name = "openrouteservice directions"; + this.name = RoutingServiceSettings.getRoutingName(); this.description = "This is a directions instructions file as GPX, generated from openrouteservice"; this.author = new GPXAuthor(); this.copyright = new GPXCopyright(); diff --git a/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXRouteElement.java b/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXRouteElement.java index 4717562ae6..352e391d67 100644 --- a/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXRouteElement.java +++ b/openrouteservice/src/main/java/heigit/ors/api/responses/routing/GPXRouteResponseObjects/GPXRouteElement.java @@ -49,7 +49,7 @@ public GPXRouteElement(RouteResult result) { for(int i=0; i The result looks weird but a name is required!! result --> https://go.openrouteservice.org/:openrouteservice routing - try { - if (!(RoutingServiceSettings.getParameter("routing_name") == null)) { - builder.setName(RoutingServiceSettings.getParameter("routing_name")); - - } else { - builder.setName("ORSRoutingFile"); - new MissingConfigParameterException(GpxResponseWriter.class, "routing_name"); - } - } finally { - if (builder.getName() == null) { - builder.setName("ORSRoutingFile"); - } - builder.add("geometry", LineString.class); - return builder.buildFeatureType(); - } + builder.setName(RoutingServiceSettings.getRoutingName()); + builder.add("geometry", LineString.class); + return builder.buildFeatureType(); } return null; } diff --git a/openrouteservice/src/main/java/heigit/ors/globalResponseProcessor/gpx/GpxResponseWriter.java b/openrouteservice/src/main/java/heigit/ors/globalResponseProcessor/gpx/GpxResponseWriter.java index b06ee3a0e8..04175488ec 100644 --- a/openrouteservice/src/main/java/heigit/ors/globalResponseProcessor/gpx/GpxResponseWriter.java +++ b/openrouteservice/src/main/java/heigit/ors/globalResponseProcessor/gpx/GpxResponseWriter.java @@ -271,13 +271,7 @@ public static String toGPX(RoutingRequest rreq, RouteResult[] routeResults) thro new MissingConfigParameterException(GpxResponseWriter.class, "routing_description"); } // set routing_name - if (RoutingServiceSettings.getParameter("routing_name") != null) { - - metadata.setName(RoutingServiceSettings.getParameter("routing_name")); - } else { - metadata.setName("ORSRoutingFile"); - new MissingConfigParameterException(GpxResponseWriter.class, "routing_name"); - } + metadata.setName(RoutingServiceSettings.getRoutingName()); metadata.setTime(cal); gpx.setMetadata(metadata); // set author_tag diff --git a/openrouteservice/src/main/java/heigit/ors/services/routing/RoutingServiceSettings.java b/openrouteservice/src/main/java/heigit/ors/services/routing/RoutingServiceSettings.java index a9ba4f50b6..d6a519bd22 100644 --- a/openrouteservice/src/main/java/heigit/ors/services/routing/RoutingServiceSettings.java +++ b/openrouteservice/src/main/java/heigit/ors/services/routing/RoutingServiceSettings.java @@ -28,6 +28,7 @@ public class RoutingServiceSettings { private static boolean distanceApproximation = false; private static String storageFormat = "Native"; private static String attribution = ""; + private static String routingName = "openrouteservice directions"; private static AppConfig _config; static @@ -70,6 +71,10 @@ private static void init(AppConfig config) value = config.getServiceParameter("routing", "attribution"); if (value != null) attribution = value; + + value = config.getServiceParameter("routing", "routing_name"); + if (value != null) + routingName = value; } public static Boolean getEnabled() @@ -129,4 +134,8 @@ public static Map getParametersMap(String paramName, boolean quo public static String getAttribution() { return attribution; } + + public static String getRoutingName() { + return routingName; + } } diff --git a/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/geoJson/SimpleFeatureTypesTest.java b/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/geoJson/SimpleFeatureTypesTest.java index 040befd566..701bc14670 100644 --- a/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/geoJson/SimpleFeatureTypesTest.java +++ b/openrouteservice/src/test/java/heigit/ors/globalResponseProcessor/geoJson/SimpleFeatureTypesTest.java @@ -25,20 +25,22 @@ package heigit.ors.globalResponseProcessor.geoJson; +import com.vividsolutions.jts.geom.LineString; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.geotools.feature.simple.SimpleFeatureTypeImpl; import org.opengis.feature.simple.SimpleFeatureType; +import org.opengis.feature.type.GeometryType; -import static heigit.ors.globalResponseProcessor.geoJson.SimpleFeatureTypes.*; + +import static heigit.ors.globalResponseProcessor.geoJson.SimpleFeatureTypes.RouteFeatureType; public class SimpleFeatureTypesTest { private static SimpleFeatureType simpleFeatureType; - /** - * - */ + @BeforeClass public static void setUp() { simpleFeatureType = new SimpleFeatureTypes(RouteFeatureType.routeFeature).create(); @@ -46,6 +48,10 @@ public static void setUp() { @Test public void testCreateRouteFeatureType() { - Assert.assertEquals("SimpleFeatureTypeImpl http://www.opengis.net/gml:ORSRoutingFile identified extends Feature(geometry:geometry)", simpleFeatureType.toString()); + Assert.assertEquals(SimpleFeatureTypeImpl.class, simpleFeatureType.getClass()); + Assert.assertNotNull(simpleFeatureType.getName()); + Assert.assertNotSame(-1, simpleFeatureType.indexOf("geometry")); + GeometryType type = simpleFeatureType.getGeometryDescriptor().getType(); + Assert.assertEquals(LineString.class.getName(), type.getBinding().getName()); } } \ No newline at end of file