|
|
|
@ -19,11 +19,10 @@
|
|
|
|
|
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet;
|
|
|
|
|
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
@ -38,7 +37,7 @@ import java.util.Map;
|
|
|
|
|
public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException {
|
|
|
|
|
public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException {
|
|
|
|
|
int totalDeviceCount;
|
|
|
|
|
try {
|
|
|
|
|
totalDeviceCount = this.getFilteredDeviceCount(null);
|
|
|
|
@ -56,7 +55,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
|
|
|
|
|
throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
int filteredDeviceCount = this.getFilteredDeviceCount(filterSet);
|
|
|
|
|
|
|
|
|
@ -69,7 +68,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getFilteredDeviceCount(FilterSet filterSet)
|
|
|
|
|
throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
@ -80,8 +79,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
|
try {
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " + GadgetDataServiceDAOConstants.DatabaseView.
|
|
|
|
|
DEVICES_VIEW_1 + " WHERE TENANT_ID = ?";
|
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " +
|
|
|
|
|
GadgetDataServiceDAOConstants.DatabaseView.DEVICES_VIEW_1 + " WHERE TENANT_ID = ?";
|
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
|
// [1] appending filter columns
|
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
@ -109,9 +108,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
filteredDeviceCount = rs.getInt("DEVICE_COUNT");
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -120,7 +116,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
|
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
@ -135,8 +131,8 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
int filteredDeviceCount = 0;
|
|
|
|
|
try {
|
|
|
|
|
con = this.getConnection();
|
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " + GadgetDataServiceDAOConstants.DatabaseView.
|
|
|
|
|
DEVICES_VIEW_2 + " WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
|
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " +
|
|
|
|
|
GadgetDataServiceDAOConstants.DatabaseView.DEVICES_VIEW_2 + " WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
|
|
|
|
|
// appending filters to support advanced filtering options
|
|
|
|
|
// [1] appending filter columns
|
|
|
|
|
if (filters != null && filters.size() > 0) {
|
|
|
|
@ -165,9 +161,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
filteredDeviceCount = rs.getInt("DEVICE_COUNT");
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -181,7 +174,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException {
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException {
|
|
|
|
|
Connection con;
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
@ -206,9 +199,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
deviceCountByConnectivityStatus.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
deviceCountsByConnectivityStatuses.add(deviceCountByConnectivityStatus);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -216,7 +206,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException {
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException {
|
|
|
|
|
// getting non-compliant device count
|
|
|
|
|
DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry();
|
|
|
|
|
nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT);
|
|
|
|
@ -236,7 +226,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
return deviceCountsByPotentialVulnerabilities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getNonCompliantDeviceCount() throws DataAccessLayerException {
|
|
|
|
|
private int getNonCompliantDeviceCount() throws SQLException {
|
|
|
|
|
FilterSet filterSet = new FilterSet();
|
|
|
|
|
filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT);
|
|
|
|
|
try {
|
|
|
|
@ -246,7 +236,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getUnmonitoredDeviceCount() throws DataAccessLayerException {
|
|
|
|
|
private int getUnmonitoredDeviceCount() throws SQLException {
|
|
|
|
|
FilterSet filterSet = new FilterSet();
|
|
|
|
|
filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED);
|
|
|
|
|
try {
|
|
|
|
@ -258,7 +248,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
|
|
|
|
|
throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
@ -304,9 +294,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -316,7 +303,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceCountByGroupEntry>
|
|
|
|
|
getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
|
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
@ -368,9 +355,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -379,7 +363,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
|
|
|
|
|
throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
@ -426,9 +410,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -438,7 +419,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
@Override
|
|
|
|
|
public List<DeviceCountByGroupEntry>
|
|
|
|
|
getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
|
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
@ -490,9 +471,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT"));
|
|
|
|
|
filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -501,7 +479,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
|
|
|
|
|
throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
|
|
|
|
|
|
|
|
|
@ -549,9 +527,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
@ -560,7 +535,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException {
|
|
|
|
|
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
|
|
|
|
|
|
|
|
|
|
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
|
|
|
|
|
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
|
|
|
|
@ -614,9 +589,6 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
|
|
|
|
|
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
|
|
|
|
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DataAccessLayerException("Error in either getting database connection, " +
|
|
|
|
|
"running SQL query or fetching results.", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
|