|
|
@ -21,7 +21,8 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException;
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
|
|
|
|
|
|
|
|
|
@ -29,115 +30,44 @@ import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getTotalDeviceCount() throws SQLException {
|
|
|
|
public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException {
|
|
|
|
return this.getDeviceCount(null);
|
|
|
|
int totalDeviceCount;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
totalDeviceCount = this.getFilteredDeviceCount(null);
|
|
|
|
|
|
|
|
} catch (InvalidParameterValueException e) {
|
|
|
|
|
|
|
|
throw new AssertionError(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
|
|
|
|
public int getActiveDeviceCount() throws SQLException {
|
|
|
|
deviceCountByGroupEntry.setGroup("total");
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
deviceCountByGroupEntry.setDisplayNameForGroup("Total");
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "ACTIVE");
|
|
|
|
deviceCountByGroupEntry.setDeviceCount(totalDeviceCount);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
return deviceCountByGroupEntry;
|
|
|
|
public int getInactiveDeviceCount() throws SQLException {
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "INACTIVE");
|
|
|
|
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
|
|
|
|
public int getRemovedDeviceCount() throws SQLException {
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "REMOVED");
|
|
|
|
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
int filteredDeviceCount = this.getFilteredDeviceCount(filterSet);
|
|
|
|
public int getNonCompliantDeviceCount() throws SQLException {
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
|
|
|
|
filters.put("IS_COMPLIANT", 0);
|
|
|
|
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
|
|
|
|
public int getUnmonitoredDeviceCount() throws SQLException {
|
|
|
|
deviceCountByGroupEntry.setGroup("non-specific");
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
deviceCountByGroupEntry.setDisplayNameForGroup("Non-specific");
|
|
|
|
filters.put("POLICY_ID", -1);
|
|
|
|
deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
return deviceCountByGroupEntry;
|
|
|
|
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
|
|
|
|
}
|
|
|
|
throws InvalidParameterException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (startIndex < 0) {
|
|
|
|
private int getFilteredDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
throw new InvalidParameterException("Start index (startIndex) should be " +
|
|
|
|
|
|
|
|
"equal to 0 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resultCount < 5) {
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
throw new InvalidParameterException("Result count (resultCount) should be " +
|
|
|
|
|
|
|
|
"equal to 5 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
List<Map<String, Object>> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
|
|
|
|
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?";
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setInt(2, startIndex);
|
|
|
|
|
|
|
|
stmt.setInt(3, resultCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
Map<String, Object> filteredNonCompliantDeviceCountByFeature;
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature = new HashMap<>();
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature.put("FEATURE_CODE", rs.getString("FEATURE_CODE"));
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature.put("DEVICE_COUNT", rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetching total records count
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " +
|
|
|
|
|
|
|
|
"(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 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("NON_COMPLIANT_FEATURE_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(totalRecordsCount);
|
|
|
|
|
|
|
|
return paginationResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getDeviceCount(Map<String, Object> filters) throws SQLException {
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -179,13 +109,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCount;
|
|
|
|
return filteredDeviceCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters)
|
|
|
|
@Override
|
|
|
|
throws InvalidParameterException, SQLException {
|
|
|
|
public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
|
|
|
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty.");
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -193,7 +126,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
// [1] appending filter columns
|
|
|
|
// [1] appending filter columns
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
@ -225,15 +159,158 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filteredDeviceCount;
|
|
|
|
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
deviceCountByGroupEntry.setGroup("feature-non-compliant");
|
|
|
|
|
|
|
|
deviceCountByGroupEntry.setDisplayNameForGroup("Feature-non-compliant");
|
|
|
|
|
|
|
|
deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return deviceCountByGroupEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException {
|
|
|
|
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, Integer> filteredDeviceCountsByPlatforms = new HashMap<>();
|
|
|
|
List<DeviceCountByGroupEntry> deviceCountsByConnectivityStatuses = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT CONNECTIVITY_STATUS, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? GROUP BY CONNECTIVITY_STATUS";
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry deviceCountByConnectivityStatus;
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
deviceCountByConnectivityStatus = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
deviceCountByConnectivityStatus.setGroup(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
|
|
|
|
deviceCountByConnectivityStatus.setDisplayNameForGroup(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
|
|
|
|
deviceCountByConnectivityStatus.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
deviceCountsByConnectivityStatuses.add(deviceCountByConnectivityStatus);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceCountsByConnectivityStatuses;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException {
|
|
|
|
|
|
|
|
// getting non-compliant device count
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT);
|
|
|
|
|
|
|
|
nonCompliantDeviceCount.setDisplayNameForGroup("Non-compliant");
|
|
|
|
|
|
|
|
nonCompliantDeviceCount.setDeviceCount(getNonCompliantDeviceCount());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// getting unmonitored device count
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry unmonitoredDeviceCount = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
unmonitoredDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED);
|
|
|
|
|
|
|
|
unmonitoredDeviceCount.setDisplayNameForGroup("Unmonitored");
|
|
|
|
|
|
|
|
unmonitoredDeviceCount.setDeviceCount(getUnmonitoredDeviceCount());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<DeviceCountByGroupEntry> deviceCountsByPotentialVulnerabilities = new ArrayList<>();
|
|
|
|
|
|
|
|
deviceCountsByPotentialVulnerabilities.add(nonCompliantDeviceCount);
|
|
|
|
|
|
|
|
deviceCountsByPotentialVulnerabilities.add(unmonitoredDeviceCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return deviceCountsByPotentialVulnerabilities;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getNonCompliantDeviceCount() throws SQLException {
|
|
|
|
|
|
|
|
FilterSet filterSet = new FilterSet();
|
|
|
|
|
|
|
|
filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return this.getFilteredDeviceCount(filterSet);
|
|
|
|
|
|
|
|
} catch (InvalidParameterValueException e) {
|
|
|
|
|
|
|
|
throw new AssertionError(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getUnmonitoredDeviceCount() throws SQLException {
|
|
|
|
|
|
|
|
FilterSet filterSet = new FilterSet();
|
|
|
|
|
|
|
|
filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return this.getFilteredDeviceCount(filterSet);
|
|
|
|
|
|
|
|
} catch (InvalidParameterValueException e) {
|
|
|
|
|
|
|
|
throw new AssertionError(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
|
|
|
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (startIndex < 0) {
|
|
|
|
|
|
|
|
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resultCount < 5) {
|
|
|
|
|
|
|
|
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
List<DeviceCountByGroupEntry> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
|
|
|
|
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?";
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setInt(2, startIndex);
|
|
|
|
|
|
|
|
stmt.setInt(3, resultCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry filteredNonCompliantDeviceCountByFeature;
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature.setGroup(rs.getString("FEATURE_CODE"));
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature.setDisplayNameForGroup(rs.getString("FEATURE_CODE"));
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountByFeature.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetching total records count
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " +
|
|
|
|
|
|
|
|
"(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 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("NON_COMPLIANT_FEATURE_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(totalRecordsCount);
|
|
|
|
|
|
|
|
return paginationResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
|
|
|
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
List<DeviceCountByGroupEntry> filteredDeviceCountsByPlatforms = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
@ -263,8 +340,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry filteredDeviceCountByPlatform;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
filteredDeviceCountByPlatform = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
filteredDeviceCountByPlatform.setGroup(rs.getString("PLATFORM"));
|
|
|
|
|
|
|
|
filteredDeviceCountByPlatform.setDisplayNameForGroup(rs.getString("PLATFORM").toUpperCase());
|
|
|
|
|
|
|
|
filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
@ -272,19 +354,21 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
|
|
|
|
@Override
|
|
|
|
Map<String, Object> filters) throws InvalidParameterException, SQLException {
|
|
|
|
public List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
|
|
|
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
"should not be either null or empty.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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, Integer> filteredDeviceCountsByPlatforms = new HashMap<>();
|
|
|
|
List<DeviceCountByGroupEntry> filteredDeviceCountsByPlatforms = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
@ -315,8 +399,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry filteredDeviceCountByPlatform;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
filteredDeviceCountByPlatform = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
filteredDeviceCountByPlatform.setGroup(rs.getString("PLATFORM"));
|
|
|
|
|
|
|
|
filteredDeviceCountByPlatform.setDisplayNameForGroup(rs.getString("PLATFORM").toUpperCase());
|
|
|
|
|
|
|
|
filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
@ -324,12 +413,17 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
|
|
|
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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, Integer> filteredDeviceCountsByOwnershipTypes = new HashMap<>();
|
|
|
|
List<DeviceCountByGroupEntry> filteredDeviceCountsByOwnershipTypes = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
@ -359,8 +453,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry filteredDeviceCountByOwnershipType;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
filteredDeviceCountByOwnershipType = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
filteredDeviceCountByOwnershipType.setGroup(rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
filteredDeviceCountByOwnershipType.setDisplayNameForGroup(rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
@ -368,19 +467,22 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
|
|
|
|
@Override
|
|
|
|
Map<String, Object> filters) throws InvalidParameterException, SQLException {
|
|
|
|
public List<DeviceCountByGroupEntry>
|
|
|
|
|
|
|
|
getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
|
|
|
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
"should not be either null or empty.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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, Integer> filteredDeviceCountsByOwnershipTypes = new HashMap<>();
|
|
|
|
List<DeviceCountByGroupEntry> filteredDeviceCountsByOwnershipTypes = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
@ -411,8 +513,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
DeviceCountByGroupEntry filteredDeviceCountByOwnershipType;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
filteredDeviceCountByOwnershipType = new DeviceCountByGroupEntry();
|
|
|
|
|
|
|
|
filteredDeviceCountByOwnershipType.setGroup(rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
filteredDeviceCountByOwnershipType.setDisplayNameForGroup(rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
@ -420,24 +527,25 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PaginationResult getDevicesWithDetails(Map<String, Object> filters,
|
|
|
|
@Override
|
|
|
|
int startIndex, int resultCount) throws InvalidParameterException, SQLException {
|
|
|
|
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
|
|
|
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
if (startIndex < 0) {
|
|
|
|
if (startIndex < 0) {
|
|
|
|
throw new InvalidParameterException("Start index (startIndex) should be " +
|
|
|
|
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
|
|
|
|
"equal to 0 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (resultCount < 5) {
|
|
|
|
if (resultCount < 5) {
|
|
|
|
throw new InvalidParameterException("Result count (resultCount) should be " +
|
|
|
|
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
|
|
|
|
"equal to 5 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
@ -473,15 +581,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
Map<String, Object> filteredDeviceWithDetails;
|
|
|
|
DetailedDeviceEntry filteredDeviceWithDetails;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
filteredDeviceWithDetails = new DetailedDeviceEntry();
|
|
|
|
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// fetching total records count
|
|
|
|
// fetching total records count
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
|
|
|
@ -503,30 +612,30 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return paginationResult;
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
|
|
|
|
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
|
|
|
|
Map<String, Object> filters, int startIndex, int resultCount)
|
|
|
|
FilterSet filterSet, int startIndex, int resultCount)
|
|
|
|
throws InvalidParameterException, SQLException {
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
"should not be either null or empty.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (startIndex < 0) {
|
|
|
|
if (startIndex < 0) {
|
|
|
|
throw new InvalidParameterException("Start index (startIndex) should be " +
|
|
|
|
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
|
|
|
|
"equal to 0 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (resultCount < 5) {
|
|
|
|
if (resultCount < 5) {
|
|
|
|
throw new InvalidParameterException("Result count (resultCount) should be " +
|
|
|
|
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
|
|
|
|
"equal to 5 or greater than that.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
@ -563,15 +672,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
Map<String, Object> filteredDeviceWithDetails;
|
|
|
|
DetailedDeviceEntry filteredDeviceWithDetails;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
filteredDeviceWithDetails = new DetailedDeviceEntry();
|
|
|
|
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// fetching total records count
|
|
|
|
// fetching total records count
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
@ -595,12 +705,17 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return paginationResult;
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
|
|
|
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
@ -629,13 +744,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
Map<String, Object> filteredDeviceWithDetails;
|
|
|
|
DetailedDeviceEntry filteredDeviceWithDetails;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
filteredDeviceWithDetails = new DetailedDeviceEntry();
|
|
|
|
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -644,19 +759,21 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
|
|
|
|
@Override
|
|
|
|
Map<String, Object> filters) throws InvalidParameterException, SQLException {
|
|
|
|
public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
|
|
|
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
|
|
|
|
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
"should not be either null or empty.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
@ -687,13 +804,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
Map<String, Object> filteredDeviceWithDetails;
|
|
|
|
DetailedDeviceEntry filteredDeviceWithDetails;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
filteredDeviceWithDetails = new DetailedDeviceEntry();
|
|
|
|
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
|
|
|
|
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
|
|
|
|
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -702,6 +819,49 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> extractDatabaseFiltersFromBean(FilterSet filterSet)
|
|
|
|
|
|
|
|
throws InvalidParameterValueException {
|
|
|
|
|
|
|
|
if (filterSet == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String connectivityStatus = filterSet.getConnectivityStatus();
|
|
|
|
|
|
|
|
if (connectivityStatus != null) {
|
|
|
|
|
|
|
|
filters.put("CONNECTIVITY_STATUS", connectivityStatus);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String potentialVulnerability = filterSet.getPotentialVulnerability();
|
|
|
|
|
|
|
|
if (potentialVulnerability != null) {
|
|
|
|
|
|
|
|
if (GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT.equals(potentialVulnerability) ||
|
|
|
|
|
|
|
|
GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED.equals(potentialVulnerability)) {
|
|
|
|
|
|
|
|
if (GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT.equals(potentialVulnerability)) {
|
|
|
|
|
|
|
|
filters.put("IS_COMPLIANT", 0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
filters.put("POLICY_ID", -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new InvalidParameterValueException("Invalid use of value for potential vulnerability. " +
|
|
|
|
|
|
|
|
"Value of potential vulnerability could only be either " +
|
|
|
|
|
|
|
|
GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT + " or " +
|
|
|
|
|
|
|
|
GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED + ".");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String platform = filterSet.getPlatform();
|
|
|
|
|
|
|
|
if (platform != null) {
|
|
|
|
|
|
|
|
filters.put("PLATFORM", platform);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String ownership = filterSet.getOwnership();
|
|
|
|
|
|
|
|
if (ownership != null) {
|
|
|
|
|
|
|
|
filters.put("OWNERSHIP", ownership);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return filters;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
return GadgetDataServiceDAOFactory.getConnection();
|
|
|
|
return GadgetDataServiceDAOFactory.getConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|