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

/src/traveldashboard/server/data/BikeGetterUtils.java

https://bitbucket.org/ambientic/traveldashboard-server
Java | 36 lines | 24 code | 12 blank | 0 comment | 15 complexity | 264dca8a55b6b90f9a0324d6116e1b8f MD5 | raw file
  1. package traveldashboard.server.data;
  2. import org.ibicoop.sdp.config.NetworkMessage;
  3. import com.google.gson.Gson;
  4. public class BikeGetterUtils extends ResponseUtils {
  5. private static final String TAG = "BikeGetterUtils";
  6. public static NetworkMessage getBikeMessage(NetworkMessage req) {
  7. String methodTag = "getBikeMessage";
  8. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "Start get bike message");
  9. NetworkMessage resp = prepareMsgReturn(req);
  10. String latitude = req.getPayload(DataConstants.PARAM_KEY_STOP_LAT);
  11. String longitude = req.getPayload(DataConstants.PARAM_KEY_STOP_LON);
  12. String radius = req.getPayload(DataConstants.PARAM_KEY_RADIUS);
  13. if ((latitude == null) || (longitude == null) || (radius == null) || (latitude.length() == 0) || (longitude.length() == 0) || (radius.length() == 0)) {
  14. resp.addPayload(DataConstants.BIKE_MESSAGE, "null");
  15. return resp;
  16. }
  17. Gson gson = new Gson();
  18. String json = gson.toJson(MongoDbManager.getBikeStationsCollection(latitude, longitude, radius));
  19. resp.addPayload(DataConstants.BIKE_MESSAGE, json);
  20. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "Finish get bike message : " + new String(resp.encode()));
  21. if (DataConstants.DEBUG) TdServerLogger.print(TAG, methodTag, "bike message size = " + resp.encode().length);
  22. return resp;
  23. }
  24. }