PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/traveldashboard/server/data/MetroClassifiedCrowdGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 48 lines | 30 code | 17 blank | 1 comment | 5 complexity | 97672efbb50ca867fba70f376bbfa4e3 MD5 | raw file
  1. package traveldashboard.server.data;
  2. import java.util.Locale;
  3. import java.util.TimeZone;
  4. import org.ibicoop.sdp.config.NetworkMessage;
  5. import com.google.gson.Gson;
  6. public class MetroClassifiedCrowdGetterUtils extends ResponseUtils {
  7. private static final String TAG = "MetroClassifiedCrowdGetterUtils";
  8. public static NetworkMessage getMetroClassifiedCrowdMessage(NetworkMessage req) {
  9. String methodTag = "getMetroClassifiedCrowdMessage";
  10. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "Getting metro classified crowd message...");
  11. NetworkMessage resp = prepareMsgReturn(req);
  12. String city = req.getPayload(DataConstants.PARAM_KEY_CITY_TYPE);
  13. String stopId = req.getPayload(DataConstants.PARAM_KEY_STOP_ID);
  14. String routeId = req.getPayload(DataConstants.PARAM_KEY_ROUTE_ID);
  15. long timestamp = Long.parseLong(req.getPayload(DataConstants.PARAM_KEY_TIMESTAMP));
  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.getMetroClassifiedCrowd(city, stopId, routeId, timestamp));
  27. resp.addPayload(DataConstants.METRO_CLASSIFIED_CROWD_MESSAGE, json);
  28. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, new String(resp.encode()));
  29. return resp;
  30. }
  31. }