Skip to content

Commit

Permalink
fix: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y committed Oct 9, 2024
1 parent 4a14710 commit e91e246
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>The supported type is `FeatureCollection`.
* <p>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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public List<GtfsGeoJsonFeature> 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");
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void testNoticeClassFieldNames() {
"fareMediaId2",
"featureId",
"featureIndex",
"featureType",
"feedEndDate",
"feedLang",
"fieldName",
Expand All @@ -106,6 +107,7 @@ public void testNoticeClassFieldNames() {
"filename",
"firstIndex",
"geoDistanceToShape",
"geoJsonType",
"geometryType",
"hasEntrance",
"hasExit",
Expand Down

0 comments on commit e91e246

Please sign in to comment.