revert-70aa11f8
hasuniea 9 years ago
commit 245e90e6f6

@ -63,7 +63,8 @@
org.wso2.carbon.device.mgt.analytics.dashboard.internal org.wso2.carbon.device.mgt.analytics.dashboard.internal
</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
</Export-Package> </Export-Package>
<Import-Package> <Import-Package>
org.osgi.framework, org.osgi.framework,

@ -18,9 +18,10 @@
package org.wso2.carbon.device.mgt.analytics.dashboard; package org.wso2.carbon.device.mgt.analytics.dashboard;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException;
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;
import java.util.Map; import java.util.Map;
@ -30,61 +31,62 @@ import java.util.Map;
public interface GadgetDataService { public interface GadgetDataService {
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getTotalDeviceCount() throws GadgetDataServiceException; int getTotalDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getActiveDeviceCount() throws GadgetDataServiceException; int getActiveDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getInactiveDeviceCount() throws GadgetDataServiceException; int getInactiveDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getRemovedDeviceCount() throws GadgetDataServiceException; int getRemovedDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getNonCompliantDeviceCount() throws GadgetDataServiceException; int getNonCompliantDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getUnmonitoredDeviceCount() throws GadgetDataServiceException; int getUnmonitoredDeviceCount() throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws GadgetDataServiceException; throws InvalidParameterException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceException; int getDeviceCount(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceException; Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceException; Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getDevicesWithDetails(Map<String, Object> filters, PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceException; int startIndex, int resultCount) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceException; Map<String, Object> filters, int startIndex, int resultCount)
throws InvalidParameterException, SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceException; List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
} }

@ -18,9 +18,10 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao; package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException;
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;
import java.util.Map; import java.util.Map;
@ -31,70 +32,71 @@ public interface GadgetDataServiceDAO {
* *
* @return Total filtered device count. * @return Total filtered device count.
*/ */
int getTotalDeviceCount() throws GadgetDataServiceDAOException; int getTotalDeviceCount() throws SQLException;
/** /**
* Method to get active device count from a particular tenant. * Method to get active device count from a particular tenant.
* *
* @return active device count. * @return active device count.
*/ */
int getActiveDeviceCount() throws GadgetDataServiceDAOException; int getActiveDeviceCount() throws SQLException;
/** /**
* Method to get inactive device count from a particular tenant. * Method to get inactive device count from a particular tenant.
* *
* @return inactive device count. * @return inactive device count.
*/ */
int getInactiveDeviceCount() throws GadgetDataServiceDAOException; int getInactiveDeviceCount() throws SQLException;
/** /**
* Method to get removed device count from a particular tenant. * Method to get removed device count from a particular tenant.
* *
* @return removed device count. * @return removed device count.
*/ */
int getRemovedDeviceCount() throws GadgetDataServiceDAOException; int getRemovedDeviceCount() throws SQLException;
/** /**
* Method to get non-compliant device count from a particular tenant. * Method to get non-compliant device count from a particular tenant.
* *
* @return Non-compliant device count. * @return Non-compliant device count.
*/ */
int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException; int getNonCompliantDeviceCount() throws SQLException;
/** /**
* Method to get unmonitored device count from a particular tenant. * Method to get unmonitored device count from a particular tenant.
* *
* @return Unmonitored device count. * @return Unmonitored device count.
*/ */
int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException; int getUnmonitoredDeviceCount() throws SQLException;
PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterException, SQLException;
int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException; int getDeviceCount(Map<String, Object> filters) throws SQLException;
int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceDAOException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException; Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException;
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceDAOException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException;
throws GadgetDataServiceDAOException;
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceDAOException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
PaginationResult getDevicesWithDetails(Map<String, Object> filters, PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; int startIndex, int resultCount) throws InvalidParameterException, SQLException;
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; Map<String, Object> filters, int startIndex, int resultCount)
throws InvalidParameterException, SQLException;
List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException; List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException;
List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceDAOException; Map<String, Object> filters) throws InvalidParameterException, SQLException;
} }

