Subversion Repositories SmartDukaan

Rev

Rev 27446 | Rev 27475 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27446 Rev 27449
Line 234... Line 234...
234
	public ResponseEntity<?> createGeofence(HttpServletRequest request)
234
	public ResponseEntity<?> createGeofence(HttpServletRequest request)
235
			throws IOException, ProfitMandiBusinessException {
235
			throws IOException, ProfitMandiBusinessException {
236
 
236
 
237
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
237
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
238
		for (FofoStore fofoStore : fofoStores) {
238
		for (FofoStore fofoStore : fofoStores) {
-
 
239
			if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
239
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
240
				CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
240
			OkHttpClient client = new OkHttpClient();
241
				OkHttpClient client = new OkHttpClient();
-
 
242
 
-
 
243
				okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
-
 
244
				JSONObject geofe = new JSONObject();
-
 
245
				JSONArray geofences = new JSONArray();
-
 
246
				JSONObject geometry = new JSONObject();
-
 
247
				JSONObject geo = new JSONObject();
-
 
248
				JSONArray coordinates = new JSONArray();
-
 
249
				coordinates.put(fofoStore.getLongitude());
-
 
250
				coordinates.put(fofoStore.getLatitude());
-
 
251
				geo.put("type", "Point");
-
 
252
				geo.put("coordinates", coordinates);
-
 
253
				geometry.put("geometry", geo);
-
 
254
				JSONObject metadata = new JSONObject();
-
 
255
				metadata.put("name", customRetailer.getBusinessName());
-
 
256
				metadata.put("city", customRetailer.getAddress().getCity());
-
 
257
				geometry.put("metadata", metadata);
-
 
258
				geometry.put("radius", 500);
-
 
259
 
-
 
260
				geofences.put(geometry);
-
 
261
				geofe.put("geofences", geofences);
-
 
262
				okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
-
 
263
				String authString = "Basic "
-
 
264
						+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
241
 
265
 
242
			okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
266
				Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
243
			JSONObject geofe = new JSONObject();
-
 
244
			JSONArray geofences = new JSONArray();
-
 
245
			JSONObject geometry = new JSONObject();
-
 
246
			JSONObject geo = new JSONObject();
-
 
247
			JSONArray coordinates = new JSONArray();
-
 
248
			coordinates.put(fofoStore.getLongitude());
267
						.addHeader("Authorization", authString).build();
249
			coordinates.put(fofoStore.getLatitude());
-
 
250
			geo.put("type", "Point");
-
 
251
			geo.put("coordinates", coordinates);
-
 
252
			geometry.put("geometry", geo);
-
 
253
			JSONObject metadata = new JSONObject();
-
 
254
			metadata.put("name", customRetailer.getBusinessName());
-
 
255
			metadata.put("city", customRetailer.getAddress().getCity());
-
 
256
			geometry.put("metadata", metadata);
-
 
257
			geometry.put("radius", 500);
-
 
258
 
-
 
259
			geofences.put(geometry);
-
 
260
			geofe.put("geofences", geofences);
-
 
261
			okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
-
 
262
			String authString = "Basic "
-
 
263
					+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
-
 
264
 
268
 
265
			Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
-
 
266
					.addHeader("Authorization", authString).build();
-
 
267
 
-
 
268
			Response response = client.newCall(request1).execute();
269
				Response response = client.newCall(request1).execute();
269
 
270
 
-
 
271
				LOGGER.info("response" + response.body().string());
-
 
272
			}
270
		}
273
		}
271
		return responseSender.ok(true);
274
		return responseSender.ok(true);
272
 
275
 
273
	}
276
	}
274
 
277
 
-
 
278
	@RequestMapping(value = "/getgeofence", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
279
	public ResponseEntity<?> getAllGeofences(HttpServletRequest request)
-
 
280
			throws IOException, ProfitMandiBusinessException {
-
 
281
 
-
 
282
		OkHttpClient client = new OkHttpClient();
-
 
283
 
-
 
284
		String authString = "Basic "
-
 
285
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
-
 
286
 
-
 
287
		// Get geofences created for all app users
-
 
288
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences")
-
 
289
				.addHeader("Authorization", authString).build();
-
 
290
 
-
 
291
		Response response = client.newCall(request1).execute();
-
 
292
		return responseSender.ok(response.body().string());
-
 
293
 
-
 
294
	}
-
 
295
 
275
}
296
}