Search in sources :

Example 11 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class UtilityLibrary method getGtfsBundlesForArguments.

public static List<GtfsBundle> getGtfsBundlesForArguments(List<String> args) {
    List<GtfsBundle> allBundles = new ArrayList<GtfsBundle>();
    List<String> contextPaths = new ArrayList<String>();
    int defaultAgencyIdOffset = 99990;
    for (String arg : args) {
        if (arg.endsWith(".xml"))
            contextPaths.add("file:" + arg);
        else {
            String defaultAgencyId = null;
            int index = arg.indexOf(':');
            if (index != -1) {
                defaultAgencyId = arg.substring(index + 1);
                arg = arg.substring(0, index);
            } else {
                defaultAgencyId = Integer.toString(defaultAgencyIdOffset++);
            }
            GtfsBundle bundle = new GtfsBundle();
            bundle.setPath(new File(arg));
            bundle.setDefaultAgencyId(defaultAgencyId);
            allBundles.add(bundle);
        }
    }
    if (!contextPaths.isEmpty()) {
        // This will get us basic behavior like property expansion
        contextPaths.add(0, "classpath:org/onebusaway/container/application-context-common.xml");
        ConfigurableApplicationContext context = ContainerLibrary.createContext(contextPaths);
        GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
        allBundles.addAll(bundles.getBundles());
    }
    return allBundles;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) ArrayList(java.util.ArrayList) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles) File(java.io.File)

Example 12 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class BundleBuildingServiceImpl method createGtfsBundles.

private List<GtfsBundle> createGtfsBundles(BundleBuildResponse response) {
    List<String> gtfsList = response.getGtfsList();
    final String gtfsMsg = "constructing configuration for bundles=" + gtfsList;
    response.addStatusMessage(gtfsMsg);
    _log.info(gtfsMsg);
    List<GtfsBundle> bundles = new ArrayList<GtfsBundle>(gtfsList.size());
    String defaultAgencyId = getDefaultAgencyId();
    response.addStatusMessage("default agency configured to be |" + defaultAgencyId + "|");
    for (String path : gtfsList) {
        GtfsBundle gtfsBundle = new GtfsBundle();
        gtfsBundle.setPath(new File(path));
        String agencySpecificId = getAgencySpecificId(path);
        if (agencySpecificId != null) {
            _log.info("using agency specific id=" + agencySpecificId);
            gtfsBundle.setDefaultAgencyId(agencySpecificId);
        } else {
            if (defaultAgencyId != null && defaultAgencyId.length() > 0) {
                final String msg = "for bundle " + path + " setting defaultAgencyId='" + defaultAgencyId + "'";
                response.addStatusMessage(msg);
                _log.info(msg);
                gtfsBundle.setDefaultAgencyId(defaultAgencyId);
            }
        }
        Map<String, String> mappings = getAgencyIdMappings(path);
        if (mappings != null) {
            _log.info("using agency specific mappings=" + mappings);
            gtfsBundle.setAgencyIdMappings(mappings);
        }
        bundles.add(gtfsBundle);
    }
    return bundles;
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) ArrayList(java.util.ArrayList) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 13 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class BaseModTask method getGtfsBundles.

protected GtfsBundles getGtfsBundles(ApplicationContext context) {
    GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
    if (bundles != null)
        return bundles;
    GtfsBundle bundle = (GtfsBundle) context.getBean("gtfs-bundle");
    if (bundle != null) {
        bundles = new GtfsBundles();
        bundles.getBundles().add(bundle);
        return bundles;
    }
    throw new IllegalStateException("must define either \"gtfs-bundles\" or \"gtfs-bundle\" in config");
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 14 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class GtfsArchiveTask method getGtfsBundles.

protected GtfsBundles getGtfsBundles(ApplicationContext context) {
    GtfsBundles bundles = (GtfsBundles) context.getBean("gtfs-bundles");
    if (bundles != null)
        return bundles;
    GtfsBundle bundle = (GtfsBundle) context.getBean("gtfs-bundle");
    if (bundle != null) {
        bundles = new GtfsBundles();
        bundles.getBundles().add(bundle);
        return bundles;
    }
    throw new IllegalStateException("must define either \"gtfs-bundles\" or \"gtfs-bundle\" in config");
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) GtfsBundles(org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)

Example 15 with GtfsBundle

use of org.onebusaway.transit_data_federation.bundle.model.GtfsBundle in project onebusaway-application-modules by camsys.

the class GtfsFullValidationTask method processGtfsBundles.

private void processGtfsBundles(GtfsBundles gtfsBundles) {
    List<GtfsFullValidationTaskJobResult> results = new ArrayList<GtfsFullValidationTaskJobResult>();
    for (GtfsBundle gtfsBundle : gtfsBundles.getBundles()) {
        try {
            results.add(submitJob(_validateService, gtfsBundle));
        } catch (Exception any) {
            _log.error("GtfsFullValidationTask failed for gtfsBundle:" + gtfsBundle.getPath().getName(), any);
        }
    }
    try {
        // give the executor a chance to run
        Thread.sleep(1 * 1000);
    } catch (InterruptedException e1) {
        return;
    }
    // here we wait on the tasks to finish up
    int i = 0;
    for (GtfsFullValidationTaskJobResult result : results) {
        while (!result.isDone()) {
            try {
                _log.info("waiting on thread[" + i + "/" + results.size() + "] " + result.getCsvFileName());
                Thread.sleep(10 * 1000);
            } catch (InterruptedException e) {
                return;
            }
        }
        i++;
        _log.info("result " + result.getCsvFileName() + " completed in " + result.getRunTime() / 1000 + "s");
        // process the results in the order they were submitted
        processResult(result);
    }
}
Also used : GtfsBundle(org.onebusaway.transit_data_federation.bundle.model.GtfsBundle) ArrayList(java.util.ArrayList)

Aggregations

GtfsBundle (org.onebusaway.transit_data_federation.bundle.model.GtfsBundle)19 GtfsBundles (org.onebusaway.transit_data_federation.bundle.model.GtfsBundles)13 ArrayList (java.util.ArrayList)7 File (java.io.File)6 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)4 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ZipFile (java.util.zip.ZipFile)2 CommandLine (org.apache.commons.cli.CommandLine)2 GnuParser (org.apache.commons.cli.GnuParser)2 Options (org.apache.commons.cli.Options)2 ParseException (org.apache.commons.cli.ParseException)2 Parser (org.apache.commons.cli.Parser)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 LineString (com.vividsolutions.jts.geom.LineString)1 BufferedReader (java.io.BufferedReader)1