Properly layering beans and custom exceptions in dashboard analytics feature

4.x.x
dilanua 9 years ago
parent a7c7452e2e
commit 975a3b915f

@ -64,8 +64,8 @@
</Private-Package> </Private-Package>
<Export-Package> <Export-Package>
org.wso2.carbon.device.mgt.analytics.dashboard, org.wso2.carbon.device.mgt.analytics.dashboard,
org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception, org.wso2.carbon.device.mgt.analytics.dashboard.exception,
org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean org.wso2.carbon.device.mgt.analytics.dashboard.bean
</Export-Package> </Export-Package>
<Import-Package> <Import-Package>
org.osgi.framework, org.osgi.framework,

@ -18,11 +18,11 @@
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.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.DataAccessLayerException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.util.List; import java.util.List;

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; package org.wso2.carbon.device.mgt.analytics.dashboard.bean;
public class DetailedDeviceEntry { public class DetailedDeviceEntry {

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; package org.wso2.carbon.device.mgt.analytics.dashboard.bean;
public class DeviceCountByGroupEntry { public class DeviceCountByGroupEntry {

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; package org.wso2.carbon.device.mgt.analytics.dashboard.bean;
public class FilterSet { public class FilterSet {

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

@ -18,55 +18,55 @@
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.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; import org.wso2.carbon.device.mgt.analytics.dashboard.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.util.List; import java.util.List;
public interface GadgetDataServiceDAO { public interface GadgetDataServiceDAO {
DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet)
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
DeviceCountByGroupEntry getTotalDeviceCount() throws DataAccessLayerException; DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException;
List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws DataAccessLayerException; List<DeviceCountByGroupEntry> getDeviceCountsByConnectivityStatuses() throws SQLException;
List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws DataAccessLayerException; List<DeviceCountByGroupEntry> getDeviceCountsByPotentialVulnerabilities() throws SQLException;
PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet) List<DeviceCountByGroupEntry> getDeviceCountsByOwnershipTypes(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, List<DeviceCountByGroupEntry> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount) FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet) List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, DataAccessLayerException; throws InvalidParameterValueException, SQLException;
List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<DetailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet) throws InvalidParameterValueException, DataAccessLayerException; FilterSet filterSet) throws InvalidParameterValueException, SQLException;
} }

@ -19,13 +19,12 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.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.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException;
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.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -41,7 +40,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -94,9 +93,6 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -108,7 +104,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -187,9 +183,6 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -202,7 +195,7 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
@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, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
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.");
@ -288,9 +281,6 @@ public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDA
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -19,13 +19,12 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.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.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException;
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.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -41,7 +40,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -94,9 +93,6 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -108,7 +104,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -187,9 +183,6 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -202,7 +195,7 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@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, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
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.");
@ -288,9 +281,6 @@ public class MSSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -19,13 +19,12 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.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.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException;
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.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -41,7 +40,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -96,9 +95,6 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -110,7 +106,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -191,9 +187,6 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -206,7 +199,7 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
@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, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
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.");
@ -292,9 +285,6 @@ public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -19,13 +19,12 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.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.dao.AbstractGadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOConstants;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException;
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.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -41,7 +40,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -95,9 +94,6 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -109,7 +105,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
@Override @Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) { if (startIndex < GadgetDataServiceDAOConstants.Pagination.MIN_START_INDEX) {
throw new InvalidParameterValueException("Start index should be equal to " + throw new InvalidParameterValueException("Start index should be equal to " +
@ -189,9 +185,6 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -204,7 +197,7 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
@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, DataAccessLayerException { throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) { if (nonCompliantFeatureCode == null || nonCompliantFeatureCode.isEmpty()) {
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.");
@ -290,9 +283,6 @@ public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServic
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new DataAccessLayerException("Error in either getting database connection, " +
"running SQL query or fetching results.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception; package org.wso2.carbon.device.mgt.analytics.dashboard.exception;
/** /**
* Custom exception class for communicating data access layer issues * Custom exception class for communicating data access layer issues

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception; package org.wso2.carbon.device.mgt.analytics.dashboard.exception;
/** /**
* Custom exception class for catching invalid parameter issues, * Custom exception class for catching invalid parameter issues,

@ -20,11 +20,11 @@ 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.DetailedDeviceEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.DataAccessLayerException; import org.wso2.carbon.device.mgt.analytics.dashboard.exception.DataAccessLayerException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.analytics.dashboard.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;
@ -43,7 +43,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -59,7 +60,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -73,7 +75,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount();
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -88,7 +91,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory. deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses(); getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses();
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -103,7 +107,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPotentialVulnerabilities(); getDeviceCountsByPotentialVulnerabilities();
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -119,7 +124,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -135,7 +141,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPlatforms(filterSet); getDeviceCountsByPlatforms(filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -151,7 +158,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet); getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -167,7 +175,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByOwnershipTypes(filterSet); getDeviceCountsByOwnershipTypes(filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -184,7 +193,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet); getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -200,7 +210,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDevicesWithDetails(filterSet, startIndex, resultCount); getDevicesWithDetails(filterSet, startIndex, resultCount);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -217,7 +228,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount); getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -233,7 +245,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
devicesWithDetails = GadgetDataServiceDAOFactory. devicesWithDetails = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); getGadgetDataServiceDAO().getDevicesWithDetails(filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -249,7 +262,8 @@ public class GadgetDataServiceImpl implements GadgetDataService {
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet); getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataAccessLayerException("Error in opening database connection.", e); throw new DataAccessLayerException("Error in either opening a database connection or " +
"accessing the database to fetch corresponding results.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }

Loading…
Cancel
Save