use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class FederatedServiceMethodInvocationHandlerFactory method getHandlerForMethod.
public FederatedServiceMethodInvocationHandler getHandlerForMethod(Method method) {
FederatedByAgencyIdMethod byAgency = method.getAnnotation(FederatedByAgencyIdMethod.class);
if (byAgency != null)
return new FederatedByAgencyIdMethodInvocationHandlerImpl(method, byAgency.argument(), byAgency.propertyExpression());
FederatedByAnyEntityIdMethod byAnyEntityId = method.getAnnotation(FederatedByAnyEntityIdMethod.class);
if (byAnyEntityId != null)
return new FederatedByAnyEntityIdMethodInvocationHandlerImpl(method, byAnyEntityId.argument(), byAnyEntityId.properties(), byAnyEntityId.agencyIdProperties());
FederatedByEntityIdMethod ann0 = method.getAnnotation(FederatedByEntityIdMethod.class);
if (ann0 != null)
return new FederatedByEntityIdMethodInvocationHandlerImpl(method, ann0.argument(), ann0.propertyExpression());
FederatedByEntityIdsMethod ann1 = method.getAnnotation(FederatedByEntityIdsMethod.class);
if (ann1 != null)
return new FederatedByEntityIdsMethodInvocationHandlerImpl(ann1.argument());
FederatedByBoundsMethod ann2 = method.getAnnotation(FederatedByBoundsMethod.class);
if (ann2 != null)
return new FederatedByBoundsMethodInvocationHandlerImpl(ann2.lat1Argument(), ann2.lon1Argument(), ann2.lat2Argument(), ann2.lon2Argument());
FederatedByLocationMethod ann3 = method.getAnnotation(FederatedByLocationMethod.class);
if (ann3 != null)
return new FederatedByLocationMethodInvocationHandlerImpl(ann3.latArgument(), ann3.lonArgument());
FederatedByAggregateMethod ann4 = method.getAnnotation(FederatedByAggregateMethod.class);
if (ann4 != null) {
EMethodAggregationType aggregationType = getAggregationTypeForMethod(method);
return new FederatedByAggregateMethodInvocationHandlerImpl(aggregationType);
}
FederatedByCoordinateBoundsMethod ann5 = method.getAnnotation(FederatedByCoordinateBoundsMethod.class);
if (ann5 != null)
return new FederatedByCoordinateBoundsMethodInvocationHandlerImpl(method, ann5.argument(), ann5.propertyExpression());
FederatedByCoordinatePointsMethod ann6 = method.getAnnotation(FederatedByCoordinatePointsMethod.class);
if (ann6 != null) {
int[] argumentIndices = ann6.arguments();
String[] expressions = ann6.propertyExpressions();
if (expressions.length == 0)
expressions = new String[argumentIndices.length];
return new FederatedByCoordinatePointsMethodInvocationHandlerImpl(method, argumentIndices, expressions);
}
FederatedByCustomMethod ann7 = method.getAnnotation(FederatedByCustomMethod.class);
if (ann7 != null) {
Class<? extends FederatedServiceMethodInvocationHandler> handlerClass = ann7.handler();
try {
return handlerClass.newInstance();
} catch (Exception ex) {
throw new ServiceException("error creating FederatedServiceMethodInvocationHandler of type " + handlerClass, ex);
}
}
throw new IllegalArgumentException("No FederatedService method annotation for method: " + method);
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class PreCacheTask method run.
@Override
public void run() {
// Clear all existing cache elements
for (String cacheName : _cacheManager.getCacheNames()) {
Cache cache = _cacheManager.getCache(cacheName);
cache.removeAll();
}
try {
List<AgencyWithCoverageBean> agenciesWithCoverage = _service.getAgenciesWithCoverage();
for (AgencyWithCoverageBean agencyWithCoverage : agenciesWithCoverage) {
AgencyBean agency = agencyWithCoverage.getAgency();
System.out.println("agency=" + agency.getId());
ListBean<String> stopIds = _service.getStopIdsForAgencyId(agency.getId());
for (String stopId : stopIds.getList()) {
System.out.println(" stop=" + stopId);
_service.getStop(stopId);
}
ListBean<String> routeIds = _service.getRouteIdsForAgencyId(agency.getId());
for (String routeId : routeIds.getList()) {
System.out.println(" route=" + routeId);
_service.getStopsForRoute(routeId);
}
}
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
for (TripEntry trip : _transitGraphDao.getAllTrips()) {
AgencyAndId shapeId = trip.getShapeId();
if (shapeId != null && shapeId.hasValues())
shapeIds.add(shapeId);
}
for (AgencyAndId shapeId : shapeIds) {
System.out.println("shape=" + shapeId);
_service.getShapeForId(AgencyAndIdLibrary.convertToString(shapeId));
}
} catch (ServiceException ex) {
_log.error("service exception", ex);
}
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class PredictionsForMultiStopsAction method isValid.
private boolean isValid(Body<Predictions> body) {
if (!isValidAgency(body, agencyId)) {
return false;
}
if (stops == null) {
body.getErrors().add(new BodyError(ErrorMsg.STOP_STOPS_NULL.getDescription()));
return false;
}
for (String stop : stops) {
String[] stopArray = stop.split("\\|");
if (stopArray.length < 2) {
String error = "The stop " + stop + " is invalid because it did not contain a route, optional dir, and stop tag";
body.getErrors().add(new BodyError(error));
return false;
}
try {
String stopId = _tdsMappingService.getStopIdFromStopCode(stopArray[1]);
StopBean stopBean;
try {
stopBean = _transitDataService.getStop(stopId);
} catch (ServiceException se) {
// The user didn't provide an agency id in stopId, so use provided
// agency
String stopIdVal = new AgencyAndId(agencyId, stopId).toString();
stopBean = _transitDataService.getStop(stopIdVal);
}
boolean routeExists = false;
for (RouteBean routeBean : stopBean.getRoutes()) {
if (routeBean.getId().equals(_tdsMappingService.getRouteIdFromShortName(stopArray[0]))) {
routeExists = true;
break;
}
}
if (!routeExists) {
String error = "For agency=" + getA() + " route r=" + stopArray[0] + " is not currently available. It might be initializing still.";
body.getErrors().add(new BodyError(error));
return false;
}
String routeTag = getIdNoAgency(_tdsMappingService.getRouteIdFromShortName(stopArray[0]));
String routeStop = getIdNoAgency(_tdsMappingService.getStopIdFromStopCode(stopArray[1]));
mappedStops.add(routeTag + "|" + routeStop);
} catch (ServiceException se) {
String error = "For agency=" + getA() + " stop s=" + stopArray[1] + " is on none of the directions for r=" + stopArray[0] + " so cannot determine which stop to provide data for.";
body.getErrors().add(new BodyError(error));
return false;
}
}
return true;
}
use of org.onebusaway.exceptions.ServiceException in project onebusaway-application-modules by camsys.
the class StopsBeanServiceImpl method getStopsByName.
@Override
public StopsBean getStopsByName(String stopName) throws ServiceException {
List<StopBean> stopBeans = new ArrayList<StopBean>();
SearchResult<AgencyAndId> results = null;
try {
results = _searchService.searchForStopsByName(stopName, MAX_STOPS, NAME_MIN_SCORE);
for (AgencyAndId aid : results.getResultsByTopScore()) {
StopBean stopBean = _stopBeanService.getStopForId(aid);
if (stopBean != null) {
stopBeans.add(stopBean);
}
}
} catch (Exception e) {
_log.error("search failed!", e);
// simply return no results, the search was not understood
return new StopsBean();
}
if (results == null) {
return new StopsBean();
}
return constructResult(stopBeans, results.size() == MAX_STOPS);
}
use of org.onebusaway.exceptions.ServiceException 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