From 7b0f12b890078e6265174e8849fdf5bc22cd9c0b Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Thu, 18 Jul 2024 13:45:39 +0530 Subject: [PATCH] Fix devices not loading in web apps --- .../dao/impl/AbstractEnrollmentDAOImpl.java | 18 ++++++++++++++---- .../core/dao/impl/AbstractGroupDAOImpl.java | 9 ++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java index 1160b4bb79..bca05c6b18 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractEnrollmentDAOImpl.java @@ -589,8 +589,11 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { "e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION " + "FROM DM_ENROLMENT e " + "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + - "WHERE e.OWNER = ? AND e.TENANT_ID = ? AND d.DEVICE_TYPE_ID = ? AND e.STATUS IN (" + deviceFilters + ")"); + "WHERE e.OWNER = ? AND e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters + ")"); + if (deviceTypeId != 0) { + sql.append(" AND d.DEVICE_TYPE_ID = ?"); + } if (deviceOwner != null && !deviceOwner.isEmpty()) { sql.append(" AND e.OWNER LIKE ?"); } @@ -607,10 +610,12 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { int index = 1; stmt.setString(index++, owner); stmt.setInt(index++, tenantId); - stmt.setInt(index++, deviceTypeId); for (String status : allowingDeviceStatuses) { stmt.setString(index++, status); } + if (deviceTypeId != 0) { + stmt.setInt(index++, deviceTypeId); + } if (deviceOwner != null && !deviceOwner.isEmpty()) { stmt.setString(index++, "%" + deviceOwner + "%"); @@ -731,8 +736,11 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { StringBuilder sql = new StringBuilder("SELECT e.DEVICE_ID, e.OWNER, e.STATUS, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION " + "FROM DM_ENROLMENT e " + "JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + - "WHERE e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ") AND d.DEVICE_TYPE_ID = ?"); + "WHERE e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")"); + if (deviceTypeId != 0) { + sql.append(" AND d.DEVICE_TYPE_ID = ?"); + } if (deviceOwner != null && !deviceOwner.isEmpty()) { sql.append(" AND e.OWNER LIKE ?"); } @@ -750,7 +758,9 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO { for (String status : allowingDeviceStatuses) { stmt.setString(index++, status); } - stmt.setInt(index++, deviceTypeId); + if (deviceTypeId != 0) { + stmt.setInt(index++, deviceTypeId); + } if (deviceOwner != null && !deviceOwner.isEmpty()) { stmt.setString(index++, "%" + deviceOwner + "%"); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java index cfa706b0e0..f747321fc4 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java @@ -1482,9 +1482,11 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { "WHERE " + " g.GROUP_NAME = ? " + " AND g.TENANT_ID = ? " + - " AND d.DEVICE_TYPE_ID = ? " + " AND e.STATUS IN (" + statusPlaceholders + ")"); + if (deviceTypeId != 0) { + sql.append(" AND d.DEVICE_TYPE_ID = ?"); + } if (deviceOwner != null && !deviceOwner.isEmpty()) { sql.append(" AND e.OWNER LIKE ?"); } @@ -1507,11 +1509,12 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { int index = 1; stmt.setString(index++, groupName); stmt.setInt(index++, tenantId); - stmt.setInt(index++, deviceTypeId); for (String status : allowedStatuses) { stmt.setString(index++, status); } - + if (deviceTypeId != 0) { + stmt.setInt(index++, deviceTypeId); + } if (deviceOwner != null && !deviceOwner.isEmpty()) { stmt.setString(index++, "%" + deviceOwner + "%"); }