diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/SubscriptionManagementAPI.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/SubscriptionManagementAPI.java index 275c400ea2e..cc61aca38ac 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/SubscriptionManagementAPI.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/SubscriptionManagementAPI.java @@ -379,6 +379,12 @@ public interface SubscriptionManagementAPI { @QueryParam("ownership") @Size(max = 45) String ownership, + @ApiParam( + name = "serialNumber", + value = "The serial number of the device.", + required = false) + @QueryParam("serialNumber") + String serialNumber, @ApiParam( name="uuid", value="uuid of the application release.", diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java index cbfdfb06704..f79c108ef52 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.store.api/src/main/java/io/entgra/device/mgt/core/application/mgt/store/api/services/impl/SubscriptionManagementAPIImpl.java @@ -314,6 +314,7 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ @QueryParam("name") String name, @QueryParam("user") String user, @QueryParam("ownership") String ownership, + @QueryParam("serialNumber") String serialNumber, @PathParam("uuid") String uuid, @DefaultValue("0") @QueryParam("offset") int offset, @@ -333,6 +334,9 @@ public class SubscriptionManagementAPIImpl implements SubscriptionManagementAPI{ RequestValidationUtil.validateOwnershipType(ownership); request.setOwnership(ownership); } + if (StringUtils.isNotBlank(serialNumber)) { + request.setSerialNumber(serialNumber); + } if (status != null && !status.isEmpty()) { boolean isStatusEmpty = true; for (String statusString : status) { 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/device/GenericDeviceDAOImpl.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/device/GenericDeviceDAOImpl.java index 2021d8fb949..400bb8c3f3b 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/device/GenericDeviceDAOImpl.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/device/GenericDeviceDAOImpl.java @@ -1184,6 +1184,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { String name = request.getDeviceName(); String user = request.getOwner(); String ownership = request.getOwnership(); + String serial = request.getSerialNumber(); String query = null; try { List devices = new ArrayList<>(); @@ -1197,6 +1198,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { boolean isDeviceNameProvided = false; boolean isOwnerProvided = false; boolean isOwnershipProvided = false; + boolean isSerialProvided = false; StringJoiner joiner = new StringJoiner(",", "SELECT " @@ -1219,6 +1221,9 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { + "DM_DEVICE.TENANT_ID = e.TENANT_ID " + "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON " + "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID " + + "INNER JOIN DM_DEVICE_INFO i ON " + + "DM_DEVICE.ID = i.DEVICE_ID " + + "AND i.KEY_FIELD = 'serial' " + "WHERE DM_DEVICE.ID IN (", ") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ?"); @@ -1233,6 +1238,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { query += " AND e.OWNERSHIP = ?"; isOwnershipProvided = true; } + if (serial != null && !serial.isEmpty()) { + query += " AND i.VALUE_FIELD LIKE ?" ; + isSerialProvided = true; + } if (user != null && !user.isEmpty()) { query += " AND e.OWNER = ?"; isOwnerProvided = true; @@ -1257,6 +1266,9 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { if (isOwnershipProvided) { ps.setString(index++, ownership); } + if (isSerialProvided) { + ps.setString(index++, "%" + serial + "%"); + } if (isOwnerProvided) { ps.setString(index++, user); }