From 74adeda997fb79a8ceeb588a5c9668a4a917fb36 Mon Sep 17 00:00:00 2001 From: Rushdi Date: Wed, 27 Apr 2022 20:14:41 +0530 Subject: [PATCH] Assign device to user when enrolling a device --- .../api/service/addons/TraccarClientImpl.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) 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/TraccarClientImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java index 124b16f044..078dbef2dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java @@ -160,8 +160,11 @@ public class TraccarClientImpl implements TraccarClient { log.info("============================="); log.info(new Gson().toJson(traccarUser)); log.info("============================="); + //device is available + //device is not available + //user is available + //user is not available fetchAllUsers(TraccarHandlerConstants.Types.USER_CREATE_WITH_INSERT_DEVICE, traccarUser, traccarId); - } }else if(type==TraccarHandlerConstants.Types.GROUP){ trackerDAO.addTrackerGroup(traccarId, groupId, tenantId); @@ -193,13 +196,13 @@ public class TraccarClientImpl implements TraccarClient { TrackerManagementDAOFactory.rollbackTransaction(); String msg = null; if(type==TraccarHandlerConstants.Types.DEVICE){ - msg = "Error occurred while mapping with deviceId ."; + msg = "Already device with deviceId " + deviceId + " exists" ; }else if(type==TraccarHandlerConstants.Types.GROUP){ - msg = "Error occurred while mapping with groupId ."; + msg = "Already the group with groupId - " + groupId + " exists!"; }else if(type==TraccarHandlerConstants.Types.USER){ - msg = "Error occurred while fetching users ."; + msg = "Error occurred while fetching users."; }else if(type==TraccarHandlerConstants.Types.PERMISSION){ - msg = "Error occurred while assigning the device to the user ."; + msg = "Error occurred while assigning the device to the user." + traccarId + deviceId; } log.error(msg, e); } finally { @@ -218,6 +221,7 @@ public class TraccarClientImpl implements TraccarClient { JSONArray fetchAllUsers = new JSONArray(result); int userAvailability = 0; + int userId = 0; for(int i=0; i