From e91e246b6bbf8b3084e904273b73a6685fe2e9bb Mon Sep 17 00:00:00 2001 From: cka-y Date: Wed, 9 Oct 2024 16:58:39 -0400 Subject: [PATCH] fix: PR comments --- .../notice/UnsupportedFeatureTypeNotice.java | 44 +++++++++++++++++++ ...java => UnsupportedGeoJsonTypeNotice.java} | 14 +++--- .../table/GeoJsonFileLoader.java | 19 +++++++- .../table/GtfsGeoJsonFeature.java | 2 + .../validator/NoticeFieldsTest.java | 2 + 5 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedFeatureTypeNotice.java rename core/src/main/java/org/mobilitydata/gtfsvalidator/notice/{UnsupportedLocationTypeNotice.java => UnsupportedGeoJsonTypeNotice.java} (67%) diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedFeatureTypeNotice.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedFeatureTypeNotice.java new file mode 100644 index 0000000000..a083acd3e3 --- /dev/null +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedFeatureTypeNotice.java @@ -0,0 +1,44 @@ +/* + * Copyright 2024 MobilityData LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mobilitydata.gtfsvalidator.notice; + +import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR; + +import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; + +/** + * An unsupported feature type is used in the `locations.geojson` file. + * + *

Use `Feature` instead to comply with the spec. + */ +@GtfsValidationNotice(severity = ERROR) +public class UnsupportedFeatureTypeNotice extends ValidationNotice { + + /** The value of the unsupported GeoJSON type. */ + Integer featureIndex; + + /** The id of the faulty record. */ + String featureId; + + /** The feature type of the faulty record. */ + String featureType; + + public UnsupportedFeatureTypeNotice(Integer featureIndex, String featureId, String featureType) { + this.featureIndex = featureIndex; + this.featureId = featureId; + this.featureType = featureType; + } +} diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedLocationTypeNotice.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java similarity index 67% rename from core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedLocationTypeNotice.java rename to core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java index bc11bb1475..e75482c293 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedLocationTypeNotice.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/notice/UnsupportedGeoJsonTypeNotice.java @@ -20,17 +20,17 @@ import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice; /** - * An unsupported location type is used in the `locations.geojson` file. + * An unsupported GeoJSON type is used in the `locations.geojson` file. * - *

The supported type is `FeatureCollection`. + *

Use `FeatureCollection` instead to comply with the spec. */ @GtfsValidationNotice(severity = ERROR) -public class UnsupportedLocationTypeNotice extends ValidationNotice { +public class UnsupportedGeoJsonTypeNotice extends ValidationNotice { - /** The value of the unsupported location type. */ - private final String locationTypeValue; + /** The value of the unsupported GeoJSON type. */ + private final String geoJsonType; - public UnsupportedLocationTypeNotice(String locationTypeValue) { - this.locationTypeValue = locationTypeValue; + public UnsupportedGeoJsonTypeNotice(String geoJsonType) { + this.geoJsonType = geoJsonType; } } diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java index 3fe5b2aa2d..dccfa1df28 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GeoJsonFileLoader.java @@ -67,7 +67,7 @@ public List extractFeaturesFromStream( throw new UnparsableGeoJsonFeatureException("Missing required field 'type'"); } else if (!jsonObject.get("type").getAsString().equals("FeatureCollection")) { noticeContainer.addValidationNotice( - new UnsupportedLocationTypeNotice(jsonObject.get("type").getAsString())); + new UnsupportedGeoJsonTypeNotice(jsonObject.get("type").getAsString())); throw new UnparsableGeoJsonFeatureException("Unsupported GeoJSON type"); } JsonArray featuresArray = jsonObject.getAsJsonArray("features"); @@ -109,6 +109,23 @@ public GtfsGeoJsonFeature extractFeature( } } + // Handle feature type + if (!featureObject.has(GtfsGeoJsonFeature.FEATURE_TYPE_FIELD_NAME)) { + missingRequiredFields.add( + GtfsGeoJsonFeature.FEATURE_COLLECTION_FIELD_NAME + + '.' + + GtfsGeoJsonFeature.FEATURE_TYPE_FIELD_NAME); + } else if (!featureObject + .get(GtfsGeoJsonFeature.FEATURE_TYPE_FIELD_NAME) + .getAsString() + .equals("Feature")) { + noticeContainer.addValidationNotice( + new UnsupportedFeatureTypeNotice( + featureIndex, + featureId, + featureObject.get(GtfsGeoJsonFeature.FEATURE_TYPE_FIELD_NAME).getAsString())); + } + // Handle properties if (!featureObject.has(GtfsGeoJsonFeature.FEATURE_PROPERTIES_FIELD_NAME)) { missingRequiredFields.add( diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsGeoJsonFeature.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsGeoJsonFeature.java index df92a21c98..a7e75d4ab5 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsGeoJsonFeature.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsGeoJsonFeature.java @@ -13,6 +13,8 @@ public final class GtfsGeoJsonFeature implements GtfsEntity { public static final String FEATURE_ID_FIELD_NAME = "id"; + public static final String FEATURE_TYPE_FIELD_NAME = "type"; + public static final String FEATURE_PROPERTIES_FIELD_NAME = "properties"; public static final String FEATURE_PROPERTIES_STOP_NAME_FIELD_NAME = "stop_name"; public static final String FEATURE_PROPERTIES_STOP_DESC_FIELD_NAME = "stop_desc"; diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java index b5f2d61353..6a1a55ae91 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java @@ -91,6 +91,7 @@ public void testNoticeClassFieldNames() { "fareMediaId2", "featureId", "featureIndex", + "featureType", "feedEndDate", "feedLang", "fieldName", @@ -106,6 +107,7 @@ public void testNoticeClassFieldNames() { "filename", "firstIndex", "geoDistanceToShape", + "geoJsonType", "geometryType", "hasEntrance", "hasExit",