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

/src/traveldashboard/server/data/ClassifiedNoiseGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 49 lines | 29 code | 19 blank | 1 comment | 5 complexity | 5de86d594bc46b899a289df47482e811 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 ClassifiedNoiseGetterUtils extends ResponseUtils {
  6. private static final String TAG = "ClassifiedNoiseGetterUtils";
  7. public static NetworkMessage getClassifiedNoiseMessage(NetworkMessage req) {
  8. String methodTag = "getClassifiedNoiseMessage";
  9. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "Getting classified 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. String timeZone = "";
  16. if (city.equals(DataConstants.PARIS)) {
  17. timeZone = "Europe/Paris";
  18. } else if (city.equals(DataConstants.LONDON)) {
  19. timeZone = "Europe/London";
  20. }
  21. //Set to local timestamp
  22. timestamp = timestamp - TimeZone.getDefault().getRawOffset() +
  23. TimeZone.getTimeZone(timeZone).getRawOffset();
  24. Gson gson = new Gson();
  25. String json = gson.toJson(MongoDbManager.getMetroClassifiedNoise(city, stopId, routeId, timestamp));
  26. resp.addPayload(DataConstants.CLASSIFIED_NOISE_MESSAGE, json);
  27. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "End get classified noise message : " + new String(resp.encode()));
  28. return resp;
  29. }
  30. }