PageRenderTime 77ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/traveldashboard/server/data/NoiseGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 50 lines | 30 code | 19 blank | 1 comment | 5 complexity | e9d56d334a6f5be2dca85899650494e6 MD5 | raw file
  1. package traveldashboard.server.data;
  2. import java.util.TimeZone;
  3. import org.ibicoop.sdp.config.NetworkMessage;
  4. import com.google.gson.Gson;
  5. public class NoiseGetterUtils extends ResponseUtils {
  6. private static final String TAG = "NoiseGetterUtils";
  7. public static NetworkMessage getNoiseMessage(NetworkMessage req) {
  8. String methodTag = "getNoiseMessage";
  9. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "Getting noise message...");
  10. NetworkMessage resp = prepareMsgReturn(req);
  11. String city = req.getPayload(DataConstants.PARAM_KEY_CITY_TYPE);
  12. String stopId = req.getPayload(DataConstants.PARAM_KEY_STOP_ID);
  13. String routeId = req.getPayload(DataConstants.PARAM_KEY_ROUTE_ID);
  14. long timestamp = Long.parseLong(req.getPayload(DataConstants.PARAM_KEY_TIMESTAMP));
  15. long interval = Long.parseLong(req.getPayload(DataConstants.PARAM_KEY_INTERVAL));
  16. String timeZone = "";
  17. if (city.equals(DataConstants.PARIS)) {
  18. timeZone = "Europe/Paris";
  19. } else if (city.equals(DataConstants.LONDON)) {
  20. timeZone = "Europe/London";
  21. }
  22. //Set to local timestamp
  23. timestamp = timestamp - TimeZone.getDefault().getRawOffset() +
  24. TimeZone.getTimeZone(timeZone).getRawOffset();
  25. Gson gson = new Gson();
  26. String json = gson.toJson(MongoDbManager.getMetroNoiseDatasCollection(city, stopId, routeId, timestamp, interval));
  27. resp.addPayload(DataConstants.NOISE_MESSAGE, json);
  28. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "End get noise message : " + new String(resp.encode()));
  29. return resp;
  30. }
  31. }