From 9786908b35ec713531bbd2982649c7cbe74eb219 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 5 May 2016 11:49:09 +0530 Subject: [PATCH 1/4] Adding temporary development code bits for dashboard analytics feature --- .../pom.xml | 3 +- .../dashboard/GadgetDataService.java | 37 +++-- .../dashboard/GadgetDataServiceException.java | 82 --------- .../dashboard/dao/GadgetDataServiceDAO.java | 39 +++-- .../dao/GadgetDataServiceDAOException.java | 82 --------- .../dao/impl/GadgetDataServiceDAOImpl.java | 145 ++++++++++------ .../dashboard/impl/GadgetDataServiceImpl.java | 157 +++--------------- 7 files changed, 159 insertions(+), 386 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml index cbc22f06c9..fd1790f61b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml @@ -63,7 +63,8 @@ org.wso2.carbon.device.mgt.analytics.dashboard.internal - org.wso2.carbon.device.mgt.analytics.dashboard + org.wso2.carbon.device.mgt.analytics.dashboard, + org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception org.osgi.framework, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java index 7c5b2038e6..bdb0b4258f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java @@ -18,9 +18,11 @@ package org.wso2.carbon.device.mgt.analytics.dashboard; +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; +import java.sql.SQLException; import java.util.List; import java.util.Map; @@ -30,61 +32,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; + throws SQLException, InvalidParameterException; @SuppressWarnings("unused") - int getDeviceCount(Map filters) throws GadgetDataServiceException; + int getDeviceCount(Map filters) throws SQLException; @SuppressWarnings("unused") int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException; + Map filters) throws SQLException, InvalidParameterException; @SuppressWarnings("unused") - Map getDeviceCountsByPlatforms(Map filters) throws GadgetDataServiceException; + Map getDeviceCountsByPlatforms(Map filters) throws SQLException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException; + Map filters) throws SQLException, InvalidParameterException; @SuppressWarnings("unused") - Map getDeviceCountsByOwnershipTypes(Map filters) throws GadgetDataServiceException; + Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException; + Map filters) throws SQLException, InvalidParameterException; @SuppressWarnings("unused") PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws GadgetDataServiceException; + PaginationRequest paginationRequest) throws SQLException, InvalidParameterException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceException; + Map filters, PaginationRequest paginationRequest) + throws SQLException, InvalidParameterException; @SuppressWarnings("unused") - List> getDevicesWithDetails(Map filters) throws GadgetDataServiceException; + List> getDevicesWithDetails(Map filters) throws SQLException; @SuppressWarnings("unused") List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException; + Map filters) throws SQLException, InvalidParameterException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java deleted file mode 100644 index 32ebef29f0..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java +++ /dev/null @@ -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; - -/** - * Custom exception class for GadgetDataService layer. - */ -public class GadgetDataServiceException 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 GadgetDataServiceException(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 GadgetDataServiceException(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 GadgetDataServiceException(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 GadgetDataServiceException(Throwable cause) { - super(cause); - } - - @SuppressWarnings("unused") - public String getErrorMessage() { - return errorMessage; - } - - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java index 6cbdba08bc..ac14fd177d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java @@ -18,9 +18,11 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; +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; +import java.sql.SQLException; import java.util.List; import java.util.Map; @@ -31,70 +33,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(PaginationRequest paginationRequest) + throws InvalidParameterException, SQLException; - int getDeviceCount(Map filters) throws GadgetDataServiceDAOException; + int getDeviceCount(Map filters) throws SQLException; int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceDAOException; + Map filters) throws InvalidParameterException, SQLException; - Map getDeviceCountsByPlatforms(Map filters) throws GadgetDataServiceDAOException; + Map getDeviceCountsByPlatforms(Map filters) throws SQLException; Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceDAOException; + Map filters) throws InvalidParameterException, SQLException; - Map getDeviceCountsByOwnershipTypes(Map filters) - throws GadgetDataServiceDAOException; + Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException; Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceDAOException; + Map filters) throws InvalidParameterException, SQLException; PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; + PaginationRequest paginationRequest) throws InvalidParameterException, SQLException; PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException; + Map filters, PaginationRequest paginationRequest) + throws InvalidParameterException, SQLException; - List> getDevicesWithDetails(Map filters) throws GadgetDataServiceDAOException; + List> getDevicesWithDetails(Map filters) throws SQLException; List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceDAOException; + Map filters) throws InvalidParameterException, SQLException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java deleted file mode 100644 index adb1917c1e..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java +++ /dev/null @@ -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; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java index 9f2250d3cf..034c3e0858 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java @@ -20,8 +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.analytics.dashboard.dao.exception.InvalidParameterException; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -38,40 +38,40 @@ 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 filters = new HashMap<>(); filters.put("CONNECTIVITY_STATUS", "ACTIVE"); return this.getDeviceCount(filters); } @Override - public int getInactiveDeviceCount() throws GadgetDataServiceDAOException { + public int getInactiveDeviceCount() throws SQLException { Map filters = new HashMap<>(); filters.put("CONNECTIVITY_STATUS", "INACTIVE"); return this.getDeviceCount(filters); } @Override - public int getRemovedDeviceCount() throws GadgetDataServiceDAOException { + public int getRemovedDeviceCount() throws SQLException { Map filters = new HashMap<>(); filters.put("CONNECTIVITY_STATUS", "REMOVED"); return this.getDeviceCount(filters); } @Override - public int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException { + public int getNonCompliantDeviceCount() throws SQLException { Map filters = new HashMap<>(); filters.put("IS_COMPLIANT", 0); return this.getDeviceCount(filters); } @Override - public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException { + public int getUnmonitoredDeviceCount() throws SQLException { Map filters = new HashMap<>(); filters.put("POLICY_ID", -1); return this.getDeviceCount(filters); @@ -79,7 +79,22 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) - throws GadgetDataServiceDAOException { + throws InvalidParameterException, SQLException { + + if (paginationRequest == null) { + throw new InvalidParameterException("PaginationRequest object should not be null."); + } + + if (paginationRequest.getStartIndex() < 0) { + throw new InvalidParameterException("startIndex of PaginationRequest object " + + "should be equal to 0 or greater than that."); + } + + if (paginationRequest.getRowCount() < 5) { + throw new InvalidParameterException("rowCount of PaginationRequest object " + + "should be equal to 5 or greater than that."); + } + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -118,9 +133,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 +142,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - public int getDeviceCount(Map filters) throws GadgetDataServiceDAOException { + public int getDeviceCount(Map filters) throws SQLException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -166,16 +178,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 filters) throws GadgetDataServiceDAOException { + public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map 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 +227,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 getDeviceCountsByPlatforms(Map filters) throws GadgetDataServiceDAOException { + public Map getDeviceCountsByPlatforms(Map filters) throws SQLException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -260,16 +271,19 @@ 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 getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map filters) throws GadgetDataServiceDAOException { + public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, + Map 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; @@ -308,16 +322,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 getDeviceCountsByOwnershipTypes(Map filters) throws GadgetDataServiceDAOException { + public Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -355,9 +366,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 +373,12 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceDAOException { + Map 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; @@ -404,10 +417,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 +424,22 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { + PaginationRequest paginationRequest) throws InvalidParameterException, SQLException { + + if (paginationRequest == null) { + throw new InvalidParameterException("PaginationRequest object should not be null."); + } + + if (paginationRequest.getStartIndex() < 0) { + throw new InvalidParameterException("startIndex of PaginationRequest object " + + "should be equal to 0 or greater than that."); + } + + if (paginationRequest.getRowCount() < 5) { + throw new InvalidParameterException("rowCount of PaginationRequest object " + + "should be equal to 5 or greater than that."); + } + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -477,10 +501,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 +511,27 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { + Map filters, PaginationRequest paginationRequest) + throws InvalidParameterException, SQLException { + + if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { + throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + } + + if (paginationRequest == null) { + throw new InvalidParameterException("PaginationRequest object should not be null."); + } + + if (paginationRequest.getStartIndex() < 0) { + throw new InvalidParameterException("startIndex of PaginationRequest object " + + "should be equal to 0 or greater than that."); + } + + if (paginationRequest.getRowCount() < 5) { + throw new InvalidParameterException("rowCount of PaginationRequest object " + + "should be equal to 5 or greater than that."); + } + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -556,10 +596,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 +605,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - public List> getDevicesWithDetails(Map filters) throws GadgetDataServiceDAOException { + public List> getDevicesWithDetails(Map filters) throws SQLException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -612,9 +648,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 +655,12 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceDAOException { + Map 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; @@ -667,9 +705,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); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java index eb01fa3ae2..16eded439c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java @@ -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(); } @@ -144,18 +108,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) - throws GadgetDataServiceException { + 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); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -163,17 +121,11 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getDeviceCount(Map filters) throws GadgetDataServiceException { + public int getDeviceCount(Map 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 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 getDeviceCountsByPlatforms(Map filters) - throws GadgetDataServiceException { + public Map getDeviceCountsByPlatforms(Map filters) throws SQLException { Map 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 getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException { + Map filters) throws SQLException, InvalidParameterException { Map 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 getDeviceCountsByOwnershipTypes(Map filters) - throws GadgetDataServiceException { + public Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException { Map 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 getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException { + Map filters) throws SQLException, InvalidParameterException { Map featureNonCompliantDeviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); - 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); + featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -283,18 +202,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws GadgetDataServiceException { + PaginationRequest paginationRequest) 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, paginationRequest); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -303,18 +216,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceException { + Map filters, PaginationRequest paginationRequest) + 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); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -322,18 +230,11 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List> getDevicesWithDetails(Map filters) - throws GadgetDataServiceException { + public List> getDevicesWithDetails(Map filters) throws SQLException { List> 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> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws GadgetDataServiceException { + Map filters) throws SQLException, InvalidParameterException { List> 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(); } From 82ffcb012b77ca5b5d21a5c78d35d1bbb77bd616 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 5 May 2016 11:51:31 +0530 Subject: [PATCH 2/4] Adding temporary development code bits for dashboard analytics feature --- .../exception/InvalidParameterException.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterException.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterException.java new file mode 100644 index 0000000000..74b0f26404 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterException.java @@ -0,0 +1,83 @@ +/* + * 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.exception; + +/** + * Custom exception class for catching invalid parameter issues, + * relevant to Gadget Data Service DAO layer. + */ +public class InvalidParameterException 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. + */ + @SuppressWarnings("unused") + public InvalidParameterException(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 InvalidParameterException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message. + * + * @param errorMessage Specific error message. + */ + public InvalidParameterException(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 InvalidParameterException(Throwable cause) { + super(cause); + } + + @SuppressWarnings("unused") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} From 945e188917f8ecc296f32802ed3c3b30d4519496 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 5 May 2016 12:03:11 +0530 Subject: [PATCH 3/4] Adding temporary development code bits for dashboard analytics feature --- .../mgt/analytics/dashboard/GadgetDataService.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java index bdb0b4258f..0c8d6bf9f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java @@ -51,43 +51,43 @@ public interface GadgetDataService { @SuppressWarnings("unused") PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) - throws SQLException, InvalidParameterException; + throws InvalidParameterException, SQLException; @SuppressWarnings("unused") int getDeviceCount(Map filters) throws SQLException; @SuppressWarnings("unused") int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException; + Map filters) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") Map getDeviceCountsByPlatforms(Map filters) throws SQLException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException; + Map filters) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException; + Map filters) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws SQLException, InvalidParameterException; + PaginationRequest paginationRequest) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, Map filters, PaginationRequest paginationRequest) - throws SQLException, InvalidParameterException; + throws InvalidParameterException, SQLException; @SuppressWarnings("unused") List> getDevicesWithDetails(Map filters) throws SQLException; @SuppressWarnings("unused") List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException; + Map filters) throws InvalidParameterException, SQLException; } From d568c6e8bd90b9f7b7ee64354af8204b699f21bc Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 5 May 2016 16:12:15 +0530 Subject: [PATCH 4/4] Adding temporary development code bits for dashboard analytics feature --- .../dashboard/GadgetDataService.java | 7 +- .../dashboard/dao/GadgetDataServiceDAO.java | 7 +- .../dao/impl/GadgetDataServiceDAOImpl.java | 89 +++++++++---------- .../dashboard/impl/GadgetDataServiceImpl.java | 12 +-- 4 files changed, 52 insertions(+), 63 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java index 0c8d6bf9f9..3931e72fc2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.analytics.dashboard; 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; import java.sql.SQLException; @@ -50,7 +49,7 @@ public interface GadgetDataService { int getUnmonitoredDeviceCount() throws SQLException; @SuppressWarnings("unused") - PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") @@ -76,11 +75,11 @@ public interface GadgetDataService { @SuppressWarnings("unused") PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException; + int startIndex, int resultCount) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) + Map filters, int startIndex, int resultCount) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java index ac14fd177d..f166fedf7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; 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; import java.sql.SQLException; @@ -70,7 +69,7 @@ public interface GadgetDataServiceDAO { */ int getUnmonitoredDeviceCount() throws SQLException; - PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterException, SQLException; int getDeviceCount(Map filters) throws SQLException; @@ -89,10 +88,10 @@ public interface GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException; PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException; + int startIndex, int resultCount) throws InvalidParameterException, SQLException; PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) + Map filters, int startIndex, int resultCount) throws InvalidParameterException, SQLException; List> getDevicesWithDetails(Map filters) throws SQLException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java index 034c3e0858..c79d38e771 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java @@ -22,7 +22,6 @@ 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.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; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -78,21 +77,17 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterException, SQLException { - if (paginationRequest == null) { - throw new InvalidParameterException("PaginationRequest object should not be null."); + if (startIndex < 0) { + throw new InvalidParameterException("Start index (startIndex) should be " + + "equal to 0 or greater than that."); } - if (paginationRequest.getStartIndex() < 0) { - throw new InvalidParameterException("startIndex of PaginationRequest object " + - "should be equal to 0 or greater than that."); - } - - if (paginationRequest.getRowCount() < 5) { - throw new InvalidParameterException("rowCount of PaginationRequest object " + - "should be equal to 5 or greater than that."); + if (resultCount < 5) { + throw new InvalidParameterException("Result count (resultCount) should be " + + "equal to 5 or greater than that."); } Connection con; @@ -107,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(); @@ -281,7 +276,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } Connection con; @@ -376,7 +372,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } Connection con; @@ -424,20 +421,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException { - - if (paginationRequest == null) { - throw new InvalidParameterException("PaginationRequest object should not be null."); - } + int startIndex, int resultCount) throws InvalidParameterException, SQLException { - if (paginationRequest.getStartIndex() < 0) { - throw new InvalidParameterException("startIndex of PaginationRequest object " + - "should be equal to 0 or greater than that."); + if (startIndex < 0) { + throw new InvalidParameterException("Start index (startIndex) should be " + + "equal to 0 or greater than that."); } - if (paginationRequest.getRowCount() < 5) { - throw new InvalidParameterException("rowCount of PaginationRequest object " + - "should be equal to 5 or greater than that."); + if (resultCount < 5) { + throw new InvalidParameterException("Result count (resultCount) should be " + + "equal to 5 or greater than that."); } Connection con; @@ -471,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(); @@ -511,25 +504,22 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) - throws InvalidParameterException, SQLException { + Map filters, int startIndex, int resultCount) + throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } - if (paginationRequest == null) { - throw new InvalidParameterException("PaginationRequest object should not be null."); + if (startIndex < 0) { + throw new InvalidParameterException("Start index (startIndex) should be " + + "equal to 0 or greater than that."); } - if (paginationRequest.getStartIndex() < 0) { - throw new InvalidParameterException("startIndex of PaginationRequest object " + - "should be equal to 0 or greater than that."); - } - - if (paginationRequest.getRowCount() < 5) { - throw new InvalidParameterException("rowCount of PaginationRequest object " + - "should be equal to 5 or greater than that."); + if (resultCount < 5) { + throw new InvalidParameterException("Result count (resultCount) should be " + + "equal to 5 or greater than that."); } Connection con; @@ -564,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(); @@ -658,7 +648,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } Connection con; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java index 16eded439c..98ceb5d88f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java @@ -107,13 +107,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws SQLException, InvalidParameterException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getNonCompliantDeviceCountsByFeatures(paginationRequest); + getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -202,12 +202,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException { + int startIndex, int resultCount) throws InvalidParameterException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDevicesWithDetails(filters, paginationRequest); + getDevicesWithDetails(filters, startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -216,13 +216,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) + Map filters, int startIndex, int resultCount) throws InvalidParameterException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest); + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); }