diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index 290f5f7d10..e8f0840f4c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -156,7 +156,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - DeviceInfo deviceInfo = new DeviceInfo(); + DeviceInfo deviceInfo = null; try { conn = this.getConnection(); @@ -169,6 +169,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { if (rs.next()) { // deviceInfo.setIMEI(rs.getString("IMEI")); // deviceInfo.setIMSI(rs.getString("IMSI")); + deviceInfo = new DeviceInfo(); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setVendor(rs.getString("VENDOR")); deviceInfo.setOsVersion(rs.getString("OS_VERSION")); 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 a9a5dbe77a..67360baf90 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 @@ -92,7 +92,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { deviceDetailsDAO.addDeviceInformation(device.getId(), device.getEnrolmentInfo().getId(), deviceInfo); newDeviceInfo = deviceInfo; } - if (previousDeviceProperties == null) { + if (previousDeviceProperties.isEmpty()) { deviceDetailsDAO.addDeviceProperties(newDeviceInfo.getDeviceDetailsMap(), device.getId(), device.getEnrolmentInfo().getId()); } else { 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 95213403d1..cd768fdd8e 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 @@ -116,6 +116,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException; @@ -169,9 +170,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv private EnrollmentDAO enrollmentDAO; private ApplicationDAO applicationDAO; private DeviceManagementPluginRepository pluginRepository; + private DeviceInformationManager deviceInformationManager; public DeviceManagementProviderServiceImpl() { this.pluginRepository = new DeviceManagementPluginRepository(); + this.deviceInformationManager = new DeviceInformationManagerImpl(); initDataAccessObjects(); /* Registering a listener to retrieve events when some device management service plugin is installed after * the component is done getting initialized */ @@ -386,6 +389,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv sendNotification(device); } extractDeviceLocationToUpdate(device); + try { + if (device.getDeviceInfo() != null) { + deviceInformationManager.addDeviceInfo(device, device.getDeviceInfo()); + } + } catch (DeviceDetailsMgtException e) { + //This is not logging as error, neither throwing an exception as this is not an exception in main + // business logic. + String msg = "Error occurred while adding device info"; + log.warn(msg, e); + } return status; } @@ -3414,7 +3427,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv deviceLocation.setDistance(Double.parseDouble(distance)); deviceLocation.setSpeed(Float.parseFloat(speed)); deviceLocation.setBearing(Float.parseFloat(bearing)); - DeviceInformationManager deviceInformationManager = new DeviceInformationManagerImpl(); deviceInformationManager.addDeviceLocation(device, deviceLocation); } catch (Exception e) { //We are not failing the execution since this is not critical for the functionality. But logging as diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java index 221ed02461..a4ab06e528 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/search/ProcessorImplTest.java @@ -88,7 +88,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest { context.setConditions(conditions); ProcessorImpl processor = new ProcessorImpl(); List devices = processor.execute(context); - Assert.assertEquals(5, devices.size(), "There should be exactly 5 devices with matching search criteria"); + Assert.assertEquals(devices.size(), 5, "There should be exactly 5 devices with matching search criteria"); } @Test (description = "Search for device with or condition") @@ -106,7 +106,7 @@ public class ProcessorImplTest extends BaseDeviceManagementTest { context.setConditions(conditions); ProcessorImpl processor = new ProcessorImpl(); List devices = processor.execute(context); - Assert.assertEquals(5, devices.size(), "There should be exactly 5 devices with matching search criteria"); + Assert.assertEquals(devices.size(), 5, "There should be exactly 5 devices with matching search criteria"); } @Test (description = "Search for device with wrong condition")