Search in sources :

Example 1 with FederatedTransitDataBundle

use of org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle in project onebusaway-application-modules by camsys.

the class FederatedTransitDataBundleCreator method run.

/**
 * Build the bundle!
 *
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws UnknownTaskException
 */
public void run() throws IOException, ClassNotFoundException, UnknownTaskException {
    _outputPath.mkdirs();
    setSystemProperties();
    ConfigurableApplicationContext context = _context;
    boolean closeContextOnCompletion = false;
    if (context == null) {
        List<String> contextPaths = getPrimaryApplicatonContextPaths();
        Map<String, BeanDefinition> contextBeans = getPrimaryBeanDefintions();
        context = ContainerLibrary.createContext(contextPaths, contextBeans);
        closeContextOnCompletion = true;
    }
    List<TaskDefinition> taskDefinitions = getTaskList(context);
    Set<String> taskNames = getReducedTaskList(taskDefinitions);
    // Clear cache files
    FederatedTransitDataBundle bundle = context.getBean(FederatedTransitDataBundle.class);
    clearExistingCacheFiles(bundle);
    int taskSize = taskNames.size();
    int i = 0;
    for (TaskDefinition def : taskDefinitions) {
        String taskName = def.getTaskName();
        if (taskNames.contains(taskName)) {
            i++;
            System.out.println("== " + taskName + " =====>");
            _status.addMessage("running task " + taskName + " (" + i + "/" + taskSize + ")");
            Runnable task = getTask(context, def.getTask(), def.getTaskBeanName());
            if (task == null)
                throw new IllegalStateException("unknown task bean with name: " + taskName);
            task.run();
        } else {
            Runnable task = getTask(context, def.getTaskWhenSkipped(), def.getTaskWhenSkippedBeanName());
            if (task != null) {
                System.out.println("== skipping " + taskName + " =====>");
                _status.addMessage("skipping task " + taskName);
                task.run();
            }
        }
    }
    // We don't need this context anymore
    if (closeContextOnCompletion) {
        context.stop();
        context.close();
        context = null;
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) TaskDefinition(org.onebusaway.transit_data_federation.bundle.model.TaskDefinition) FederatedTransitDataBundle(org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle)

Example 2 with FederatedTransitDataBundle

use of org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle in project onebusaway-application-modules by camsys.

the class ShapeGeospatialIndexTaskTest method test.

@Test
public void test() throws IOException, ClassNotFoundException {
    ShapeGeospatialIndexTask task = new ShapeGeospatialIndexTask();
    File path = File.createTempFile(ShapeGeospatialIndexTaskTest.class.getName(), ".tmp");
    path.delete();
    path.deleteOnExit();
    FederatedTransitDataBundle bundle = Mockito.mock(FederatedTransitDataBundle.class);
    Mockito.when(bundle.getShapeGeospatialIndexDataPath()).thenReturn(path);
    task.setBundle(bundle);
    RefreshService refreshService = Mockito.mock(RefreshService.class);
    task.setRefreshService(refreshService);
    ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
    task.setShapePointHelper(shapePointHelper);
    TransitGraphDao transitGraphDao = Mockito.mock(TransitGraphDao.class);
    task.setTransitGraphDao(transitGraphDao);
    StopEntry stopA = stop("stopA", 47.65, -122.32);
    StopEntry stopB = stop("stopB", 47.67, -122.30);
    Mockito.when(transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
    TripEntryImpl tripA = trip("tripA");
    AgencyAndId shapeIdA = aid("shapeA");
    tripA.setShapeId(shapeIdA);
    TripEntryImpl tripB = trip("tripB");
    AgencyAndId shapeIdB = aid("shapeB");
    tripB.setShapeId(shapeIdB);
    Mockito.when(transitGraphDao.getAllTrips()).thenReturn(Arrays.asList((TripEntry) tripA, tripB));
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.652300128129454, -122.30622018270873);
    factory.addPoint(47.653181844549394, -122.30523312979125);
    factory.addPoint(47.654265901710744, -122.30511511259459);
    ShapePoints shapeA = factory.create();
    factory = new ShapePointsFactory();
    factory.addPoint(47.661275594717026, -122.31189573698424);
    factory.addPoint(47.661347854692465, -122.3240622370758);
    factory.addPoint(47.661368177792546, -122.32508885257624);
    factory.addPoint(47.66496659665593, -122.32501375072383);
    ShapePoints shapeB = factory.create();
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdA)).thenReturn(shapeA);
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdB)).thenReturn(shapeB);
    task.run();
    Mockito.verify(refreshService).refresh(RefreshableResources.SHAPE_GEOSPATIAL_INDEX);
    Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByBounds = ObjectSerializationLibrary.readObject(path);
    assertEquals(5, shapeIdsByBounds.size());
    CoordinateBounds b = new CoordinateBounds(47.65048049686506, -122.30767397879845, 47.654977097836735, -122.300997795721);
    assertEquals(Arrays.asList(shapeIdA), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.32102634495334, 47.66397029978009, -122.3143501618759);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.66397029978009, -122.32770252803078, 47.66846690075177, -122.32102634495334);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.3143501618759, 47.66397029978009, -122.30767397879845);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
    b = new CoordinateBounds(47.65947369880841, -122.32770252803078, 47.66397029978009, -122.32102634495334);
    assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
}
Also used : TransitGraphDao(org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) FederatedTransitDataBundle(org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle) RefreshService(org.onebusaway.container.refresh.RefreshService) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) List(java.util.List) File(java.io.File) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Test(org.junit.Test)

