use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class NotifyResourceTest method testToTweet.
@Test
public void testToTweet() {
ServiceAlertBean bean = null;
NotificationServiceImpl nsi = new NotificationServiceImpl();
NotificationStrategy ns = new TestNotificationStrategy();
nsi.setNotificationStrategy(ns);
NotifyResource resource = new NotifyResource();
resource.setNotificationService(nsi);
assertNull(resource.toTweet(bean));
bean = new ServiceAlertBean();
assertNull(resource.toTweet(bean));
bean.setSummaries(new ArrayList<NaturalLanguageStringBean>());
bean.getSummaries().add(createNLS("Snow Routes in Affect"));
// service alert has no affects clause, nothing to do
assertEquals(null, resource.toTweet(bean));
SituationAffectsBean affects = new SituationAffectsBean();
affects.setAgencyId("ACTA");
bean.setAllAffects(new ArrayList<SituationAffectsBean>());
bean.getAllAffects().add(affects);
// we don't include agency in tweet -- it will be obvious from the twitter handle
assertEquals("Snow Routes in Affect", resource.toTweet(bean));
// add a single route
affects.setRouteId("A1");
assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1", resource.toTweet(bean));
// add a stop
affects = new SituationAffectsBean();
affects.setAgencyId("ACTA");
bean.getAllAffects().add(affects);
affects.setStopId("Water and Blowers");
try {
assertEquals("Snow Routes in Affect affecting route(s) A1 and stop(s) Water and Blowers", resource.toTweet(bean));
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException iae) {
// pass
}
affects.setStopId("ACTA_6968");
assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1 and stop(s) ACTA_6968", resource.toTweet(bean));
// add another route
affects = new SituationAffectsBean();
affects.setAgencyId("ACTA");
bean.getAllAffects().add(affects);
affects.setRouteId("B2");
assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1, ACTA_B2 and stop(s) ACTA_6968", resource.toTweet(bean));
// add another stop
affects = new SituationAffectsBean();
affects.setAgencyId("ACTA");
bean.getAllAffects().add(affects);
affects.setStopId("ACTA_4370");
assertEquals("Snow Routes in Affect affecting route(s) ACTA_A1, ACTA_B2 and stop(s) ACTA_6968, ACTA_4370", resource.toTweet(bean));
// clear out routes, add a single stop
affects = new SituationAffectsBean();
affects.setAgencyId("ACTA");
bean.setAllAffects(new ArrayList<SituationAffectsBean>());
bean.getAllAffects().add(affects);
affects.setStopId("ACTA_4370");
assertEquals("Snow Routes in Affect affecting stop(s) ACTA_4370", resource.toTweet(bean));
// add another stop
affects = new SituationAffectsBean();
affects.setAgencyId("ACTA");
bean.getAllAffects().add(affects);
affects.setStopId("ACTA_6968");
assertEquals("Snow Routes in Affect affecting stop(s) ACTA_4370, ACTA_6968", resource.toTweet(bean));
// we don't support trip level tweets
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class AlertsAction method getModel.
@Override
public FeedMessage getModel() {
FeedMessage cachedAlerts = _cache.getAlerts();
if (cachedAlerts != null) {
return cachedAlerts;
} else {
FeedMessage.Builder feedMessage = createFeedWithDefaultHeader();
List<String> agencyIds = new ArrayList<String>();
if (agencyId != null) {
agencyIds.add(agencyId);
} else {
Map<String, List<CoordinateBounds>> agencies = _transitDataService.getAgencyIdsWithCoverageArea();
agencyIds.addAll(agencies.keySet());
}
for (String agencyId : agencyIds) {
ListBean<ServiceAlertBean> serviceAlertBeans = _transitDataService.getAllServiceAlertsForAgencyId(agencyId);
for (ServiceAlertBean serviceAlert : serviceAlertBeans.getList()) {
try {
Alert.Builder alert = Alert.newBuilder();
fillAlertHeader(alert, serviceAlert.getSummaries());
fillAlertDescriptions(alert, serviceAlert.getDescriptions());
fillActiveWindows(alert, serviceAlert.getActiveWindows());
fillSituationAffects(alert, serviceAlert.getAllAffects());
FeedEntity.Builder feedEntity = FeedEntity.newBuilder();
feedEntity.setAlert(alert);
feedEntity.setId(id(agencyId, serviceAlert.getId()));
feedMessage.addEntity(feedEntity);
} catch (Exception e) {
_log.error("Unable to process service alert", e);
}
}
}
FeedMessage builtFeedMessage = feedMessage.build();
_cache.putAlerts(builtFeedMessage);
return builtFeedMessage;
}
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class StopWithArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.
public StopWithArrivalsAndDeparturesBean getArrivalsAndDeparturesByStopId(AgencyAndId id, ArrivalsAndDeparturesQueryBean query) {
StopBean stop = _stopBeanService.getStopForId(id);
if (stop == null)
return null;
List<ArrivalAndDepartureBean> arrivalsAndDepartures = _arrivalsAndDeparturesBeanService.getArrivalsAndDeparturesByStopId(id, query);
List<AgencyAndId> nearbyStopIds = _nearbyStopsBeanService.getNearbyStops(stop, 100);
List<StopBean> nearbyStops = new ArrayList<StopBean>();
for (AgencyAndId nearbyStopId : nearbyStopIds) nearbyStops.add(_stopBeanService.getStopForId(nearbyStopId));
List<ServiceAlertBean> situations = _serviceAlertsBeanService.getServiceAlertsForStopId(query.getTime(), id);
return new StopWithArrivalsAndDeparturesBean(stop, arrivalsAndDepartures, nearbyStops, situations);
}
use of org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getBlockLocationAsStatusBean.
@Override
public TripStatusBean getBlockLocationAsStatusBean(BlockLocation blockLocation, long time) {
TripStatusBean bean = new TripStatusBean();
bean.setStatus("default");
BlockInstance blockInstance = blockLocation.getBlockInstance();
long serviceDate = blockInstance.getServiceDate();
bean.setServiceDate(serviceDate);
bean.setLastUpdateTime(blockLocation.getLastUpdateTime());
bean.setLastLocationUpdateTime(blockLocation.getLastLocationUpdateTime());
bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
bean.setLocation(blockLocation.getLocation());
bean.setOrientation(blockLocation.getOrientation());
bean.setLastKnownLocation(blockLocation.getLastKnownLocation());
if (blockLocation.isLastKnownOrientationSet())
bean.setLastKnownOrientation(blockLocation.getLastKnownOrientation());
bean.setScheduleDeviation(blockLocation.getScheduleDeviation());
BlockTripInstance activeTripInstance = blockLocation.getActiveTripInstance();
if (activeTripInstance != null) {
BlockTripEntry activeBlockTrip = activeTripInstance.getBlockTrip();
bean.setScheduledDistanceAlongTrip(blockLocation.getScheduledDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
bean.setDistanceAlongTrip(blockLocation.getDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
TripEntry activeTrip = activeBlockTrip.getTrip();
bean.setTotalDistanceAlongTrip(activeTrip.getTotalTripDistance());
TripBean activeTripBean = _tripBeanService.getTripForId(activeTrip.getId());
bean.setActiveTrip(activeTripBean);
bean.setBlockTripSequence(activeBlockTrip.getSequence());
if (blockLocation.isLastKnownDistanceAlongBlockSet()) {
bean.setLastKnownDistanceAlongTrip(blockLocation.getLastKnownDistanceAlongBlock() - activeBlockTrip.getDistanceAlongBlock());
}
FrequencyEntry frequencyLabel = activeTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
bean.setFrequency(fb);
}
} else {
_log.warn("no active block trip for block location: blockInstance=" + blockLocation.getBlockInstance() + " time=" + time);
}
BlockStopTimeEntry closestStop = blockLocation.getClosestStop();
if (closestStop != null) {
StopTimeEntry stopTime = closestStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setClosestStop(stopBean);
bean.setClosestStopTimeOffset(blockLocation.getClosestStopTimeOffset());
}
BlockStopTimeEntry nextStop = blockLocation.getNextStop();
if (nextStop != null) {
StopTimeEntry stopTime = nextStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setNextStop(stopBean);
bean.setNextStopTimeOffset(blockLocation.getNextStopTimeOffset());
bean.setNextStopDistanceFromVehicle(blockLocation.getNextStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
}
BlockStopTimeEntry previousStop = blockLocation.getPreviousStop();
if (previousStop != null) {
StopTimeEntry stopTime = previousStop.getStopTime();
StopBean stopBean = _stopBeanService.getStopForId(stopTime.getStop().getId());
bean.setPreviousStop(stopBean);
bean.setPreviousStopTimeOffset(blockLocation.getPreviousStopTimeOffset());
bean.setPreviousStopDistanceFromVehicle(blockLocation.getPreviousStop().getDistanceAlongBlock() - blockLocation.getDistanceAlongBlock());
}
EVehiclePhase phase = blockLocation.getPhase();
if (phase != null)
bean.setPhase(phase.toLabel());
String status = blockLocation.getStatus();
if (status != null)
bean.setStatus(status);
if (blockLocation.getVehicleType() != null)
bean.setVehicleType(blockLocation.getVehicleType().toLabel());
bean.setPredicted(blockLocation.isPredicted());
AgencyAndId vid = blockLocation.getVehicleId();
if (vid != null)
bean.setVehicleId(ApplicationBeanLibrary.getId(vid));
if (activeTripInstance != null) {
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, activeTripInstance, blockLocation.getVehicleId());
if (!situations.isEmpty())
bean.setSituations(situations);
}
if (blockLocation.getTimepointPredictions() != null && blockLocation.getTimepointPredictions().size() > 0) {
List<TimepointPredictionBean> timepointPredictions = new ArrayList<TimepointPredictionBean>();
for (TimepointPredictionRecord tpr : blockLocation.getTimepointPredictions()) {
TimepointPredictionBean tpb = new TimepointPredictionBean();
tpb.setTimepointId(tpr.getTimepointId().toString());
tpb.setTripId(tpr.getTripId().toString());
tpb.setStopSequence(tpr.getStopSequence());
tpb.setTimepointPredictedArrivalTime(tpr.getTimepointPredictedArrivalTime());
tpb.setTimepointPredictedDepartureTime(tpr.getTimepointPredictedDepartureTime());
timepointPredictions.add(tpb);
}
bean.setTimepointPredictions(timepointPredictions);
}
return bean;
}
Aggregations