| 27417 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 27421 |
tejbeer |
3 |
import java.io.IOException;
|
|
|
4 |
import java.time.LocalDate;
|
| 27417 |
tejbeer |
5 |
import java.time.LocalDateTime;
|
| 27445 |
tejbeer |
6 |
import java.time.LocalTime;
|
|
|
7 |
import java.time.temporal.ChronoUnit;
|
|
|
8 |
import java.util.ArrayList;
|
| 27421 |
tejbeer |
9 |
import java.util.Base64;
|
|
|
10 |
import java.util.List;
|
| 27417 |
tejbeer |
11 |
|
| 27421 |
tejbeer |
12 |
import javax.mail.MessagingException;
|
| 27417 |
tejbeer |
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
|
|
|
15 |
import org.apache.logging.log4j.LogManager;
|
|
|
16 |
import org.apache.logging.log4j.Logger;
|
| 27421 |
tejbeer |
17 |
import org.json.JSONArray;
|
|
|
18 |
import org.json.JSONObject;
|
| 27417 |
tejbeer |
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 27493 |
tejbeer |
20 |
import org.springframework.format.annotation.DateTimeFormat;
|
| 27417 |
tejbeer |
21 |
import org.springframework.http.MediaType;
|
|
|
22 |
import org.springframework.http.ResponseEntity;
|
|
|
23 |
import org.springframework.stereotype.Controller;
|
|
|
24 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
25 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 27421 |
tejbeer |
28 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 27417 |
tejbeer |
29 |
|
|
|
30 |
import com.google.gson.Gson;
|
| 27421 |
tejbeer |
31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 27417 |
tejbeer |
32 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 27421 |
tejbeer |
33 |
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
|
| 27417 |
tejbeer |
34 |
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
|
|
|
35 |
import com.spice.profitmandi.dao.entity.dtr.HypertrackKey;
|
| 27421 |
tejbeer |
36 |
import com.spice.profitmandi.dao.enumuration.dtr.PunchType;
|
|
|
37 |
import com.spice.profitmandi.dao.model.EmployeeAttendanceModel;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.dtr.EmployeeAttendanceRepository;
|
|
|
39 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 27417 |
tejbeer |
40 |
import com.spice.profitmandi.dao.repository.user.HypertrackKeyRepository;
|
| 27421 |
tejbeer |
41 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 27417 |
tejbeer |
42 |
|
|
|
43 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
44 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
45 |
import io.swagger.annotations.ApiOperation;
|
| 27421 |
tejbeer |
46 |
import okhttp3.OkHttpClient;
|
|
|
47 |
import okhttp3.Request;
|
|
|
48 |
import okhttp3.Response;
|
| 27417 |
tejbeer |
49 |
|
|
|
50 |
@Controller
|
|
|
51 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
52 |
public class HyperTrackController {
|
|
|
53 |
|
|
|
54 |
private static final Logger LOGGER = LogManager.getLogger(HyperTrackController.class);
|
|
|
55 |
|
|
|
56 |
@Autowired
|
|
|
57 |
ResponseSender<?> responseSender;
|
|
|
58 |
|
|
|
59 |
@Autowired
|
|
|
60 |
Gson gson;
|
|
|
61 |
|
|
|
62 |
@Autowired
|
|
|
63 |
private HypertrackKeyRepository hypertrackKeyRepository;
|
|
|
64 |
|
| 27421 |
tejbeer |
65 |
@Autowired
|
|
|
66 |
private EmployeeAttendanceRepository employeeAttendanceRepository;
|
|
|
67 |
|
|
|
68 |
@Autowired
|
|
|
69 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
70 |
|
|
|
71 |
@Autowired
|
|
|
72 |
private RetailerService retailerService;
|
|
|
73 |
|
| 27417 |
tejbeer |
74 |
private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
|
|
|
75 |
private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";
|
|
|
76 |
|
|
|
77 |
@RequestMapping(value = "/devices/hypertrackId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
78 |
@ApiImplicitParams({
|
|
|
79 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
80 |
@ApiOperation(value = "")
|
|
|
81 |
public ResponseEntity<?> deviceHypertrackId(HttpServletRequest request,
|
|
|
82 |
@RequestBody HyperTrackKeyModel hyperTrackKeyModel) {
|
|
|
83 |
HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(hyperTrackKeyModel.getUserId(),
|
|
|
84 |
hyperTrackKeyModel.getDeviceId());
|
|
|
85 |
if (hyperTrackKey == null) {
|
|
|
86 |
hyperTrackKey = new HypertrackKey();
|
| 27444 |
tejbeer |
87 |
hyperTrackKey.setUserId(hyperTrackKeyModel.getUserId());
|
|
|
88 |
hyperTrackKey.setCreatedTimestamp(LocalDateTime.now());
|
| 27417 |
tejbeer |
89 |
hyperTrackKey.setDeviceId(hyperTrackKeyModel.getDeviceId());
|
|
|
90 |
}
|
| 27422 |
tejbeer |
91 |
|
| 27444 |
tejbeer |
92 |
hyperTrackKey.setHypertrackKeyId(hyperTrackKeyModel.getHyperTrackId());
|
|
|
93 |
|
| 27417 |
tejbeer |
94 |
hyperTrackKey.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
95 |
hypertrackKeyRepository.persist(hyperTrackKey);
|
|
|
96 |
return responseSender.ok(true);
|
|
|
97 |
}
|
|
|
98 |
|
| 27421 |
tejbeer |
99 |
@RequestMapping(value = "/devices/location", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
100 |
public ResponseEntity<?> getLocationByKeyId(HttpServletRequest request, @RequestParam int userId,
|
| 27426 |
tejbeer |
101 |
@RequestParam int deviceId) throws IOException, MessagingException, ProfitMandiBusinessException {
|
| 27421 |
tejbeer |
102 |
|
| 27781 |
amit.gupta |
103 |
LOGGER.info("UserId -> {}, Device Id -> {}", userId, deviceId);
|
| 27426 |
tejbeer |
104 |
double lat1 = 28.516045882182738;
|
|
|
105 |
double lng1 = 77.3771954997187;
|
| 27421 |
tejbeer |
106 |
|
|
|
107 |
HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(userId, deviceId);
|
| 27428 |
tejbeer |
108 |
// EmployeeAttendance employeeAttendance =
|
|
|
109 |
// employeeAttendanceRepository.selectLatestPunchTimeStamp();
|
|
|
110 |
|
|
|
111 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKey(userId, deviceId,
|
|
|
112 |
LocalDate.now());
|
| 28112 |
tejbeer |
113 |
EmployeeAttendanceModel em = null;
|
| 27432 |
tejbeer |
114 |
LOGGER.info("hyperTrackKey" + hyperTrackKey);
|
|
|
115 |
LOGGER.info("employeeAttendance" + employeeAttendances);
|
| 27421 |
tejbeer |
116 |
OkHttpClient client = new OkHttpClient();
|
|
|
117 |
|
|
|
118 |
String authString = "Basic "
|
|
|
119 |
+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
|
|
|
120 |
|
|
|
121 |
Request request1 = new Request.Builder()
|
| 27426 |
tejbeer |
122 |
.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId()).get()
|
| 27421 |
tejbeer |
123 |
.addHeader("Authorization", authString).build();
|
|
|
124 |
|
|
|
125 |
Response response = client.newCall(request1).execute();
|
| 28112 |
tejbeer |
126 |
|
| 27421 |
tejbeer |
127 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
| 27498 |
tejbeer |
128 |
|
|
|
129 |
JSONObject deviceStatus = jsonObj.getJSONObject("device_status");
|
| 27502 |
tejbeer |
130 |
String status = deviceStatus.getString("value");
|
| 27498 |
tejbeer |
131 |
|
| 28113 |
tejbeer |
132 |
if (status.equals("inactive") || status.equals("disconnected")) {
|
| 27432 |
tejbeer |
133 |
|
| 28113 |
tejbeer |
134 |
LOGGER.info("status" + status);
|
| 28114 |
tejbeer |
135 |
okhttp3.RequestBody reqbody = okhttp3.RequestBody.create(null, new byte[0]);
|
| 28113 |
tejbeer |
136 |
|
| 28112 |
tejbeer |
137 |
Request request2 = new Request.Builder()
|
|
|
138 |
.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId() + "/start")
|
| 28114 |
tejbeer |
139 |
.post(reqbody).addHeader("Authorization", authString).build();
|
| 28112 |
tejbeer |
140 |
|
|
|
141 |
Response resp = client.newCall(request2).execute();
|
| 28113 |
tejbeer |
142 |
LOGGER.info("resp" + resp);
|
| 28116 |
tejbeer |
143 |
em = new EmployeeAttendanceModel();
|
|
|
144 |
em.setPunchIn(false);
|
| 28123 |
tejbeer |
145 |
em.setDeviceStatus(status);
|
| 28113 |
tejbeer |
146 |
} else if (status.equals("active")) {
|
| 28112 |
tejbeer |
147 |
JSONObject c = jsonObj.getJSONObject("location");
|
|
|
148 |
JSONObject d = c.getJSONObject("geometry");
|
|
|
149 |
JSONArray coords = d.getJSONArray("coordinates");
|
|
|
150 |
|
|
|
151 |
double lat2 = coords.getDouble(1);
|
|
|
152 |
double lng2 = coords.getDouble(0);
|
|
|
153 |
double dist = distance(lat1, lng1, lat2, lng2, "m");
|
|
|
154 |
LOGGER.info("jsonObj" + jsonObj);
|
|
|
155 |
JSONObject deviceData = deviceStatus.getJSONObject("data");
|
| 28122 |
tejbeer |
156 |
LOGGER.info("status1" + status);
|
| 28112 |
tejbeer |
157 |
|
|
|
158 |
em = new EmployeeAttendanceModel();
|
|
|
159 |
em.setDistance(dist);
|
|
|
160 |
em.setLatitude(lat2);
|
|
|
161 |
em.setLongitude(lng2);
|
|
|
162 |
em.setDeviceStatus(status);
|
|
|
163 |
|
|
|
164 |
if (!employeeAttendances.isEmpty()) {
|
|
|
165 |
if (employeeAttendances.get(0).getCreateTimestamp().toLocalDate().equals(LocalDate.now())) {
|
|
|
166 |
if (employeeAttendances.get(0).getPunch().equals("punchIn")) {
|
|
|
167 |
em.setPunchIn(true);
|
|
|
168 |
} else {
|
|
|
169 |
em.setPunchIn(false);
|
|
|
170 |
}
|
| 27428 |
tejbeer |
171 |
} else {
|
|
|
172 |
em.setPunchIn(false);
|
|
|
173 |
}
|
| 28112 |
tejbeer |
174 |
|
|
|
175 |
if (employeeAttendances.get(0).getPunch().equals("punchOut")) {
|
|
|
176 |
LocalTime startTime = employeeAttendances.get(employeeAttendances.size() - 1).getCreateTimestamp()
|
|
|
177 |
.toLocalTime();
|
|
|
178 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime,
|
|
|
179 |
employeeAttendances.get(0).getCreateTimestamp().toLocalTime());
|
|
|
180 |
long hours = secondsBetween / 3600;
|
|
|
181 |
long minutes = (secondsBetween % 3600) / 60;
|
|
|
182 |
long seconds = secondsBetween % 60;
|
|
|
183 |
em.setPunchHours(hours);
|
|
|
184 |
em.setPunchMinutes(minutes);
|
|
|
185 |
em.setPunchSeconds(seconds);
|
|
|
186 |
|
|
|
187 |
} else if (employeeAttendances.get(employeeAttendances.size() - 1).getPunch().equals("punchIn")) {
|
|
|
188 |
LocalTime startTime = employeeAttendances.get(employeeAttendances.size() - 1).getCreateTimestamp()
|
|
|
189 |
.toLocalTime();
|
|
|
190 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime, LocalDateTime.now().toLocalTime());
|
|
|
191 |
long hours = secondsBetween / 3600;
|
|
|
192 |
long minutes = (secondsBetween % 3600) / 60;
|
|
|
193 |
long seconds = secondsBetween % 60;
|
|
|
194 |
em.setPunchHours(hours);
|
|
|
195 |
em.setPunchMinutes(minutes);
|
|
|
196 |
em.setPunchSeconds(seconds);
|
|
|
197 |
}
|
|
|
198 |
|
| 27421 |
tejbeer |
199 |
} else {
|
|
|
200 |
em.setPunchIn(false);
|
| 28123 |
tejbeer |
201 |
em.setDeviceStatus(status);
|
| 27421 |
tejbeer |
202 |
}
|
| 28122 |
tejbeer |
203 |
} else {
|
|
|
204 |
|
|
|
205 |
LOGGER.info("status3" + status);
|
|
|
206 |
|
|
|
207 |
em.setPunchIn(false);
|
| 28123 |
tejbeer |
208 |
em.setDeviceStatus(status);
|
| 27421 |
tejbeer |
209 |
}
|
|
|
210 |
return responseSender.ok(em);
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
private static double distance(double lat1, double lon1, double lat2, double lon2, String unit) {
|
|
|
214 |
if ((lat1 == lat2) && (lon1 == lon2)) {
|
|
|
215 |
return 0;
|
|
|
216 |
} else {
|
|
|
217 |
double theta = lon1 - lon2;
|
|
|
218 |
double dist = Math.sin(Math.toRadians(lat1)) * Math.sin(Math.toRadians(lat2))
|
|
|
219 |
+ Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.cos(Math.toRadians(theta));
|
|
|
220 |
dist = Math.acos(dist);
|
|
|
221 |
dist = Math.toDegrees(dist);
|
|
|
222 |
dist = dist * 60 * 1.1515;
|
|
|
223 |
if (unit.equals("m")) {
|
|
|
224 |
dist = dist * 1.609344;
|
|
|
225 |
dist = dist / 0.0010000;
|
|
|
226 |
} else if (unit.equals("N")) {
|
|
|
227 |
dist = dist * 0.8684;
|
|
|
228 |
}
|
|
|
229 |
return (dist);
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
|
| 27475 |
tejbeer |
233 |
@RequestMapping(value = "/getPunchHistory", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
234 |
public ResponseEntity<?> getPunchHistory(HttpServletRequest request, @RequestParam int userId,
|
|
|
235 |
@RequestParam int deviceId) {
|
|
|
236 |
|
|
|
237 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKey(userId, deviceId,
|
|
|
238 |
LocalDate.now());
|
|
|
239 |
|
|
|
240 |
return responseSender.ok(employeeAttendances);
|
|
|
241 |
}
|
|
|
242 |
|
| 27421 |
tejbeer |
243 |
@RequestMapping(value = "/employee/attendance", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
244 |
@ApiImplicitParams({
|
|
|
245 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
246 |
@ApiOperation(value = "")
|
|
|
247 |
public ResponseEntity<?> employeeAttendance(HttpServletRequest request, @RequestParam(name = "userId") int userId,
|
|
|
248 |
@RequestParam(name = "deviceId") int deviceId, @RequestParam(name = "punchType") PunchType punchType,
|
| 27493 |
tejbeer |
249 |
@RequestParam(name = "punch") String punch) {
|
| 27421 |
tejbeer |
250 |
|
|
|
251 |
EmployeeAttendance employeeAttendance = new EmployeeAttendance();
|
|
|
252 |
employeeAttendance.setUserId(userId);
|
|
|
253 |
employeeAttendance.setDeviceId(deviceId);
|
|
|
254 |
employeeAttendance.setPunch(punch);
|
|
|
255 |
employeeAttendance.setPunchType(punchType);
|
|
|
256 |
employeeAttendance.setCreateTimestamp(LocalDateTime.now());
|
|
|
257 |
employeeAttendanceRepository.persist(employeeAttendance);
|
| 27445 |
tejbeer |
258 |
if (punch.equals("punchOut")) {
|
|
|
259 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKeyASC(userId,
|
|
|
260 |
deviceId, LocalDate.now());
|
|
|
261 |
long hours = 0;
|
|
|
262 |
long minutes = 0;
|
|
|
263 |
long seconds = 0;
|
| 27446 |
tejbeer |
264 |
long totalSeconds = 0;
|
|
|
265 |
LocalTime startTime = null;
|
|
|
266 |
LocalTime endTime = null;
|
| 27445 |
tejbeer |
267 |
|
|
|
268 |
for (EmployeeAttendance em : employeeAttendances) {
|
|
|
269 |
if (em.getPunch().equals("punchIn")) {
|
| 27446 |
tejbeer |
270 |
startTime = em.getCreateTimestamp().toLocalTime();
|
| 27445 |
tejbeer |
271 |
} else if (em.getPunch().equals("punchOut")) {
|
| 27446 |
tejbeer |
272 |
endTime = em.getCreateTimestamp().toLocalTime();
|
| 27445 |
tejbeer |
273 |
}
|
|
|
274 |
if (startTime != null && endTime != null) {
|
| 27446 |
tejbeer |
275 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime, endTime);
|
|
|
276 |
totalSeconds += secondsBetween;
|
| 27445 |
tejbeer |
277 |
startTime = null;
|
|
|
278 |
endTime = null;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
}
|
| 27446 |
tejbeer |
282 |
hours = totalSeconds / 3600;
|
|
|
283 |
minutes = (totalSeconds % 3600) / 60;
|
|
|
284 |
seconds = totalSeconds % 60;
|
| 27445 |
tejbeer |
285 |
EmployeeAttendanceModel emm = new EmployeeAttendanceModel();
|
|
|
286 |
emm.setHours(hours);
|
|
|
287 |
emm.setMinutes(minutes);
|
|
|
288 |
emm.setSeconds(seconds);
|
|
|
289 |
return responseSender.ok(emm);
|
|
|
290 |
|
|
|
291 |
}
|
| 27421 |
tejbeer |
292 |
return responseSender.ok(true);
|
|
|
293 |
}
|
|
|
294 |
|
| 27426 |
tejbeer |
295 |
@RequestMapping(value = "/create/geofence", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 27445 |
tejbeer |
296 |
public ResponseEntity<?> createGeofence(HttpServletRequest request)
|
| 27426 |
tejbeer |
297 |
throws IOException, ProfitMandiBusinessException {
|
|
|
298 |
|
| 27475 |
tejbeer |
299 |
/*
|
|
|
300 |
* List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores(); for
|
|
|
301 |
* (FofoStore fofoStore : fofoStores) { if (fofoStore.getLatitude() != null &&
|
|
|
302 |
* fofoStore.getLongitude() != null) { CustomRetailer customRetailer =
|
|
|
303 |
* retailerService.getFofoRetailer(fofoStore.getId());
|
|
|
304 |
*/
|
|
|
305 |
OkHttpClient client = new OkHttpClient();
|
| 27426 |
tejbeer |
306 |
|
| 27475 |
tejbeer |
307 |
okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
|
|
|
308 |
JSONObject geofe = new JSONObject();
|
|
|
309 |
JSONArray geofences = new JSONArray();
|
|
|
310 |
JSONObject geometry = new JSONObject();
|
|
|
311 |
JSONObject geo = new JSONObject();
|
|
|
312 |
JSONArray coordinates = new JSONArray();
|
|
|
313 |
coordinates.put(77.08596155373755);
|
|
|
314 |
coordinates.put(28.64944201113976);
|
|
|
315 |
geo.put("type", "Point");
|
|
|
316 |
geo.put("coordinates", coordinates);
|
|
|
317 |
geometry.put("geometry", geo);
|
|
|
318 |
JSONObject metadata = new JSONObject();
|
|
|
319 |
metadata.put("name", "Test");
|
|
|
320 |
geometry.put("radius", 500);
|
|
|
321 |
geofences.put(geometry);
|
|
|
322 |
geofe.put("geofences", geofences);
|
|
|
323 |
okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, geofe.toString());
|
|
|
324 |
String authString = "Basic "
|
|
|
325 |
+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
|
| 27426 |
tejbeer |
326 |
|
| 27475 |
tejbeer |
327 |
Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences").post(body)
|
|
|
328 |
.addHeader("Authorization", authString).build();
|
| 27426 |
tejbeer |
329 |
|
| 27475 |
tejbeer |
330 |
Response response = client.newCall(request1).execute();
|
|
|
331 |
String geofenceId = null;
|
|
|
332 |
JSONArray ja = new JSONArray(response.body().string());
|
|
|
333 |
for (int i = 0; i < ja.length(); i++) {
|
|
|
334 |
JSONObject c = ja.getJSONObject(i);
|
|
|
335 |
geofenceId = c.getString("geofence_id");
|
|
|
336 |
}
|
| 27426 |
tejbeer |
337 |
|
| 27475 |
tejbeer |
338 |
LOGGER.info("response" + response.body().string());
|
| 27426 |
tejbeer |
339 |
|
| 27475 |
tejbeer |
340 |
return responseSender.ok(geofenceId);
|
| 27426 |
tejbeer |
341 |
|
|
|
342 |
}
|
|
|
343 |
|
| 27449 |
tejbeer |
344 |
@RequestMapping(value = "/getgeofence", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
345 |
public ResponseEntity<?> getAllGeofences(HttpServletRequest request)
|
|
|
346 |
throws IOException, ProfitMandiBusinessException {
|
|
|
347 |
|
|
|
348 |
OkHttpClient client = new OkHttpClient();
|
|
|
349 |
|
|
|
350 |
String authString = "Basic "
|
|
|
351 |
+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
|
|
|
352 |
|
|
|
353 |
// Get geofences created for all app users
|
|
|
354 |
Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences")
|
|
|
355 |
.addHeader("Authorization", authString).build();
|
|
|
356 |
|
|
|
357 |
Response response = client.newCall(request1).execute();
|
|
|
358 |
return responseSender.ok(response.body().string());
|
|
|
359 |
|
|
|
360 |
}
|
|
|
361 |
|
| 27475 |
tejbeer |
362 |
@RequestMapping(value = "/deletegeofence", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
363 |
public ResponseEntity<?> deleteGeofences(HttpServletRequest request, String geofenceId)
|
|
|
364 |
throws IOException, ProfitMandiBusinessException {
|
|
|
365 |
OkHttpClient client = new OkHttpClient();
|
|
|
366 |
|
|
|
367 |
String authString = "Basic "
|
|
|
368 |
+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
|
|
|
369 |
|
|
|
370 |
Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/geofences/" + geofenceId).delete()
|
|
|
371 |
.addHeader("Authorization", authString).build();
|
|
|
372 |
|
|
|
373 |
Response response = client.newCall(request1).execute();
|
|
|
374 |
return responseSender.ok(response.body().string());
|
|
|
375 |
|
|
|
376 |
}
|
|
|
377 |
|
| 27417 |
tejbeer |
378 |
}
|