From ce626327021398b1a05da23c4fae56dd7dfa863e Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Fri, 3 Nov 2023 09:44:36 +0530 Subject: [PATCH] Fix geofence search by partial name --- .../device/mgt/core/dao/impl/AbstractGeofenceDAOImpl.java | 4 ++-- .../mgt/core/dao/impl/geofence/GenericGeofenceDAOImpl.java | 4 ++-- .../mgt/core/dao/impl/geofence/SQLServerGeofenceDAOImpl.java | 2 +- 3 files changed, 5 insertions(+), 5 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/AbstractGeofenceDAOImpl.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/AbstractGeofenceDAOImpl.java index 393a11bf20..9c560a35cc 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/AbstractGeofenceDAOImpl.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/AbstractGeofenceDAOImpl.java @@ -153,7 +153,7 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO { try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(index++, tenantId); if (isNameProvided) { - stmt.setString(index++, request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%"); + stmt.setString(index++, "%" + request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%"); } stmt.setInt(index++, request.getRowCount()); stmt.setInt(index, request.getStartIndex()); @@ -190,7 +190,7 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO { "WHERE FENCE_NAME LIKE ?" + "AND TENANT_ID = ? "; try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, fenceName + "%"); + stmt.setString(1, "%" + fenceName + "%"); stmt.setInt(2, tenantId); try (ResultSet rst = stmt.executeQuery()) { geofenceData = extractGeofenceData(rst); 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/geofence/GenericGeofenceDAOImpl.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/geofence/GenericGeofenceDAOImpl.java index cebd70012d..d49adaa9d4 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/geofence/GenericGeofenceDAOImpl.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/geofence/GenericGeofenceDAOImpl.java @@ -143,7 +143,7 @@ public class GenericGeofenceDAOImpl extends AbstractGeofenceDAOImpl { try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(index++, tenantId); if (isNameProvided) { - stmt.setString(index++, request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%"); + stmt.setString(index++, request.getProperty("%" + DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%"); } stmt.setInt(index++, request.getRowCount()); stmt.setInt(index, request.getStartIndex()); @@ -180,7 +180,7 @@ public class GenericGeofenceDAOImpl extends AbstractGeofenceDAOImpl { "WHERE FENCE_NAME LIKE ?" + "AND TENANT_ID = ? "; try (PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, fenceName + "%"); + stmt.setString(1,"%" + fenceName + "%"); stmt.setInt(2, tenantId); try (ResultSet rst = stmt.executeQuery()) { geofenceData = extractGeofenceData(rst); 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/geofence/SQLServerGeofenceDAOImpl.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/geofence/SQLServerGeofenceDAOImpl.java index fa04264286..1a40be25bd 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/geofence/SQLServerGeofenceDAOImpl.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/geofence/SQLServerGeofenceDAOImpl.java @@ -71,7 +71,7 @@ public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl { try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(index++, tenantId); if (isNameProvided) { - stmt.setString(index++, request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%"); + stmt.setString(index++, "%" + request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%"); } stmt.setInt(index++, request.getStartIndex()); stmt.setInt(index, request.getRowCount());