diff --git a/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java b/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java index 9603af95d..98c0f1000 100644 --- a/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java +++ b/onebusaway-gtfs-transformer-cli/src/main/java/org/onebusaway/gtfs_transformer/GtfsTransformerMain.java @@ -72,6 +72,8 @@ public class GtfsTransformerMain { private static final String ARG_OMNY_STOPS_FILE = "omnyStopsFile"; + private static final String ARG_VERIFY_ROUTES_FILE = "verifyRoutesFile"; + private static final String ARG_LOCAL_VS_EXPRESS = "localVsExpress"; private static final String ARG_CHECK_STOP_TIMES = "checkStopTimes"; @@ -158,6 +160,7 @@ protected void buildOptions(Options options) { options.addOption(ARG_CONCURRENCY_FILE, true, "file to remap wrong way concurrencies"); options.addOption(ARG_OMNY_ROUTES_FILE, true, "file to add OMNY enabled routes to GTFS"); options.addOption(ARG_OMNY_STOPS_FILE, true, "file to add OMNY enabled stops to GTFS"); + options.addOption(ARG_VERIFY_ROUTES_FILE, true, "file to check route names vs route ids in GTFS"); options.addOption(ARG_LOCAL_VS_EXPRESS, false, "add additional local vs express fields"); @@ -257,6 +260,10 @@ protected void runApplication(CommandLine cli, String[] originalArgs) configureOmnyStopsFile(transformer, option.getValue()); } + if (name.equals(ARG_VERIFY_ROUTES_FILE)) { + configureVerifyRoutesFile(transformer, option.getValue()); + } + if (name.equals(ARG_LOCAL_VS_EXPRESS)) configureLocalVsExpressUpdates(transformer); @@ -350,6 +357,10 @@ private void configureOmnyStopsFile(GtfsTransformer updater, String file) { updater.addParameter("omnyStopsFile", file); } + private void configureVerifyRoutesFile(GtfsTransformer updater, String file) { + updater.addParameter("verifyRoutesFile", file); + } + /***************************************************************************** * Protected Methods ****************************************************************************/ diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java index 92017fe51..0bf5a159e 100644 --- a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/factory/TransformFactory.java @@ -237,6 +237,9 @@ else if (opType.equals("update_stop_id_by_id")) { else if (opType.equals("update_route_name")) { handleTransformOperation(line, json, new UpdateRouteNames()); } + else if (opType.equals("validate_gtfs")) { + handleTransformOperation(line, json, new ValidateGTFS()); + } else if (opType.equals("count_and_test")) { handleTransformOperation(line, json, new CountAndTest()); } @@ -289,11 +292,14 @@ else if (opType.equals("add_omny_subway_data")) { handleTransformOperation(line, json, new AddOmnySubwayData()); } else if (opType.equals("add_omny_lirr_data")) { - handleTransformOperation(line, json, new AddOmnyLIRRData()); + handleTransformOperation(line, json, new AddStopZoneId()); } else if (opType.equals("add_omny_bus_data")) { handleTransformOperation(line, json, new AddOmnyBusData()); } + else if (opType.equals("verify_route_ids")) { + handleTransformOperation(line, json, new VerifyRouteIds()); + } else if (opType.equals("transform")) { handleTransformOperation(line, json); } else { diff --git a/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyRouteIds.java b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyRouteIds.java new file mode 100644 index 000000000..53c33fc61 --- /dev/null +++ b/onebusaway-gtfs-transformer/src/main/java/org/onebusaway/gtfs_transformer/impl/VerifyRouteIds.java @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2019 Cambridge Systematics, Inc. + * + * 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.onebusaway.gtfs_transformer.impl; + +import org.onebusaway.gtfs.model.AgencyAndId; +import org.onebusaway.gtfs.model.Route; +import org.onebusaway.gtfs.services.GtfsMutableRelationalDao; +import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy; +import org.onebusaway.gtfs_transformer.services.TransformContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.List; + +public class VerifyRouteIds implements GtfsTransformStrategy { + + //routes + private static final int ROUTE_ID = 0; + private static final int ROUTE_NAME = 1; + + + private static Logger _log = LoggerFactory.getLogger(VerifyRouteIds.class); + + public String getName() { + return this.getClass().getName(); + } + + @Override + public void run(TransformContext context, GtfsMutableRelationalDao dao) { + + String agency = dao.getAllTrips().iterator().next().getId().getAgencyId(); + + File routesFile = new File((String)context.getParameter("verifyRoutesFile")); + if(!routesFile.exists()) { + throw new IllegalStateException( + "verifyRouteIds Routes file does not exist: " + routesFile.getName()); + } + + List routeLines = new InputLibrary().readList((String) context.getParameter("verifyRoutesFile")); + _log.info("Length of route file: {}", routeLines.size()); + + for (String routeInfo : routeLines) { + String[] routeArray = routeInfo.split(","); + if (routeArray == null) { + _log.info("routeArray is null"); + continue; + } + if (routeArray.length < 2) { + _log.info("routeArray.length: {} {}", routeArray.length, routeInfo); + continue; + } + + String routeId = routeArray[ROUTE_ID]; + String routeName = routeArray[ROUTE_NAME]; + + Route route = dao.getRouteForId(new AgencyAndId(agency, routeId)); + if (route != null ) { + if (!route.getLongName().contains(routeName)) { + _log.error("NJT MNR West of Hudson Route Id->Route name error. CSV routeId: {} routeName: {} GTFS Route id: {}, longName {}", routeId, routeName, route.getId().getId(), route.getLongName()); + throw new IllegalStateException( + "NJT MNR West of Hudson Route Id->Route name error. Route id is for unexpected route name"); + } + } + else { + _log.error("NJT MNR West of Hudson Route Id->Route name error. Route id is not present in GTFS. Expected CSV routeId: {} routeName: {}", routeId, routeName); + throw new IllegalStateException( + "NJT MNR West of Hudson Route Id->Route name error. Route is null"); + } + } + } +}