use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class AgencyListAction method getModel.
@Override
public Body<Agency> getModel() {
Body<Agency> body = new Body<Agency>();
try {
List<AgencyWithCoverageBean> agencies = _service.getAgenciesWithCoverage();
for (AgencyWithCoverageBean agencyBean : agencies) {
Agency agency = new Agency();
agency.setTag(agencyBean.getAgency().getId());
agency.setTitle(agencyBean.getAgency().getName());
agency.setRegionTitle(agencyBean.getAgency().getName());
body.getResponse().add(agency);
}
} catch (ServiceException e) {
body.getErrors().add(new BodyError(ErrorMsg.SERVICE_ERROR.getDescription()));
}
return body;
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class StopsBeanServiceImpl method getStopsByBounds.
private StopsBean getStopsByBounds(SearchQueryBean queryBean) throws ServiceException {
CoordinateBounds bounds = queryBean.getBounds();
List<AgencyAndId> stopIds = _geospatialBeanService.getStopsByBounds(bounds);
boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopIds, queryBean.getMaxCount());
List<StopBean> stopBeans = new ArrayList<StopBean>();
for (AgencyAndId stopId : stopIds) {
StopBean stopBean = _stopBeanService.getStopForId(stopId);
if (stopBean == null)
throw new ServiceException();
/**
* If the stop doesn't have any routes actively serving it, don't include
* it in the results
*/
if (stopBean.getRoutes().isEmpty())
continue;
stopBeans.add(stopBean);
}
return constructResult(stopBeans, limitExceeded);
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class TransitDataServiceTemplateImpl method getAgenciesWithCoverage.
// @Override
public List<AgencyWithCoverageBean> getAgenciesWithCoverage() throws ServiceException {
Map<String, CoordinateBounds> agencyIdsAndCoverageAreas = _agencyService.getAgencyIdsAndCoverageAreas();
List<AgencyWithCoverageBean> beans = new ArrayList<AgencyWithCoverageBean>();
for (Map.Entry<String, CoordinateBounds> entry : agencyIdsAndCoverageAreas.entrySet()) {
String agencyId = entry.getKey();
CoordinateBounds bounds = entry.getValue();
AgencyBean agencyBean = _agencyBeanService.getAgencyForId(agencyId);
if (agencyBean == null)
throw new ServiceException("agency not found: " + agencyId);
AgencyWithCoverageBean bean = new AgencyWithCoverageBean();
bean.setAgency(agencyBean);
bean.setLat((bounds.getMaxLat() + bounds.getMinLat()) / 2);
bean.setLon((bounds.getMaxLon() + bounds.getMinLon()) / 2);
bean.setLatSpan(bounds.getMaxLat() - bounds.getMinLat());
bean.setLonSpan(bounds.getMaxLon() - bounds.getMinLon());
beans.add(bean);
}
return beans;
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureAlarmServiceImpl method registerAlarmForArrivalAndDepartureAtStop.
/**
**
* {@link ArrivalAndDepartureAlarmService} Interface
***
*/
@Override
public AgencyAndId registerAlarmForArrivalAndDepartureAtStop(ArrivalAndDepartureQuery query, RegisterAlarmQueryBean alarmBean) {
ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
if (instance == null)
throw new ServiceException("no arrival-departure found");
/**
* We group alarms by block instance
*/
BlockInstance blockInstance = instance.getBlockInstance();
/**
* Retrieve the alarms for the block instance
*/
AlarmsForBlockInstance alarms = getAlarmsForBlockInstance(blockInstance);
/**
* The effective schedule time is the point in the transit vehicle's
* schedule run time when the alarm should be fired
*/
int effectiveScheduleTime = computeEffectiveScheduleTimeForAlarm(alarmBean, instance);
/**
* Create and register the alarm
*/
AlarmAction action = new AlarmAction();
action.setUrl(alarmBean.getUrl());
AlarmForBlockInstance alarm = alarms.registerAlarm(action, effectiveScheduleTime, instance);
_alarmsById.put(alarm.getId(), alarm);
_log.debug("alarm created: {}", alarm.getId());
return alarm.getId();
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class SituationQueryBeanFederatedServiceMethodInvocationHandler method invoke.
@Override
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
if (args.length == 0) {
throw new ServiceException("unexpected number of arguments");
}
SituationQueryBean query = (SituationQueryBean) args[0];
Set<String> agencyIds = new HashSet<String>();
if (query.getAffects() != null) {
for (SituationQueryBean.AffectsBean affects : query.getAffects()) {
if (affects.getAgencyId() != null) {
agencyIds.add(affects.getAgencyId());
}
addAgencyId(affects.getRouteId(), agencyIds);
addAgencyId(affects.getTripId(), agencyIds);
addAgencyId(affects.getStopId(), agencyIds);
}
}
FederatedService service = collection.getServiceForAgencyIds(agencyIds);
return method.invoke(service, args);
}
Aggregations