Search in sources :

Example 1 with RouteResult

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getRouteResult.

@Override
public SearchResult getRouteResult(RouteBean routeBean) {
    List<RouteDirection> directions = new ArrayList<RouteDirection>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    // create stop ID->stop bean map
    Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
    for (StopBean stopBean : stopsForRoute.getStops()) {
        stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
    }
    // add stops in both directions
    List<VehicleActivityStructure> journeyList = _realtimeService.getVehicleActivityForRoute(routeBean.getId(), null, 0, SystemTime.currentTimeMillis(), false);
    Map<String, List<String>> stopIdToDistanceAwayStringMap = new HashMap<String, List<String>>();
    Map<String, List<String>> stopIdToVehicleIdMap = new HashMap<String, List<String>>();
    Map<String, Boolean> stopIdToRealtimeDataMap = new HashMap<String, Boolean>();
    // build map of stop IDs to list of distance strings
    for (VehicleActivityStructure journey : journeyList) {
        // on detour?
        MonitoredCallStructure monitoredCall = journey.getMonitoredVehicleJourney().getMonitoredCall();
        if (monitoredCall == null) {
            continue;
        }
        String stopId = monitoredCall.getStopPointRef().getValue();
        fillDistanceAwayStringsList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToDistanceAwayStringMap);
        fillVehicleIdsStringList(journey.getMonitoredVehicleJourney(), journey.getRecordedAtTime(), stopId, stopIdToVehicleIdMap);
        fillRealtimeData(journey.getMonitoredVehicleJourney(), stopId, stopIdToRealtimeDataMap);
    }
    List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
    for (StopGroupingBean stopGroupingBean : stopGroupings) {
        for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
            NameBean name = stopGroupBean.getName();
            String type = name.getType();
            if (!type.equals("destination"))
                continue;
            // service in this direction
            Boolean hasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), stopGroupBean.getId());
            // if there are buses on route, always have "scheduled service"
            Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForRoute(routeBean.getId(), stopGroupBean.getId(), SystemTime.currentTimeMillis());
            if (routeHasVehiclesInService) {
                hasUpcomingScheduledService = true;
            }
            // stops in this direction
            List<StopOnRoute> stopsOnRoute = null;
            if (!stopGroupBean.getStopIds().isEmpty()) {
                stopsOnRoute = new ArrayList<StopOnRoute>();
                for (String stopId : stopGroupBean.getStopIds()) {
                    if (_transitDataService.stopHasRevenueServiceOnRoute((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), stopId, routeBean.getId(), stopGroupBean.getId())) {
                        stopsOnRoute.add(new StopOnRoute(stopIdToStopBeanMap.get(stopId), stopIdToDistanceAwayStringMap.get(stopId), stopIdToRealtimeDataMap.get(stopId), stopIdToVehicleIdMap.get(stopId)));
                    }
                }
            }
            directions.add(new RouteDirection(stopGroupBean.getName().getName(), stopGroupBean, stopsOnRoute, hasUpcomingScheduledService, null));
        }
    }
    // service alerts in this direction
    Set<String> serviceAlertDescriptions = new HashSet<String>();
    List<ServiceAlertBean> serviceAlertBeans = _realtimeService.getServiceAlertsForRoute(routeBean.getId());
    populateServiceAlerts(serviceAlertDescriptions, serviceAlertBeans);
    return new RouteResult(routeBean, directions, serviceAlertDescriptions);
}
Also used : HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) ArrayList(java.util.ArrayList) List(java.util.List) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure) HashSet(java.util.HashSet) RouteDirection(org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) NameBean(org.onebusaway.transit_data.model.NameBean) StopOnRoute(org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)

Example 2 with RouteResult

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImplTest method testGetRouteResultServiceAlertWithSummariesOnly.

