Search in sources :

Example 11 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method getTripProblemReportSummaries.

@Override
public ListBean<TripProblemReportSummaryBean> getTripProblemReportSummaries(TripProblemReportQueryBean query, ETripProblemGroupBy groupBy) {
    List<T2<Object, Integer>> records = _userReportingDao.getTripProblemReportSummaries(query, groupBy);
    List<TripProblemReportSummaryBean> beans = new ArrayList<TripProblemReportSummaryBean>(records.size());
    for (T2<Object, Integer> record : records) {
        TripProblemReportSummaryBean bean = new TripProblemReportSummaryBean();
        bean.setCount(record.getSecond());
        switch(groupBy) {
            case TRIP:
                {
                    AgencyAndId tripId = (AgencyAndId) record.getFirst();
                    bean.setTrip(_tripBeanService.getTripForId(tripId));
                    break;
                }
            case STATUS:
                {
                    EProblemReportStatus status = (EProblemReportStatus) record.getFirst();
                    bean.setStatus(status);
                    break;
                }
            case LABEL:
                {
                    String label = (String) record.getFirst();
                    bean.setLabel(label);
                    break;
                }
        }
        beans.add(bean);
    }
    return new ListBean<TripProblemReportSummaryBean>(beans, false);
}
Also used : TripProblemReportSummaryBean(org.onebusaway.transit_data.model.problems.TripProblemReportSummaryBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) EProblemReportStatus(org.onebusaway.transit_data.model.problems.EProblemReportStatus) ListBean(org.onebusaway.transit_data.model.ListBean) T2(org.onebusaway.collections.tuple.T2)

Example 12 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class UserReportingServiceImpl method getStopProblemReportSummaries.

@Override
public ListBean<StopProblemReportSummaryBean> getStopProblemReportSummaries(StopProblemReportQueryBean query) {
    List<T2<AgencyAndId, Integer>> records = _userReportingDao.getStopProblemReportSummaries(query.getAgencyId(), query.getTimeFrom(), query.getTimeTo(), query.getStatus());
    List<StopProblemReportSummaryBean> beans = new ArrayList<StopProblemReportSummaryBean>(records.size());
    for (T2<AgencyAndId, Integer> record : records) {
        AgencyAndId stopId = record.getFirst();
        Integer count = record.getSecond();
        StopProblemReportSummaryBean bean = new StopProblemReportSummaryBean();
        bean.setStop(_stopBeanService.getStopForId(stopId));
        bean.setStatus(query.getStatus());
        bean.setCount(count);
        beans.add(bean);
    }
    return new ListBean<StopProblemReportSummaryBean>(beans, false);
}
Also used : StopProblemReportSummaryBean(org.onebusaway.transit_data.model.problems.StopProblemReportSummaryBean) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) T2(org.onebusaway.collections.tuple.T2)

Example 13 with ListBean

use of org.onebusaway.transit_data.model.ListBean 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)

Example 14 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class StopsBeanServiceImpl method getStopsIdsForAgencyId.

@Override
public ListBean<String> getStopsIdsForAgencyId(String agencyId) {
    AgencyEntry agency = _transitGraphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<String> ids = new ArrayList<String>();
    for (StopEntry stop : agency.getStops()) {
        AgencyAndId id = stop.getId();
        ids.add(AgencyAndIdLibrary.convertToString(id));
    }
    return new ListBean<String>(ids, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)

Example 15 with ListBean

use of org.onebusaway.transit_data.model.ListBean in project onebusaway-application-modules by camsys.

the class CurrentVehicleEstimationServiceImpl method getCurrentVehicleEstimates.

@Override
public ListBean<CurrentVehicleEstimateBean> getCurrentVehicleEstimates(CurrentVehicleEstimateQueryBean query) {
    long minT = SystemTime.currentTimeMillis() - _maxWindow * 60 * 1000;
    minT = 0;
    List<Record> records = getRecords(query.getRecords(), minT);
    if (records.isEmpty())
        return new ListBean<CurrentVehicleEstimateBean>();
    List<CurrentVehicleEstimateBean> beans = new ArrayList<CurrentVehicleEstimateBean>();
    if (tryDirectMatchAgainstVehicleId(query, records, beans))
        return new ListBean<CurrentVehicleEstimateBean>(beans, true);
    Map<Date, Record> recordsByTime = getRecordsByTimestamp(records);
    List<Date> timestamps = new ArrayList<Date>(recordsByTime.keySet());
    Collections.sort(timestamps);
    if (tryDirectMatchAgainstBlockId(query, records, recordsByTime, timestamps, query.getMinProbability(), beans))
        return new ListBean<CurrentVehicleEstimateBean>(beans, true);
    Set<BlockSequenceIndex> allIndices = getBlockSequenceIndicesForRecords(recordsByTime);
    for (BlockSequenceIndex index : allIndices) {
        Map<BlockInstance, List<List<BlockLocation>>> allLocations = _blockStatusService.getBlocksForIndex(index, timestamps);
        for (Map.Entry<BlockInstance, List<List<BlockLocation>>> entry : allLocations.entrySet()) {
            BlockInstance blockInstance = entry.getKey();
            List<List<BlockLocation>> realTimeLocations = entry.getValue();
            computeEstimatesForBlockInstance(records, recordsByTime, blockInstance, realTimeLocations, query.getMinProbability(), beans);
        }
    }
    Collections.sort(beans);
    return new ListBean<CurrentVehicleEstimateBean>(beans, false);
}
Also used : BlockSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockSequenceIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) CurrentVehicleEstimateBean(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateBean) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) Record(org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)17 ListBean (org.onebusaway.transit_data.model.ListBean)17 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)5 Date (java.util.Date)4 List (java.util.List)4 Test (org.junit.Test)4 RouteBean (org.onebusaway.transit_data.model.RouteBean)4 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)3 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)3 IOException (java.io.IOException)3 ResponseBean (org.onebusaway.api.model.ResponseBean)3 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)3 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)3 Map (java.util.Map)2 T2 (org.onebusaway.collections.tuple.T2)2 Cacheable (org.onebusaway.container.cache.Cacheable)2 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)2 TripBean (org.onebusaway.transit_data.model.trips.TripBean)2 TripDetailsBean (org.onebusaway.transit_data.model.trips.TripDetailsBean)2