Search in sources :

Example 1 with SingleFieldMapping

use of org.onebusaway.csv_entities.schema.SingleFieldMapping 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 SingleFieldMapping

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

the class TransformFactory method getPropertyValueSettersFromJsonObject.

private Map<String, ValueSetter> getPropertyValueSettersFromJsonObject(Class<?> entityType, JSONObject obj, Set<String> propertiesToExclude) throws JSONException {
    Map<String, Object> map = getPropertyValuesFromJsonObject(obj, propertiesToExclude);
    Map<String, ValueSetter> setters = new HashMap<String, ValueSetter>();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        String propertyName = entry.getKey();
        SingleFieldMapping mapping = _schemaCache.getFieldMappingForCsvFieldName(entityType, propertyName);
        if (mapping != null) {
            propertyName = mapping.getObjFieldName();
        }
        ValueSetter setter = createSetterForValue(entry.getValue());
        setters.put(propertyName, setter);
    }
    return setters;
}
Also used : HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) DeferredValueSetter(org.onebusaway.gtfs_transformer.deferred.DeferredValueSetter) ValueSetter(org.onebusaway.gtfs_transformer.deferred.ValueSetter) PropertyPathExpressionValueSetter(org.onebusaway.gtfs_transformer.deferred.PropertyPathExpressionValueSetter) ReplaceValueSetter(org.onebusaway.gtfs_transformer.deferred.ReplaceValueSetter) Map(java.util.Map) HashMap(java.util.HashMap) SingleFieldMapping(org.onebusaway.csv_entities.schema.SingleFieldMapping)

Example 3 with SingleFieldMapping

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

the class EntitySchemaCache method addEntitySchema.

public void addEntitySchema(EntitySchema schema) {
    _entitySchemasByEntityType.put(schema.getEntityClass(), schema);
    if (schema.getFilename() != null) {
        _entitySchemasByFileName.put(schema.getFilename(), schema);
    }
    for (FieldMapping mapping : schema.getFields()) {
        if (mapping instanceof SingleFieldMapping) {
            SingleFieldMapping single = (SingleFieldMapping) mapping;
            putMappingForEntityTypeAndName(_mappingsByTypeAndCsvFieldName, schema.getEntityClass(), single.getCsvFieldName(), single);
            putMappingForEntityTypeAndName(_mappingsByTypeAndObjectFieldName, schema.getEntityClass(), single.getObjFieldName(), single);
        }
    }
}
Also used : FieldMapping(org.onebusaway.csv_entities.schema.FieldMapping) SingleFieldMapping(org.onebusaway.csv_entities.schema.SingleFieldMapping) SingleFieldMapping(org.onebusaway.csv_entities.schema.SingleFieldMapping)

Aggregations

SingleFieldMapping (org.onebusaway.csv_entities.schema.SingleFieldMapping)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 PropertyMethod (org.onebusaway.collections.beans.PropertyMethod)1 FieldMapping (org.onebusaway.csv_entities.schema.FieldMapping)1 DeferredValueSetter (org.onebusaway.gtfs_transformer.deferred.DeferredValueSetter)1 PropertyPathExpressionValueSetter (org.onebusaway.gtfs_transformer.deferred.PropertyPathExpressionValueSetter)1 ReplaceValueSetter (org.onebusaway.gtfs_transformer.deferred.ReplaceValueSetter)1 ValueSetter (org.onebusaway.gtfs_transformer.deferred.ValueSetter)1