Example 3 with FederatedTransitDataBundle

use of org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle in project onebusaway-application-modules by camsys.

the class TransitGraphTaskTest method testInterpolation.

@Test
public void testInterpolation() throws IOException, ClassNotFoundException {
    AgencyEntriesFactory agencyEntriesFactory = Mockito.mock(AgencyEntriesFactory.class);
    BlockEntriesFactory blockEntriesFactory = Mockito.mock(BlockEntriesFactory.class);
    RouteCollectionEntriesFactory routeCollectionEntriesFactory = Mockito.mock(RouteCollectionEntriesFactory.class);
    RouteEntriesFactory routeEntriesFactory = Mockito.mock(RouteEntriesFactory.class);
    StopEntriesFactory stopEntriesFactory = Mockito.mock(StopEntriesFactory.class);
    TripEntriesFactory tripEntriesFactory = Mockito.mock(TripEntriesFactory.class);
    FrequencyEntriesFactory frequencyEntriesFactory = Mockito.mock(FrequencyEntriesFactory.class);
    RefreshService refreshService = Mockito.mock(RefreshService.class);
    TransitGraphTask task = new TransitGraphTask();
    task.setAgencyEntriesFactory(agencyEntriesFactory);
    task.setBlockEntriesFactory(blockEntriesFactory);
    task.setRouteCollectionEntriesFactroy(routeCollectionEntriesFactory);
    task.setRouteEntriesFactory(routeEntriesFactory);
    task.setStopEntriesFactory(stopEntriesFactory);
    task.setTripEntriesFactory(tripEntriesFactory);
    task.setFrequencyEntriesFactory(frequencyEntriesFactory);
    task.setRefreshService(refreshService);
    File path = File.createTempFile("TemporaryBundleDirectory-", "");
    path.delete();
    FederatedTransitDataBundle bundle = Mockito.mock(FederatedTransitDataBundle.class);
    Mockito.when(bundle.getTransitGraphPath()).thenReturn(path);
    task.setBundle(bundle);
    task.run();
    Mockito.verify(agencyEntriesFactory).processAgencies(Mockito.any(TransitGraphImpl.class));
    Mockito.verify(routeEntriesFactory).processRoutes(Mockito.any(TransitGraphImpl.class));
    Mockito.verify(routeCollectionEntriesFactory).processRouteCollections(Mockito.any(TransitGraphImpl.class));
    Mockito.verify(stopEntriesFactory).processStops(Mockito.any(TransitGraphImpl.class));
    Mockito.verify(tripEntriesFactory).processTrips(Mockito.any(TransitGraphImpl.class));
    Mockito.verify(refreshService).refresh(RefreshableResources.TRANSIT_GRAPH);
    assertTrue(path.exists());
    TransitGraphImpl graph = ObjectSerializationLibrary.readObject(path);
    assertNotNull(graph);
}
Also used : RefreshService(org.onebusaway.container.refresh.RefreshService) FederatedTransitDataBundle(org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) File(java.io.File) Test(org.junit.Test)

Aggregations

FederatedTransitDataBundle (org.onebusaway.transit_data_federation.services.FederatedTransitDataBundle)3 File (java.io.File)2 Test (org.junit.Test)2 RefreshService (org.onebusaway.container.refresh.RefreshService)2 List (java.util.List)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 TaskDefinition (org.onebusaway.transit_data_federation.bundle.model.TaskDefinition)1 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)1 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)1 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)1 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1 TransitGraphDao (org.onebusaway.transit_data_federation.services.transit_graph.TransitGraphDao)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1