|
|
|
@ -153,6 +153,137 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Device> searchDevicesInGroup(PaginationRequest request, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
Connection conn;
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
List<Device> devices = null;
|
|
|
|
|
|
|
|
|
|
int groupId = request.getGroupId();
|
|
|
|
|
String deviceType = request.getDeviceType();
|
|
|
|
|
boolean isDeviceTypeProvided = false;
|
|
|
|
|
String deviceName = request.getDeviceName();
|
|
|
|
|
boolean isDeviceNameProvided = false;
|
|
|
|
|
String owner = request.getOwner();
|
|
|
|
|
boolean isOwnerProvided = false;
|
|
|
|
|
String ownerPattern = request.getOwnerPattern();
|
|
|
|
|
boolean isOwnerPatternProvided = false;
|
|
|
|
|
String ownership = request.getOwnership();
|
|
|
|
|
boolean isOwnershipProvided = false;
|
|
|
|
|
String status = request.getStatus();
|
|
|
|
|
boolean isStatusProvided = false;
|
|
|
|
|
Date since = request.getSince();
|
|
|
|
|
boolean isSinceProvided = false;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
|
|
|
|
"(SELECT gd.DEVICE_ID, gd.DESCRIPTION, gd.NAME, gd.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " +
|
|
|
|
|
"FROM (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID " +
|
|
|
|
|
"FROM DM_DEVICE d, (SELECT dgm.DEVICE_ID FROM DM_DEVICE_GROUP_MAP dgm WHERE dgm.GROUP_ID = ?) dgm1 WHERE" +
|
|
|
|
|
" d.ID = dgm1.DEVICE_ID AND d.TENANT_ID = ?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Add the query for device-name
|
|
|
|
|
if (deviceName != null && !deviceName.isEmpty()) {
|
|
|
|
|
sql = sql + " AND d.NAME LIKE ?";
|
|
|
|
|
isDeviceNameProvided = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql = sql + ") gd, DM_DEVICE_TYPE t";
|
|
|
|
|
|
|
|
|
|
if (since != null) {
|
|
|
|
|
sql = sql + ", DM_DEVICE_DETAIL dt";
|
|
|
|
|
isSinceProvided = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql = sql + " WHERE gd.DEVICE_TYPE_ID = t.ID";
|
|
|
|
|
|
|
|
|
|
//Add query for last updated timestamp
|
|
|
|
|
if (isSinceProvided) {
|
|
|
|
|
sql = sql + " AND dt.DEVICE_ID = gd.DEVICE_ID AND dt.UPDATE_TIMESTAMP > ?";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Add the query for device-type
|
|
|
|
|
if (deviceType != null && !deviceType.isEmpty()) {
|
|
|
|
|
sql = sql + " AND t.NAME = ?";
|
|
|
|
|
isDeviceTypeProvided = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql = sql + " ) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? ";
|
|
|
|
|
|
|
|
|
|
//Add the query for ownership
|
|
|
|
|
if (ownership != null && !ownership.isEmpty()) {
|
|
|
|
|
sql = sql + " AND e.OWNERSHIP = ?";
|
|
|
|
|
isOwnershipProvided = true;
|
|
|
|
|
}
|
|
|
|
|
//Add the query for owner
|
|
|
|
|
if (owner != null && !owner.isEmpty()) {
|
|
|
|
|
sql = sql + " AND e.OWNER = ?";
|
|
|
|
|
isOwnerProvided = true;
|
|
|
|
|
} else if (ownerPattern != null && !ownerPattern.isEmpty()) {
|
|
|
|
|
sql = sql + " AND e.OWNER LIKE ?";
|
|
|
|
|
isOwnerPatternProvided = true;
|
|
|
|
|
}
|
|
|
|
|
//Add the query for status
|
|
|
|
|
if (status != null && !status.isEmpty()) {
|
|
|
|
|
sql = sql + " AND e.STATUS = ?";
|
|
|
|
|
isStatusProvided = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sql = sql + " LIMIT ?,?";
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
|
|
stmt.setInt(1, groupId);
|
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
|
|
|
|
|
|
int paramIdx = 3;
|
|
|
|
|
if (isDeviceNameProvided) {
|
|
|
|
|
stmt.setString(paramIdx++, deviceName + "%");
|
|
|
|
|
}
|
|
|
|
|
if (isSinceProvided) {
|
|
|
|
|
stmt.setLong(paramIdx++, since.getTime());
|
|
|
|
|
}
|
|
|
|
|
if (isDeviceTypeProvided) {
|
|
|
|
|
stmt.setString(paramIdx++, deviceType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stmt.setInt(paramIdx++, tenantId);
|
|
|
|
|
if (isOwnershipProvided) {
|
|
|
|
|
stmt.setString(paramIdx++, ownership);
|
|
|
|
|
}
|
|
|
|
|
if (isOwnerProvided) {
|
|
|
|
|
stmt.setString(paramIdx++, owner);
|
|
|
|
|
} else if (isOwnerPatternProvided) {
|
|
|
|
|
stmt.setString(paramIdx++, ownerPattern + "%");
|
|
|
|
|
}
|
|
|
|
|
if (isStatusProvided) {
|
|
|
|
|
stmt.setString(paramIdx++, status);
|
|
|
|
|
}
|
|
|
|
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
|
|
|
|
stmt.setInt(paramIdx, request.getRowCount());
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
devices = new ArrayList<>();
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
|
|
|
devices.add(device);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving information of" +
|
|
|
|
|
" devices belonging to group : " + groupId, e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Device> getDevicesOfUser(PaginationRequest request, int tenantId)
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|