PageRenderTime 115ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/traveldashboard/server/data/TubeStationGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 43 lines | 25 code | 16 blank | 2 comment | 2 complexity | 55c8d9332cf88042c747760a1f821a98 MD5 | raw file
  1. package traveldashboard.server.data;
  2. import org.ibicoop.sdp.config.NetworkMessage;
  3. import traveldashboard.data.TransportArea;
  4. import com.google.gson.Gson;
  5. public class TubeStationGetterUtils extends ResponseUtils {
  6. private static final String TAG = "TubeStationGetterUtils";
  7. public static NetworkMessage getTubeStationMessage(NetworkMessage req) {
  8. String methodTag = "getTubeStationMessage";
  9. TdServerLogger.print(TAG, methodTag, "Start getting tube stations message");
  10. NetworkMessage resp = prepareMsgReturn(req);
  11. String latitude = req.getPayload(DataConstants.PARAM_KEY_STOP_LAT);
  12. String longitude = req.getPayload(DataConstants.PARAM_KEY_STOP_LON);
  13. String radius = req.getPayload(DataConstants.PARAM_KEY_RADIUS);
  14. Gson gson = new Gson();
  15. String json = "null";
  16. if (TransportArea.getArea(Double.parseDouble(latitude), Double.parseDouble(longitude)).equals(TransportArea.PARIS)) {
  17. //Paris
  18. json = gson.toJson(MongoDbManager.getParisMetroStationsCollection(latitude, longitude, radius));
  19. } else {
  20. //London
  21. json = gson.toJson(MongoDbManager.getLondonMetroStationsCollection(latitude, longitude, radius));
  22. }
  23. resp.addPayload(DataConstants.TUBE_STATION_MESSAGE, json);
  24. TdServerLogger.print(TAG, methodTag, "End get tube stations message : " + new String(resp.encode()));
  25. return resp;
  26. }
  27. }