|
|
@ -357,7 +357,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
|
|
|
|
|
|
|
|
Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -404,24 +405,27 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public PaginationResult getDevicesWithDetails(Map<String, Object> filters,
|
|
|
|
|
|
|
|
PaginationRequest paginationRequest) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
// appending filters if exist, to support advanced filtering options
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
sql = sql + " AND " + column + " = ?";
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?";
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
@ -435,6 +439,11 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt.setInt(i, paginationRequest.getStartIndex());
|
|
|
|
|
|
|
|
stmt.setInt(++i, paginationRequest.getRowCount());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stmt.setInt(2, paginationRequest.getStartIndex());
|
|
|
|
|
|
|
|
stmt.setInt(3, paginationRequest.getRowCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
@ -446,33 +455,50 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetching total records count
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
totalRecordsCount = rs.getInt("DEVICE_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
paginationResult.setData(filteredDevicesWithDetails);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(totalRecordsCount);
|
|
|
|
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
|
|
|
|
|
|
|
|
Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " +
|
|
|
|
// appending filters if exist, to support advanced filtering options
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
sql = sql + " AND " + column + " = ?";
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?";
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
@ -487,6 +513,11 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt.setInt(i, paginationRequest.getStartIndex());
|
|
|
|
|
|
|
|
stmt.setInt(++i, paginationRequest.getRowCount());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stmt.setInt(3, paginationRequest.getStartIndex());
|
|
|
|
|
|
|
|
stmt.setInt(4, paginationRequest.getRowCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
@ -498,12 +529,29 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetching total records count
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, nonCompliantFeatureCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
totalRecordsCount = rs.getInt("DEVICE_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
paginationResult.setData(filteredDevicesWithDetails);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(totalRecordsCount);
|
|
|
|
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|