Search in sources :

Example 11 with FederatedService

use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.

the class FederatedByLocationMethodInvocationHandlerImpl method invoke.

public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    double lat = arg(args, _latArgumentIndex);
    double lon = arg(args, _lonArgumentIndex);
    FederatedService service = collection.getServiceForLocation(lat, lon);
    return method.invoke(service, args);
}
Also used : FederatedService(org.onebusaway.federations.FederatedService)

Example 12 with FederatedService

use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.

the class FederatedByAggregateMethodInvocationHandlerImplTest method testMap.

@SuppressWarnings("unchecked")
@Test
public void testMap() throws Exception {
    Map<String, String> vA = new HashMap<String, String>();
    vA.put("a", "a1");
    vA.put("b", "b2");
    Map<String, String> vB = new HashMap<String, String>();
    vB.put("c", "c3");
    vB.put("d", "d4");
    SimpleFederatedService mockServiceA = Mockito.mock(SimpleFederatedService.class);
    Mockito.when(mockServiceA.getValuesAsMap()).thenReturn(vA);
    SimpleFederatedService mockServiceB = Mockito.mock(SimpleFederatedService.class);
    Mockito.when(mockServiceB.getValuesAsMap()).thenReturn(vB);
    Set<FederatedService> services = new HashSet<FederatedService>();
    services.add(mockServiceA);
    services.add(mockServiceB);
    FederatedServiceCollection mockCollection = Mockito.mock(FederatedServiceCollectionImpl.class);
    Mockito.when(mockCollection.getAllServices()).thenReturn(services);
    Method method = SimpleFederatedService.class.getDeclaredMethod("getValuesAsMap");
    FederatedServiceMethodInvocationHandler handler = new FederatedByAggregateMethodInvocationHandlerImpl(EMethodAggregationType.MAP);
    Map<String, String> results = (Map<String, String>) handler.invoke(mockCollection, method, new Object[] {});
    Mockito.verify(mockServiceA).getValuesAsMap();
    Mockito.verify(mockServiceB).getValuesAsMap();
    assertEquals(4, results.size());
    assertEquals("a1", results.get("a"));
    assertEquals("b2", results.get("b"));
    assertEquals("c3", results.get("c"));
    assertEquals("d4", results.get("d"));
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) FederatedService(org.onebusaway.federations.FederatedService) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) FederatedServiceCollection(org.onebusaway.federations.FederatedServiceCollection) SimpleFederatedService(org.onebusaway.federations.SimpleFederatedService) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with FederatedService

use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.

the class FederatedByBoundsMethodInvocationHandlerImpl method invoke.

public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    double lat1 = arg(args, _lat1ArgumentIndex);
    double lon1 = arg(args, _lon1ArgumentIndex);
    double lat2 = arg(args, _lat2ArgumentIndex);
    double lon2 = arg(args, _lon2ArgumentIndex);
    FederatedService service = collection.getServiceForBounds(lat1, lon1, lat2, lon2);
    return method.invoke(service, args);
}
Also used : FederatedService(org.onebusaway.federations.FederatedService)

Example 14 with FederatedService

use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.

the class FederatedByCoordinatePointsMethodInvocationHandlerImpl method invoke.

public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
    for (int i = 0; i < _argumentIndices.length; i++) {
        Object value = args[_argumentIndices[i]];
        PropertyPathExpression expression = _expressions[i];
        if (expression != null)
            value = expression.invoke(value);
        CoordinatePoint point = (CoordinatePoint) value;
        points.add(point);
    }
    FederatedService service = collection.getServiceForLocations(points);
    return method.invoke(service, args);
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) FederatedService(org.onebusaway.federations.FederatedService) ArrayList(java.util.ArrayList) PropertyPathExpression(org.onebusaway.collections.beans.PropertyPathExpression) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint)

Aggregations

FederatedService (org.onebusaway.federations.FederatedService)14 HashSet (java.util.HashSet)6 Test (org.junit.Test)3 SimpleFederatedService (org.onebusaway.federations.SimpleFederatedService)3 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 PropertyPathExpression (org.onebusaway.collections.beans.PropertyPathExpression)2 FederatedServiceCollection (org.onebusaway.federations.FederatedServiceCollection)2 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)2 ArrayList (java.util.ArrayList)1 NoSuchAgencyServiceException (org.onebusaway.exceptions.NoSuchAgencyServiceException)1 ServiceException (org.onebusaway.exceptions.ServiceException)1 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)1