Search in sources :

Example 11 with ServiceCalendarDate

use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.

the class ServiceIdTransformStrategyImpl method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
    AgencyAndId oldServiceId = context.resolveId(ServiceIdKey.class, _oldServiceId);
    AgencyAndId newServiceId = context.resolveId(ServiceIdKey.class, _newServiceId);
    ServiceCalendar calendar = dao.getCalendarForServiceId(oldServiceId);
    if (calendar != null) {
        calendar.setServiceId(newServiceId);
    }
    for (ServiceCalendarDate calendarDate : dao.getCalendarDatesForServiceId(oldServiceId)) {
        calendarDate.setServiceId(newServiceId);
    }
    for (Trip trip : dao.getTripsForServiceId(oldServiceId)) {
        trip.setServiceId(newServiceId);
    }
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 12 with ServiceCalendarDate

use of org.onebusaway.gtfs.model.ServiceCalendarDate 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 13 with ServiceCalendarDate

use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.

the class ServiceCalendarMergeStrategy method renameKey.

/**
   * Replaces all references to the specified old service_id with the new
   * service_id for all {@link ServiceCalendar}, {@link ServiceCalendarDate},
   * and {@link Trip} entities in the source feed.
   */
@Override
protected void renameKey(GtfsMergeContext context, AgencyAndId oldId, AgencyAndId newId) {
    GtfsRelationalDao source = context.getSource();
    ServiceCalendar calendar = source.getCalendarForServiceId(oldId);
    if (calendar != null) {
        calendar.setServiceId(newId);
    }
    for (ServiceCalendarDate calendarDate : source.getCalendarDatesForServiceId(oldId)) {
        calendarDate.setServiceId(newId);
    }
    for (Trip trip : source.getTripsForServiceId(oldId)) {
        trip.setServiceId(newId);
    }
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 14 with ServiceCalendarDate

use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.

the class ServiceCalendarMergeStrategy method saveElementsForKey.

/**
   * Writes all {@link ServiceCalendar} and {@link ServiceCalendarDate} entities
   * with the specified {@code service_id} to the merged output feed.
   */
@Override
protected void saveElementsForKey(GtfsMergeContext context, AgencyAndId serviceId) {
    GtfsRelationalDao source = context.getSource();
    GtfsMutableRelationalDao target = context.getTarget();
    ServiceCalendar calendar = source.getCalendarForServiceId(serviceId);
    if (calendar != null) {
        calendar.setId(0);
        target.saveEntity(calendar);
    }
    for (ServiceCalendarDate calendarDate : source.getCalendarDatesForServiceId(serviceId)) {
        calendarDate.setId(0);
        target.saveEntity(calendarDate);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 15 with ServiceCalendarDate

use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.

the class EntityRetentionGraph method retainServiceId.

private void retainServiceId(AgencyAndId serviceId, boolean retainUp) {
    if (retainUp) {
        // Retain up: retain things that depend on the target object
        for (Trip trip : _dao.getTripsForServiceId(serviceId)) {
            retainUp(trip);
        }
    } else {
        // Retain down: retain things that the target object depends on
        ServiceCalendar calendar = _dao.getCalendarForServiceId(serviceId);
        if (calendar != null)
            retainDown(calendar);
        for (ServiceCalendarDate calendarDate : _dao.getCalendarDatesForServiceId(serviceId)) retainDown(calendarDate);
        /**
       * Need to make sure a service id's agency is included as well, since the
       * agency might not be included by any trips serving that service id
       */
        String agencyId = serviceId.getAgencyId();
        Agency agency = _dao.getAgencyForId(agencyId);
        if (agency != null) {
            retainDown(agency);
        }
    }
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Aggregations

ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)23 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)15 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)10 Agency (org.onebusaway.gtfs.model.Agency)8 Route (org.onebusaway.gtfs.model.Route)5 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)5 Stop (org.onebusaway.gtfs.model.Stop)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)4 StopTime (org.onebusaway.gtfs.model.StopTime)4 Calendar (java.util.Calendar)3 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)3 FareRule (org.onebusaway.gtfs.model.FareRule)3 Frequency (org.onebusaway.gtfs.model.Frequency)3 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2