use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class ExtensionsTest method testExtensionWrite.
@Test
public void testExtensionWrite() throws IOException {
DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
factory.addExtension(Stop.class, StopExtension.class);
{
MockGtfs gtfs = MockGtfs.create();
gtfs.putMinimal();
gtfs.putStops(2, "label=a,b");
GtfsReader reader = new GtfsReader();
reader.setEntitySchemaFactory(factory);
GtfsMutableRelationalDao dao = gtfs.read(reader);
Stop stop = dao.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension = stop.getExtension(StopExtension.class);
assertEquals("a", extension.getLabel());
GtfsWriter writer = new GtfsWriter();
writer.setEntitySchemaFactory(factory);
writer.setOutputLocation(_tmpDirectory);
writer.run(dao);
writer.close();
}
{
GtfsReader reader2 = new GtfsReader();
reader2.setEntitySchemaFactory(factory);
reader2.setInputLocation(_tmpDirectory);
GtfsRelationalDaoImpl dao2 = new GtfsRelationalDaoImpl();
reader2.setDefaultAgencyId("a0");
reader2.setEntityStore(dao2);
reader2.readEntities(Stop.class);
Stop stop2 = dao2.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension2 = stop2.getExtension(StopExtension.class);
assertEquals("a", extension2.getLabel());
}
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class GenericDaoImplTest method testSaveOrUpdate.
@Test
public void testSaveOrUpdate() {
GenericDaoImpl impl = new GenericDaoImpl();
AgencyAndId id = new AgencyAndId("1", "stopA");
Stop entity = impl.getEntityForId(Stop.class, id);
assertNull(entity);
Stop stopA = new Stop();
stopA.setId(id);
impl.saveOrUpdateEntity(stopA);
entity = impl.getEntityForId(Stop.class, id);
assertSame(stopA, entity);
impl.saveOrUpdateEntity(stopA);
entity = impl.getEntityForId(Stop.class, id);
assertSame(stopA, entity);
Stop stopB = new Stop();
stopB.setId(id);
impl.saveOrUpdateEntity(stopB);
entity = impl.getEntityForId(Stop.class, id);
assertSame(stopB, entity);
Collection<Stop> entities = impl.getAllEntitiesForType(Stop.class);
assertEquals(1, entities.size());
assertSame(stopB, entities.iterator().next());
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImpl method createData.
@Override
public CalendarServiceData createData() {
CalendarServiceData data = new CalendarServiceData();
setTimeZonesForAgencies(data);
List<AgencyAndId> serviceIds = _dao.getAllServiceIds();
int index = 0;
for (AgencyAndId serviceId : serviceIds) {
index++;
_log.info("serviceId=" + serviceId + " (" + index + "/" + serviceIds.size() + ")");
TimeZone serviceIdTimeZone = data.getTimeZoneForAgencyId(serviceId.getAgencyId());
if (serviceIdTimeZone == null) {
serviceIdTimeZone = TimeZone.getDefault();
}
Set<ServiceDate> activeDates = getServiceDatesForServiceId(serviceId, serviceIdTimeZone);
List<ServiceDate> serviceDates = new ArrayList<ServiceDate>(activeDates);
Collections.sort(serviceDates);
data.putServiceDatesForServiceId(serviceId, serviceDates);
List<String> tripAgencyIds = _dao.getTripAgencyIdsReferencingServiceId(serviceId);
Set<TimeZone> timeZones = new HashSet<TimeZone>();
for (String tripAgencyId : tripAgencyIds) {
TimeZone timeZone = data.getTimeZoneForAgencyId(tripAgencyId);
timeZones.add(timeZone);
}
for (TimeZone timeZone : timeZones) {
List<Date> dates = new ArrayList<Date>(serviceDates.size());
for (ServiceDate serviceDate : serviceDates) dates.add(serviceDate.getAsDate(timeZone));
LocalizedServiceId id = new LocalizedServiceId(serviceId, timeZone);
data.putDatesForLocalizedServiceId(id, dates);
}
}
return data;
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class ServiceCalendarComparator method compare.
@Override
public int compare(ServiceCalendar o1, ServiceCalendar o2) {
AgencyAndId id1 = o1.getServiceId();
AgencyAndId id2 = o2.getServiceId();
return id1.compareTo(id2);
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class EntityFieldMappingImpl method translateFromObjectToCSV.
@SuppressWarnings("unchecked")
public void translateFromObjectToCSV(CsvEntityContext context, BeanWrapper object, Map<String, Object> csvValues) {
IdentityBean<AgencyAndId> entity = (IdentityBean<AgencyAndId>) object.getPropertyValue(_objFieldName);
if (isOptional() && entity == null)
return;
AgencyAndId id = entity.getId();
csvValues.put(_csvFieldName, id.getId());
}
Aggregations