Subversion Repositories SmartDukaan

Rev

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

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