Search in sources :

Example 6 with BeanWrapper

use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.

the class StringModificationStrategy method run.

public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
    BeanWrapper wrapper = BeanWrapperFactory.wrap(entity);
    for (Map.Entry<String, Pair<String>> entry : _propertyUpdates.entrySet()) {
        String property = entry.getKey();
        Pair<String> value = entry.getValue();
        Object propertyValue = wrapper.getPropertyValue(property);
        if (propertyValue != null) {
            String propertyStringValue = propertyValue.toString();
            propertyStringValue = propertyStringValue.replaceAll(value.getFirst(), value.getSecond());
            wrapper.setPropertyValue(property, propertyStringValue);
        }
    }
}
Also used : BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) Map(java.util.Map) Pair(org.onebusaway.collections.tuple.Pair)

Example 7 with BeanWrapper

use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.

the class AgencyMergeStrategy method bulkRenameAgencyIdInProperties.

private <T> void bulkRenameAgencyIdInProperties(Iterable<T> elements, String oldAgencyId, String newAgencyId, String... properties) {
    for (Object element : elements) {
        BeanWrapper wrapped = BeanWrapperFactory.wrap(element);
        for (String property : properties) {
            AgencyAndId id = (AgencyAndId) wrapped.getPropertyValue(property);
            if (id != null && id.getAgencyId().equals(oldAgencyId)) {
                AgencyAndId updatedId = new AgencyAndId(newAgencyId, id.getId());
                wrapped.setPropertyValue(property, updatedId);
            }
        }
    }
}
Also used : BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

Example 8 with BeanWrapper

use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTestData method grep.

public static <T> List<T> grep(Iterable<T> elements, String propertyExpression, Object value) {
    String[] properties = propertyExpression.split("\\.");
    List<T> matches = new ArrayList<T>();
    for (T element : elements) {
        Object v = element;
        for (String property : properties) {
            BeanWrapper wrapper = BeanWrapperFactory.wrap(v);
            v = wrapper.getPropertyValue(property);
        }
        if ((value == null && v == null) || (value != null && value.equals(v)))
            matches.add(element);
    }
    return matches;
}
Also used : BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) ArrayList(java.util.ArrayList)

Example 9 with BeanWrapper

use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.

the class DeferredValueSupportTest method testResolveAgencyAndId_DefaultAgencyId.

@Test
public void testResolveAgencyAndId_DefaultAgencyId() {
    Stop stop = new Stop();
    BeanWrapper bean = BeanWrapperFactory.wrap(stop);
    AgencyAndId id = _support.resolveAgencyAndId(bean, "id", "1");
    assertEquals(new AgencyAndId("a0", "1"), id);
}
Also used : BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Aggregations

BeanWrapper (org.onebusaway.csv_entities.schema.BeanWrapper)9 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 CsvEntityContext (org.onebusaway.csv_entities.CsvEntityContext)3 CsvEntityContextImpl (org.onebusaway.csv_entities.CsvEntityContextImpl)3 FieldMapping (org.onebusaway.csv_entities.schema.FieldMapping)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 DefaultEntitySchemaFactory (org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)2 Stop (org.onebusaway.gtfs.model.Stop)2 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 Pair (org.onebusaway.collections.tuple.Pair)1 MissingRequiredFieldException (org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException)1 EntitySchema (org.onebusaway.csv_entities.schema.EntitySchema)1 EntitySchemaFactory (org.onebusaway.csv_entities.schema.EntitySchemaFactory)1 SingleFieldMapping (org.onebusaway.csv_entities.schema.SingleFieldMapping)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 StopTimeFieldMappingFactory.getSecondsAsString (org.onebusaway.gtfs.serialization.mappings.StopTimeFieldMappingFactory.getSecondsAsString)1