@ -1,82 +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;
/**
* Custom exception class for GadgetDataServiceDAO layer.
*/
public class GadgetDataServiceDAOException extends Exception {
private String errorMessage;
private static final long serialVersionUID = 2021891706072918864L;
/**
* Constructs a new exception with the specific error message and nested exception.
*
* @param errorMessage specific error message.
* @param nestedException Nested exception.
*/
public GadgetDataServiceDAOException(String errorMessage, Exception nestedException) {
super(errorMessage, nestedException);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message and cause.
*
* @param errorMessage Specific error message.
* @param cause Cause of this exception.
*/
@SuppressWarnings("unused")
public GadgetDataServiceDAOException(String errorMessage, Throwable cause) {
super(errorMessage, cause);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message.
*
* @param errorMessage Specific error message.
*/
@SuppressWarnings("unused")
public GadgetDataServiceDAOException(String errorMessage) {
super(errorMessage);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message and cause.
*
* @param cause Cause of this exception.
*/
@SuppressWarnings("unused")
public GadgetDataServiceDAOException(Throwable cause) {
super(cause);
}
@SuppressWarnings("unused")
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

@ -16,12 +16,13 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard; package org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception;
/** /**
* Custom exception class for GadgetDataService layer. * Custom exception class for catching invalid parameter issues,
* relevant to Gadget Data Service DAO layer.
*/ */
public class GadgetDataServiceException extends Exception { public class InvalidParameterException extends Exception {
private String errorMessage; private String errorMessage;
private static final long serialVersionUID = 2021891706072918864L; private static final long serialVersionUID = 2021891706072918864L;
@ -32,7 +33,8 @@ public class GadgetDataServiceException extends Exception {
* @param errorMessage specific error message. * @param errorMessage specific error message.
* @param nestedException Nested exception. * @param nestedException Nested exception.
*/ */
public GadgetDataServiceException(String errorMessage, Exception nestedException) { @SuppressWarnings("unused")
public InvalidParameterException(String errorMessage, Exception nestedException) {
super(errorMessage, nestedException); super(errorMessage, nestedException);
setErrorMessage(errorMessage); setErrorMessage(errorMessage);
} }
@ -44,7 +46,7 @@ public class GadgetDataServiceException extends Exception {
* @param cause Cause of this exception. * @param cause Cause of this exception.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public GadgetDataServiceException(String errorMessage, Throwable cause) { public InvalidParameterException(String errorMessage, Throwable cause) {
super(errorMessage, cause); super(errorMessage, cause);
setErrorMessage(errorMessage); setErrorMessage(errorMessage);
} }
@ -54,8 +56,7 @@ public class GadgetDataServiceException extends Exception {
* *
* @param errorMessage Specific error message. * @param errorMessage Specific error message.
*/ */
@SuppressWarnings("unused") public InvalidParameterException(String errorMessage) {
public GadgetDataServiceException(String errorMessage) {
super(errorMessage); super(errorMessage);
setErrorMessage(errorMessage); setErrorMessage(errorMessage);
} }
@ -66,7 +67,7 @@ public class GadgetDataServiceException extends Exception {
* @param cause Cause of this exception. * @param cause Cause of this exception.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public GadgetDataServiceException(Throwable cause) { public InvalidParameterException(Throwable cause) {
super(cause); super(cause);
} }

@ -20,9 +20,8 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
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.common.PaginationRequest; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException;
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;
@ -38,48 +37,59 @@ import java.util.Map;
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@Override @Override
public int getTotalDeviceCount() throws GadgetDataServiceDAOException { public int getTotalDeviceCount() throws SQLException {
return this.getDeviceCount(null); return this.getDeviceCount(null);
} }
@Override @Override
public int getActiveDeviceCount() throws GadgetDataServiceDAOException { public int getActiveDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>(); Map<String, Object> filters = new HashMap<>();
filters.put("CONNECTIVITY_STATUS", "ACTIVE"); filters.put("CONNECTIVITY_STATUS", "ACTIVE");
return this.getDeviceCount(filters); return this.getDeviceCount(filters);
} }
@Override @Override
public int getInactiveDeviceCount() throws GadgetDataServiceDAOException { public int getInactiveDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>(); Map<String, Object> filters = new HashMap<>();
filters.put("CONNECTIVITY_STATUS", "INACTIVE"); filters.put("CONNECTIVITY_STATUS", "INACTIVE");
return this.getDeviceCount(filters); return this.getDeviceCount(filters);
} }
@Override @Override
public int getRemovedDeviceCount() throws GadgetDataServiceDAOException { public int getRemovedDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>(); Map<String, Object> filters = new HashMap<>();
filters.put("CONNECTIVITY_STATUS", "REMOVED"); filters.put("CONNECTIVITY_STATUS", "REMOVED");
return this.getDeviceCount(filters); return this.getDeviceCount(filters);
} }
@Override @Override
public int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException { public int getNonCompliantDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>(); Map<String, Object> filters = new HashMap<>();
filters.put("IS_COMPLIANT", 0); filters.put("IS_COMPLIANT", 0);
return this.getDeviceCount(filters); return this.getDeviceCount(filters);
} }
@Override @Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException { public int getUnmonitoredDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>(); Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1); filters.put("POLICY_ID", -1);
return this.getDeviceCount(filters); return this.getDeviceCount(filters);
} }
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws GadgetDataServiceDAOException { throws InvalidParameterException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterException("Start index (startIndex) should be " +
"equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterException("Result count (resultCount) should be " +
"equal to 5 or greater than that.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -92,8 +102,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?"; "WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?";
stmt = con.prepareStatement(sql); stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setInt(2, paginationRequest.getStartIndex()); stmt.setInt(2, startIndex);
stmt.setInt(3, paginationRequest.getRowCount()); stmt.setInt(3, resultCount);
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -118,9 +128,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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 GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting non compliant device counts by features.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -130,7 +137,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult; return paginationResult;
} }
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException { public int getDeviceCount(Map<String, Object> filters) throws SQLException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -166,16 +173,19 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
filteredDeviceCount = rs.getInt("DEVICE_COUNT"); filteredDeviceCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered device count.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return filteredDeviceCount; return filteredDeviceCount;
} }
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException { public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters)
throws InvalidParameterException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -212,17 +222,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
filteredDeviceCount = rs.getInt("DEVICE_COUNT"); filteredDeviceCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered device count, " +
"non compliant by a particular feature.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return filteredDeviceCount; return filteredDeviceCount;
} }
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException { public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -260,16 +266,20 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of device counts by platforms.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return filteredDeviceCountsByPlatforms; return filteredDeviceCountsByPlatforms;
} }
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map<String, Object> filters) throws GadgetDataServiceDAOException { public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws InvalidParameterException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
"should not be either null or empty.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -308,16 +318,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a set of feature non-compliant device counts by platforms.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return filteredDeviceCountsByPlatforms; return filteredDeviceCountsByPlatforms;
} }
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException { public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -355,9 +362,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of device counts by ownership types.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -365,7 +369,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceDAOException { Map<String, Object> filters) throws InvalidParameterException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
"should not be either null or empty.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -404,10 +414,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of feature " +
"non-compliant device counts by ownership types.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -415,7 +421,18 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
public PaginationResult getDevicesWithDetails(Map<String, Object> filters, public PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { int startIndex, int resultCount) throws InvalidParameterException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterException("Start index (startIndex) should be " +
"equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterException("Result count (resultCount) should be " +
"equal to 5 or greater than that.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -447,11 +464,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
i++; i++;
} }
stmt.setInt(i, paginationRequest.getStartIndex()); stmt.setInt(i, startIndex);
stmt.setInt(++i, paginationRequest.getRowCount()); stmt.setInt(++i, resultCount);
} else { } else {
stmt.setInt(2, paginationRequest.getStartIndex()); stmt.setInt(2, startIndex);
stmt.setInt(3, paginationRequest.getRowCount()); stmt.setInt(3, resultCount);
} }
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -477,10 +494,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of devices " +
"with details when pagination is enabled.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -491,7 +504,24 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { Map<String, Object> filters, int startIndex, int resultCount)
throws InvalidParameterException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
"should not be either null or empty.");
}
if (startIndex < 0) {
throw new InvalidParameterException("Start index (startIndex) should be " +
"equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterException("Result count (resultCount) should be " +
"equal to 5 or greater than that.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -524,11 +554,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
i++; i++;
} }
stmt.setInt(i, paginationRequest.getStartIndex()); stmt.setInt(i, startIndex);
stmt.setInt(++i, paginationRequest.getRowCount()); stmt.setInt(++i, resultCount);
} else { } else {
stmt.setInt(3, paginationRequest.getStartIndex()); stmt.setInt(3, startIndex);
stmt.setInt(4, paginationRequest.getRowCount()); stmt.setInt(4, resultCount);
} }
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -556,10 +586,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) { while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of feature non-compliant devices " +
"with details when pagination is enabled.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -569,7 +595,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult; return paginationResult;
} }
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException { public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -612,9 +638,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS")); filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of devices with details.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -622,7 +645,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceDAOException { Map<String, Object> filters) throws InvalidParameterException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " +
"should not be either null or empty.");
}
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -667,9 +696,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS")); filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting filtered set of feature non-compliant devices with details.", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -19,9 +19,8 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.impl; 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.GadgetDataServiceException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -35,17 +34,11 @@ import java.util.Map;
public class GadgetDataServiceImpl implements GadgetDataService { public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public int getTotalDeviceCount() throws GadgetDataServiceException { public int getTotalDeviceCount() throws SQLException {
int totalDeviceCount; int totalDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for total device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -53,17 +46,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getActiveDeviceCount() throws GadgetDataServiceException { public int getActiveDeviceCount() throws SQLException {
int activeDeviceCount; int activeDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount(); activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for active device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -71,17 +58,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getInactiveDeviceCount() throws GadgetDataServiceException { public int getInactiveDeviceCount() throws SQLException {
int inactiveDeviceCount; int inactiveDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount(); inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for inactive device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -89,17 +70,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getRemovedDeviceCount() throws GadgetDataServiceException { public int getRemovedDeviceCount() throws SQLException {
int removedDeviceCount; int removedDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount(); removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for removed device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -107,17 +82,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getNonCompliantDeviceCount() throws GadgetDataServiceException { public int getNonCompliantDeviceCount() throws SQLException {
int nonCompliantDeviceCount; int nonCompliantDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
nonCompliantDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount(); nonCompliantDeviceCount = GadgetDataServiceDAOFactory.
} catch (SQLException e) { getGadgetDataServiceDAO().getNonCompliantDeviceCount();
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for non-compliant device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -125,17 +95,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceException { public int getUnmonitoredDeviceCount() throws SQLException {
int unmonitoredDeviceCount; int unmonitoredDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(); unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for unmonitored device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -143,19 +107,13 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws GadgetDataServiceException { throws SQLException, InvalidParameterException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getNonCompliantDeviceCountsByFeatures(paginationRequest); getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for non-compliant device counts by features.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -163,17 +121,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceException { public int getDeviceCount(Map<String, Object> filters) throws SQLException {
int deviceCount; int deviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters); deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for getting a filtered device count.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -182,18 +134,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters) public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters)
throws GadgetDataServiceException { throws SQLException, InvalidParameterException {
int featureNonCompliantDeviceCount; int featureNonCompliantDeviceCount;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters); getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting a filtered device count, non compliant by a particular feature.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -201,19 +147,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException {
throws GadgetDataServiceException {
Map<String, Integer> deviceCountsByPlatforms; Map<String, Integer> deviceCountsByPlatforms;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPlatforms(filters); getDeviceCountsByPlatforms(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by platforms.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -222,18 +161,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException { Map<String, Object> filters) throws SQLException, InvalidParameterException {
Map<String, Integer> featureNonCompliantDeviceCountsByPlatforms; Map<String, Integer> featureNonCompliantDeviceCountsByPlatforms;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory. featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters); getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by platforms, non compliant by a particular feature.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -241,19 +174,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException {
throws GadgetDataServiceException {
Map<String, Integer> deviceCountsByOwnershipTypes; Map<String, Integer> deviceCountsByOwnershipTypes;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByOwnershipTypes(filters); getDeviceCountsByOwnershipTypes(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by ownership types.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -262,19 +188,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException { Map<String, Object> filters) throws SQLException, InvalidParameterException {
Map<String, Integer> featureNonCompliantDeviceCountsByOwnershipTypes; Map<String, Integer> featureNonCompliantDeviceCountsByOwnershipTypes;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByOwnershipTypes = featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters); getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by ownership types, non compliant by a particular feature.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -283,18 +202,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getDevicesWithDetails(Map<String, Object> filters, public PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceException { int startIndex, int resultCount) throws InvalidParameterException, SQLException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDevicesWithDetails(filters, paginationRequest); getDevicesWithDetails(filters, startIndex, resultCount);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details when pagination is enabled.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -303,18 +216,13 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceException { Map<String, Object> filters, int startIndex, int resultCount)
throws InvalidParameterException, SQLException {
PaginationResult paginationResult; PaginationResult paginationResult;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest); getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, startIndex, resultCount);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details, non compliant by feature when pagination is enabled.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -322,18 +230,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
} }
@Override @Override
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException {
throws GadgetDataServiceException {
List<Map<String, Object>> devicesWithDetails; List<Map<String, Object>> devicesWithDetails;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters); devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }
@ -342,18 +243,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override @Override
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException { Map<String, Object> filters) throws SQLException, InvalidParameterException {
List<Map<String, Object>> featureNonCompliantDevicesWithDetails; List<Map<String, Object>> featureNonCompliantDevicesWithDetails;
try { try {
GadgetDataServiceDAOFactory.openConnection(); GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters); getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details, non compliant by feature.", e);
} finally { } finally {
GadgetDataServiceDAOFactory.closeConnection(); GadgetDataServiceDAOFactory.closeConnection();
} }

Loading…
Cancel
Save