Search in sources :

Example 1 with InvalidArgumentServiceException

use of org.onebusaway.exceptions.InvalidArgumentServiceException in project onebusaway-application-modules by camsys.

the class AlarmServiceImpl method getDataAsApnsPayload.

private String getDataAsApnsPayload(String alarmId, JSONObject data) {
    PayloadBuilder b = PayloadBuilder.newPayload();
    b.customField("alarmId", alarmId);
    try {
        if (data.has("actionKey"))
            b.actionKey(data.getString("actionKey"));
        if (data.has("alertBody"))
            b.alertBody(data.getString("alertBody"));
        if (data.has("badge"))
            b.badge(data.getInt("badge"));
        if (data.has("sound"))
            b.sound(data.getString("sound"));
    } catch (JSONException e) {
        throw new InvalidArgumentServiceException("data", e.getMessage());
    }
    return b.build();
}
Also used : PayloadBuilder(com.notnoop.apns.PayloadBuilder) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) JSONException(org.json.JSONException)

Example 2 with InvalidArgumentServiceException

use of org.onebusaway.exceptions.InvalidArgumentServiceException in project onebusaway-application-modules by camsys.

the class StopsBeanServiceImpl method getStopsByBoundsAndQuery.

private StopsBean getStopsByBoundsAndQuery(SearchQueryBean queryBean) throws ServiceException {
    CoordinateBounds bounds = queryBean.getBounds();
    String query = queryBean.getQuery();
    int maxCount = queryBean.getMaxCount();
    CoordinatePoint center = SphericalGeometryLibrary.getCenterOfBounds(bounds);
    SearchResult<AgencyAndId> stops;
    try {
        stops = _searchService.searchForStopsByCode(query, 10, MIN_SCORE);
    } catch (ParseException e) {
        throw new InvalidArgumentServiceException("query", "queryParseError");
    } catch (IOException e) {
        _log.error("error executing stop search: query=" + query, e);
        e.printStackTrace();
        throw new ServiceException();
    }
    Min<StopBean> closest = new Min<StopBean>();
    List<StopBean> stopBeans = new ArrayList<StopBean>();
    for (AgencyAndId aid : stops.getResults()) {
        StopBean stopBean = _stopBeanService.getStopForId(aid);
        if (bounds.contains(stopBean.getLat(), stopBean.getLon()))
            stopBeans.add(stopBean);
        double distance = SphericalGeometryLibrary.distance(center.getLat(), center.getLon(), stopBean.getLat(), stopBean.getLon());
        closest.add(distance, stopBean);
    }
    boolean limitExceeded = BeanServiceSupport.checkLimitExceeded(stopBeans, maxCount);
    // If nothing was found in range, add the closest result
    if (stopBeans.isEmpty() && !closest.isEmpty())
        stopBeans.add(closest.getMinElement());
    return constructResult(stopBeans, limitExceeded);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Min(org.onebusaway.collections.Min) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) ServiceException(org.onebusaway.exceptions.ServiceException) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) StopBean(org.onebusaway.transit_data.model.StopBean) ParseException(org.apache.lucene.queryParser.ParseException) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Aggregations

InvalidArgumentServiceException (org.onebusaway.exceptions.InvalidArgumentServiceException)2 PayloadBuilder (com.notnoop.apns.PayloadBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ParseException (org.apache.lucene.queryParser.ParseException)1 JSONException (org.json.JSONException)1 Min (org.onebusaway.collections.Min)1 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)1 ServiceException (org.onebusaway.exceptions.ServiceException)1 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 StopBean (org.onebusaway.transit_data.model.StopBean)1