Adding inter-mediate development code bits for dashboard analytics feature

4.x.x
dilanua 9 years ago
parent 7b43d28298
commit 17e958d838

@ -18,13 +18,12 @@
package org.wso2.carbon.device.mgt.analytics.dashboard; package org.wso2.carbon.device.mgt.analytics.dashboard;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; 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.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* To be updated... * To be updated...
@ -32,48 +31,39 @@ import java.util.Map;
public interface GadgetDataService { public interface GadgetDataService {
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getTotalDeviceCount() throws SQLException; DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getActiveDeviceCount() throws SQLException; DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getInactiveDeviceCount() throws SQLException; DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getRemovedDeviceCount() throws SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getNonCompliantDeviceCount() throws SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException;
@SuppressWarnings("unused")
int getUnmonitoredDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
@SuppressWarnings("unused")
int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByOwnershipTypes(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -86,11 +76,11 @@ public interface GadgetDataService {
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<Map<String, Object>> getDevicesWithDetails(FilterSet filterSet) List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
} }

@ -18,76 +18,44 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao; package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; 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.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map;
public interface GadgetDataServiceDAO { public interface GadgetDataServiceDAO {
/** DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException;
* Method to get total filtered device count from a particular tenant.
*
* @return Total filtered device count.
*/
int getTotalDeviceCount() throws SQLException;
/** DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
* Method to get active device count from a particular tenant. FilterSet filterSet) throws InvalidParameterValueException, SQLException;
*
* @return active device count.
*/
int getActiveDeviceCount() throws SQLException;
/** /**
* Method to get inactive device count from a particular tenant. * Method to get total device count from a particular tenant.
* *
* @return inactive device count. * @return Total device count.
*/ */
int getInactiveDeviceCount() throws SQLException; DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException;
/** List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException;
* Method to get removed device count from a particular tenant.
*
* @return removed device count.
*/
int getRemovedDeviceCount() throws SQLException;
/** List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException;
* Method to get non-compliant device count from a particular tenant.
*
* @return Non-compliant device count.
*/
int getNonCompliantDeviceCount() throws SQLException;
/**
* Method to get unmonitored device count from a particular tenant.
*
* @return Unmonitored device count.
*/
int getUnmonitoredDeviceCount() throws SQLException;
PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException;
Map<String, Integer> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
Map<String, Integer> getDeviceCountsByOwnershipTypes(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
@ -96,10 +64,10 @@ public interface GadgetDataServiceDAO {
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException;
List<Map<String, Object>> getDevicesWithDetails(FilterSet filterSet) List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException; throws InvalidParameterValueException, SQLException;
List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
} }

@ -1,23 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean;
public enum ConnectivityStatus {
active, inactive, removed
}

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean;
public class FilterSet { public class FilterSet {
private String connectivityStatus; private String connectivityStatus;
private String potentialVulnerability; private String potentialVulnerability;
private String platform; private String platform;
@ -44,6 +45,7 @@ public class FilterSet {
return platform; return platform;
} }
@SuppressWarnings("unused")
public void setPlatform(String platform) { public void setPlatform(String platform) {
this.platform = platform; this.platform = platform;
} }
@ -52,7 +54,9 @@ public class FilterSet {
return ownership; return ownership;
} }
@SuppressWarnings("unused")
public void setOwnership(String ownership) { public void setOwnership(String ownership) {
this.ownership = ownership; this.ownership = ownership;
} }
} }

@ -1,23 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean;
public enum Ownership {
byod, cope
}

@ -1,23 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean;
public enum Platform {
android, ios, windows
}

@ -1,23 +0,0 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean;
public enum PotentialVulnerability {
non_compliant, unmonitored
}

@ -35,129 +35,36 @@ import java.util.*;
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@Override @Override
public int getTotalDeviceCount() throws SQLException { public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException {
int totalDeviceCount;
try { try {
return this.getDeviceCount(null); totalDeviceCount = this.getFilteredDeviceCount(null);
} catch (InvalidParameterValueException e) { } catch (InvalidParameterValueException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
}
@Override
public int getActiveDeviceCount() throws SQLException {
FilterSet filterSet = new FilterSet();
filterSet.setConnectivityStatus(ConnectivityStatus.active.toString());
try {
return this.getDeviceCount(filterSet);
} catch (InvalidParameterValueException e) {
throw new AssertionError(e);
}
}
@Override
public int getInactiveDeviceCount() throws SQLException {
FilterSet filterSet = new FilterSet();
filterSet.setConnectivityStatus(ConnectivityStatus.inactive.toString());
try {
return this.getDeviceCount(filterSet);
} catch (InvalidParameterValueException e) {
throw new AssertionError(e);
}
}
@Override
public int getRemovedDeviceCount() throws SQLException {
FilterSet filterSet = new FilterSet();
filterSet.setConnectivityStatus(ConnectivityStatus.removed.toString());
try {
return this.getDeviceCount(filterSet);
} catch (InvalidParameterValueException e) {
throw new AssertionError(e);
}
}
@Override DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
public int getNonCompliantDeviceCount() throws SQLException { deviceCountByGroupEntry.setGroup("total");
FilterSet filterSet = new FilterSet(); deviceCountByGroupEntry.setDisplayNameForGroup("Total");
filterSet.setPotentialVulnerability(PotentialVulnerability.non_compliant.toString()); deviceCountByGroupEntry.setDeviceCount(totalDeviceCount);
try {
return this.getDeviceCount(filterSet);
} catch (InvalidParameterValueException e) {
throw new AssertionError(e);
}
}
@Override return deviceCountByGroupEntry;
public int getUnmonitoredDeviceCount() throws SQLException {
FilterSet filterSet = new FilterSet();
filterSet.setPotentialVulnerability(PotentialVulnerability.unmonitored.toString());
try {
return this.getDeviceCount(filterSet);
} catch (InvalidParameterValueException e) {
throw new AssertionError(e);
}
} }
@Override public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterValueException, SQLException {
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) { int filteredDeviceCount = this.getFilteredDeviceCount(filterSet);
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) { DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that."); deviceCountByGroupEntry.setGroup("non-specific");
} deviceCountByGroupEntry.setDisplayNameForGroup("Non-specific");
deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount);
Connection con; return deviceCountByGroupEntry;
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(FilterSet filterSet) throws InvalidParameterValueException, SQLException { private int getFilteredDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -202,8 +109,9 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDeviceCount; return filteredDeviceCount;
} }
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) @Override
throws InvalidParameterValueException, SQLException { public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
@ -219,7 +127,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
try { try {
con = this.getConnection(); con = this.getConnection();
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; "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) {
@ -251,10 +159,149 @@ 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;
}
@Override
public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException {
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
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);
}
} }
public Map<String, Integer> getDeviceCountsByPlatforms(FilterSet filterSet) @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 { throws InvalidParameterValueException, SQLException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -263,7 +310,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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 = "";
@ -293,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);
@ -302,7 +354,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDeviceCountsByPlatforms; return filteredDeviceCountsByPlatforms;
} }
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, @Override
public List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
@ -315,7 +368,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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 = "";
@ -346,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);
@ -355,7 +413,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDeviceCountsByPlatforms; return filteredDeviceCountsByPlatforms;
} }
public Map<String, Integer> getDeviceCountsByOwnershipTypes(FilterSet filterSet) @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -364,7 +423,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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 = "";
@ -394,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);
@ -403,7 +467,9 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDeviceCountsByOwnershipTypes; return filteredDeviceCountsByOwnershipTypes;
} }
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, @Override
public List<DeviceCountByGroupEntry>
getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
@ -416,7 +482,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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 = "";
@ -447,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);
@ -456,6 +527,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDeviceCountsByOwnershipTypes; return filteredDeviceCountsByOwnershipTypes;
} }
@Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
@ -473,7 +545,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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();
@ -509,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 = ?";
@ -539,6 +612,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult; return paginationResult;
} }
@Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
@ -561,7 +635,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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();
@ -598,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 = ?";
@ -630,7 +705,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult; return paginationResult;
} }
public List<Map<String, Object>> getDevicesWithDetails(FilterSet filterSet) @Override
public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet); Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
@ -639,7 +715,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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;
@ -668,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 {
@ -683,7 +759,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDevicesWithDetails; return filteredDevicesWithDetails;
} }
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, @Override
public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
@ -696,7 +773,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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;
@ -727,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 {
@ -752,52 +829,34 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
String connectivityStatus = filterSet.getConnectivityStatus(); String connectivityStatus = filterSet.getConnectivityStatus();
if (connectivityStatus != null) { if (connectivityStatus != null) {
if (ConnectivityStatus.active.toString().equals(connectivityStatus) || filters.put("CONNECTIVITY_STATUS", connectivityStatus);
ConnectivityStatus.inactive.toString().equals(connectivityStatus) ||
ConnectivityStatus.removed.toString().equals(connectivityStatus)) {
filters.put("CONNECTIVITY_STATUS", connectivityStatus.toUpperCase());
} else {
throw new InvalidParameterValueException("Invalid use of value for platform. " +
"Value of platform could only be either android, ios or windows.");
}
} }
String potentialVulnerability = filterSet.getPotentialVulnerability(); String potentialVulnerability = filterSet.getPotentialVulnerability();
if (potentialVulnerability != null) { if (potentialVulnerability != null) {
if (PotentialVulnerability.non_compliant.toString().equals(potentialVulnerability) || if (GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT.equals(potentialVulnerability) ||
PotentialVulnerability.unmonitored.toString().equals(potentialVulnerability)) { GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED.equals(potentialVulnerability)) {
if (PotentialVulnerability.non_compliant.toString().equals(potentialVulnerability)) { if (GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT.equals(potentialVulnerability)) {
filters.put("IS_COMPLIANT", 0); filters.put("IS_COMPLIANT", 0);
} else { } else {
filters.put("POLICY_ID", -1); filters.put("POLICY_ID", -1);
} }
} else { } else {
throw new InvalidParameterValueException("Invalid use of value for potential vulnerability. " + throw new InvalidParameterValueException("Invalid use of value for potential vulnerability. " +
"Value of potential vulnerability could only be non_compliant or unmonitored."); "Value of potential vulnerability could only be either " +
GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT + " or " +
GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED + ".");
} }
} }
String platform = filterSet.getPlatform(); String platform = filterSet.getPlatform();
if (platform != null) { if (platform != null) {
if (Platform.android.toString().equals(platform) || filters.put("PLATFORM", platform);
Platform.ios.toString().equals(platform) ||
Platform.windows.toString().equals(platform)) {
filters.put("PLATFORM", platform);
} else {
throw new InvalidParameterValueException("Invalid use of value for platform. " +
"Value of platform could only be either android, ios or windows.");
}
} }
String ownership = filterSet.getOwnership(); String ownership = filterSet.getOwnership();
if (ownership != null) { if (ownership != null) {
if (Ownership.byod.toString().equals(ownership) || filters.put("OWNERSHIP", ownership);
Ownership.cope.toString().equals(ownership)) {
filters.put("OWNERSHIP", ownership.toUpperCase());
} else {
throw new InvalidParameterValueException("Invalid use of value for ownership. " +
"Value of ownership could only be either BYOD or COPE.");
}
} }
return filters; return filters;

@ -20,13 +20,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.impl;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
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.bean.FilterSet; 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.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* To be updated... * To be updated...
@ -34,81 +33,72 @@ import java.util.Map;
public class GadgetDataServiceImpl implements GadgetDataService { public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public int getTotalDeviceCount() throws SQLException { public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException {
int totalDeviceCount; DeviceCountByGroupEntry filteredDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
return totalDeviceCount; return filteredDeviceCount;
} }
@Override @Override
public int getActiveDeviceCount() throws SQLException { public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet)
int activeDeviceCount; throws InvalidParameterValueException, SQLException {
DeviceCountByGroupEntry featureNonCompliantDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount(); featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
} finally { getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet);
GadgetDataServiceDAOFactory.closeConnection();
}
return activeDeviceCount;
}
@Override
public int getInactiveDeviceCount() throws SQLException {
int inactiveDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount();
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
return inactiveDeviceCount; return featureNonCompliantDeviceCount;
} }
@Override @Override
public int getRemovedDeviceCount() throws SQLException { public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException {
int removedDeviceCount; DeviceCountByGroupEntry totalDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount();
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
return removedDeviceCount; return totalDeviceCount;
} }
@Override @Override
public int getNonCompliantDeviceCount() throws SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException {
int nonCompliantDeviceCount; List<DeviceCountByGroupEntry> deviceCountsByConnectivityStatuses;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
nonCompliantDeviceCount = GadgetDataServiceDAOFactory. deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getNonCompliantDeviceCount(); getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses();
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
return nonCompliantDeviceCount; return deviceCountsByConnectivityStatuses;
} }
@Override @Override
public int getUnmonitoredDeviceCount() throws SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException {
int unmonitoredDeviceCount; List<DeviceCountByGroupEntry> deviceCountsByPotentialVulnerabilities;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(); deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPotentialVulnerabilities();
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
return unmonitoredDeviceCount; return deviceCountsByPotentialVulnerabilities;
} }
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws SQLException, InvalidParameterValueException { throws SQLException, InvalidParameterValueException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
@ -121,35 +111,9 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
int deviceCount; throws InvalidParameterValueException, SQLException {
try { List<DeviceCountByGroupEntry> deviceCountsByPlatforms;
GadgetDataServiceDAOFactory.openConnection();
deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCount;
}
@Override
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet)
throws InvalidParameterValueException, SQLException {
int featureNonCompliantDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDeviceCount;
}
@Override
public Map<String, Integer> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException {
Map<String, Integer> deviceCountsByPlatforms;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
@ -161,9 +125,9 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, public List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, SQLException {
Map<String, Integer> featureNonCompliantDeviceCountsByPlatforms; List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByPlatforms;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
@ -175,9 +139,9 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(FilterSet filterSet) public List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
Map<String, Integer> deviceCountsByOwnershipTypes; List<DeviceCountByGroupEntry> deviceCountsByOwnershipTypes;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
@ -189,9 +153,10 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, public List<DeviceCountByGroupEntry>
FilterSet filterSet) throws SQLException, InvalidParameterValueException { getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Integer> featureNonCompliantDeviceCountsByOwnershipTypes; FilterSet filterSet) throws SQLException, InvalidParameterValueException {
List<DeviceCountByGroupEntry> featureNonCompliantDeviceCountsByOwnershipTypes;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
@ -204,7 +169,7 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, public PaginationResult getDevicesWithDetails(FilterSet filterSet,
int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { int startIndex, int resultCount) throws InvalidParameterValueException, SQLException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
@ -218,8 +183,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
@ -232,12 +197,13 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public List<Map<String, Object>> getDevicesWithDetails(FilterSet filterSet) public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
List<Map<String, Object>> devicesWithDetails; List<DetailedDeviceEntry> devicesWithDetails;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); devicesWithDetails = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDevicesWithDetails(filterSet);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -245,9 +211,9 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, SQLException { FilterSet filterSet) throws InvalidParameterValueException, SQLException {
List<Map<String, Object>> featureNonCompliantDevicesWithDetails; List<DetailedDeviceEntry> featureNonCompliantDevicesWithDetails;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().

Loading…
Cancel
Save