From 15abfa218d1087e624e1109cbad19838a76b29f0 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Tue, 5 Nov 2019 19:17:37 +0530 Subject: [PATCH] Fix uninstall device list retrieving issue --- .../dao/impl/device/GenericDeviceDAOImpl.java | 32 +++++++++++++------ .../dao/impl/device/OracleDeviceDAOImpl.java | 32 +++++++++++++------ .../impl/device/PostgreSQLDeviceDAOImpl.java | 32 +++++++++++++------ .../impl/device/SQLServerDeviceDAOImpl.java | 32 +++++++++++++------ 4 files changed, 88 insertions(+), 40 deletions(-) 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 a4a50e0429f..e316baa78c1 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 @@ -597,21 +597,33 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isStatusProvided = false; StringJoiner joiner = new StringJoiner(",", - "SELECT " + - "f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " + - "f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + - "e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " + - "e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " + - "FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t "+ - "WHERE " + - "e.DEVICE_ID=f.ID AND " + - "e.DEVICE_ID IN (", ") AND e.TENANT_ID=?"); + "SELECT " + + "DM_DEVICE.ID AS DEVICE_ID, " + + "DM_DEVICE.NAME AS DEVICE_NAME, " + + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + + "DM_DEVICE.DEVICE_TYPE_ID, " + + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + + "DM_ENROLMENT.ID AS ENROLMENT_ID, " + + "DM_ENROLMENT.OWNER, " + + "DM_ENROLMENT.OWNERSHIP, " + + "DM_ENROLMENT.DATE_OF_ENROLMENT, " + + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " + + "DM_ENROLMENT.STATUS, " + + "device_types.NAME AS DEVICE_TYPE " + + "FROM DM_DEVICE " + + "INNER JOIN DM_ENROLMENT ON " + + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + + "WHERE DM_DEVICE.ID IN (", + ") AND DM_DEVICE.TENANT_ID = ?"); deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND e.STATUS=?"; + query = query + " AND DM_ENROLMENT.STATUS=?"; isStatusProvided = true; } 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 a1e496513f5..d09b53fa3ce 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 @@ -600,21 +600,33 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isStatusProvided = false; StringJoiner joiner = new StringJoiner(",", - "SELECT " + - "f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " + - "f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + - "e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " + - "e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " + - "FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t " + - "WHERE " + - "e.DEVICE_ID=f.ID AND " + - "e.DEVICE_ID IN (", ") AND e.TENANT_ID=?"); + "SELECT " + + "DM_DEVICE.ID AS DEVICE_ID, " + + "DM_DEVICE.NAME AS DEVICE_NAME, " + + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + + "DM_DEVICE.DEVICE_TYPE_ID, " + + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + + "DM_ENROLMENT.ID AS ENROLMENT_ID, " + + "DM_ENROLMENT.OWNER, " + + "DM_ENROLMENT.OWNERSHIP, " + + "DM_ENROLMENT.DATE_OF_ENROLMENT, " + + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " + + "DM_ENROLMENT.STATUS, " + + "device_types.NAME AS DEVICE_TYPE " + + "FROM DM_DEVICE " + + "INNER JOIN DM_ENROLMENT ON " + + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + + "WHERE DM_DEVICE.ID IN (", + ") AND DM_DEVICE.TENANT_ID = ?"); deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND e.STATUS=?"; + query = query + " AND DM_ENROLMENT.STATUS=?"; isStatusProvided = true; } 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 97f43c15542..044bbeb85a1 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 @@ -580,21 +580,33 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isStatusProvided = false; StringJoiner joiner = new StringJoiner(",", - "SELECT " + - "f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " + - "f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + - "e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " + - "e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " + - "FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t "+ - "WHERE " + - "e.DEVICE_ID=f.ID AND " + - "e.DEVICE_ID IN (", ") AND e.TENANT_ID=?"); + "SELECT " + + "DM_DEVICE.ID AS DEVICE_ID, " + + "DM_DEVICE.NAME AS DEVICE_NAME, " + + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + + "DM_DEVICE.DEVICE_TYPE_ID, " + + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + + "DM_ENROLMENT.ID AS ENROLMENT_ID, " + + "DM_ENROLMENT.OWNER, " + + "DM_ENROLMENT.OWNERSHIP, " + + "DM_ENROLMENT.DATE_OF_ENROLMENT, " + + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " + + "DM_ENROLMENT.STATUS, " + + "device_types.NAME AS DEVICE_TYPE " + + "FROM DM_DEVICE " + + "INNER JOIN DM_ENROLMENT ON " + + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + + "WHERE DM_DEVICE.ID IN (", + ") AND DM_DEVICE.TENANT_ID = ?"); deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND e.STATUS=?"; + query = query + " AND DM_ENROLMENT.STATUS=?"; isStatusProvided = true; } 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 1ee4657210f..ad6c887cf78 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 @@ -535,21 +535,33 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isStatusProvided = false; StringJoiner joiner = new StringJoiner(",", - "SELECT " + - "f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " + - "f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + - "e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " + - "e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " + - "FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t "+ - "WHERE " + - "e.DEVICE_ID=f.ID AND " + - "e.DEVICE_ID IN (", ") AND e.TENANT_ID=?"); + "SELECT " + + "DM_DEVICE.ID AS DEVICE_ID, " + + "DM_DEVICE.NAME AS DEVICE_NAME, " + + "DM_DEVICE.DESCRIPTION AS DESCRIPTION, " + + "DM_DEVICE.DEVICE_TYPE_ID, " + + "DM_DEVICE.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " + + "DM_ENROLMENT.ID AS ENROLMENT_ID, " + + "DM_ENROLMENT.OWNER, " + + "DM_ENROLMENT.OWNERSHIP, " + + "DM_ENROLMENT.DATE_OF_ENROLMENT, " + + "DM_ENROLMENT.DATE_OF_LAST_UPDATE, " + + "DM_ENROLMENT.STATUS, " + + "device_types.NAME AS DEVICE_TYPE " + + "FROM DM_DEVICE " + + "INNER JOIN DM_ENROLMENT ON " + + "DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID AND " + + "DM_DEVICE.TENANT_ID = DM_ENROLMENT.TENANT_ID " + + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + + "WHERE DM_DEVICE.ID IN (", + ") AND DM_DEVICE.TENANT_ID = ?"); deviceIds.stream().map(ignored -> "?").forEach(joiner::add); String query = joiner.toString(); if (status != null && !status.isEmpty()) { - query = query + " AND e.STATUS=?"; + query = query + " AND DM_ENROLMENT.STATUS=?"; isStatusProvided = true; }