From 6f325862ec927ee3772fc811da401b205d07c2c3 Mon Sep 17 00:00:00 2001 From: MalshaPiumini Date: Thu, 6 May 2021 14:12:03 +0530 Subject: [PATCH] Formatting the SQL query. --- .../mgt/jaxrs/service/api/DeviceManagementService.java | 2 +- .../jaxrs/service/impl/DeviceManagementServiceImpl.java | 2 +- .../mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 7 +++++-- .../mgt/core/dao/impl/device/OracleDeviceDAOImpl.java | 7 +++++-- .../mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java | 7 +++++-- .../mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java | 7 +++++-- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index 8268fbaac6..01145b05ec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -271,7 +271,7 @@ public interface DeviceManagementService { String ownership, @ApiParam( name = "serialNumber", - value = "The serialNumber of the device.", + value = "The serial number of the device.", required = false) @QueryParam("serialNumber") String serialNumber, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 1a151bddf9..7648a102b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -206,7 +206,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { RequestValidationUtil.validateOwnershipType(ownership); request.setOwnership(ownership); } - if (serialNumber != null && !serialNumber.isEmpty()) { + if (StringUtils.isNotBlank(serialNumber)) { request.setSerialNumber(serialNumber); } if (status != null && !status.isEmpty()) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 22f06c3471..eb3fa87f54 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -94,8 +94,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { if (serial != null) { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_INFO i " + - "WHERE DEVICE_TYPE_ID = t.ID AND d.ID= i.DEVICE_ID " + - "AND i.KEY_FIELD='serial' AND i.VALUE_FIELD = ? AND d.TENANT_ID = ? "; + "WHERE DEVICE_TYPE_ID = t.ID " + + "AND d.ID= i.DEVICE_ID " + + "AND i.KEY_FIELD = 'serial' " + + "AND i.VALUE_FIELD = ? " + + "AND d.TENANT_ID = ? "; isSerialProvided = true; } else { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? "; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index 044a681c9d..4393a4546e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -94,8 +94,11 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { if (serial != null) { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_INFO i " + - "WHERE DEVICE_TYPE_ID = t.ID AND d.ID= i.DEVICE_ID " + - "AND i.KEY_FIELD='serial' AND i.VALUE_FIELD = ? AND d.TENANT_ID = ? "; + "WHERE DEVICE_TYPE_ID = t.ID " + + "AND d.ID= i.DEVICE_ID " + + "AND i.KEY_FIELD = 'serial' " + + "AND i.VALUE_FIELD = ? " + + "AND d.TENANT_ID = ? "; isSerialProvided = true; } else { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? "; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 5bcbbea8bc..66313603cb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -93,8 +93,11 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { if (serial != null) { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_INFO i " + - "WHERE DEVICE_TYPE_ID = t.ID AND d.ID= i.DEVICE_ID " + - "AND i.KEY_FIELD='serial' AND i.VALUE_FIELD = ? AND d.TENANT_ID = ? "; + "WHERE DEVICE_TYPE_ID = t.ID " + + "AND d.ID= i.DEVICE_ID " + + "AND i.KEY_FIELD = 'serial' " + + "AND i.VALUE_FIELD = ? " + + "AND d.TENANT_ID = ? "; isSerialProvided = true; } else { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? "; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java index 95a69d3642..4e87d8ab61 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/SQLServerDeviceDAOImpl.java @@ -95,8 +95,11 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { if (serial != null) { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_INFO i " + - "WHERE DEVICE_TYPE_ID = t.ID AND d.ID= i.DEVICE_ID " + - "AND i.KEY_FIELD='serial' AND i.VALUE_FIELD = ? AND d.TENANT_ID = ? "; + "WHERE DEVICE_TYPE_ID = t.ID " + + "AND d.ID= i.DEVICE_ID " + + "AND i.KEY_FIELD = 'serial' " + + "AND i.VALUE_FIELD = ? " + + "AND d.TENANT_ID = ? "; isSerialProvided = true; } else { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? ";