PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/traveldashboard/server/data/TramStationGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 40 lines | 23 code | 16 blank | 1 comment | 1 complexity | 4858161c7a376cc5ffb6eb78108fec85 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 TramStationGetterUtils extends ResponseUtils {
  6. private static final String TAG = "TramStationGetterUtils";
  7. public static NetworkMessage getTramStationMessage(NetworkMessage req) {
  8. String methodTag = "getTramStationMessage";
  9. TdServerLogger.print(TAG, methodTag, "Start get tram 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.getParisTramStationsCollection(latitude, longitude, radius));
  19. }
  20. resp.addPayload(DataConstants.TRAM_STATION_MESSAGE, json);
  21. TdServerLogger.print(TAG, methodTag, "End get tram stations message : " + new String(resp.encode()));
  22. return resp;
  23. }
  24. }