Search in sources :

Example 1 with ServiceException

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;
}
Also used : Agency(org.onebusaway.nextbus.model.nextbus.Agency) ServiceException(org.onebusaway.exceptions.ServiceException) BodyError(org.onebusaway.nextbus.model.nextbus.BodyError) AgencyWithCoverageBean(org.onebusaway.transit_data.model.AgencyWithCoverageBean) Body(org.onebusaway.nextbus.model.nextbus.Body)

Example 2 with ServiceException

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);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) StopBean(org.onebusaway.transit_data.model.StopBean) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 3 with ServiceException

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;
}
Also used : OutOfServiceAreaServiceException(org.onebusaway.exceptions.OutOfServiceAreaServiceException) NoSuchTripServiceException(org.onebusaway.exceptions.NoSuchTripServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 4 with ServiceException

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();
}
Also used : ServiceException(org.onebusaway.exceptions.ServiceException) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) AlarmAction(org.onebusaway.transit_data_federation.services.AlarmAction)

Example 5 with ServiceException

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);
}
Also used : ServiceException(org.onebusaway.exceptions.ServiceException) FederatedService(org.onebusaway.federations.FederatedService) HashSet(java.util.HashSet)

Aggregations

ServiceException (org.onebusaway.exceptions.ServiceException)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopBean (org.onebusaway.transit_data.model.StopBean)4 ArrayList (java.util.ArrayList)3 InvalidArgumentServiceException (org.onebusaway.exceptions.InvalidArgumentServiceException)3 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)3 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ParseException (org.apache.lucene.queryParser.ParseException)2 BodyError (org.onebusaway.nextbus.model.nextbus.BodyError)2 AgencyWithCoverageBean (org.onebusaway.transit_data.model.AgencyWithCoverageBean)2 Cache (net.sf.ehcache.Cache)1 Min (org.onebusaway.collections.Min)1 NoSuchTripServiceException (org.onebusaway.exceptions.NoSuchTripServiceException)1 OutOfServiceAreaServiceException (org.onebusaway.exceptions.OutOfServiceAreaServiceException)1 FederatedService (org.onebusaway.federations.FederatedService)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 Agency (org.onebusaway.nextbus.model.nextbus.Agency)1 Body (org.onebusaway.nextbus.model.nextbus.Body)1