@Test
public void testGetRouteResultServiceAlertWithSummariesOnly() {
    RouteResult result = runGetRouteResult(createServiceAlerts(new String[] {}, new String[] { TEST_SUMMARY }));
    Set<String> alerts = result.getServiceAlerts();
    assertEquals(1, alerts.size());
    assertEquals(TEST_SUMMARY, alerts.toArray()[0]);
    assertEquals("name not expected", ROUTE_ID, result.getId());
}
Also used : RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with RouteResult

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.

the class IndexAction method getUniqueServiceAlertsForResults.

public Set<String> getUniqueServiceAlertsForResults() {
    Set<String> uniqueServiceAlerts = new HashSet<String>();
    for (SearchResult _result : _results.getMatches()) {
        if (_results.getResultType().equals("RouteResult")) {
            RouteResult result = (RouteResult) _result;
            uniqueServiceAlerts.addAll(result.getServiceAlerts());
        } else if (_results.getResultType().equals("StopResult")) {
            StopResult result = (StopResult) _result;
            for (RouteAtStop route : result.getAllRoutesAvailable()) {
                uniqueServiceAlerts.addAll(route.getServiceAlerts());
            }
        }
    }
    return uniqueServiceAlerts;
}
Also used : RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) SearchResult(org.onebusaway.presentation.model.SearchResult) RouteAtStop(org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop) StopResult(org.onebusaway.enterprise.webapp.actions.m.model.StopResult) HashSet(java.util.HashSet)

Example 4 with RouteResult

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.

the class IndexAction method getRouteColors.

public String getRouteColors() {
    Set<String> routeColors = new HashSet<String>();
    for (SearchResult _result : _results.getMatches()) {
        RouteResult result = (RouteResult) _result;
        routeColors.add(result.getColor());
    }
    return StringUtils.join(routeColors, ",");
}
Also used : RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) SearchResult(org.onebusaway.presentation.model.SearchResult) HashSet(java.util.HashSet)

Example 5 with RouteResult

use of org.onebusaway.enterprise.webapp.actions.m.model.RouteResult in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImplTest method testGetRouteResultServiceAlertWithDescriptionsOnly.

@Test
public void testGetRouteResultServiceAlertWithDescriptionsOnly() {
    RouteResult result = runGetRouteResult(createServiceAlerts(new String[] { TEST_DESCRIPTION, TEST_DESCRIPTION2 }, new String[] { TEST_SUMMARY }));
    Set<String> alerts = result.getServiceAlerts();
    assertEquals(2, alerts.size());
    String[] array = alerts.toArray(new String[] {});
    // array position is no longer guaranteed
    boolean found0 = ((TEST_DESCRIPTION).equals(array[0])) || ((TEST_DESCRIPTION).equals(array[1]));
    boolean found1 = ((TEST_DESCRIPTION2).equals(array[0])) || ((TEST_DESCRIPTION2).equals(array[1]));
    assertTrue(found0);
    assertTrue(found1);
    assertEquals("name not expected", ROUTE_ID, result.getId());
}
Also used : RouteResult(org.onebusaway.enterprise.webapp.actions.m.model.RouteResult) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

RouteResult (org.onebusaway.enterprise.webapp.actions.m.model.RouteResult)8 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 HashSet (java.util.HashSet)3 SearchResult (org.onebusaway.presentation.model.SearchResult)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 RouteAtStop (org.onebusaway.enterprise.webapp.actions.m.model.RouteAtStop)1 RouteDirection (org.onebusaway.enterprise.webapp.actions.m.model.RouteDirection)1 StopOnRoute (org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)1 StopResult (org.onebusaway.enterprise.webapp.actions.m.model.StopResult)1 NameBean (org.onebusaway.transit_data.model.NameBean)1 StopBean (org.onebusaway.transit_data.model.StopBean)1 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)1 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1 MonitoredCallStructure (uk.org.siri.siri.MonitoredCallStructure)1 VehicleActivityStructure (uk.org.siri.siri.VehicleActivityStructure)1