Search in sources :

Example 1 with RouteCollectionNarrative

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

the class RouteBeanServiceImpl method getStopsForRoute.

@Cacheable
public StopsForRouteBean getStopsForRoute(AgencyAndId routeId) {
    RouteCollectionEntry routeCollectionEntry = _transitGraphDao.getRouteCollectionForId(routeId);
    RouteCollectionNarrative narrative = _narrativeService.getRouteCollectionForId(routeId);
    if (routeCollectionEntry == null || narrative == null)
        return null;
    return getStopsForRouteCollectionAndNarrative(routeCollectionEntry, narrative);
}
Also used : RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 2 with RouteCollectionNarrative

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

the class RouteBeanServiceImplTest method testGetRouteForId.

@Test
public void testGetRouteForId() {
    AgencyAndId routeId = new AgencyAndId("1", "route");
    RouteCollectionNarrative.Builder routeBuilder = RouteCollectionNarrative.builder();
    routeBuilder.setColor("blue");
    routeBuilder.setDescription("route desc");
    routeBuilder.setLongName("route long name");
    routeBuilder.setShortName("route short name");
    routeBuilder.setTextColor("red");
    routeBuilder.setType(3);
    routeBuilder.setUrl("http://wwww.route.com");
    RouteCollectionNarrative route = routeBuilder.create();
    AgencyBean agency = new AgencyBean();
    Mockito.when(_agencyBeanService.getAgencyForId("1")).thenReturn(agency);
    Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(route);
    RouteBean bean = _service.getRouteForId(routeId);
    assertEquals(route.getColor(), bean.getColor());
    assertEquals(route.getDescription(), bean.getDescription());
    assertEquals(AgencyAndIdLibrary.convertToString(routeId), bean.getId());
    assertEquals(route.getLongName(), bean.getLongName());
    assertEquals(route.getShortName(), bean.getShortName());
    assertEquals(route.getTextColor(), bean.getTextColor());
    assertEquals(route.getType(), bean.getType());
    assertEquals(route.getUrl(), bean.getUrl());
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) Test(org.junit.Test)

Example 3 with RouteCollectionNarrative

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

the class GenerateRouteCollectionSearchIndexTask method buildIndex.

private void buildIndex() throws IOException, ParseException {
    IndexWriter writer = new IndexWriter(_bundle.getRouteSearchIndexPath(), new StandardAnalyzer(ENGLISH_STOP_WORDS), true, IndexWriter.MaxFieldLength.LIMITED);
    for (RouteCollectionEntry routeCollection : _transitGraphDao.getAllRouteCollections()) {
        RouteCollectionNarrative narrative = _narrativeService.getRouteCollectionForId(routeCollection.getId());
        Document document = getRouteCollectionAsDocument(routeCollection, narrative);
        writer.addDocument(document);
    }
    writer.optimize();
    writer.close();
    _refreshService.refresh(RefreshableResources.ROUTE_COLLECTION_SEARCH_DATA);
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Document(org.apache.lucene.document.Document) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)

Example 4 with RouteCollectionNarrative

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

the class GenerateNarrativesTaskTest method testGenerateRouteNarratives.

@Test
public void testGenerateRouteNarratives() {
    RouteEntryImpl r1 = route("routeA1");
    RouteEntryImpl r2 = route("routeA2");
    RouteCollectionEntryImpl rc = routeCollection("routeA", r1, r2);
    TripEntry t1 = trip("t1");
    TripEntry t2 = trip("t2");
    TripEntry t3 = trip("t3");
    // r2's values should win out over r1's because it has more trips
    r1.setTrips(Arrays.asList(t1));
    r2.setTrips(Arrays.asList(t2, t3));
    Mockito.when(_transitGraphDao.getAllRouteCollections()).thenReturn(Arrays.asList((RouteCollectionEntry) rc));
    Route route1 = new Route();
    route1.setId(r1.getId());
    route1.setBikesAllowed(0);
    route1.setColor("#000000");
    route1.setDesc("Route One Desc");
    route1.setLongName("Route One");
    route1.setShortName("One");
    route1.setTextColor("#ff0000");
    route1.setType(3);
    route1.setUrl("http://agency.gov/route-one");
    Route route2 = new Route();
    route2.setId(r2.getId());
    route2.setBikesAllowed(1);
    route2.setColor("#0000ff");
    route2.setDesc("Route Two Desc");
    route2.setLongName("Route Two");
    route2.setShortName("Two");
    route2.setTextColor("#000000");
    route2.setType(3);
    route2.setUrl("http://agency.gov/route-two");
    Mockito.when(_gtfsDao.getRouteForId(r1.getId())).thenReturn(route1);
    Mockito.when(_gtfsDao.getRouteForId(r2.getId())).thenReturn(route2);
    _task.generateRouteNarratives(_provider);
    RouteCollectionNarrative narrative = _provider.getNarrativeForRouteCollectionId(rc.getId());
    assertEquals(route2.getColor(), narrative.getColor());
    assertEquals(route2.getDesc(), narrative.getDescription());
    assertEquals(route2.getLongName(), narrative.getLongName());
    assertEquals(route2.getShortName(), narrative.getShortName());
    assertEquals(route2.getTextColor(), narrative.getTextColor());
    assertEquals(route2.getType(), narrative.getType());
    assertEquals(route2.getUrl(), narrative.getUrl());
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Route(org.onebusaway.gtfs.model.Route) RouteCollectionNarrative(org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative) Test(org.junit.Test)

Aggregations

RouteCollectionNarrative (org.onebusaway.transit_data_federation.model.narrative.RouteCollectionNarrative)4 RouteCollectionEntry (org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry)3 Test (org.junit.Test)2 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 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Route (org.onebusaway.gtfs.model.Route)1 AgencyBean (org.onebusaway.transit_data.model.AgencyBean)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)1 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)1 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1