From b3a229a0e72d6831e55e832db6da436b8b407548 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Sat, 25 Sep 2021 18:58:23 +0530 Subject: [PATCH] Update device property table in dm db when updating properties (cherry picked from commit 5f64b0b1ad938f92353f55a97da96a7c7b0e55ba) --- .../type/template/DeviceTypeManager.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java index 2022447e646..7e65a244e91 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java @@ -489,13 +489,14 @@ public class DeviceTypeManager implements DeviceManager { throws DeviceManagementException { boolean status = false; if (propertiesExist) { + Device updatedDevice = new Device(); + updatedDevice.setDeviceIdentifier(deviceId.getId()); + updatedDevice.setProperties(propertyList); try { if (log.isDebugEnabled()) { - log.debug("Getting the details of " + deviceType + " device : '" + deviceId.getId() + "'"); + log.debug("Updating device properties of " + deviceType + " device : '" + + deviceId.getId() + "'"); } - Device updatedDevice = new Device(); - updatedDevice.setDeviceIdentifier(deviceId.getId()); - updatedDevice.setProperties(propertyList); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(updatedDevice); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); @@ -506,6 +507,24 @@ public class DeviceTypeManager implements DeviceManager { } finally { deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection(); } + if (propertyBasedDeviceTypePluginDAOManager != null && status) { + try { + if (log.isDebugEnabled()) { + log.debug("Updating device properties of " + deviceType + " device : '" + + deviceId.getId() + "'"); + } + propertyBasedDeviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); + status = propertyBasedDeviceTypePluginDAOManager.getDeviceDAO().updateDevice(updatedDevice); + propertyBasedDeviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); + } catch (DeviceTypeMgtPluginException e) { + propertyBasedDeviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); + String msg = "Error while updating properties for " + deviceType + " device : " + + deviceId.getId(); + throw new DeviceManagementException(msg, e); + } finally { + propertyBasedDeviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection(); + } + } } return status; }