From aa6c9f6734e1c98c7e5e00c3a0814d919bb136a4 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Fri, 10 Nov 2023 16:02:34 +0530 Subject: [PATCH] Fix certificate search by partial device identifiers --- .../mgt/core/dao/impl/GenericCertificateDAOImpl.java | 8 ++++---- .../mgt/core/dao/impl/OracleCertificateDAOImpl.java | 10 +++++----- .../core/dao/impl/PostgreSQLCertificateDAOImpl.java | 8 ++++---- .../mgt/core/dao/impl/SQLServerCertificateDAOImpl.java | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java index 3703101fd2b..26cb256e294 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java @@ -67,7 +67,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - sql += " AND DEVICE_IDENTIFIER = ?"; + sql += " AND DEVICE_IDENTIFIER LIKE ?"; } if (StringUtils.isNotEmpty(username)) { @@ -83,7 +83,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (StringUtils.isNotEmpty(username)) { @@ -129,7 +129,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - query += "AND DEVICE_IDENTIFIER = ? "; + query += "AND DEVICE_IDENTIFIER LIKE ? "; isCertificateDeviceIdentifierProvided = true; } @@ -147,7 +147,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (isCertificateDeviceIdentifierProvided) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (isCertificateUsernameProvided) { stmt.setString(paramIdx++, "%" + username + "%"); diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java index 31c4779dc51..e60ee4a6c00 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/OracleCertificateDAOImpl.java @@ -68,7 +68,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - query += "AND DEVICE_IDENTIFIER = ? "; + query += "AND DEVICE_IDENTIFIER LIKE ? "; isCertificateDeviceIdentifierProvided = true; } @@ -83,10 +83,10 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { int paramIdx = 1; stmt.setInt(paramIdx++, tenantId); if (isCertificateSerialNumberProvided) { - stmt.setString(paramIdx++, "%" + serialNumber+ "%"); + stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (isCertificateDeviceIdentifierProvided) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (isCertificateUsernameProvided) { stmt.setString(paramIdx++, "%" + username + "%"); @@ -140,7 +140,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - sql += " AND DEVICE_IDENTIFIER = ?"; + sql += " AND DEVICE_IDENTIFIER LIKE ?"; } if (StringUtils.isNotEmpty(username)) { @@ -156,7 +156,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (StringUtils.isNotEmpty(username)) { diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java index 55fd124a95f..48effed43ba 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/PostgreSQLCertificateDAOImpl.java @@ -68,7 +68,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - query += "AND DEVICE_IDENTIFIER = ? "; + query += "AND DEVICE_IDENTIFIER LIKE ? "; isCertificateDeviceIdentifierProvided = true; } @@ -86,7 +86,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (isCertificateDeviceIdentifierProvided) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (isCertificateUsernameProvided) { stmt.setString(paramIdx++, "%" + username + "%"); @@ -140,7 +140,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - sql += " AND DEVICE_IDENTIFIER = ?"; + sql += " AND DEVICE_IDENTIFIER LIKE ?"; } if (StringUtils.isNotEmpty(username)) { @@ -156,7 +156,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (StringUtils.isNotEmpty(username)) { diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java index 6734fcd997f..5cd02c63d02 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/SQLServerCertificateDAOImpl.java @@ -68,7 +68,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - query += "AND DEVICE_IDENTIFIER = ? "; + query += "AND DEVICE_IDENTIFIER LIKE ? "; isCertificateDeviceIdentifierProvided = true; } @@ -86,7 +86,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (isCertificateDeviceIdentifierProvided) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (isCertificateUsernameProvided) { stmt.setString(paramIdx++, "%" + username + "%"); @@ -140,7 +140,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - sql += " AND DEVICE_IDENTIFIER = ?"; + sql += " AND DEVICE_IDENTIFIER LIKE ?"; } if (StringUtils.isNotEmpty(username)) { @@ -156,7 +156,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(deviceIdentifier)) { - stmt.setString(paramIdx++, deviceIdentifier); + stmt.setString(paramIdx++, "%" + deviceIdentifier + "%"); } if (StringUtils.isNotEmpty(username)) {