Search in sources :

Example 1 with DefaultEntitySchemaFactory

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);
}
Also used : DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) SchemaUpdateStrategy(org.onebusaway.gtfs_transformer.services.SchemaUpdateStrategy)

Example 2 with DefaultEntitySchemaFactory

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;
}
Also used : CsvEntityMappingBean(org.onebusaway.csv_entities.schema.beans.CsvEntityMappingBean) EntitySchemaFactoryHelper(org.onebusaway.csv_entities.schema.EntitySchemaFactoryHelper) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)

Example 3 with DefaultEntitySchemaFactory

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));
}
Also used : CsvEntityContextImpl(org.onebusaway.csv_entities.CsvEntityContextImpl) BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HashMap(java.util.HashMap) FieldMapping(org.onebusaway.csv_entities.schema.FieldMapping) CsvEntityContext(org.onebusaway.csv_entities.CsvEntityContext) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) Test(org.junit.Test)

Example 4 with DefaultEntitySchemaFactory

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));
}
Also used : CsvEntityContextImpl(org.onebusaway.csv_entities.CsvEntityContextImpl) BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) HashMap(java.util.HashMap) FieldMapping(org.onebusaway.csv_entities.schema.FieldMapping) CsvEntityContext(org.onebusaway.csv_entities.CsvEntityContext) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) StopTimeFieldMappingFactory.getSecondsAsString(org.onebusaway.gtfs.serialization.mappings.StopTimeFieldMappingFactory.getSecondsAsString) Test(org.junit.Test)

Example 5 with DefaultEntitySchemaFactory

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));
}
Also used : PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) EntitySchema(org.onebusaway.csv_entities.schema.EntitySchema) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Aggregations

DefaultEntitySchemaFactory (org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)8 Test (org.junit.Test)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 HashMap (java.util.HashMap)2 CsvEntityContext (org.onebusaway.csv_entities.CsvEntityContext)2 CsvEntityContextImpl (org.onebusaway.csv_entities.CsvEntityContextImpl)2 BeanWrapper (org.onebusaway.csv_entities.schema.BeanWrapper)2 FieldMapping (org.onebusaway.csv_entities.schema.FieldMapping)2 Stop (org.onebusaway.gtfs.model.Stop)2 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)2 GtfsWriterTest (org.onebusaway.gtfs.serialization.GtfsWriterTest)2 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)2 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)2 PropertyMethod (org.onebusaway.collections.beans.PropertyMethod)1 EntitySchema (org.onebusaway.csv_entities.schema.EntitySchema)1 EntitySchemaFactoryHelper (org.onebusaway.csv_entities.schema.EntitySchemaFactoryHelper)1 CsvEntityMappingBean (org.onebusaway.csv_entities.schema.beans.CsvEntityMappingBean)1 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)1 Route (org.onebusaway.gtfs.model.Route)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1