Subversion Repositories SmartDukaan

Rev

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

Rev 27485 Rev 27486
Line 1078... Line 1078...
1078
		// throw new Exception();
1078
		// throw new Exception();
1079
	}
1079
	}
1080
 
1080
 
1081
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
1081
	public void createGeofence() throws IOException, ProfitMandiBusinessException {
1082
 
1082
 
1083
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1083
		// List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
1084
		for (FofoStore fofoStore : fofoStores) {
1084
		// for (FofoStore fofoStore : fofoStores) {
1085
			if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
1085
		// if (fofoStore.getLatitude() != null && fofoStore.getLongitude() != null) {
-
 
1086
		// CustomRetailer customRetailer =
1086
				CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
1087
		// retailerService.getFofoRetailer(fofoStore.getId());
1087
				OkHttpClient client = new OkHttpClient();
1088
		OkHttpClient client = new OkHttpClient();
1088
				okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
1089
		okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
1089
				JSONObject geofe = new JSONObject();
1090
		JSONObject geofe = new JSONObject();
1090
				JSONArray geofences = new JSONArray();
1091
		JSONArray geofences = new JSONArray();
1091
				JSONObject geometry = new JSONObject();
1092
		JSONObject geometry = new JSONObject();
1092
				JSONObject geo = new JSONObject();
1093
		JSONObject geo = new JSONObject();
1093
				JSONArray coordinates = new JSONArray();
1094
		JSONArray coordinates = new JSONArray();
1094
				ArrayList<Double> crds = new ArrayList<>();
1095
		ArrayList<Double> crds = new ArrayList<>();
1095
				crds.add(Double.parseDouble(fofoStore.getLongitude()));
1096
		// crds.add(Double.parseDouble(fofoStore.getLongitude()));
1096
				crds.add(Double.parseDouble(fofoStore.getLatitude()));
1097
		// crds.add(Double.parseDouble(fofoStore.getLatitude()));
-
 
1098
		crds.add(77.3771954997187);
-
 
1099
		crds.add(28.516045882182738);
1097
				// crds.add(77.08596155373755);
1100
		// crds.add(77.08596155373755);
1098
				// crds.add(28.64944201113976);
1101
		// crds.add(28.64944201113976);
1099
				// coordinates.put(fofoStore.getLongitude());
1102
		// coordinates.put(fofoStore.getLongitude());
1100
				// coordinates.put(fofoStore.getLatitude());
1103
		// coordinates.put(fofoStore.getLatitude());
1101
				geo.put("type", "Point");
1104
		geo.put("type", "Point");
1102
				geo.put("coordinates", crds);
1105
		geo.put("coordinates", crds);
1103
				geometry.put("geometry", geo);
1106
		geometry.put("geometry", geo);
1104
				JSONObject metadata = new JSONObject();
1107
		JSONObject metadata = new JSONObject();
1105
				metadata.put("name", customRetailer.getBusinessName());
1108
		metadata.put("name", "SMARTDUKAAN HO");
1106
				metadata.put("city", customRetailer.getAddress().getCity());
1109
		// metadata.put("city", customRetailer.getAddress().getCity());
1107
				metadata.put("Code", customRetailer.getCode());
1110
		// metadata.put("Code", customRetailer.getCode());
1108
				geometry.put("metadata", metadata);
1111
		// geometry.put("metadata", metadata);
1109
				geometry.put("radius", 200);
1112
		geometry.put("radius", 200);
1110
 
1113
 
1111
				geofences.put(geometry);
1114
		geofences.put(geometry);
1112
				geofe.put("geofences", geofences);
1115
		geofe.put("geofences", geofences);
1113
				okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
1116
		okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
1114
				String authString = "Basic "
1117
		String authString = "Basic "
1115
						+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1118
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
1116
 
1119
 
1117
				Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1120
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
1118
						.addHeader("Authorization", authString).build();
1121
				.addHeader("Authorization", authString).build();
1119
 
1122
 
1120
				Response response = client.newCall(request1).execute();
1123
		Response response = client.newCall(request1).execute();
1121
 
1124
 
1122
				JSONArray ja = new JSONArray(response.body().string());
1125
		JSONArray ja = new JSONArray(response.body().string());
1123
				LOGGER.info("geofence" + ja);
1126
		LOGGER.info("geofence" + ja);
1124
				LOGGER.info("jalength" + ja.length());
1127
		LOGGER.info("jalength" + ja.length());
-
 
1128
		/*
1125
				for (int i = 0; i < ja.length(); i++) {
1129
		 * for (int i = 0; i < ja.length(); i++) { JSONObject c = ja.getJSONObject(i);
1126
					JSONObject c = ja.getJSONObject(i);
-
 
1127
					String geofenceId = c.getString("geofence_id");
1130
		 * String geofenceId = c.getString("geofence_id"); LOGGER.info("geofenceId" +
1128
					LOGGER.info("geofenceId" + geofenceId);
-
 
1129
					FofoStoreGeofence fsg = new FofoStoreGeofence();
1131
		 * geofenceId); FofoStoreGeofence fsg = new FofoStoreGeofence();
1130
					fsg.setFofoId(customRetailer.getPartnerId());
1132
		 * fsg.setFofoId(customRetailer.getPartnerId()); fsg.setGeofenceId(geofenceId);
1131
					fsg.setGeofenceId(geofenceId);
-
 
1132
					fofoStoreGeofenceRepository.persist(fsg);
1133
		 * fofoStoreGeofenceRepository.persist(fsg); }
1133
				}
1134
		 * 
1134
 
1135
		 * }
1135
			}
1136
		 * 
1136
 
1137
		 * }
1137
		}
1138
		 */
1138
 
1139
 
1139
	}
1140
	}
1140
 
1141
 
1141
	public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
1142
	public void getAllGeofences() throws IOException, ProfitMandiBusinessException {
1142
 
1143