use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationStrategy method computeUpdatedTripIdForMergedTripsIfApplicable.
private AgencyAndId computeUpdatedTripIdForMergedTripsIfApplicable(Map<AgencyAndId, List<AgencyAndId>> mergeToolIdMapping, List<Trip> trips) {
AgencyAndId unmergedTripId = null;
for (Trip trip : trips) {
AgencyAndId id = computeUnmergedTripId(trip.getId());
if (unmergedTripId == null) {
unmergedTripId = id;
} else if (!unmergedTripId.equals(id)) {
return null;
}
}
List<AgencyAndId> originalIds = mergeToolIdMapping.get(unmergedTripId);
if (originalIds == null || originalIds.size() != trips.size())
return null;
return unmergedTripId;
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationStrategy method createUpdatedServiceId.
private AgencyAndId createUpdatedServiceId(Map<Set<AgencyAndId>, AgencyAndId> serviceIdsToUpdatedServiceId, Set<AgencyAndId> serviceIds) {
AgencyAndId updatedServiceId = serviceIdsToUpdatedServiceId.get(serviceIds);
if (updatedServiceId == null) {
if (serviceIds.isEmpty())
throw new IllegalStateException();
List<AgencyAndId> toSort = new ArrayList<AgencyAndId>(serviceIds);
Collections.sort(toSort);
StringBuilder b = new StringBuilder();
String agencyId = null;
for (int i = 0; i < toSort.size(); i++) {
AgencyAndId serviceId = toSort.get(i);
if (i == 0)
agencyId = serviceId.getAgencyId();
else
b.append("-");
b.append(serviceId.getId());
}
updatedServiceId = new AgencyAndId(agencyId, b.toString());
serviceIdsToUpdatedServiceId.put(serviceIds, updatedServiceId);
}
return updatedServiceId;
}
use of org.onebusaway.gtfs.model.AgencyAndId 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);
}
}
use of org.onebusaway.gtfs.model.AgencyAndId 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());
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class SubsectionTripTransformStrategy method updateShape.
private void updateShape(GtfsMutableRelationalDao dao, Trip trip, List<StopTime> stopTimes, Set<AgencyAndId> newShapeIds) {
if (stopTimes.size() < 2) {
trip.setShapeId(null);
return;
}
AgencyAndId shapeId = trip.getShapeId();
if (shapeId == null || !shapeId.hasValues()) {
return;
}
List<ShapePoint> points = dao.getShapePointsForShapeId(shapeId);
if (points.isEmpty()) {
return;
}
Stop firstStop = stopTimes.get(0).getStop();
Stop lastStop = stopTimes.get(stopTimes.size() - 1).getStop();
String id = shapeId.getId() + "-" + firstStop.getId().getId() + "-" + lastStop.getId().getId();
AgencyAndId newShapeId = new AgencyAndId("1", id);
trip.setShapeId(newShapeId);
if (!newShapeIds.add(newShapeId)) {
return;
}
int shapePointFrom = getClosestShapePointToStop(points, firstStop);
int shapePointTo = getClosestShapePointToStop(points, lastStop);
for (int index = shapePointFrom; index <= shapePointTo; ++index) {
ShapePoint point = new ShapePoint(points.get(index));
point.setId(0);
point.setShapeId(newShapeId);
dao.saveEntity(point);
}
}
Aggregations