From 9d9f420c83bf4cf84bc9415b0febf6a794a47879 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 5 Aug 2019 18:26:30 +0530 Subject: [PATCH] Fix formatting issues --- .../impl/admin/DeviceManagementAdminServiceImpl.java | 12 ++++++------ .../wso2/carbon/device/mgt/core/dao/DeviceDAO.java | 4 ++-- .../mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 4 ++-- .../device/mgt/core/dao/impl/EnrollmentDAOImpl.java | 12 +++++++++--- .../service/DeviceManagementProviderServiceImpl.java | 6 +++--- .../mgt/jaxrs/service/api/UserManagementService.java | 1 + .../impl/admin/DeviceManagementAdminServiceImpl.java | 12 ++++++------ 7 files changed, 29 insertions(+), 22 deletions(-) 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 38e5804751..ecae28ff4f 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 @@ -99,24 +99,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 5ea2a87b5b..6674c37a77 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 1cd83aa794..413e9bc56c 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 7bbb94bc89..77aab5bae9 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 11b6866433..943ee8079c 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 @@ -3086,12 +3086,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(); @@ -3114,7 +3114,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); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index a1bee403a8..3cb23087b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -147,6 +147,7 @@ import java.util.List; key = "perm:get-activity", permissions = {"/device-mgt/devices/owning-device/view"} ) + } ) @Path("/users") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 7227f3cb0c..ddbf7eb72e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.v09.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -97,24 +97,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 the device owner."; - 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(); } }