Search in sources :

Example 1 with ValueSetter

use of org.onebusaway.gtfs_transformer.deferred.ValueSetter in project onebusaway-gtfs-modules by OneBusAway.

the class SimpleModificationStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
    BeanWrapper wrapper = BeanWrapperFactory.wrap(entity);
    for (Map.Entry<String, ValueSetter> entry : _propertyUpdates.entrySet()) {
        String propertyName = entry.getKey();
        ValueSetter setter = entry.getValue();
        setter.setValue(wrapper, propertyName);
    }
}
Also used : BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) Map(java.util.Map) ValueSetter(org.onebusaway.gtfs_transformer.deferred.ValueSetter)

Example 2 with ValueSetter

use of org.onebusaway.gtfs_transformer.deferred.ValueSetter in project onebusaway-gtfs-modules by OneBusAway.

the class TransformFactory method handleAddOperation.

/****
   * Private Method
   ****/
private void handleAddOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
    if (!json.has(ARG_OBJ)) {
        throw new TransformSpecificationMissingArgumentException(line, ARG_OBJ);
    }
    JSONObject objectSpec = json.getJSONObject(ARG_OBJ);
    Class<?> entityType = getEntityClassFromJsonSpec(line, objectSpec);
    if (entityType == null) {
        throw new TransformSpecificationMissingArgumentException(line, new String[] { ARG_CLASS, ARG_FILE }, ARG_OBJ);
    }
    Map<String, ValueSetter> propertyUpdates = getPropertyValueSettersFromJsonObject(entityType, objectSpec, _excludeForObjectSpec);
    EntitySourceImpl source = new EntitySourceImpl(entityType, propertyUpdates);
    AddEntitiesTransformStrategy strategy = getStrategy(AddEntitiesTransformStrategy.class);
    strategy.addEntityFactory(source);
}
Also used : JSONObject(org.json.JSONObject) TransformSpecificationMissingArgumentException(org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException) 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)

Example 3 with ValueSetter

use of org.onebusaway.gtfs_transformer.deferred.ValueSetter 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)

Aggregations

ValueSetter (org.onebusaway.gtfs_transformer.deferred.ValueSetter)3 Map (java.util.Map)2 JSONObject (org.json.JSONObject)2 DeferredValueSetter (org.onebusaway.gtfs_transformer.deferred.DeferredValueSetter)2 PropertyPathExpressionValueSetter (org.onebusaway.gtfs_transformer.deferred.PropertyPathExpressionValueSetter)2 ReplaceValueSetter (org.onebusaway.gtfs_transformer.deferred.ReplaceValueSetter)2 HashMap (java.util.HashMap)1 BeanWrapper (org.onebusaway.csv_entities.schema.BeanWrapper)1 SingleFieldMapping (org.onebusaway.csv_entities.schema.SingleFieldMapping)1 TransformSpecificationMissingArgumentException (org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException)1