From 3cd6b01f4a954b0c2561a42f35b140e9e0596ccc Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Fri, 27 Oct 2023 00:46:26 +0530 Subject: [PATCH] Add certificate search by partial serial number --- .../mgt/core/dao/impl/GenericCertificateDAOImpl.java | 8 ++++---- .../mgt/core/dao/impl/OracleCertificateDAOImpl.java | 8 ++++---- .../core/dao/impl/PostgreSQLCertificateDAOImpl.java | 10 +++++----- .../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 7655e46005..3703101fd2 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 @@ -63,7 +63,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { "WHERE TENANT_ID = ?"; if (StringUtils.isNotEmpty(serialNumber)) { - sql += " AND SERIAL_NUMBER = ?"; + sql += " AND SERIAL_NUMBER LIKE ?"; } if (StringUtils.isNotEmpty(deviceIdentifier)) { @@ -79,7 +79,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { int paramIdx = 2; if (StringUtils.isNotEmpty(serialNumber)) { - stmt.setString(paramIdx++, serialNumber); + stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (StringUtils.isNotEmpty(deviceIdentifier)) { @@ -124,7 +124,7 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl { "WHERE TENANT_ID = ? "; if (StringUtils.isNotEmpty(serialNumber)) { - query += "AND SERIAL_NUMBER = ? "; + query += "AND SERIAL_NUMBER LIKE ? "; isCertificateSerialNumberProvided = true; } @@ -144,7 +144,7 @@ public class GenericCertificateDAOImpl 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); 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 9231a0d746..31c4779dc5 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 @@ -63,7 +63,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { "FROM DM_DEVICE_CERTIFICATE " + "WHERE TENANT_ID = ? "; if (StringUtils.isNotEmpty(serialNumber)) { - query += "AND SERIAL_NUMBER = ? "; + query += "AND SERIAL_NUMBER LIKE ? "; isCertificateSerialNumberProvided = true; } @@ -83,7 +83,7 @@ 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); @@ -136,7 +136,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { "WHERE TENANT_ID = ?"; if (StringUtils.isNotEmpty(serialNumber)) { - sql += " AND SERIAL_NUMBER = ?"; + sql += " AND SERIAL_NUMBER LIKE ?"; } if (StringUtils.isNotEmpty(deviceIdentifier)) { @@ -152,7 +152,7 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl { int paramIdx = 2; if (StringUtils.isNotEmpty(serialNumber)) { - stmt.setString(paramIdx++, serialNumber); + stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (StringUtils.isNotEmpty(deviceIdentifier)) { 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 e31e005f0b..55fd124a95 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 @@ -63,7 +63,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { "FROM DM_DEVICE_CERTIFICATE " + "WHERE TENANT_ID = ? "; if (StringUtils.isNotEmpty(serialNumber)) { - query += "AND SERIAL_NUMBER = ? "; + query += "AND SERIAL_NUMBER LIKE ? "; isCertificateSerialNumberProvided = true; } @@ -83,7 +83,7 @@ public class PostgreSQLCertificateDAOImpl 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); @@ -136,7 +136,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { "WHERE TENANT_ID = ?"; if (StringUtils.isNotEmpty(serialNumber)) { - sql += " AND SERIAL_NUMBER = ?"; + sql += " AND SERIAL_NUMBER LIKE ?"; } if (StringUtils.isNotEmpty(deviceIdentifier)) { @@ -144,7 +144,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { } if (StringUtils.isNotEmpty(username)) { - sql += " AND USERNAME ILIKE ?"; + sql += " AND USERNAME LIKE ?"; } try (PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -152,7 +152,7 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl { int paramIdx = 2; if (StringUtils.isNotEmpty(serialNumber)) { - stmt.setString(paramIdx++, serialNumber); + stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (StringUtils.isNotEmpty(deviceIdentifier)) { 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 6e0908a286..6734fcd997 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 @@ -63,7 +63,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { "FROM DM_DEVICE_CERTIFICATE " + "WHERE TENANT_ID = ? "; if (StringUtils.isNotEmpty(serialNumber)) { - query += "AND SERIAL_NUMBER = ? "; + query += "AND SERIAL_NUMBER LIKE ? "; isCertificateSerialNumberProvided = true; } @@ -83,7 +83,7 @@ public class SQLServerCertificateDAOImpl 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); @@ -136,7 +136,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { "WHERE TENANT_ID = ?"; if (StringUtils.isNotEmpty(serialNumber)) { - sql += " AND SERIAL_NUMBER = ?"; + sql += " AND SERIAL_NUMBER LIKE ?"; } if (StringUtils.isNotEmpty(deviceIdentifier)) { @@ -152,7 +152,7 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl { int paramIdx = 2; if (StringUtils.isNotEmpty(serialNumber)) { - stmt.setString(paramIdx++, serialNumber); + stmt.setString(paramIdx++, "%" + serialNumber + "%"); } if (StringUtils.isNotEmpty(deviceIdentifier)) {