diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 3c08f86339..d5b6128daf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -82,16 +82,17 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { int rows; try { conn = this.getConnection(); - String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, LAST_UPDATED_TIMESTAMP = ? " + + String sql = "UPDATE DM_DEVICE SET NAME = ?, DESCRIPTION = ?, LAST_UPDATED_TIMESTAMP = ? " + "WHERE DEVICE_TYPE_ID = (SELECT ID FROM DM_DEVICE_TYPE WHERE NAME = ? AND PROVIDER_TENANT_ID = ?) " + "AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql, new String[] {"id"}); - stmt.setString(1, device.getDescription()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setString(3, device.getType()); - stmt.setInt(4, tenantId); - stmt.setString(5, device.getDeviceIdentifier()); - stmt.setInt(6, tenantId); + stmt.setString(1, device.getName()); + stmt.setString(2, device.getDescription()); + stmt.setTimestamp(3, new Timestamp(new Date().getTime())); + stmt.setString(4, device.getType()); + stmt.setInt(5, tenantId); + stmt.setString(6, device.getDeviceIdentifier()); + stmt.setInt(7, tenantId); rows = stmt.executeUpdate(); return (rows > 0); } catch (SQLException e) { 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 d0b4f58a36..b183ada935 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 @@ -274,7 +274,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device currentDevice = deviceDAO.getDevice(deviceIdentifier, tenantId); device.setId(currentDevice.getId()); device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId()); - + if (device.getName() == null) { + device.setName(currentDevice.getName()); + } deviceDAO.updateDevice(device, tenantId); enrollmentDAO.updateEnrollment(device.getEnrolmentInfo()); DeviceManagementDAOFactory.commitTransaction(); @@ -365,7 +367,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" + - "id '" + deviceId.getId() + "'", e); + "id '" + deviceId.getId() + "'", e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } finally { @@ -876,7 +878,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (device == null) { if (log.isDebugEnabled()) { log.debug("No device is found upon the type '" + deviceId.getType() + "' and id '" + - deviceId.getId() + "'"); + deviceId.getId() + "'"); } return null; } @@ -889,7 +891,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv device.setApplications(applications); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "'", e); + "'" + deviceId.getId() + "'", e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } catch (DeviceDetailsMgtDAOException e) { @@ -903,7 +905,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (deviceManager == null) { if (log.isDebugEnabled()) { log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " + - "Therefore, not attempting method 'getDevice'"); + "Therefore, not attempting method 'getDevice'"); } return device; } @@ -1226,7 +1228,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List taskOperations; Map> deviceTypeSpecificTasks = new HashMap<>(); - for(DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()){ + for (DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()) { dms = deviceManagementServiceMap.get(dti); taskOperations = dms.getTasksForPlatform(); if (taskOperations != null) { @@ -1847,7 +1849,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" + - "id '" + deviceId.getId() + "' and user : " + user, e); + "id '" + deviceId.getId() + "' and user : " + user, e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } finally { @@ -1915,8 +1917,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv /** * Checks for the default group existence and create group based on device ownership * - * @param service {@link GroupManagementProviderService} instance. - * @param groupName of the group to create. + * @param service {@link GroupManagementProviderService} instance. + * @param groupName of the group to create. * @return Group with details. * @throws GroupManagementException */