Search in sources :

Example 16 with GtfsRelationalDaoImpl

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

the class AgencyMergeStrategyTest method testRenameAllAgencyIdReferences.

@Test
public void testRenameAllAgencyIdReferences() {
    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");
    agencyA.setName("Metra");
    agencyA.setUrl("http://metra.gov/");
    sourceB.saveEntity(agencyB);
    Route route = new Route();
    route.setAgency(agencyB);
    route.setId(new AgencyAndId("1", "routeId"));
    sourceB.saveEntity(route);
    Trip trip = new Trip();
    trip.setRoute(route);
    trip.setId(new AgencyAndId("1", "tripId"));
    trip.setServiceId(new AgencyAndId("1", "serviceId"));
    trip.setShapeId(new AgencyAndId("1", "shapeId"));
    sourceB.saveEntity(trip);
    FareAttribute fare = new FareAttribute();
    fare.setId(new AgencyAndId("1", "fareId"));
    sourceB.saveEntity(fare);
    Stop stop = new Stop();
    stop.setId(new AgencyAndId("1", "stopId"));
    sourceB.saveEntity(stop);
    ServiceCalendar calendar = new ServiceCalendar();
    calendar.setServiceId(new AgencyAndId("1", "serviceId"));
    sourceB.saveEntity(calendar);
    ServiceCalendarDate calendarDate = new ServiceCalendarDate();
    calendarDate.setServiceId(new AgencyAndId("1", "serviceId"));
    sourceB.saveEntity(calendarDate);
    ShapePoint point = new ShapePoint();
    point.setShapeId(new AgencyAndId("1", "shapeId"));
    sourceB.saveEntity(point);
    _strategy.merge(context(sourceA, _target, "a-"));
    _strategy.merge(context(sourceB, _target, "b-"));
    Collection<Agency> agencies = _target.getAllAgencies();
    assertEquals(2, agencies.size());
    assertSame(agencyA, _target.getAgencyForId("1"));
    assertSame(agencyB, _target.getAgencyForId("b-1"));
    assertEquals("b-1", route.getId().getAgencyId());
    assertEquals("b-1", trip.getId().getAgencyId());
    assertEquals("b-1", trip.getServiceId().getAgencyId());
    assertEquals("b-1", trip.getShapeId().getAgencyId());
    assertEquals("b-1", fare.getId().getAgencyId());
    assertEquals("b-1", stop.getId().getAgencyId());
    assertEquals("b-1", calendar.getServiceId().getAgencyId());
    assertEquals("b-1", calendarDate.getServiceId().getAgencyId());
    assertEquals("b-1", point.getShapeId().getAgencyId());
}
Also used : FareAttribute(org.onebusaway.gtfs.model.FareAttribute) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 17 with GtfsRelationalDaoImpl

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

the class AgencyMergeStrategyTest method testFuzzyMatchAgencyName.

@Test
public void testFuzzyMatchAgencyName() {
    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("Metra");
    agencyB.setUrl("http://metra.gov/");
    sourceB.saveEntity(agencyB);
    Agency agencyC = new Agency();
    agencyC.setId("2");
    agencyC.setName("Metro");
    agencyC.setUrl("http://metro.gov/");
    sourceB.saveEntity(agencyC);
    GtfsMergeContext contextA = context(sourceA, _target, "a-");
    _strategy.merge(contextA);
    GtfsMergeContext contextB = context(sourceB, _target, "b-");
    _strategy.merge(contextB);
    assertEquals(EDuplicateDetectionStrategy.FUZZY, contextB.getResolvedDuplicateDetectionStrategy());
    Collection<Agency> agencies = _target.getAllAgencies();
    assertEquals(2, agencies.size());
    assertSame(agencyA, _target.getAgencyForId("1"));
    assertSame(agencyB, _target.getAgencyForId("b-1"));
}
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 18 with GtfsRelationalDaoImpl

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

the class GtfsMergerTest method merge.

private GtfsRelationalDao merge() throws IOException {
    List<File> paths = new ArrayList<File>();
    paths.add(_oldGtfs.getPath());
    paths.add(_newGtfs.getPath());
    if (_pugetGtfs != null) {
        paths.add(_pugetGtfs.getPath());
    }
    _merger.run(paths, _mergedGtfs.getPath());
    GtfsReader reader = new GtfsReader();
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    reader.setEntityStore(dao);
    reader.setInputLocation(_mergedGtfs.getPath());
    reader.run();
    return dao;
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) ArrayList(java.util.ArrayList) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) File(java.io.File)

Example 19 with GtfsRelationalDaoImpl

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

the class GtfsTransformer method readReferenceGtfs.

private void readReferenceGtfs() throws IOException {
    _log.info("reading reference GTFS at " + _gtfsReferenceDirectory);
    GenericMutableDao dao = new GtfsRelationalDaoImpl();
    _referenceReader.setEntityStore(dao);
    if (_agencyId != null)
        _referenceReader.setDefaultAgencyId(_agencyId);
    _referenceReader.setInputLocation(_gtfsReferenceDirectory);
    _referenceReader.run();
    _context.setReferenceReader(_referenceReader);
}
Also used : GenericMutableDao(org.onebusaway.gtfs.services.GenericMutableDao) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)

Example 20 with GtfsRelationalDaoImpl

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

the class LastStopToHeadsignStrategyTest method setup.

@Before
public void setup() throws IOException, URISyntaxException {
    _dao = new GtfsRelationalDaoImpl();
    GtfsReader reader = new GtfsReader();
    File path = new File(getClass().getResource("/org/onebusaway/gtfs_transformer/testagency").toURI());
    reader.setInputLocation(path);
    reader.setEntityStore(_dao);
    reader.run();
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) File(java.io.File) 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