public ListWithReferencesBean<TripDetailsV2Bean> getTripDetailsResponse(
      ListBean<TripDetailsBean> trips) {

    List<TripDetailsV2Bean> beans = new ArrayList<TripDetailsV2Bean>();
    for (TripDetailsBean trip : trips.getList()) beans.add(getTripDetails(trip));
    return list(beans, trips.isLimitExceeded(), false);
  }
  public ListWithReferencesBean<VehicleStatusV2Bean> getVehicleStatusResponse(
      ListBean<VehicleStatusBean> vehicles) {

    List<VehicleStatusV2Bean> beans = new ArrayList<VehicleStatusV2Bean>();
    for (VehicleStatusBean vehicle : vehicles.getList()) beans.add(getVehicleStatus(vehicle));
    return list(beans, vehicles.isLimitExceeded(), false);
  }
  public ListWithReferencesBean<CurrentVehicleEstimateV2Bean> getCurrentVehicleEstimates(
      ListBean<CurrentVehicleEstimateBean> estimates) {

    if (estimates == null || estimates.getList() == null)
      return list(new ArrayList<CurrentVehicleEstimateV2Bean>(), false);

    List<CurrentVehicleEstimateV2Bean> beans = new ArrayList<CurrentVehicleEstimateV2Bean>();
    for (CurrentVehicleEstimateBean estimate : estimates.getList())
      beans.add(getCurrentVehicleEstimate(estimate));

    return list(beans, estimates.isLimitExceeded());
  }
 /**
  * **
  *
  * <p>***
  */
 public ListWithReferencesBean<String> getEntityIdsResponse(ListBean<String> ids) {
   return list(ids.getList(), ids.isLimitExceeded());
 }
  /**
   * This is the default action, corresponding to a SIRI VehicleMonitoringRequest
   *
   * @return
   * @throws IOException
   */
  public DefaultHttpHeaders index() throws IOException {

    String agencyId = _request.getParameter("OperatorRef");

    if (_time == null) _time = new Date();

    String detailLevel = _request.getParameter("VehicleMonitoringDetailLevel");
    boolean onwardCalls = false;
    if (detailLevel != null) {
      onwardCalls = detailLevel.equals("calls");
    }

    String vehicleId = _request.getParameter("VehicleRef");

    // single trip, by vehicle
    if (vehicleId != null) {
      String vehicleIdWithAgency = agencyId + "_" + vehicleId;
      VehicleStatusBean vehicle =
          _transitDataService.getVehicleForAgency(vehicleIdWithAgency, _time.getTime());
      ArrayList<VehicleActivity> activities = new ArrayList<VehicleActivity>();
      if (vehicle != null) {
        if (!(vehicle.getPhase().equals("DEADHEAD_AFTER")
            || vehicle.getPhase().equals("DEADHEAD_BEFORE")
            || vehicle.getPhase().equals("DEADHEAD_DURING"))) {
          activities.add(createActivity(vehicle, onwardCalls));
        }
      }
      _response = generateSiriResponse(_time, activities);
      return new DefaultHttpHeaders();
    }

    String directionId = _request.getParameter("DirectionRef");

    // by trip (may be more than one trip)
    String tripId = _request.getParameter("VehicleJourneyRef");
    if (tripId != null) {
      TripBean tripBean = _transitDataService.getTrip(agencyId + "_" + tripId);
      if (tripBean == null) {
        throw new IllegalArgumentException("No such trip: " + tripId);
      }
      TripDetailsQueryBean query = new TripDetailsQueryBean();
      query.setTripId(tripId);
      ListBean<TripDetailsBean> trips = _transitDataService.getTripDetails(query);
      ArrayList<VehicleActivity> activities = new ArrayList<VehicleActivity>();
      for (TripDetailsBean trip : trips.getList()) {
        if (directionId != null && !trip.getTrip().getDirectionId().equals(directionId)) {
          continue;
        }
        if (trip.getStatus().isPredicted() == false) {
          /* only show trips with realtime info */
          continue;
        }
        VehicleActivity activity = createActivity(trip, onwardCalls);
        if (activity != null) {
          activities.add(activity);
        }
      }
      _response = generateSiriResponse(_time, activities);
      return new DefaultHttpHeaders();
    }

    String routeId = _request.getParameter("LineRef");
    // multiple trips by route
    if (routeId != null) {
      TripsForRouteQueryBean query = new TripsForRouteQueryBean();
      query.setRouteId(agencyId + "_" + routeId);
      query.setTime(_time.getTime());
      ListBean<TripDetailsBean> trips = _transitDataService.getTripsForRoute(query);
      ArrayList<VehicleActivity> activities = new ArrayList<VehicleActivity>();
      for (TripDetailsBean trip : trips.getList()) {
        if (directionId != null && !trip.getTrip().getDirectionId().equals(directionId)) {
          continue;
        }
        if (trip.getStatus().isPredicted() == false) {
          /* only show trips with realtime info */
          continue;
        }
        VehicleActivity activity = createActivity(trip, onwardCalls);
        if (activity != null) {
          activities.add(activity);
        }
      }
      _response = generateSiriResponse(_time, activities);
      return new DefaultHttpHeaders();
    }

    /* All vehicles */
    ListBean<VehicleStatusBean> vehicles =
        _transitDataService.getAllVehiclesForAgency(agencyId, _time.getTime());
    ArrayList<VehicleActivity> activities = new ArrayList<VehicleActivity>();
    for (VehicleStatusBean v : vehicles.getList()) {
      VehicleActivity activity = createActivity(v, onwardCalls);
      if (activity != null) {
        activities.add(activity);
      }
    }
    _response = generateSiriResponse(_time, activities);
    return new DefaultHttpHeaders();
  }