Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 1927 flex geo json parsing failed #1947

Merged
merged 9 commits into from
Jan 28, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public class MalformedJsonNotice extends ValidationNotice {
/** The name of the faulty file. */
private final String filename;

public MalformedJsonNotice(String filename) {
/** The detailed message describing the error. */
private final String message;

public MalformedJsonNotice(String filename, String message) {
this.filename = filename;
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public class UnsupportedGeoJsonTypeNotice extends ValidationNotice {
/** The value of the unsupported GeoJSON type. */
private final String geoJsonType;

public UnsupportedGeoJsonTypeNotice(String geoJsonType) {
/** The detailed message describing the error. */
private final String message;

public UnsupportedGeoJsonTypeNotice(String geoJsonType, String message) {
this.geoJsonType = geoJsonType;
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public GtfsEntityContainer load(
List<GtfsGeoJsonFeature> entities = extractFeaturesFromStream(inputStream, noticeContainer);
return geoJsonFileDescriptor.createContainerForEntities(entities, noticeContainer);
} catch (JsonParseException jpex) {
noticeContainer.addValidationNotice(new MalformedJsonNotice(GtfsGeoJsonFeature.FILENAME));
noticeContainer.addValidationNotice(
new MalformedJsonNotice(GtfsGeoJsonFeature.FILENAME, jpex.getMessage()));
logger.atSevere().withCause(jpex).log("Malformed JSON in locations.geojson");
return fileDescriptor.createContainerForInvalidStatus(TableStatus.UNPARSABLE_ROWS);
} catch (IOException ioex) {
Expand All @@ -55,6 +56,15 @@ public GtfsEntityContainer load(
}
}

/**
* Extracts features from the provided GeoJSON input stream.
*
* @param inputStream the input stream containing GeoJSON data
* @param noticeContainer the container to collect validation notices
* @return a list of parsed GeoJSON features
* @throws IOException if an I/O error occurs while reading the input stream
* @throws UnparsableGeoJsonFeatureException if any GeoJSON feature is unparsable
*/
public List<GtfsGeoJsonFeature> extractFeaturesFromStream(
InputStream inputStream, NoticeContainer noticeContainer)
throws IOException, UnparsableGeoJsonFeatureException {
Expand All @@ -67,7 +77,11 @@ public List<GtfsGeoJsonFeature> extractFeaturesFromStream(
throw new UnparsableGeoJsonFeatureException("Missing required field 'type'");
} else if (!jsonObject.get("type").getAsString().equals("FeatureCollection")) {
noticeContainer.addValidationNotice(
new UnsupportedGeoJsonTypeNotice(jsonObject.get("type").getAsString()));
new UnsupportedGeoJsonTypeNotice(
jsonObject.get("type").getAsString(),
"Unsupported GeoJSON type: "
+ jsonObject.get("type").getAsString()
+ ". Use 'FeatureCollection' instead."));
throw new UnparsableGeoJsonFeatureException("Unsupported GeoJSON type");
}
JsonArray featuresArray = jsonObject.getAsJsonArray("features");
Expand Down
Loading