use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsTransformer method writeGtfs.
private void writeGtfs() throws IOException {
if (_outputDirectory == null) {
return;
}
_writer.setOutputLocation(_outputDirectory);
DefaultEntitySchemaFactory schemaFactory = new DefaultEntitySchemaFactory();
schemaFactory.addFactory(GtfsEntitySchemaFactory.createEntitySchemaFactory());
for (SchemaUpdateStrategy strategy : _outputSchemaUpdates) strategy.updateSchema(schemaFactory);
_writer.setEntitySchemaFactory(schemaFactory);
_writer.run(_dao);
}
use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsEntitySchemaFactory method createEntitySchemaFactory.
public static DefaultEntitySchemaFactory createEntitySchemaFactory() {
DefaultEntitySchemaFactory factory = new DefaultEntitySchemaFactory();
EntitySchemaFactoryHelper helper = new EntitySchemaFactoryHelper(factory);
CsvEntityMappingBean agencyId = helper.addEntity(AgencyAndId.class);
helper.addIgnorableField(agencyId, "agencyId");
return factory;
}
use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class ServiceDateFieldMappingFactoryTest method test.
@Test
public void test() {
ServiceDateFieldMappingFactory factory = new ServiceDateFieldMappingFactory();
DefaultEntitySchemaFactory schemaFactory = new DefaultEntitySchemaFactory();
String propName = "date";
FieldMapping mapping = factory.createFieldMapping(schemaFactory, Dummy.class, propName, propName, ServiceDate.class, true);
CsvEntityContext context = new CsvEntityContextImpl();
Map<String, Object> csvValues = new HashMap<String, Object>();
csvValues.put(propName, "20100212");
Dummy obj = new Dummy();
BeanWrapper wrapped = BeanWrapperFactory.wrap(obj);
mapping.translateFromCSVToObject(context, csvValues, wrapped);
assertEquals(new ServiceDate(2010, 2, 12), obj.getDate());
csvValues.clear();
mapping.translateFromObjectToCSV(context, wrapped, csvValues);
assertEquals("20100212", csvValues.get(propName));
}
use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class StopTimeFieldMappingFactoryTest method test.
@Test
public void test() {
StopTimeFieldMappingFactory factory = new StopTimeFieldMappingFactory();
DefaultEntitySchemaFactory schemaFactory = new DefaultEntitySchemaFactory();
String propName = "time";
FieldMapping mapping = factory.createFieldMapping(schemaFactory, Dummy.class, propName, propName, Integer.class, true);
CsvEntityContext context = new CsvEntityContextImpl();
Map<String, Object> csvValues = new HashMap<String, Object>();
csvValues.put(propName, "1234:23:32");
Dummy obj = new Dummy();
BeanWrapper wrapped = BeanWrapperFactory.wrap(obj);
mapping.translateFromCSVToObject(context, csvValues, wrapped);
assertEquals(new Integer(1234 * 60 * 60 + 23 * 60 + 32), obj.getTime());
csvValues.clear();
mapping.translateFromObjectToCSV(context, wrapped, csvValues);
assertEquals("1234:23:32", csvValues.get(propName));
}
use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method testUseCsvFieldMappings.
@Test
public void testUseCsvFieldMappings() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
EntitySchema entitySchema = factory.getSchema(Route.class);
_schemaCache.addEntitySchema(entitySchema);
PropertyMethod method = _resolver.getPropertyMethod(Route.class, "route_id");
Route route = new Route();
AgencyAndId id = new AgencyAndId("1", "10");
route.setId(id);
assertSame(id, method.invoke(route));
}
Aggregations