Search in sources :

Example 6 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative in project onebusaway-application-modules by camsys.

the class StopBeanServiceImplTest method testGetStopForId.

@Test
public void testGetStopForId() {
    AgencyAndId stopId = new AgencyAndId("29", "1109");
    StopEntryImpl stopEntry = new StopEntryImpl(stopId, 47.1, -122.1);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopId)).thenReturn(stopEntry);
    StopNarrative.Builder builder = StopNarrative.builder();
    builder.setCode("1109-b");
    builder.setDescription("stop description");
    builder.setLocationType(0);
    builder.setName("stop name");
    builder.setUrl("http://some/url");
    builder.setDirection("N");
    StopNarrative stop = builder.create();
    Mockito.when(_narrativeService.getStopForId(stopId)).thenReturn(stop);
    AgencyAndId routeId = new AgencyAndId("1", "route");
    Set<AgencyAndId> routeIds = new HashSet<AgencyAndId>();
    routeIds.add(routeId);
    Mockito.when(_routeService.getRouteCollectionIdsForStop(stopId)).thenReturn(routeIds);
    RouteBean.Builder routeBuilder = RouteBean.builder();
    routeBuilder.setId(AgencyAndIdLibrary.convertToString(routeId));
    RouteBean route = routeBuilder.create();
    Mockito.when(_routeBeanService.getRouteForId(routeId)).thenReturn(route);
    StopBean stopBean = _service.getStopForId(stopId);
    assertNotNull(stopBean);
    assertEquals(stopId.toString(), stopBean.getId());
    assertEquals(stop.getName(), stopBean.getName());
    assertEquals(stopEntry.getStopLat(), stopBean.getLat(), 0.0);
    assertEquals(stopEntry.getStopLon(), stopBean.getLon(), 0.0);
    assertEquals(stop.getCode(), stopBean.getCode());
    assertEquals(stop.getLocationType(), stopBean.getLocationType());
    List<RouteBean> routes = stopBean.getRoutes();
    assertEquals(1, routes.size());
    assertSame(route, routes.get(0));
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopBean(org.onebusaway.transit_data.model.StopBean) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative in project onebusaway-application-modules by camsys.

the class StopBeanServiceImpl method getStopForId.

@Cacheable
public StopBean getStopForId(AgencyAndId id) {
    StopEntry stop = _transitGraphDao.getStopEntryForId(id);
    StopNarrative narrative = _narrativeService.getStopForId(id);
    if (stop == null) {
        // try looking up consolidated id
        AgencyAndId consolidatedId = _consolidatedStopsService.getConsolidatedStopIdForHiddenStopId(id);
        if (consolidatedId != null)
            return getStopForId(consolidatedId);
        throw new NoSuchStopServiceException(AgencyAndIdLibrary.convertToString(id));
    }
    StopBean sb = new StopBean();
    fillStopBean(stop, narrative, sb);
    fillRoutesForStopBean(stop, sb);
    return sb;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopBean(org.onebusaway.transit_data.model.StopBean) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Aggregations

StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)6 Test (org.junit.Test)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 Stop (org.onebusaway.gtfs.model.Stop)4 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)4 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)3 StopBean (org.onebusaway.transit_data.model.StopBean)2 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)2 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)2 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)2 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2 HashSet (java.util.HashSet)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Document (org.apache.lucene.document.Document)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 Cacheable (org.onebusaway.container.cache.Cacheable)1 NoSuchStopServiceException (org.onebusaway.exceptions.NoSuchStopServiceException)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1