Update traccar cofiguration

merge-requests/899/head
Rushdi Mohamed 3 years ago
parent 2e5a9002da
commit 1dd2e35f89

@ -343,18 +343,8 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0.wso2v1</version>
<scope>compile</scope>
</dependency>
</dependencies>

@ -43,8 +43,6 @@ import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDA
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.report.mgt.Constants;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.TraccarAPIClientServiceImpl;
import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfigurationException;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil;
@ -390,8 +388,12 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
}
//Traccar update GPS Location
DeviceAPIClientService dac= DeviceManagementDataHolder.getInstance().getDeviceAPIClientService();
dac.updateLocation(device, deviceLocation);
try {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.updateLocation(device, deviceLocation);
} catch (TraccarConfigurationException e) {
log.error("Error on Traccar while adding GEO Location" + e);
}
//Traccar update GPS Location
DeviceManagementDAOFactory.commitTransaction();
@ -407,9 +409,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
// } catch (DataPublisherConfigurationException e) {
// DeviceManagementDAOFactory.rollbackTransaction();
// throw new DeviceDetailsMgtException("Error occurred while publishing the device location information.", e);
} catch (TraccarConfigurationException e) {
log.error("Error on Traccar" + e);
//e.printStackTrace();
} finally {
DeviceManagementDAOFactory.closeConnection();
}

@ -396,11 +396,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
//enroll Traccar device
try {
DeviceAPIClientService dac= DeviceManagementDataHolder.getInstance().getDeviceAPIClientService();
dac.addDevice(device);
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService().addDevice(device);
} catch (TraccarConfigurationException e) {
log.error("Error on Traccar add device" + e);
//e.printStackTrace();
log.error("Error while adding a device to traccar " + e);
}
//enroll Traccar device
@ -567,11 +565,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
//disenroll Traccar device
try {
DeviceAPIClientService dac= DeviceManagementDataHolder.getInstance().getDeviceAPIClientService();
dac.disDevice(device.getDeviceIdentifier());
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.disDevice(device.getDeviceIdentifier());
} catch (TraccarConfigurationException e) {
log.error("Error on Traccar disenroll a device" + e);
//e.printStackTrace();
log.error("Error while disenrolling a device from Traccar " + e);
}
//disenroll Traccar device

@ -49,6 +49,8 @@ import java.util.concurrent.TimeUnit;
import static org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants.ENDPOINT;
import static org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants.AUTHORIZATION;
import static org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants.AUTHORIZATION_KEY;
import static org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants.DEFAULT_PORT;
import static org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants.LOCATION_UPDATE_PORT;
public class TrackerClient implements TraccarClient {
private static final Log log = LogFactory.getLog(TrackerClient.class);
@ -60,6 +62,8 @@ public class TrackerClient implements TraccarClient {
final String endpoint = traccarGateway.getPropertyByName(ENDPOINT).getValue();
final String authorization = traccarGateway.getPropertyByName(AUTHORIZATION).getValue();
final String authorizationKey = traccarGateway.getPropertyByName(AUTHORIZATION_KEY).getValue();
final String defaultPort = traccarGateway.getPropertyByName(DEFAULT_PORT).getValue();
final String locationUpdatePort = traccarGateway.getPropertyByName(LOCATION_UPDATE_PORT).getValue();
public TrackerClient() {
client = new OkHttpClient.Builder()
@ -89,7 +93,7 @@ public class TrackerClient implements TraccarClient {
Request request;
if(method=="post"){
requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), payload.toString());
requestBody = RequestBody.create(payload.toString(), MediaType.parse("application/json; charset=utf-8"));
builder = builder.post(requestBody);
}else if(method=="delete"){
builder = builder.delete();
@ -134,7 +138,7 @@ public class TrackerClient implements TraccarClient {
List<String> geoFenceIds = new ArrayList<>();
payload.put("geofenceIds", geoFenceIds);
payload.put("attributes", new JSONObject());
String context = "8082/api/devices";
String context = defaultPort+"/api/devices";
Runnable trackerExecutor = new TrackerExecutor(endpoint, context, payload, "post");
executor.execute(trackerExecutor);
log.info("Device successfully enorolled on traccar");
@ -151,7 +155,7 @@ public class TrackerClient implements TraccarClient {
*/
public void updateLocation(TraccarPosition deviceInfo) throws TraccarConfigurationException {
try{
String context = "5055/?id="+deviceInfo.getDeviceIdentifier()+"&timestamp="+deviceInfo.getTimestamp()+
String context = locationUpdatePort+"/?id="+deviceInfo.getDeviceIdentifier()+"&timestamp="+deviceInfo.getTimestamp()+
"&lat="+deviceInfo.getLat()+"&lon="+deviceInfo.getLon()+"&bearing="+deviceInfo.getBearing()+
"&speed="+deviceInfo.getSpeed()+"&ignition=true";
Runnable trackerExecutor = new TrackerExecutor(endpoint, context, null, "get");
@ -173,7 +177,7 @@ public class TrackerClient implements TraccarClient {
@Override
public String getDeviceByDeviceIdentifier(String deviceId) throws TraccarConfigurationException {
try {
String context = "8082/api/devices?uniqueId="+ deviceId;
String context = defaultPort+"/api/devices?uniqueId="+ deviceId;
Runnable trackerExecutor = new TrackerExecutor(endpoint, context, null, "get");
executor.execute(trackerExecutor);
Request request = new Request.Builder()
@ -210,7 +214,7 @@ public class TrackerClient implements TraccarClient {
JSONArray geodata = obj.getJSONArray("geodata");
JSONObject jsonResponse = geodata.getJSONObject(0);
String context = "8082/api/devices/"+jsonResponse.getInt("id");
String context = defaultPort+"/api/devices/"+jsonResponse.getInt("id");
Runnable trackerExecutor = new TrackerExecutor(endpoint, context, null, "delete");
executor.execute(trackerExecutor);
log.info("Device successfully dis-enrolled");
@ -236,7 +240,7 @@ public class TrackerClient implements TraccarClient {
payload.put("name", groupInfo.getName());
payload.put("attributes", new JSONObject());
String context = "8082/api/groups";
String context = defaultPort+"/api/groups";
Runnable trackerExecutor = new TrackerExecutor(endpoint, context, payload, "post");
executor.execute(trackerExecutor);
log.info("Group successfully on traccar");

@ -20,7 +20,6 @@
package org.wso2.carbon.device.mgt.core.traccar.api.service.impl;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
@ -34,7 +33,6 @@ import java.util.Date;
public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
public void addDevice(Device device) throws TraccarConfigurationException {
TrackerClient client = new TrackerClient();
String lastUpdatedTime = String.valueOf((new Date().getTime()));

@ -25,4 +25,6 @@ public class TraccarHandlerConstants {
public static final String ENDPOINT = "api-endpoint";
public static final String AUTHORIZATION = "authorization";
public static final String AUTHORIZATION_KEY = "authorization-key";
public static final String DEFAULT_PORT = "default-port";
public static final String LOCATION_UPDATE_PORT = "location-update-port";
}

@ -0,0 +1,39 @@
/*
* Copyright (C) 2018 - 2022 Entgra (Pvt) Ltd, Inc - All Rights Reserved.
*
* Unauthorised copying/redistribution of this file, via any medium is strictly prohibited.
*
* Licensed under the Entgra Commercial License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://entgra.io/licenses/entgra-commercial/1.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.traccar.common.beans;
public class TraccarGroups {
private String name;
public TraccarGroups(String name){
this.name =name;
}
public TraccarGroups(){ }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~ Copyright (c) 2022, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
~
~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except

Loading…
Cancel
Save