Search in sources :

Example 1 with IdKeyMatch

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

the class EntitiesTransformStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    for (MatchAndTransform modification : _modifications) {
        TypedEntityMatch match = modification.getMatch();
        Class<?> entityType = match.getType();
        EntityTransformStrategy transform = modification.getTransform();
        if (IdKey.class.isAssignableFrom(entityType)) {
            IdKeyMatch keyMatch = (IdKeyMatch) match.getPropertyMatches();
            transform.run(context, dao, keyMatch.getKey());
        } else {
            Collection<Object> entities = new ArrayList<Object>(dao.getAllEntitiesForType(entityType));
            for (Object object : entities) {
                if (match.isApplicableToObject(object)) {
                    transform.run(context, dao, object);
                }
            }
        }
    }
}
Also used : TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) EntityTransformStrategy(org.onebusaway.gtfs_transformer.services.EntityTransformStrategy) ArrayList(java.util.ArrayList) IdKeyMatch(org.onebusaway.gtfs_transformer.collections.IdKeyMatch)

Example 2 with IdKeyMatch

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

the class RetainEntitiesTransformStrategy method run.

@SuppressWarnings("unchecked")
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    if (_retentionMatchesByType.isEmpty())
        return;
    EntityRetentionGraph graph = new EntityRetentionGraph(dao);
    graph.setRetainBlocks(_retainBlocks);
    for (Map.Entry<Class<?>, List<EntityRetention>> entry : _retentionMatchesByType.entrySet()) {
        Class<?> entityType = entry.getKey();
        List<EntityRetention> retentions = entry.getValue();
        if (IdKey.class.isAssignableFrom(entityType)) {
            for (EntityRetention retention : retentions) {
                TypedEntityMatch typedMatch = retention.getMatch();
                IdKeyMatch match = (IdKeyMatch) typedMatch.getPropertyMatches();
                graph.retain(match.getKey(), retention.isRetainUp());
            }
        } else {
            Collection<Object> entities = new ArrayList<Object>(dao.getAllEntitiesForType(entityType));
            for (Object object : entities) {
                for (EntityRetention retention : retentions) {
                    EntityMatch match = retention.getMatch();
                    if (match.isApplicableToObject(object))
                        graph.retain(object, retention.isRetainUp());
                }
            }
        }
    }
    for (Class<?> entityClass : GtfsEntitySchemaFactory.getEntityClasses()) {
        List<Object> objectsToRemove = new ArrayList<Object>();
        for (Object entity : dao.getAllEntitiesForType(entityClass)) {
            if (!graph.isRetained(entity))
                objectsToRemove.add(entity);
        }
        for (Object toRemove : objectsToRemove) dao.removeEntity((IdentityBean<Serializable>) toRemove);
    }
}
Also used : TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) ArrayList(java.util.ArrayList) EntityMatch(org.onebusaway.gtfs_transformer.match.EntityMatch) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IdKeyMatch(org.onebusaway.gtfs_transformer.collections.IdKeyMatch) IdentityBean(org.onebusaway.gtfs.model.IdentityBean)

Aggregations

ArrayList (java.util.ArrayList)2 IdKeyMatch (org.onebusaway.gtfs_transformer.collections.IdKeyMatch)2 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 IdentityBean (org.onebusaway.gtfs.model.IdentityBean)1 EntityMatch (org.onebusaway.gtfs_transformer.match.EntityMatch)1 EntityTransformStrategy (org.onebusaway.gtfs_transformer.services.EntityTransformStrategy)1