diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index d5618ef1d84..3a8962b6023 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -343,18 +343,8 @@ guava - com.fasterxml.jackson.core - jackson-databind - 2.11.2 - - - io.github.openfeign - feign-okhttp - - - org.wso2.orbit.com.squareup.okhttp + com.squareup.okhttp3 okhttp - 4.2.0.wso2v1 compile diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index e019716bdf4..57e672bd622 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -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(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 845e335b404..bd7e2ebb509 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -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 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TrackerClient.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TrackerClient.java index 62091212311..4d4f7ada436 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TrackerClient.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TrackerClient.java @@ -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 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()+"×tamp="+deviceInfo.getTimestamp()+ + String context = locationUpdatePort+"/?id="+deviceInfo.getDeviceIdentifier()+"×tamp="+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"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/TraccarAPIClientServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/TraccarAPIClientServiceImpl.java index a64cf6d31be..eac0c63b985 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/TraccarAPIClientServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/TraccarAPIClientServiceImpl.java @@ -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())); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/TraccarHandlerConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/TraccarHandlerConstants.java index 256ed44f30c..b4b2ba0e2d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/TraccarHandlerConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/TraccarHandlerConstants.java @@ -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"; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/beans/TraccarGroups.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/beans/TraccarGroups.java new file mode 100644 index 00000000000..b82496980a8 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/beans/TraccarGroups.java @@ -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; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml index 2072aca2371..67de666e5e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml @@ -1,7 +1,7 @@