예제 #1
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/getneareststations")
  public Response getNearestStations(
      @QueryParam("lat") Double lat,
      @QueryParam("lon") Double lon,
      @QueryParam("range") Integer range,
      @QueryParam("objects") Boolean obj)
      throws IOException {

    log.write("\nstations/getneareststations");
    log.flush();

    if ((lat == null) || (lon == null))
      return Response.ok()
          .entity(new boa.server.plugin.json.Response(400, "Lat and Lon cannot be blank"))
          .build();

    Collection<Station> stations;

    if (range == null)
      stations = boa.server.domain.Stations.getStations().getNearestStations(lat, lon);
    else stations = boa.server.domain.Stations.getStations().getNearestStations(lat, lon, range);

    if (stations.size() == 0) return Response.ok().entity(null).build();

    if (obj != null && obj) {
      boa.server.plugin.json.StationsObjects stationList =
          new boa.server.plugin.json.StationsObjects();

      for (Station s : stations) {
        boa.server.plugin.json.Station js = new boa.server.plugin.json.Station(s);
        stationList.add(js);
      }

      return Response.ok().entity(stationList).build();
    } else {
      boa.server.plugin.json.Stations stationList = new boa.server.plugin.json.Stations();

      for (Station s : stations) {
        boa.server.plugin.json.Station js = new boa.server.plugin.json.Station(s);
        stationList.add(js);
      }

      return Response.ok().entity(stationList).build();
    }
  }
예제 #2
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/getall")
  public Response getAll(@QueryParam("objects") Boolean obj) {

    ArrayList<Station> stations = boa.server.domain.Stations.getStations().getAll();

    if (obj != null && obj) {
      boa.server.plugin.json.StationsObjects stationList =
          new boa.server.plugin.json.StationsObjects();
      for (Station s : stations) {
        boa.server.plugin.json.Station js = new boa.server.plugin.json.Station(s);
        stationList.add(js);
      }
      return Response.ok().entity(stationList).build();
    } else {
      boa.server.plugin.json.Stations stationList = new boa.server.plugin.json.Stations();
      for (Station s : stations) {
        boa.server.plugin.json.Station js = new boa.server.plugin.json.Station(s);
        stationList.add(js);
      }
      return Response.ok().entity(stationList).build();
    }
  }