Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ List of additional rules:
* `NoInvalidReferenceToPricingPlansInVehicleStatus`
* `NoInvalidReferenceToPricingPlansInVehicleTypes`
* `NoInvalidReferenceToRegionInStationInformation`
* `NoInvalidReferenceToStation`
* `NoInvalidReferenceToVehicleTypesInStationStatus`
* `NoMissingVehicleTypesAvailableWhenVehicleTypesExists`
* `NoMissingOrInvalidVehicleTypeIdInVehicleStatusWhenVehicleTypesExist`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
*
* *
* *
* * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * * the European Commission - subsequent versions of the EUPL (the "Licence");
* * * You may not use this work except in compliance with the Licence.
* * * You may obtain a copy of the Licence at:
* * *
* * * https://joinup.ec.europa.eu/software/page/eupl
* * *
* * * Unless required by applicable law or agreed to in writing, software
* * * distributed under the Licence is distributed on an "AS IS" basis,
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * See the Licence for the specific language governing permissions and
* * * limitations under the Licence.
* *
*
*/

package org.entur.gbfs.validation.validator.rules;

import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;

/**
* References to stations in station_information must exist in station_status file and vice versa.
*/
public class NoInvalidReferenceToStation implements CustomRuleSchemaPatcher {

public static final String STATION_IDS_SCHEMA_PATH =
"$.properties.data.properties.stations.items.properties.station_id";

private final String stationReferenceFileName;

public NoInvalidReferenceToStation(String stationReferenceFileName) {
this.stationReferenceFileName = stationReferenceFileName;
}

/**
* Adds an enum to the station_id schema of stations.station_id with the station ids from station_status.json
*/
@Override
public DocumentContext addRule(
DocumentContext rawSchemaDocumentContext,
Map<String, JSONObject> feeds
) {
JSONObject stationReferenceFeed = feeds.get(stationReferenceFileName);

JSONObject stationIdSchema = rawSchemaDocumentContext.read(
STATION_IDS_SCHEMA_PATH
);

JSONArray stationIds = stationReferenceFeed != null
? JsonPath
.parse(stationReferenceFeed)
.read("$.data.stations[*].station_id")
: new JSONArray();

stationIdSchema.put("enum", stationIds);

return rawSchemaDocumentContext.set(
STATION_IDS_SCHEMA_PATH,
stationIdSchema
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import org.entur.gbfs.validation.validator.rules.CustomRuleSchemaPatcher;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToRegionInStationInformation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToStation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToVehicleTypesInStationStatus;
import org.entur.gbfs.validation.validator.rules.NoMissingCurrentRangeMetersInVehicleStatusForMotorizedVehicles;
import org.entur.gbfs.validation.validator.rules.NoMissingOrInvalidVehicleTypeIdInVehicleStatusWhenVehicleTypesExist;
Expand Down Expand Up @@ -54,7 +55,8 @@ public class Version21 extends AbstractVersion {
"station_status",
List.of(
new NoInvalidReferenceToVehicleTypesInStationStatus(),
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists()
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists(),
new NoInvalidReferenceToStation("station_information")
),
"free_bike_status",
List.of(
Expand All @@ -68,7 +70,10 @@ public class Version21 extends AbstractVersion {
"system_information",
List.of(new NoMissingStoreUriInSystemInformation("free_bike_status")),
"station_information",
List.of(new NoInvalidReferenceToRegionInStationInformation())
List.of(
new NoInvalidReferenceToRegionInStationInformation(),
new NoInvalidReferenceToStation("station_status")
)
);

protected Version21() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.entur.gbfs.validation.validator.rules.CustomRuleSchemaPatcher;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToPricingPlansInVehicleStatus;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToRegionInStationInformation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToStation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToVehicleTypesInStationStatus;
import org.entur.gbfs.validation.validator.rules.NoMissingCurrentRangeMetersInVehicleStatusForMotorizedVehicles;
import org.entur.gbfs.validation.validator.rules.NoMissingOrInvalidVehicleTypeIdInVehicleStatusWhenVehicleTypesExist;
Expand Down Expand Up @@ -55,7 +56,8 @@ public class Version22 extends AbstractVersion {
"station_status",
List.of(
new NoInvalidReferenceToVehicleTypesInStationStatus(),
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists()
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists(),
new NoInvalidReferenceToStation("station_information")
),
"free_bike_status",
List.of(
Expand All @@ -70,7 +72,10 @@ public class Version22 extends AbstractVersion {
"system_information",
List.of(new NoMissingStoreUriInSystemInformation("free_bike_status")),
"station_information",
List.of(new NoInvalidReferenceToRegionInStationInformation())
List.of(
new NoInvalidReferenceToRegionInStationInformation(),
new NoInvalidReferenceToStation("station_status")
)
);

protected Version22() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToPricingPlansInVehicleStatus;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToPricingPlansInVehicleTypes;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToRegionInStationInformation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToStation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToVehicleTypesInStationStatus;
import org.entur.gbfs.validation.validator.rules.NoMissingCurrentRangeMetersInVehicleStatusForMotorizedVehicles;
import org.entur.gbfs.validation.validator.rules.NoMissingOrInvalidVehicleTypeIdInVehicleStatusWhenVehicleTypesExist;
Expand Down Expand Up @@ -58,7 +59,8 @@ public class Version23 extends AbstractVersion {
"station_status",
List.of(
new NoInvalidReferenceToVehicleTypesInStationStatus(),
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists()
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists(),
new NoInvalidReferenceToStation("station_information")
),
"free_bike_status",
List.of(
Expand All @@ -73,7 +75,10 @@ public class Version23 extends AbstractVersion {
"system_information",
List.of(new NoMissingStoreUriInSystemInformation("free_bike_status")),
"station_information",
List.of(new NoInvalidReferenceToRegionInStationInformation())
List.of(
new NoInvalidReferenceToRegionInStationInformation(),
new NoInvalidReferenceToStation("station_status")
)
);

protected Version23() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToPricingPlansInVehicleStatus;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToPricingPlansInVehicleTypes;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToRegionInStationInformation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToStation;
import org.entur.gbfs.validation.validator.rules.NoInvalidReferenceToVehicleTypesInStationStatus;
import org.entur.gbfs.validation.validator.rules.NoMissingCurrentRangeMetersInVehicleStatusForMotorizedVehicles;
import org.entur.gbfs.validation.validator.rules.NoMissingOrInvalidVehicleTypeIdInVehicleStatusWhenVehicleTypesExist;
Expand Down Expand Up @@ -57,7 +58,8 @@ public class Version30 extends AbstractVersion {
"station_status",
List.of(
new NoInvalidReferenceToVehicleTypesInStationStatus(),
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists()
new NoMissingVehicleTypesAvailableWhenVehicleTypesExists(),
new NoInvalidReferenceToStation("station_information")
),
"vehicle_status",
List.of(
Expand All @@ -72,7 +74,10 @@ public class Version30 extends AbstractVersion {
"system_information",
List.of(new NoMissingStoreUriInSystemInformation("vehicle_status")),
"station_information",
List.of(new NoInvalidReferenceToRegionInStationInformation())
List.of(
new NoInvalidReferenceToRegionInStationInformation(),
new NoInvalidReferenceToStation("station_status")
)
);

protected Version30() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
"data": {
"stations": [
{
"station_id": "pga",
"station_id": "station1",
"name": "Parking garage A",
"lat": 12.345678,
"lon": 45.678901,
"vehicle_type_capacity": {
"abc123": 7,
"def456": 9
}
},
{
"station_id": "station2",
"name": "SE Belmont & SE 10th",
"lat": 45.516445,
"lon": -122.655775,
"vehicle_type_capacity": {
"abc123": 0,
"def456": 0
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data":{
"stations":[
{
"station_id":"station12",
"station_id":"station2",
"station_name":"SE Belmont & SE 10 th ",
"is_valet_station":false,
"is_virtual_station":true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data": {
"stations": [
{
"station_id": "station 1",
"station_id": "station1",
"is_installed": true,
"is_renting": true,
"is_returning": true,
Expand All @@ -27,7 +27,7 @@
"count": 0
}]
}, {
"station_id": "station 2",
"station_id": "station2",
"is_installed": true,
"is_renting": true,
"is_returning": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
"data": {
"stations": [
{
"station_id": "pga",
"station_id": "station1",
"name": "Parking garage A",
"lat": 12.345678,
"lon": 45.678901,
"vehicle_type_capacity": {
"abc123": 7,
"def456": 9
}
},
{
"station_id": "station2",
"name": "SE Belmont & SE 10th",
"lat": 45.516445,
"lon": -122.655775,
"vehicle_type_capacity": {
"abc123": 0,
"def456": 0
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data":{
"stations":[
{
"station_id":"station12",
"station_id":"station2",
"station_name":"SE Belmont & SE 10 th ",
"is_valet_station":false,
"is_virtual_station":true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data": {
"stations": [
{
"station_id": "station 1",
"station_id": "station1",
"is_installed": true,
"is_renting": true,
"is_returning": true,
Expand All @@ -27,7 +27,7 @@
"count": 0
}]
}, {
"station_id": "station 2",
"station_id": "station2",
"is_installed": true,
"is_renting": true,
"is_returning": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data": {
"stations": [
{
"station_id": "pga",
"station_id": "station1",
"name": "Parking garage A",
"lat": 12.345678,
"lon": 45.678901,
Expand All @@ -17,6 +17,16 @@
"abc123": 7,
"def456": 9
}
},
{
"station_id": "station2",
"name": "SE Belmont & SE 10th",
"lat": 45.516445,
"lon": -122.655775,
"vehicle_type_capacity": {
"abc123": 0,
"def456": 0
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data": {
"stations": [
{
"station_id": "station12",
"station_id": "station2",
"name": "SE Belmont & SE 10 th",
"lat": 45.516445,
"lon": -122.655775,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"data": {
"stations": [
{
"station_id": "pga",
"station_id": "station1",
"name": [
{
"text": "Parking garage A",
Expand All @@ -31,7 +31,7 @@
]
},
{
"station_id": "station12",
"station_id": "station2",
"name": [
{
"text": "SE Belmont & SE 10th",
Expand Down