Search in sources :

Example 6 with VehicleActivityStructure

use of uk.org.siri.siri.VehicleActivityStructure in project onebusaway-application-modules by camsys.

the class RealtimeServiceImpl method getVehicleActivityForRoute.

/**
 * SIRI METHODS
 */
@Override
public List<VehicleActivityStructure> getVehicleActivityForRoute(String routeId, String directionId, int maximumOnwardCalls, long currentTime, boolean showRawLocation) {
    List<VehicleActivityStructure> output = new ArrayList<VehicleActivityStructure>();
    ListBean<TripDetailsBean> trips = getAllTripsForRoute(routeId, currentTime);
    for (TripDetailsBean tripDetails : trips.getList()) {
        // filter out interlined routes
        if (routeId != null && !tripDetails.getTrip().getRoute().getId().equals(routeId))
            continue;
        // filtered out by user
        if (tripDetails.getTrip().getDirectionId() != null) {
            if (directionId != null && !tripDetails.getTrip().getDirectionId().equals(directionId)) {
                continue;
            }
        }
        if (!_presentationService.include(tripDetails.getStatus()))
            continue;
        VehicleActivityStructure activity = new VehicleActivityStructure();
        // Check for Realtime Data
        if (!tripDetails.getStatus().isPredicted()) {
            activity.setRecordedAtTime(new Date(getTime()));
        } else {
            activity.setRecordedAtTime(new Date(tripDetails.getStatus().getLastUpdateTime()));
        }
        List<TimepointPredictionRecord> timePredictionRecords = null;
        timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(routeId).getAgencyId(), tripDetails.getStatus());
        activity.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
        SiriSupport.fillMonitoredVehicleJourney(activity.getMonitoredVehicleJourney(), tripDetails.getTrip(), tripDetails.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetails.getStatus().isPredicted(), currentTime, showRawLocation);
        output.add(activity);
    }
    Collections.sort(output, new Comparator<VehicleActivityStructure>() {

        public int compare(VehicleActivityStructure arg0, VehicleActivityStructure arg1) {
            try {
                SiriExtensionWrapper wrapper0 = (SiriExtensionWrapper) arg0.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
                SiriExtensionWrapper wrapper1 = (SiriExtensionWrapper) arg1.getMonitoredVehicleJourney().getMonitoredCall().getExtensions().getAny();
                return wrapper0.getDistances().getDistanceFromCall().compareTo(wrapper1.getDistances().getDistanceFromCall());
            } catch (Exception e) {
                return -1;
            }
        }
    });
    return output;
}
Also used : ArrayList(java.util.ArrayList) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) TripDetailsBean(org.onebusaway.transit_data.model.trips.TripDetailsBean) Date(java.util.Date) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)

Example 7 with VehicleActivityStructure

use of uk.org.siri.siri.VehicleActivityStructure in project onebusaway-application-modules by camsys.

the class VehicleMonitoringActionTest method testExecuteByRouteNoActivity.

@Test
public void testExecuteByRouteNoActivity() throws Exception {
    when(request.getParameter(eq("LineRef"))).thenReturn("40_100479");
    when(request.getParameter(eq("OperatorRef"))).thenReturn("1");
    PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
        // Do nothing
        }
    });
    when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
    List<VehicleActivityStructure> vehicleActivities = new ArrayList<VehicleActivityStructure>();
    when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities);
    ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1");
    when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean);
    RouteBean routeBean = RouteBean.builder().create();
    when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean);
    ListBean<ServiceAlertBean> serviceAlertListBean = new ListBean<ServiceAlertBean>();
    List<ServiceAlertBean> list = new ArrayList<ServiceAlertBean>();
    list.add(serviceAlertBean);
    serviceAlertListBean.setList(list);
    when(transitDataService.getServiceAlerts(any(SituationQueryBean.class))).thenReturn(serviceAlertListBean);
    SiriXmlSerializer serializer = new SiriXmlSerializer();
    when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
    action.setServletRequest(request);
    action.setServletResponse(servletResponse);
    action.index();
    String monitoring = action.getVehicleMonitoring();
    assertTrue("Result XML does not match expected", monitoring.matches("(?s).*<SituationExchangeDelivery><Situations><PtSituationElement><SituationNumber>1_1</SituationNumber><Summary xml:lang=\"EN\">summary</Summary><Description xml:lang=\"EN\">description</Description><Affects><VehicleJourneys><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney></VehicleJourneys></Affects></PtSituationElement></Situations></SituationExchangeDelivery></ServiceDelivery></Siri>.*"));
}
Also used : OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) RouteBean(org.onebusaway.transit_data.model.RouteBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) SiriXmlSerializer(org.onebusaway.transit_data_federation.siri.SiriXmlSerializer) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

VehicleActivityStructure (uk.org.siri.siri.VehicleActivityStructure)7 ArrayList (java.util.ArrayList)6 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)4 IOException (java.io.IOException)3 MonitoredVehicleJourney (uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)3 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)2 ListBean (org.onebusaway.transit_data.model.ListBean)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)2 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)2 SiriXmlSerializer (org.onebusaway.transit_data_federation.siri.SiriXmlSerializer)2 GoogleAnalyticsRequest (com.brsanthu.googleanalytics.GoogleAnalyticsRequest)1