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();
}
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);
}
Aggregations