Search in sources :

Example 6 with TransformSpecificationException

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

the class TransformFactory method addModificationsFromReader.

public void addModificationsFromReader(BufferedReader reader) throws IOException, TransformSpecificationException {
    String line = null;
    while ((line = reader.readLine()) != null) {
        try {
            line = line.trim();
            if (line.length() == 0 || line.startsWith("#") || line.equals("{{{") || line.equals("}}}"))
                continue;
            JSONObject json = new JSONObject(line);
            if (!json.has(ARG_OP)) {
                throw new TransformSpecificationMissingArgumentException(line, ARG_OP);
            }
            String opType = json.getString(ARG_OP);
            if (opType.equals("add")) {
                handleAddOperation(line, json);
            } else if (opType.equals(ARG_UPDATE) || opType.equals("change") || opType.equals("modify")) {
                handleUpdateOperation(line, json);
            } else if (opType.equals("remove") || opType.equals("delete")) {
                handleRemoveOperation(line, json);
            } else if (opType.equals("retain")) {
                handleRetainOperation(line, json);
            } else if (opType.equals("subsection")) {
                handleSubsectionOperation(line, json);
            } else if (opType.equals("trim_trip")) {
                handleTrimOperation(line, json);
            } else if (opType.equals("stop_times_factory")) {
                handleStopTimesOperation(line, json);
            } else if (opType.equals("calendar_extension")) {
                handleTransformOperation(line, json, new CalendarExtensionStrategy());
            } else if (opType.equals("calendar_simplification")) {
                handleTransformOperation(line, json, new CalendarSimplicationStrategy());
            } else if (opType.equals("deduplicate_service_ids")) {
                handleTransformOperation(line, json, new DeduplicateServiceIdsStrategy());
            } else if (opType.equals("shift_negative_stop_times")) {
                handleTransformOperation(line, json, new ShiftNegativeStopTimesUpdateStrategy());
            } else if (opType.equals("shape_direction")) {
                handleTransformOperation(line, json, new ShapeDirectionTransformStrategy());
            } else if (opType.equals("transform")) {
                handleTransformOperation(line, json);
            } else {
                throw new TransformSpecificationException("unknown transform op \"" + opType + "\"", line);
            }
        } catch (JSONException ex) {
            throw new TransformSpecificationException("error parsing json", ex, line);
        }
    }
}
Also used : ShiftNegativeStopTimesUpdateStrategy(org.onebusaway.gtfs_transformer.updates.ShiftNegativeStopTimesUpdateStrategy) JSONObject(org.json.JSONObject) CalendarSimplicationStrategy(org.onebusaway.gtfs_transformer.updates.CalendarSimplicationStrategy) ShapeDirectionTransformStrategy(org.onebusaway.gtfs_transformer.updates.ShapeDirectionTransformStrategy) JSONException(org.json.JSONException) TransformSpecificationMissingArgumentException(org.onebusaway.gtfs_transformer.TransformSpecificationMissingArgumentException) DeduplicateServiceIdsStrategy(org.onebusaway.gtfs_transformer.updates.DeduplicateServiceIdsStrategy) CalendarExtensionStrategy(org.onebusaway.gtfs_transformer.updates.CalendarExtensionStrategy) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException)

Example 7 with TransformSpecificationException

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

the class TransformFactory method getEntityClassFromJsonSpec.

private Class<?> getEntityClassFromJsonSpec(String line, JSONObject objectSpec) throws JSONException, TransformSpecificationException, TransformSpecificationMissingArgumentException {
    if (objectSpec.has(ARG_FILE)) {
        String fileName = objectSpec.getString(ARG_FILE);
        EntitySchema schema = _schemaCache.getSchemaForFileName(fileName);
        if (schema == null) {
            throw new TransformSpecificationException("unknown file type: " + fileName, line);
        }
        return schema.getEntityClass();
    } else if (objectSpec.has(ARG_CLASS)) {
        return getEntityTypeForName(line, objectSpec.getString(ARG_CLASS));
    }
    return null;
}
Also used : EntitySchema(org.onebusaway.csv_entities.schema.EntitySchema) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException)

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