|
|
@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.Connection;
|
|
|
@ -37,122 +39,141 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getTotalDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public int getTotalDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
int filteringViewID = 1;
|
|
|
|
return this.getDeviceCount(null);
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int getFeatureNonCompliantDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
int filteringViewID = 2;
|
|
|
|
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getActiveDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
public int getActiveDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
int filteringViewID = 1;
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "ACTIVE");
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "ACTIVE");
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getInactiveDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
public int getInactiveDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
int filteringViewID = 1;
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "INACTIVE");
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "INACTIVE");
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getRemovedDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
public int getRemovedDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
int filteringViewID = 1;
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "REMOVED");
|
|
|
|
filters.put("CONNECTIVITY_STATUS", "REMOVED");
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
public int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
int filteringViewID = 1;
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
filters.put("IS_COMPLIANT", 0);
|
|
|
|
filters.put("IS_COMPLIANT", 0);
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Map<String, Integer> getNonCompliantDeviceCountsByFeatures() throws GadgetDataServiceDAOException {
|
|
|
|
public PaginationResult getNonCompliantDeviceCountsByFeatures(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, Integer> filteredNonCompliantDeviceCountsByFeatures = new HashMap<>();
|
|
|
|
List<Map<String, Object>> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
|
|
|
|
|
|
|
|
int totalRecordsCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
|
|
|
|
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE";
|
|
|
|
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?";
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setInt(2, paginationRequest.getStartIndex());
|
|
|
|
|
|
|
|
stmt.setInt(3, paginationRequest.getRowCount());
|
|
|
|
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
// executing query
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
// fetching query results
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
Map<String, Object> filteredNonCompliantDeviceCountByFeature;
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
filteredNonCompliantDeviceCountsByFeatures.
|
|
|
|
filteredNonCompliantDeviceCountByFeature = new HashMap<>();
|
|
|
|
put(rs.getString("FEATURE_CODE"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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 filteredNonCompliantDeviceCountsByFeatures;
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
|
|
|
|
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
|
|
|
|
|
|
|
|
paginationResult.setRecordsTotal(totalRecordsCount);
|
|
|
|
|
|
|
|
return paginationResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
|
|
|
|
int filteringViewID = 1;
|
|
|
|
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
Map<String, Object> filters = new HashMap<>();
|
|
|
|
filters.put("POLICY_ID", -1);
|
|
|
|
filters.put("POLICY_ID", -1);
|
|
|
|
return this.getDeviceCount(filteringViewID, filters);
|
|
|
|
return this.getDeviceCount(filters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
int filteringViewID = 1;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
return this.getDeviceCountsByPlatforms(filteringViewID, filters);
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
|
|
|
|
// [1] appending filter columns
|
|
|
|
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
|
|
|
|
sql = sql + " AND " + column + " = ?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
int filteringViewID = 2;
|
|
|
|
|
|
|
|
return this.getDeviceCountsByPlatforms(filteringViewID, filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
@Override
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
int filteringViewID = 1;
|
|
|
|
if (filters != null && filters.values().size() > 0) {
|
|
|
|
return this.getDeviceCountsByOwnershipTypes(filteringViewID, filters);
|
|
|
|
int i = 2;
|
|
|
|
|
|
|
|
for (Object value : filters.values()) {
|
|
|
|
|
|
|
|
if (value instanceof Integer) {
|
|
|
|
|
|
|
|
stmt.setInt(i, (Integer) value);
|
|
|
|
|
|
|
|
} else if (value instanceof String) {
|
|
|
|
|
|
|
|
stmt.setString(i, (String) value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
int filteringViewID = 2;
|
|
|
|
|
|
|
|
return this.getDeviceCountsByOwnershipTypes(filteringViewID, filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
int filteringViewID = 1;
|
|
|
|
|
|
|
|
return this.getDevicesWithDetails(filteringViewID, filters);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
@Override
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
// fetching query results
|
|
|
|
int filteringViewID = 2;
|
|
|
|
while (rs.next()) {
|
|
|
|
return this.getDevicesWithDetails(filteringViewID, filters);
|
|
|
|
filteredDeviceCount = rs.getInt("DEVICE_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredDeviceCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getDeviceCount(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -160,13 +181,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
if (filteringViewID == 1) {
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if filteringViewID == 2
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
@ -177,8 +192,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
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);
|
|
|
|
|
|
|
|
stmt.setString(2, nonCompliantFeatureCode);
|
|
|
|
if (filters != null && filters.values().size() > 0) {
|
|
|
|
if (filters != null && filters.values().size() > 0) {
|
|
|
|
int i = 2;
|
|
|
|
int i = 3;
|
|
|
|
for (Object value : filters.values()) {
|
|
|
|
for (Object value : filters.values()) {
|
|
|
|
if (value instanceof Integer) {
|
|
|
|
if (value instanceof Integer) {
|
|
|
|
stmt.setInt(i, (Integer) value);
|
|
|
|
stmt.setInt(i, (Integer) value);
|
|
|
@ -202,7 +218,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCount;
|
|
|
|
return filteredDeviceCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Integer> getDeviceCountsByPlatforms(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -218,14 +234,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filteringViewID == 1) {
|
|
|
|
|
|
|
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
|
|
|
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
|
|
|
|
advancedSqlFiltering + "GROUP BY PLATFORM";
|
|
|
|
advancedSqlFiltering + "GROUP BY PLATFORM";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if filteringViewID == 2
|
|
|
|
|
|
|
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
|
|
|
|
|
|
|
|
advancedSqlFiltering + "GROUP BY PLATFORM";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
@ -254,7 +264,54 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Integer> getDeviceCountsByOwnershipTypes(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
Map<String, Integer> filteredDeviceCountsByPlatforms = new HashMap<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
|
|
|
|
// appending filters if exist, to support advanced filtering options
|
|
|
|
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
|
|
|
|
|
|
|
|
"AND FEATURE_CODE = ? " + advancedSqlFiltering + "GROUP BY PLATFORM";
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, nonCompliantFeatureCode);
|
|
|
|
|
|
|
|
if (filters != null && filters.values().size() > 0) {
|
|
|
|
|
|
|
|
int i = 3;
|
|
|
|
|
|
|
|
for (Object value : filters.values()) {
|
|
|
|
|
|
|
|
if (value instanceof Integer) {
|
|
|
|
|
|
|
|
stmt.setInt(i, (Integer) value);
|
|
|
|
|
|
|
|
} else if (value instanceof String) {
|
|
|
|
|
|
|
|
stmt.setString(i, (String) value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredDeviceCountsByPlatforms;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -270,14 +327,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filteringViewID == 1) {
|
|
|
|
|
|
|
|
sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
|
|
|
|
sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
|
|
|
|
advancedSqlFiltering + "GROUP BY OWNERSHIP";
|
|
|
|
advancedSqlFiltering + "GROUP BY OWNERSHIP";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if filteringViewID == 2
|
|
|
|
|
|
|
|
sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
|
|
|
|
|
|
|
|
advancedSqlFiltering + "GROUP BY OWNERSHIP";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
@ -306,7 +357,54 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> getDevicesWithDetails(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
Map<String, Integer> filteredDeviceCountsByOwnershipTypes = new HashMap<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql, advancedSqlFiltering = "";
|
|
|
|
|
|
|
|
// appending filters if exist, to support advanced filtering options
|
|
|
|
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
|
|
|
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
|
|
|
|
|
|
|
|
"AND FEATURE_CODE = ? " + advancedSqlFiltering + "GROUP BY OWNERSHIP";
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, nonCompliantFeatureCode);
|
|
|
|
|
|
|
|
if (filters != null && filters.values().size() > 0) {
|
|
|
|
|
|
|
|
int i = 3;
|
|
|
|
|
|
|
|
for (Object value : filters.values()) {
|
|
|
|
|
|
|
|
if (value instanceof Integer) {
|
|
|
|
|
|
|
|
stmt.setInt(i, (Integer) value);
|
|
|
|
|
|
|
|
} else if (value instanceof String) {
|
|
|
|
|
|
|
|
stmt.setString(i, (String) value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredDeviceCountsByOwnershipTypes;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
Connection con;
|
|
|
|
Connection con;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -316,12 +414,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con = this.getConnection();
|
|
|
|
con = this.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
|
if (filteringViewID == 1) {
|
|
|
|
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// if filteringViewID == 2
|
|
|
|
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// appending filters 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) {
|
|
|
@ -361,6 +454,58 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
|
|
|
|
|
|
|
Connection con;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
|
|
|
|
|
|
|
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
|
|
|
String sql;
|
|
|
|
|
|
|
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " +
|
|
|
|
|
|
|
|
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
|
|
|
|
// [1] appending filter columns, if exist
|
|
|
|
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
|
|
|
|
for (String column : filters.keySet()) {
|
|
|
|
|
|
|
|
sql = sql + " AND " + column + " = ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt = con.prepareStatement(sql);
|
|
|
|
|
|
|
|
// [2] appending filter column values, if exist
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, nonCompliantFeatureCode);
|
|
|
|
|
|
|
|
if (filters != null && filters.values().size() > 0) {
|
|
|
|
|
|
|
|
int i = 3;
|
|
|
|
|
|
|
|
for (Object value : filters.values()) {
|
|
|
|
|
|
|
|
if (value instanceof Integer) {
|
|
|
|
|
|
|
|
stmt.setInt(i, (Integer) value);
|
|
|
|
|
|
|
|
} else if (value instanceof String) {
|
|
|
|
|
|
|
|
stmt.setString(i, (String) value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// executing query
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
// fetching query results
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
|
|
|
|
|
|
|
|
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
|
|
|
|
|
|
|
|
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredDevicesWithDetails;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
return GadgetDataServiceDAOFactory.getConnection();
|
|
|
|
return GadgetDataServiceDAOFactory.getConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|