Search in sources :

Example 11 with GtfsRelationalDaoImpl

use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.

the class TransformFactoryTest method testPathInUpdate.

@Test
public void testPathInUpdate() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 'path(route.longName)'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Route route = new Route();
    route.setLongName("long cat");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "1"));
    trip.setRoute(route);
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("long cat", trip.getTripHeadsign());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 12 with GtfsRelationalDaoImpl

use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project OpenTripPlanner by opentripplanner.

the class GtfsLibrary method readGtfs.

public static GtfsContext readGtfs(File path) throws IOException {
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(path);
    reader.setEntityStore(dao);
    GtfsFeedId feedId = new GtfsFeedId.Builder().fromGtfsFeed(reader.getInputSource()).build();
    reader.setDefaultAgencyId(feedId.getId());
    reader.run();
    CalendarService calendarService = createCalendarService(dao);
    return new GtfsContextImpl(feedId, dao, calendarService);
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService)

Example 13 with GtfsRelationalDaoImpl

use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderTest method processFeed.

/**
 **
 * Private Methods
 ***
 */
private GtfsRelationalDao processFeed(File resourcePath, String agencyId, boolean internStrings) throws IOException {
    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId(agencyId);
    reader.setInternStrings(internStrings);
    reader.setInputLocation(resourcePath);
    GtfsRelationalDaoImpl entityStore = new GtfsRelationalDaoImpl();
    entityStore.setGenerateIds(true);
    reader.setEntityStore(entityStore);
    reader.run();
    return entityStore;
}
Also used : GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)

Example 14 with GtfsRelationalDaoImpl

use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.

the class AgencyMergeStrategyTest method testIdentityMatch.

@Test
public void testIdentityMatch() {
    GtfsRelationalDaoImpl sourceA = new GtfsRelationalDaoImpl();
    Agency agencyA = new Agency();
    agencyA.setId("1");
    agencyA.setName("Metro");
    agencyA.setUrl("http://metro.gov/");
    sourceA.saveEntity(agencyA);
    GtfsRelationalDaoImpl sourceB = new GtfsRelationalDaoImpl();
    Agency agencyB = new Agency();
    agencyB.setId("1");
    agencyB.setName("Metro");
    agencyB.setUrl("http://metro.gov/");
    sourceB.saveEntity(agencyB);
    Agency agencyC = new Agency();
    agencyC.setId("2");
    agencyC.setName("Metra");
    agencyC.setUrl("http://metra.gov/");
    sourceB.saveEntity(agencyC);
    GtfsMergeContext contextA = context(sourceA, _target, "a-");
    _strategy.merge(contextA);
    GtfsMergeContext contextB = context(sourceB, _target, "b-");
    _strategy.merge(contextB);
    assertEquals(EDuplicateDetectionStrategy.IDENTITY, contextB.getResolvedDuplicateDetectionStrategy());
    Collection<Agency> agencies = _target.getAllAgencies();
    assertEquals(2, agencies.size());
    assertSame(agencyA, _target.getAgencyForId("1"));
    assertSame(agencyC, _target.getAgencyForId("2"));
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) GtfsMergeContext(org.onebusaway.gtfs_merge.GtfsMergeContext) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Test(org.junit.Test)

Example 15 with GtfsRelationalDaoImpl

use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.

the class AgencyMergeStrategyTest method before.

@Before
public void before() {
    _strategy = new AgencyMergeStrategy();
    _target = new GtfsRelationalDaoImpl();
}
Also used : GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Before(org.junit.Before)

Aggregations

GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)34 Test (org.junit.Test)19 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 Agency (org.onebusaway.gtfs.model.Agency)10 Trip (org.onebusaway.gtfs.model.Trip)9 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)8 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)7 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)6 File (java.io.File)5 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)5 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)5 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Before (org.junit.Before)4 Route (org.onebusaway.gtfs.model.Route)3 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)3 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)3 Stop (org.onebusaway.gtfs.model.Stop)3 IOException (java.io.IOException)2