use of uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney in project onebusaway-application-modules by camsys.
the class VehicleMonitoringActionTest method testExecuteByRoute.
@Test
public void testExecuteByRoute() 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);
VehicleActivityStructure vehicleActivity = new VehicleActivityStructure();
vehicleActivities.add(vehicleActivity);
MonitoredVehicleJourney mvJourney = new MonitoredVehicleJourney();
vehicleActivity.setMonitoredVehicleJourney(mvJourney);
LocationStructure locationStructure = new LocationStructure();
mvJourney.setVehicleLocation(locationStructure);
locationStructure.setLatitude(BigDecimal.valueOf(88.0));
locationStructure.setLongitude(BigDecimal.valueOf(89.0));
ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1");
when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean);
RouteBean routeBean = RouteBean.builder().create();
when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean);
when(configurationService.getConfigurationValueAsString(eq("display.googleAnalyticsSiteId"), anyString())).thenReturn("foo");
List<SituationRefStructure> sitRef = mvJourney.getSituationRef();
SituationRefStructure sitRefStructure = new SituationRefStructure();
sitRef.add(sitRefStructure);
SituationSimpleRefStructure sitSimpleRef = new SituationSimpleRefStructure();
sitRefStructure.setSituationSimpleRef(sitSimpleRef);
sitSimpleRef.setValue("situation ref");
SiriXmlSerializer serializer = new SiriXmlSerializer();
when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
// doNothing().when(gaService).post(new PageViewHit());
when(gaService.post(new GoogleAnalyticsRequest())).thenReturn(new GoogleAnalyticsResponse());
action.setServletRequest(request);
action.setServletResponse(servletResponse);
action.index();
String monitoring = action.getVehicleMonitoring();
assertTrue("Result XML does not match expected", monitoring.matches("(?s).*<ServiceDelivery><ResponseTimestamp>.+</ResponseTimestamp><VehicleMonitoringDelivery><ResponseTimestamp>.+</ResponseTimestamp><ValidUntil>.+</ValidUntil><VehicleActivity><MonitoredVehicleJourney><SituationRef><SituationSimpleRef>situation ref</SituationSimpleRef></SituationRef><VehicleLocation><Longitude>89.0</Longitude><Latitude>88.0</Latitude></VehicleLocation></MonitoredVehicleJourney></VehicleActivity></VehicleMonitoringDelivery><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>.*"));
}
use of uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney in project onebusaway-application-modules by camsys.
the class RealtimeServiceImpl method getVehicleActivityForVehicle.
@Override
public VehicleActivityStructure getVehicleActivityForVehicle(String vehicleId, int maximumOnwardCalls, long currentTime, String tripId) {
TripForVehicleQueryBean query = new TripForVehicleQueryBean();
query.setTime(new Date(currentTime));
query.setVehicleId(vehicleId);
TripDetailsInclusionBean inclusion = new TripDetailsInclusionBean();
inclusion.setIncludeTripStatus(true);
inclusion.setIncludeTripBean(true);
query.setInclusion(inclusion);
TripDetailsBean tripDetailsForCurrentTrip = _transitDataService.getTripDetailsForVehicleAndTime(query);
if (tripDetailsForCurrentTrip == null) {
TripDetailsQueryBean detailsQuery = new TripDetailsQueryBean();
detailsQuery.setTime(currentTime);
detailsQuery.setTripId(tripId);
tripDetailsForCurrentTrip = _transitDataService.getSingleTripDetails(detailsQuery);
}
if (tripDetailsForCurrentTrip == null || !_presentationService.include(tripDetailsForCurrentTrip.getStatus()))
return null;
VehicleActivityStructure output = new VehicleActivityStructure();
// Check for Realtime Data
if (!tripDetailsForCurrentTrip.getStatus().isPredicted()) {
output.setRecordedAtTime(new Date(getTime()));
} else {
output.setRecordedAtTime(new Date(tripDetailsForCurrentTrip.getStatus().getLastUpdateTime()));
}
List<TimepointPredictionRecord> timePredictionRecords = null;
timePredictionRecords = _transitDataService.getPredictionRecordsForTrip(AgencyAndId.convertFromString(vehicleId).getAgencyId(), tripDetailsForCurrentTrip.getStatus());
output.setMonitoredVehicleJourney(new MonitoredVehicleJourney());
SiriSupport.fillMonitoredVehicleJourney(output.getMonitoredVehicleJourney(), tripDetailsForCurrentTrip.getTrip(), tripDetailsForCurrentTrip.getStatus(), null, OnwardCallsMode.VEHICLE_MONITORING, _presentationService, _transitDataService, maximumOnwardCalls, timePredictionRecords, tripDetailsForCurrentTrip.getStatus().isPredicted(), currentTime, false);
return output;
}
use of uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney 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;
}
use of uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney in project onebusaway-application-modules by camsys.
the class SiriService method handleVehicleMonitoring.
/**
**
* Private Methods
***
*/
private void handleVehicleMonitoring(ServiceDelivery serviceDelivery, VehicleMonitoringDeliveryStructure deliveryForModule, SiriEndpointDetails endpointDetails) {
List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();
Date now = new Date();
long timeFrom = now.getTime() - _blockInstanceSearchWindow * 60 * 1000;
long timeTo = now.getTime() + _blockInstanceSearchWindow * 60 * 1000;
for (VehicleActivityStructure vehicleActivity : deliveryForModule.getVehicleActivity()) {
Date time = vehicleActivity.getRecordedAtTime();
if (time == null)
time = now;
MonitoredVehicleJourney mvj = vehicleActivity.getMonitoredVehicleJourney();
Duration delay = mvj.getDelay();
if (delay == null)
continue;
VehicleRefStructure vehicleRef = mvj.getVehicleRef();
if (vehicleRef == null || vehicleRef.getValue() == null)
continue;
BlockEntry block = getBlockForMonitoredVehicleJourney(mvj, endpointDetails);
if (block == null) {
TripEntry trip = getTripForMonitoredVehicleJourney(mvj, endpointDetails);
if (trip != null)
block = trip.getBlock();
}
if (block == null)
continue;
List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(block.getId(), timeFrom, timeTo);
// TODO : We currently assume that a block won't overlap with itself
if (instances.size() != 1)
continue;
BlockInstance instance = instances.get(0);
VehicleLocationRecord r = new VehicleLocationRecord();
r.setTimeOfRecord(time.getTime());
r.setServiceDate(instance.getServiceDate());
r.setBlockId(block.getId());
String agencyId = block.getId().getAgencyId();
r.setVehicleId(new AgencyAndId(agencyId, vehicleRef.getValue()));
r.setScheduleDeviation(delay.getTimeInMillis(now) / 1000);
LocationStructure location = mvj.getVehicleLocation();
if (location != null) {
r.setCurrentLocationLat(location.getLatitude().doubleValue());
r.setCurrentLocationLon(location.getLongitude().doubleValue());
}
records.add(r);
}
if (!records.isEmpty())
_vehicleLocationListener.handleVehicleLocationRecords(records);
}
Aggregations