Search in sources :

Example 11 with GtfsTransformStrategy

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

the class TransformFactoryTest method testFileMatch.

@Test
public void testFileMatch() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'remove', 'match':{'file':'routes.txt', 'shortName':'10'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    assertEquals(EntitiesTransformStrategy.class, transform.getClass());
    EntitiesTransformStrategy strategy = (EntitiesTransformStrategy) transform;
    List<MatchAndTransform> transforms = strategy.getModifications();
    assertEquals(1, transforms.size());
}
Also used : MatchAndTransform(org.onebusaway.gtfs_transformer.factory.EntitiesTransformStrategy.MatchAndTransform) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) Test(org.junit.Test)

Example 12 with GtfsTransformStrategy

use of org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy 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 13 with GtfsTransformStrategy

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

the class TransformFactory method getStrategy.

@SuppressWarnings("unchecked")
private <T extends GtfsTransformStrategy> T getStrategy(Class<T> transformerType) {
    GtfsTransformStrategy lastTransform = _transformer.getLastTransform();
    if (lastTransform != null && transformerType.isAssignableFrom(lastTransform.getClass()))
        return (T) lastTransform;
    T strategy = (T) instantiate(transformerType);
    _transformer.addTransform(strategy);
    return strategy;
}
Also used : GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)

Aggregations

GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)13 Test (org.junit.Test)9 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)6 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)6 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 Route (org.onebusaway.gtfs.model.Route)2 MatchAndTransform (org.onebusaway.gtfs_transformer.factory.EntitiesTransformStrategy.MatchAndTransform)2 URL (java.net.URL)1 TransformSpecificationException (org.onebusaway.gtfs_transformer.TransformSpecificationException)1 EntityMatch (org.onebusaway.gtfs_transformer.match.EntityMatch)1 EntityTransformStrategy (org.onebusaway.gtfs_transformer.services.EntityTransformStrategy)1 GtfsEntityTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy)1 GtfsTransformStrategyFactory (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategyFactory)1 CalendarSimplicationStrategy (org.onebusaway.gtfs_transformer.updates.CalendarSimplicationStrategy)1