Search in sources :

Example 1 with FederatedService

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

the class FederatedByCoordinateBoundsMethodInvocationHandlerImpl method invoke.

public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Object value = args[_argumentIndex];
    if (_expression != null)
        value = _expression.invoke(value);
    CoordinateBounds bounds = (CoordinateBounds) value;
    FederatedService service = collection.getServiceForBounds(bounds);
    return method.invoke(service, args);
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

Example 2 with FederatedService

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

the class FederatedByEntityIdMethodInvocationHandlerImpl method invoke.

public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Object value = args[_argumentIndex];
    if (_expression != null)
        value = _expression.invoke(value);
    String entityId = value.toString();
    String agencyId = AgencyIdSupport.getAgencyIdFromEntityId(entityId);
    FederatedService service = collection.getServiceForAgencyId(agencyId);
    return method.invoke(service, args);
}
Also used : FederatedService(org.onebusaway.federations.FederatedService)

Example 3 with FederatedService

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

the class FederatedByEntityIdsMethodInvocationHandlerImpl method invoke.

@SuppressWarnings("unchecked")
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Iterable<String> entityIds = (Iterable<String>) args[_argumentIndex];
    Set<String> agencyIds = new HashSet<String>();
    for (String entityId : entityIds) agencyIds.add(AgencyIdSupport.getAgencyIdFromEntityId(entityId));
    FederatedService service = collection.getServiceForAgencyIds(agencyIds);
    return method.invoke(service, args);
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) HashSet(java.util.HashSet)

Example 4 with FederatedService

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

the class FederatedServiceCollectionImpl method getServiceForAgencyIds.

@Override
public FederatedService getServiceForAgencyIds(Iterable<String> agencyIds) throws ServiceAreaServiceException {
    Set<FederatedService> providers = new HashSet<FederatedService>();
    for (String id : agencyIds) {
        FederatedService provider = getServiceForAgencyId(id);
        if (provider == null)
            throw new NoSuchAgencyServiceException(id);
        providers.add(provider);
    }
    return getProviderFromProviders(providers);
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) HashSet(java.util.HashSet)

Example 5 with FederatedService

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

the class FederatedServiceLibrary method getFederatedServiceAgencyCoverage.

/**
 * Given a list of {@link FederatedService} instances {@code
 * federatedServiceInstances} that implement a target {@code
 * federatedServiceInterface}, query each instance in turn to determine its
 * set of agencies and geographic bounds, verifying that no two distinct
 * federated service instances have overlapping agency ids or geographic
 * bounds. We construct a map from each service instance to its set of agency
 * ids along with their geographic regions.
 *
 * @param federatedServiceInstances
 * @param federatedServiceInterface
 * @return a map of service instances along with their agency ids and coverage
 *         areas
 */
public static Map<FederatedService, Map<String, List<CoordinateBounds>>> getFederatedServiceAgencyCoverage(List<? extends FederatedService> federatedServiceInstances, Class<? extends FederatedService> federatedServiceInterface) {
    Map<FederatedService, Map<String, List<CoordinateBounds>>> byProvider = new HashMap<FederatedService, Map<String, List<CoordinateBounds>>>();
    for (FederatedService service : federatedServiceInstances) {
        if (!federatedServiceInterface.isAssignableFrom(service.getClass()))
            throw new IllegalArgumentException("service provider " + service + " not instance of " + federatedServiceInterface.getName());
        Map<String, List<CoordinateBounds>> agencyIdsWithCoverageArea = service.getAgencyIdsWithCoverageArea();
        for (Map.Entry<String, List<CoordinateBounds>> entry : agencyIdsWithCoverageArea.entrySet()) {
            String agencyId = entry.getKey();
            List<CoordinateBounds> coverage = entry.getValue();
            checkAgencyAndCoverageAgainstExisting(byProvider, agencyId, coverage, federatedServiceInterface, true);
        }
        byProvider.put(service, agencyIdsWithCoverageArea);
    }
    return byProvider;
}
Also used : FederatedService(org.onebusaway.federations.FederatedService) HashMap(java.util.HashMap) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds)

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