Search in sources :

Example 6 with GtfsReader

use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.

the class AbstractTestSupport method transform.

protected GtfsRelationalDao transform() {
    try {
        _transformer.run();
        GtfsReader reader = new GtfsReader();
        reader.setInputLocation(_outputPath);
        GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
        reader.setEntityStore(dao);
        reader.run();
        return dao;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) IOException(java.io.IOException)

Example 7 with GtfsReader

use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.

the class EntityRetentionGraphTest method setup.

@Before
public void setup() throws IOException {
    _dao = new GtfsRelationalDaoImpl();
    _graph = new EntityRetentionGraph(_dao);
    GtfsReader reader = new GtfsReader();
    File path = new File(getClass().getResource("/org/onebusaway/gtfs_transformer/testagency").getPath());
    reader.setInputLocation(path);
    reader.setEntityStore(_dao);
    reader.run();
}
Also used : EntityRetentionGraph(org.onebusaway.gtfs_transformer.factory.EntityRetentionGraph) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) File(java.io.File) Before(org.junit.Before)

Example 8 with GtfsReader

use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTestData method readGtfs.

public static <T extends GenericMutableDao> void readGtfs(T entityStore, File resourcePath, String defaultAgencyId) throws IOException {
    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId(defaultAgencyId);
    reader.setInputLocation(resourcePath);
    reader.setEntityStore(entityStore);
    reader.run();
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader)

Example 9 with GtfsReader

use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderExampleMain method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("usage: gtfsPath");
        System.exit(-1);
    }
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    /**
     * You can register an entity handler that listens for new objects as they
     * are read
     */
    reader.addEntityHandler(new GtfsEntityHandler());
    /**
     * Or you can use the internal entity store, which has references to all the
     * loaded entities
     */
    GtfsDaoImpl store = new GtfsDaoImpl();
    reader.setEntityStore(store);
    reader.run();
    // Access entities through the store
    Map<AgencyAndId, Route> routesById = store.getEntitiesByIdForEntityType(AgencyAndId.class, Route.class);
    for (Route route : routesById.values()) {
        System.out.println("route: " + route.getShortName());
    }
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsDaoImpl(org.onebusaway.gtfs.impl.GtfsDaoImpl) File(java.io.File) Route(org.onebusaway.gtfs.model.Route)

Example 10 with GtfsReader

use of org.onebusaway.gtfs.serialization.GtfsReader in project onebusaway-gtfs-modules by OneBusAway.

the class EntityCounterMain method main.

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("usage: path/to/gtfs_feed");
        System.exit(-1);
    }
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    EntityCounter counter = new EntityCounter();
    reader.addEntityHandler(counter);
    reader.run();
    Map<Class<?>, Integer> counts = counter.getCounts();
    List<Class<?>> types = new ArrayList<Class<?>>(counts.keySet());
    Collections.sort(types, new ClassNameComparator());
    for (Class<?> type : types) System.out.println(type.getName() + " " + counts.get(type));
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)16 File (java.io.File)10 Configuration (org.hibernate.cfg.Configuration)5 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)4 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 Stop (org.onebusaway.gtfs.model.Stop)3 Test (org.junit.Test)2 DefaultEntitySchemaFactory (org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)2 GtfsWriter (org.onebusaway.gtfs.serialization.GtfsWriter)2 GtfsWriterTest (org.onebusaway.gtfs.serialization.GtfsWriterTest)2 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)2 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CommandLine (org.apache.commons.cli.CommandLine)1