Refactor SQL query to filter out 'REMOVED' and 'DELETED' statuses

pull/393/head
Pramila Niroshan 7 months ago
parent 62722718f2
commit 2ab1cf767a

@ -1297,7 +1297,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
query = query.concat("WHERE DM_DEVICE.ID IN ("); query = query.concat("WHERE DM_DEVICE.ID IN (");
StringJoiner joiner = new StringJoiner(",", query , StringJoiner joiner = new StringJoiner(",", query ,
") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ?"); ") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ? AND e.STATUS != ?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add); deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
query = joiner.toString(); query = joiner.toString();
@ -1341,6 +1341,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
ps.setInt(index++, tenantId); ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString()); ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
ps.setString(index++, name + "%"); ps.setString(index++, name + "%");
} }

@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Count;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceBilling; import io.entgra.device.mgt.core.device.mgt.common.DeviceBilling;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -1078,7 +1079,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
+ "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON "
+ "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID "
+ "WHERE DM_DEVICE.ID IN (", + "WHERE DM_DEVICE.ID IN (",
") AND DM_DEVICE.TENANT_ID = ?"); ") AND DM_DEVICE.TENANT_ID AND e.STATUS NOT IN (?, ?)");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add); deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
@ -1120,6 +1121,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
ps.setInt(index++, tenantId); ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
ps.setString(index++, name + "%"); ps.setString(index++, name + "%");
} }

@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Count;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceBilling; import io.entgra.device.mgt.core.device.mgt.common.DeviceBilling;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -1057,7 +1058,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
+ "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON "
+ "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID "
+ "WHERE DM_DEVICE.ID IN (", + "WHERE DM_DEVICE.ID IN (",
") AND DM_DEVICE.TENANT_ID = ?"); ") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS NOT IN (?, ?)");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add); deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
@ -1099,6 +1100,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
ps.setInt(index++, tenantId); ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
ps.setString(index++, name + "%"); ps.setString(index++, name + "%");
} }

@ -926,7 +926,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
+ "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON "
+ "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID "
+ "WHERE DM_DEVICE.ID IN (", + "WHERE DM_DEVICE.ID IN (",
") AND DM_DEVICE.TENANT_ID = ?"); ") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ? AND e.STATUS != ?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add); deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
@ -968,6 +968,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
ps.setInt(index++, tenantId); ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) { if (isDeviceNameProvided) {
ps.setString(index++, name + "%"); ps.setString(index++, name + "%");
} }

Loading…
Cancel
Save