revert-70aa11f8
hasuniea 9 years ago
commit 245e90e6f6

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

@ -18,9 +18,10 @@
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 java.sql.SQLException;
import java.util.List;
import java.util.Map;
@ -30,61 +31,62 @@ import java.util.Map;
public interface GadgetDataService {
@SuppressWarnings("unused")
int getTotalDeviceCount() throws GadgetDataServiceException;
int getTotalDeviceCount() throws SQLException;
@SuppressWarnings("unused")
int getActiveDeviceCount() throws GadgetDataServiceException;
int getActiveDeviceCount() throws SQLException;
@SuppressWarnings("unused")
int getInactiveDeviceCount() throws GadgetDataServiceException;
int getInactiveDeviceCount() throws SQLException;
@SuppressWarnings("unused")
int getRemovedDeviceCount() throws GadgetDataServiceException;
int getRemovedDeviceCount() throws SQLException;
@SuppressWarnings("unused")
int getNonCompliantDeviceCount() throws GadgetDataServiceException;
int getNonCompliantDeviceCount() throws SQLException;
@SuppressWarnings("unused")
int getUnmonitoredDeviceCount() throws GadgetDataServiceException;
int getUnmonitoredDeviceCount() throws SQLException;
@SuppressWarnings("unused")
PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceException;
PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterException, SQLException;
@SuppressWarnings("unused")
int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceException;
int getDeviceCount(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused")
int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException;
Map<String, Object> filters) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceException;
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException;
Map<String, Object> filters) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceException;
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException;
Map<String, Object> filters) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused")
PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceException;
int startIndex, int resultCount) throws InvalidParameterException, SQLException;
@SuppressWarnings("unused")
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")
List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceException;
List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException;
@SuppressWarnings("unused")
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;
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 java.sql.SQLException;
import java.util.List;
import java.util.Map;
@ -31,70 +32,71 @@ public interface GadgetDataServiceDAO {
*
* @return Total filtered device count.
*/
int getTotalDeviceCount() throws GadgetDataServiceDAOException;
int getTotalDeviceCount() throws SQLException;
/**
* Method to get active device count from a particular tenant.
*
* @return active device count.
*/
int getActiveDeviceCount() throws GadgetDataServiceDAOException;
int getActiveDeviceCount() throws SQLException;
/**
* Method to get inactive device count from a particular tenant.
*
* @return inactive device count.
*/
int getInactiveDeviceCount() throws GadgetDataServiceDAOException;
int getInactiveDeviceCount() throws SQLException;
/**
* Method to get removed device count from a particular tenant.
*
* @return removed device count.
*/
int getRemovedDeviceCount() throws GadgetDataServiceDAOException;
int getRemovedDeviceCount() throws SQLException;
/**
* Method to get non-compliant device count from a particular tenant.
*
* @return Non-compliant device count.
*/
int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException;
int getNonCompliantDeviceCount() throws SQLException;
/**
* Method to get unmonitored device count from a particular tenant.
*
* @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,
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, Object> filters) throws GadgetDataServiceDAOException;
Map<String, Object> filters) throws InvalidParameterException, SQLException;
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters)
throws GadgetDataServiceDAOException;
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException;
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,
PaginationRequest paginationRequest) throws GadgetDataServiceDAOException;
int startIndex, int resultCount) throws InvalidParameterException, SQLException;
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,
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.
*/
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 static final long serialVersionUID = 2021891706072918864L;
@ -32,7 +33,8 @@ public class GadgetDataServiceException extends Exception {
* @param errorMessage specific error message.
* @param nestedException Nested exception.
*/
public GadgetDataServiceException(String errorMessage, Exception nestedException) {
@SuppressWarnings("unused")
public InvalidParameterException(String errorMessage, Exception nestedException) {
super(errorMessage, nestedException);
setErrorMessage(errorMessage);
}
@ -44,7 +46,7 @@ public class GadgetDataServiceException extends Exception {
* @param cause Cause of this exception.
*/
@SuppressWarnings("unused")
public GadgetDataServiceException(String errorMessage, Throwable cause) {
public InvalidParameterException(String errorMessage, Throwable cause) {
super(errorMessage, cause);
setErrorMessage(errorMessage);
}
@ -54,8 +56,7 @@ public class GadgetDataServiceException extends Exception {
*
* @param errorMessage Specific error message.
*/
@SuppressWarnings("unused")
public GadgetDataServiceException(String errorMessage) {
public InvalidParameterException(String errorMessage) {
super(errorMessage);
setErrorMessage(errorMessage);
}
@ -66,7 +67,7 @@ public class GadgetDataServiceException extends Exception {
* @param cause Cause of this exception.
*/
@SuppressWarnings("unused")
public GadgetDataServiceException(Throwable cause) {
public InvalidParameterException(Throwable 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.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.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.core.dao.util.DeviceManagementDAOUtil;
@ -38,48 +37,59 @@ import java.util.Map;
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@Override
public int getTotalDeviceCount() throws GadgetDataServiceDAOException {
public int getTotalDeviceCount() throws SQLException {
return this.getDeviceCount(null);
}
@Override
public int getActiveDeviceCount() throws GadgetDataServiceDAOException {
public int getActiveDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>();
filters.put("CONNECTIVITY_STATUS", "ACTIVE");
return this.getDeviceCount(filters);
}
@Override
public int getInactiveDeviceCount() throws GadgetDataServiceDAOException {
public int getInactiveDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>();
filters.put("CONNECTIVITY_STATUS", "INACTIVE");
return this.getDeviceCount(filters);
}
@Override
public int getRemovedDeviceCount() throws GadgetDataServiceDAOException {
public int getRemovedDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>();
filters.put("CONNECTIVITY_STATUS", "REMOVED");
return this.getDeviceCount(filters);
}
@Override
public int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException {
public int getNonCompliantDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>();
filters.put("IS_COMPLIANT", 0);
return this.getDeviceCount(filters);
}
@Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
public int getUnmonitoredDeviceCount() throws SQLException {
Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1);
return this.getDeviceCount(filters);
}
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceDAOException {
public PaginationResult getNonCompliantDeviceCountsByFeatures(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;
PreparedStatement stmt = 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 ?, ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, paginationRequest.getStartIndex());
stmt.setInt(3, paginationRequest.getRowCount());
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
// executing query
rs = stmt.executeQuery();
@ -118,9 +128,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -130,7 +137,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult;
}
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
public int getDeviceCount(Map<String, Object> filters) throws SQLException {
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -166,16 +173,19 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -212,17 +222,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -260,16 +266,20 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -308,16 +318,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -355,9 +362,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -365,7 +369,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -404,10 +414,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -415,7 +421,18 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -447,11 +464,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
i++;
}
stmt.setInt(i, paginationRequest.getStartIndex());
stmt.setInt(++i, paginationRequest.getRowCount());
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(2, paginationRequest.getStartIndex());
stmt.setInt(3, paginationRequest.getRowCount());
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
}
// executing query
rs = stmt.executeQuery();
@ -477,10 +494,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -491,7 +504,24 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -524,11 +554,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
i++;
}
stmt.setInt(i, paginationRequest.getStartIndex());
stmt.setInt(++i, paginationRequest.getRowCount());
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(3, paginationRequest.getStartIndex());
stmt.setInt(4, paginationRequest.getRowCount());
stmt.setInt(3, startIndex);
stmt.setInt(4, resultCount);
}
// executing query
rs = stmt.executeQuery();
@ -556,10 +586,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
while (rs.next()) {
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -569,7 +595,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -612,9 +638,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -622,7 +645,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
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;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -667,9 +696,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
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 {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}

@ -19,9 +19,8 @@
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.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.exception.InvalidParameterException;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
@ -35,17 +34,11 @@ import java.util.Map;
public class GadgetDataServiceImpl implements GadgetDataService {
@Override
public int getTotalDeviceCount() throws GadgetDataServiceException {
public int getTotalDeviceCount() throws SQLException {
int totalDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -53,17 +46,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public int getActiveDeviceCount() throws GadgetDataServiceException {
public int getActiveDeviceCount() throws SQLException {
int activeDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -71,17 +58,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public int getInactiveDeviceCount() throws GadgetDataServiceException {
public int getInactiveDeviceCount() throws SQLException {
int inactiveDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -89,17 +70,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public int getRemovedDeviceCount() throws GadgetDataServiceException {
public int getRemovedDeviceCount() throws SQLException {
int removedDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -107,17 +82,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public int getNonCompliantDeviceCount() throws GadgetDataServiceException {
public int getNonCompliantDeviceCount() throws SQLException {
int nonCompliantDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
nonCompliantDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount();
} 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 count.", e);
nonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getNonCompliantDeviceCount();
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -125,17 +95,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceException {
public int getUnmonitoredDeviceCount() throws SQLException {
int unmonitoredDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -143,19 +107,13 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceException {
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws SQLException, InvalidParameterException {
PaginationResult paginationResult;
try {
GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getNonCompliantDeviceCountsByFeatures(paginationRequest);
} 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);
getNonCompliantDeviceCountsByFeatures(startIndex, resultCount);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -163,17 +121,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceException {
public int getDeviceCount(Map<String, Object> filters) throws SQLException {
int deviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -182,18 +134,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters)
throws GadgetDataServiceException {
throws SQLException, InvalidParameterException {
int featureNonCompliantDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -201,19 +147,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters)
throws GadgetDataServiceException {
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws SQLException {
Map<String, Integer> deviceCountsByPlatforms;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -222,18 +161,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
Map<String, Object> filters) throws SQLException, InvalidParameterException {
Map<String, Integer> featureNonCompliantDeviceCountsByPlatforms;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().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);
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -241,19 +174,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters)
throws GadgetDataServiceException {
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws SQLException {
Map<String, Integer> deviceCountsByOwnershipTypes;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -262,19 +188,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
Map<String, Object> filters) throws SQLException, InvalidParameterException {
Map<String, Integer> featureNonCompliantDeviceCountsByOwnershipTypes;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByOwnershipTypes =
GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -283,18 +202,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override
public PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceException {
int startIndex, int resultCount) throws InvalidParameterException, SQLException {
PaginationResult paginationResult;
try {
GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDevicesWithDetails(filters, paginationRequest);
} 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);
getDevicesWithDetails(filters, startIndex, resultCount);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -303,18 +216,13 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override
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;
try {
GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest);
} 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);
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, startIndex, resultCount);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -322,18 +230,11 @@ public class GadgetDataServiceImpl implements GadgetDataService {
}
@Override
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters)
throws GadgetDataServiceException {
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws SQLException {
List<Map<String, Object>> devicesWithDetails;
try {
GadgetDataServiceDAOFactory.openConnection();
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 {
GadgetDataServiceDAOFactory.closeConnection();
}
@ -342,18 +243,12 @@ public class GadgetDataServiceImpl implements GadgetDataService {
@Override
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;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
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 {
GadgetDataServiceDAOFactory.closeConnection();
}

Loading…
Cancel
Save