Search in sources :

Example 1 with PropertyMethod

use of org.onebusaway.collections.beans.PropertyMethod in project onebusaway-gtfs-modules by OneBusAway.

the class PropertyMethodResolverImpl method getPropertyMethod.

@Override
public PropertyMethod getPropertyMethod(Class<?> targetType, String propertyName) {
    @SuppressWarnings("rawtypes") PropertyMethod method = _virtualPropertyMethods.get(Tuples.tuple((Class) targetType, propertyName));
    if (method != null) {
        return method;
    }
    SingleFieldMapping mapping = _schemaCache.getFieldMappingForCsvFieldName(targetType, propertyName);
    if (mapping != null) {
        propertyName = mapping.getObjFieldName();
    }
    return super.getPropertyMethod(targetType, propertyName);
}
Also used : PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) SingleFieldMapping(org.onebusaway.csv_entities.schema.SingleFieldMapping)

Example 2 with PropertyMethod

use of org.onebusaway.collections.beans.PropertyMethod in project onebusaway-gtfs-modules by OneBusAway.

the class PropertyMethodResolverImplTest method testTripCalendarsVirtualMethod.

@Test
public void testTripCalendarsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "t0"));
    trip.setServiceId(new AgencyAndId("1", "sid0"));
    _dao.saveEntity(trip);
    ServiceCalendar calendar = new ServiceCalendar();
    calendar.setServiceId(trip.getServiceId());
    _dao.saveEntity(calendar);
    PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "calendar");
    assertEquals(calendar, method.invoke(trip));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 3 with PropertyMethod

use of org.onebusaway.collections.beans.PropertyMethod in project onebusaway-gtfs-modules by OneBusAway.

the class PropertyMethodResolverImplTest method testAgencyRoutesVirtualMethod.

@Test
public void testAgencyRoutesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Agency agency = new Agency();
    agency.setId("1");
    Route route = new Route();
    route.setId(new AgencyAndId("1", "r0"));
    route.setAgency(agency);
    _dao.saveEntity(route);
    PropertyMethod method = _resolver.getPropertyMethod(Agency.class, "routes");
    assertEquals(Arrays.asList(route), method.invoke(agency));
}
Also used : PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 4 with PropertyMethod

use of org.onebusaway.collections.beans.PropertyMethod in project onebusaway-gtfs-modules by OneBusAway.

the class PropertyMethodResolverImplTest method testTripStopTimesVirtualMethod.

@Test
public void testTripStopTimesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "t0"));
    _dao.saveEntity(trip);
    StopTime stopTime = new StopTime();
    stopTime.setTrip(trip);
    stopTime.setStop(new Stop());
    _dao.saveEntity(stopTime);
    PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "stop_times");
    assertEquals(Arrays.asList(stopTime), method.invoke(trip));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 5 with PropertyMethod

use of org.onebusaway.collections.beans.PropertyMethod 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

PropertyMethod (org.onebusaway.collections.beans.PropertyMethod)6 Test (org.junit.Test)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Route (org.onebusaway.gtfs.model.Route)3 Trip (org.onebusaway.gtfs.model.Trip)3 DefaultEntitySchemaFactory (org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)1 EntitySchema (org.onebusaway.csv_entities.schema.EntitySchema)1 SingleFieldMapping (org.onebusaway.csv_entities.schema.SingleFieldMapping)1 Agency (org.onebusaway.gtfs.model.Agency)1 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)1 Stop (org.onebusaway.gtfs.model.Stop)1 StopTime (org.onebusaway.gtfs.model.StopTime)1