Search in sources :

Example 1 with TransformSpecificationException

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

the class TransformFactory method handleSubsectionOperation.

private void handleSubsectionOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
    SubsectionTripTransformStrategy strategy = getStrategy(SubsectionTripTransformStrategy.class);
    SubsectionOperation operation = new SubsectionTripTransformStrategy.SubsectionOperation();
    setObjectPropertiesFromJsonUsingCsvFields(operation, json, line);
    if (operation.getFromStopId() == null && operation.getToStopId() == null) {
        throw new TransformSpecificationException("must specify at least fromStopId or toStopId in subsection op", line);
    }
    strategy.addOperation(operation);
}
Also used : SubsectionOperation(org.onebusaway.gtfs_transformer.updates.SubsectionTripTransformStrategy.SubsectionOperation) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException) SubsectionTripTransformStrategy(org.onebusaway.gtfs_transformer.updates.SubsectionTripTransformStrategy)

Example 2 with TransformSpecificationException

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

the class TransformFactory method handleTransformOperation.

private void handleTransformOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
    if (!json.has(ARG_CLASS)) {
        throw new TransformSpecificationMissingArgumentException(line, ARG_CLASS);
    }
    String value = json.getString(ARG_CLASS);
    Object factoryObj = null;
    try {
        Class<?> clazz = Class.forName(value);
        factoryObj = clazz.newInstance();
    } catch (Exception ex) {
        throw new TransformSpecificationException("error instantiating class: " + value, ex, line);
    }
    handleTransformOperation(line, json, factoryObj);
}
Also used : TransformSpecificationMissingArgumentException(org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException) JSONObject(org.json.JSONObject) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException) JSONException(org.json.JSONException) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException) MissingRequiredFieldException(org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException) IOException(java.io.IOException) TransformSpecificationMissingArgumentException(org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException)

Example 3 with TransformSpecificationException

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

the class TransformFactory method handleTrimOperation.

private void handleTrimOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
    TypedEntityMatch match = getMatch(line, json);
    if (match.getType() != Trip.class) {
        throw new TransformSpecificationException("the trim_trip op only supports matching against trips", line);
    }
    TrimTripTransformStrategy strategy = getStrategy(TrimTripTransformStrategy.class);
    TrimOperation operation = new TrimTripTransformStrategy.TrimOperation();
    operation.setMatch(match);
    if (json.has("to_stop_id")) {
        operation.setToStopId(json.getString("to_stop_id"));
    }
    if (json.has("from_stop_id")) {
        operation.setFromStopId(json.getString("from_stop_id"));
    }
    if (operation.getToStopId() == null && operation.getFromStopId() == null) {
        throw new TransformSpecificationMissingArgumentException(line, new String[] { "to_stop_id", "from_stop_id" });
    }
    strategy.addOperation(operation);
}
Also used : TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) TrimTripTransformStrategy(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy) TransformSpecificationMissingArgumentException(org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException)

Example 4 with TransformSpecificationException

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

the class TransformFactory method handleTransformOperation.

private void handleTransformOperation(String line, JSONObject json, Object factoryObj) throws JSONException, TransformSpecificationException {
    setObjectPropertiesFromJsonUsingCsvFields(factoryObj, json, line);
    boolean added = false;
    if (factoryObj instanceof GtfsTransformStrategy) {
        _transformer.addTransform((GtfsTransformStrategy) factoryObj);
        added = true;
    }
    if (factoryObj instanceof GtfsEntityTransformStrategy) {
        _transformer.addEntityTransform((GtfsEntityTransformStrategy) factoryObj);
        added = true;
    }
    if (factoryObj instanceof GtfsTransformStrategyFactory) {
        GtfsTransformStrategyFactory factory = (GtfsTransformStrategyFactory) factoryObj;
        factory.createTransforms(_transformer);
        added = true;
    }
    if (!added) {
        throw new TransformSpecificationException("factory object is not an instance of GtfsTransformStrategy, GtfsEntityTransformStrategy, or GtfsTransformStrategyFactory: " + factoryObj.getClass().getName(), line);
    }
}
Also used : GtfsTransformStrategyFactory(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategyFactory) GtfsEntityTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException)

Example 5 with TransformSpecificationException

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

the class TransformFactory method handleUpdateOperation.

private void handleUpdateOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
    EntitiesTransformStrategy strategy = getStrategy(EntitiesTransformStrategy.class);
    TypedEntityMatch match = getMatch(line, json);
    if (json.has("factory")) {
        String factoryType = json.getString("factory");
        try {
            Class<?> clazz = Class.forName(factoryType);
            Object factoryObj = clazz.newInstance();
            if (!(factoryObj instanceof EntityTransformStrategy)) {
                throw new TransformSpecificationException("factory object is not an instance of EntityTransformStrategy: " + clazz.getName(), line);
            }
            strategy.addModification(match, (EntityTransformStrategy) factoryObj);
        } catch (Throwable ex) {
            throw new TransformSpecificationException("error creating factory ModificationStrategy instance", ex, line);
        }
        return;
    }
    if (json.has(ARG_UPDATE)) {
        JSONObject update = json.getJSONObject(ARG_UPDATE);
        EntityTransformStrategy mod = getUpdateEntityTransformStrategy(line, match, update);
        strategy.addModification(match, mod);
    }
    if (json.has("strings")) {
        JSONObject strings = json.getJSONObject("strings");
        Map<String, Pair<String>> replacements = getEntityPropertiesAndStringReplacementsFromJsonObject(match.getType(), strings);
        StringModificationStrategy mod = new StringModificationStrategy(replacements);
        strategy.addModification(match, mod);
    }
}
Also used : TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) EntityTransformStrategy(org.onebusaway.gtfs_transformer.services.EntityTransformStrategy) GtfsEntityTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy) JSONObject(org.json.JSONObject) StringModificationStrategy(org.onebusaway.gtfs_transformer.impl.StringModificationStrategy) JSONObject(org.json.JSONObject) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException) Pair(org.onebusaway.collections.tuple.Pair)

Aggregations

TransformSpecificationException (org.onebusaway.gtfs_transformer.TransformSpecificationException)7 JSONObject (org.json.JSONObject)3 TransformSpecificationMissingArgumentException (org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException)3 JSONException (org.json.JSONException)2 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)2 GtfsEntityTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy)2 IOException (java.io.IOException)1 Pair (org.onebusaway.collections.tuple.Pair)1 MissingRequiredFieldException (org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException)1 EntitySchema (org.onebusaway.csv_entities.schema.EntitySchema)1 StringModificationStrategy (org.onebusaway.gtfs_transformer.impl.StringModificationStrategy)1 EntityTransformStrategy (org.onebusaway.gtfs_transformer.services.EntityTransformStrategy)1 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)1 GtfsTransformStrategyFactory (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategyFactory)1 CalendarExtensionStrategy (org.onebusaway.gtfs_transformer.updates.CalendarExtensionStrategy)1 CalendarSimplicationStrategy (org.onebusaway.gtfs_transformer.updates.CalendarSimplicationStrategy)1 DeduplicateServiceIdsStrategy (org.onebusaway.gtfs_transformer.updates.DeduplicateServiceIdsStrategy)1 ShapeDirectionTransformStrategy (org.onebusaway.gtfs_transformer.updates.ShapeDirectionTransformStrategy)1 ShiftNegativeStopTimesUpdateStrategy (org.onebusaway.gtfs_transformer.updates.ShiftNegativeStopTimesUpdateStrategy)1 SubsectionTripTransformStrategy (org.onebusaway.gtfs_transformer.updates.SubsectionTripTransformStrategy)1