Add serial number and custom property filters to device count query

Pramila Niroshan 2 weeks ago
parent a10bdd1d05
commit 2338a6745d

@ -1319,6 +1319,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
boolean isSinceProvided = false;
List<String> tagList = request.getTags();
boolean isTagsProvided = false;
String serial = request.getSerialNumber();
boolean isSerialProvided = false;
try {
Connection conn = getConnection();
@ -1370,6 +1372,23 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
sql += ") GROUP BY dtm.ENROLMENT_ID HAVING COUNT(DISTINCT t.NAME) = ? )";
isTagsProvided = true;
}
if (serial != null && !serial.isEmpty()) {
sql += " AND EXISTS (" +
"SELECT VALUE_FIELD FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d1.ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ?)";
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
sql += " AND EXISTS (" +
"SELECT VALUE_FIELD FROM DM_DEVICE_INFO di2 " +
"WHERE di2.DEVICE_ID = d1.ID " +
"AND di2.KEY_FIELD = '" + entry.getKey() + "' " +
"AND di2.VALUE_FIELD LIKE ?)";
}
}
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIdx = 1;
@ -1402,6 +1421,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
}
stmt.setInt(paramIdx++, tagList.size());
}
if (isSerialProvided) {
stmt.setString(paramIdx++, "%" + serial + "%");
}
if (!request.getCustomProperty().isEmpty()) {
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
stmt.setString(paramIdx++, "%" + entry.getValue() + "%");
}
}
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {

Loading…
Cancel
Save