diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 3864276fe82..a7ef07324ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -96,24 +96,24 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @QueryParam("owner") String owner, List deviceIdentifiers){ try { - if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, deviceIdentifiers)){ + if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, deviceIdentifiers)) { String msg = "Device owner is updated successfully."; return Response.status(Response.Status.OK).entity(msg).build(); } String msg = "Device owner updating is failed."; log.error(msg); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch(InvalidDeviceException e){ + } catch (InvalidDeviceException e) { String msg = "Invalid device identifiers are found with the request."; - log.error(msg); + log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); - }catch (DeviceManagementException e) { + } catch (DeviceManagementException e) { String msg = "Error occurred when updating device owners."; - log.error(msg); + log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (UserNotFoundException e) { String msg = "Couldn't found the owner in user store to update the owner of devices."; - log.error(msg); + log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 5ea2a87b5b6..6674c37a778 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -498,7 +498,8 @@ public interface DeviceDAO { * @throws DeviceManagementDAOException throws {@link DeviceManagementDAOException} if connections establishment * fails. */ - List getDevicesByIdentifiers(List deviceIdentifiers, int tenantId) throws DeviceManagementDAOException; + List getDevicesByIdentifiers(List deviceIdentifiers, int tenantId) + throws DeviceManagementDAOException; /** * This method is used to permanently delete the device and its related details @@ -508,4 +509,3 @@ public interface DeviceDAO { */ void deleteDevice(DeviceIdentifier deviceIdentifier, int tenantId) throws DeviceManagementDAOException; } - 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 1cd83aa7948..413e9bc56c3 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 @@ -1507,8 +1507,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } return devices; } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection when adding tags", - e); + throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection to get devices for" + + " given device identifiers.", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java index 7bbb94bc897..77aab5bae9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java @@ -369,7 +369,11 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { try { Connection conn = this.getConnection(); boolean updateStatus = true; - String sql = "UPDATE DM_ENROLMENT SET OWNER = ? WHERE ID = ? AND TENANT_ID = ?"; + String sql = "UPDATE " + + "DM_ENROLMENT " + + "SET OWNER = ? " + + "WHERE ID = ? AND " + + "TENANT_ID = ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { if (conn.getMetaData().supportsBatchUpdates()) { for (Device device : devices) { @@ -381,6 +385,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { for (int i : ps.executeBatch()) { if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) { updateStatus = false; + break; } } } else { @@ -390,14 +395,15 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { ps.setInt(3, tenantId); if (ps.executeUpdate() == 0) { updateStatus = false; + break; } } } } return updateStatus; } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection when adding tags", - e); + throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection to update the " + + "owner of the device enrollment.", 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 d9d34f5fd4e..cc39dff8ff7 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 @@ -3090,12 +3090,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.rollbackTransaction(); return false; } catch (TransactionManagementException e) { - String msg = "Error occurred while initiating transaction"; + String msg = "Error occurred while initiating the transaction."; log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (DeviceManagementDAOException e) { String msg = "Error occurred either verifying existence of device ids or updating owner of the device."; - log.error(msg); + log.error(msg, e); throw new DeviceManagementException(msg, e); } finally { DeviceManagementDAOFactory.closeConnection(); @@ -3118,7 +3118,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return owner; } catch (UserStoreException e) { String msg = "Error occurred when checking whether owner is exist or not. Owner: " + owner; - log.error(msg); + log.error(msg, e); throw new DeviceManagementException(msg, e); } }