@GET @Produces(MediaType.APPLICATION_JSON) @Path("{id}/getallstops") public Response getAllStops(@PathParam("id") Integer id, @QueryParam("objects") Boolean obj) { boa.server.domain.Station s = boa.server.domain.Stations.getStations().getStationById(id); if (s == null) return Response.ok() .entity(new boa.server.plugin.json.Response(404, "No station having the specified id.")) .build(); Collection<Stop> stops = (Collection<Stop>) s.getAllStops(); if (stops.size() == 0) return Response.ok().entity("").build(); if (obj != null && obj) { boa.server.plugin.json.StopsObjects jstops = new boa.server.plugin.json.StopsObjects(); for (boa.server.domain.Stop stop : stops) jstops.add(stop); return Response.ok().entity(jstops).build(); } else { boa.server.plugin.json.Stops jstops = new boa.server.plugin.json.Stops(); for (boa.server.domain.Stop stop : stops) jstops.add(stop); return Response.ok().entity(jstops).build(); } }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("{id}/getfirststopfrom") public Response getFirstStopFrom(@PathParam("id") Integer id, @QueryParam("time") Integer time) throws IOException { log.write("\ngetfirststopfrom/" + id); log.flush(); boa.server.domain.Station s = boa.server.domain.Stations.getStations().getStationById(id); if (s == null) return Response.ok() .entity(new boa.server.plugin.json.Response(404, "No station having the specified id.")) .build(); if (time == null) time = new Integer(0); boa.server.domain.Stop fs = s.getFirstStopFromTime(time); if (fs == null) return Response.ok().entity("").build(); boa.server.plugin.json.Stop js = new boa.server.plugin.json.Stop(fs); return Response.ok().entity(js).build(); }
@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(); } }
public static void main(String[] args) { DbConnection.createEmbeddedDbConnection(); Station staz = Stations.getStations().getStationById(132); System.out.print("\n\nstaz.getAllStops():"); for (Stop s : staz.getAllStops()) { System.out.print("\n" + s.getId() + "\t --> " + s.getStaticTime()); } // System.out.print("\n\nstaz.getAllIncidentStops():"); // for(Stop s : staz.getAllIncidentStops()){ // System.out.print("\n" + s.getId()); // } // // System.out.print("\n\nstaz.getAllStopsInIndex():"); // for(Stop s : staz.getAllStopsInIndex()){ // System.out.print("\n" + s.getId()); // } // DbConnection.turnoff(); }
@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(); } }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("{id}") public Response getStation(@PathParam("id") Integer id) throws IOException { log.write("\nstations/" + id); log.flush(); if (id == null) return Response.ok() .entity(new boa.server.plugin.json.Response(400, "Id cannot be blank")) .build(); boa.server.domain.Station s = boa.server.domain.Stations.getStations().getStationById(id); if (s != null) { boa.server.plugin.json.Station js = new boa.server.plugin.json.Station(s); return Response.ok().entity(js).build(); } else { return Response.ok() .entity(new boa.server.plugin.json.Response(404, "No station having the specified id.")) .build(); } }