From 7b43d2829874ecbb6b89556dddd1366c68e76a57 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 6 May 2016 12:54:04 +0530 Subject: [PATCH 1/3] Adding temporary development code bits for dashboard analytics feature --- .../pom.xml | 3 +- .../dashboard/GadgetDataService.java | 32 +-- .../dashboard/dao/GadgetDataServiceDAO.java | 31 +-- .../dao/bean/ConnectivityStatus.java | 23 ++ .../dashboard/dao/bean/FilterSet.java | 58 +++++ .../dashboard/dao/bean/Ownership.java | 23 ++ .../dashboard/dao/bean/Platform.java | 23 ++ .../dao/bean/PotentialVulnerability.java | 23 ++ ...va => InvalidParameterValueException.java} | 10 +- .../dao/impl/GadgetDataServiceDAOImpl.java | 215 +++++++++++++----- .../dashboard/impl/GadgetDataServiceImpl.java | 55 ++--- .../internal/GadgetDataServiceComponent.java | 4 +- 12 files changed, 381 insertions(+), 119 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/ConnectivityStatus.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/{InvalidParameterException.java => InvalidParameterValueException.java} (86%) 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 fd1790f61b..35aa312a0f 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 @@ -64,7 +64,8 @@ org.wso2.carbon.device.mgt.analytics.dashboard, - org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception + org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception, + org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean 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 3931e72fc2..22afb893da 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,7 +18,8 @@ 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.analytics.dashboard.dao.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; @@ -50,43 +51,46 @@ public interface GadgetDataService { @SuppressWarnings("unused") PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterException, SQLException; + throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - int getDeviceCount(Map filters) throws SQLException; + int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - Map getDeviceCountsByPlatforms(Map filters) throws SQLException; + Map getDeviceCountsByPlatforms(FilterSet filterSet) + throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException; + Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - PaginationResult getDevicesWithDetails(Map filters, - int startIndex, int resultCount) throws InvalidParameterException, SQLException; + PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, int startIndex, int resultCount) - throws InvalidParameterException, SQLException; + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - List> getDevicesWithDetails(Map filters) throws SQLException; + List> getDevicesWithDetails(FilterSet filterSet) + throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, 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/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 f166fedf7f..04620a57a4 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,7 +18,8 @@ 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.analytics.dashboard.dao.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; @@ -70,33 +71,35 @@ public interface GadgetDataServiceDAO { int getUnmonitoredDeviceCount() throws SQLException; PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterException, SQLException; + throws InvalidParameterValueException, SQLException; - int getDeviceCount(Map filters) throws SQLException; + int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; - Map getDeviceCountsByPlatforms(Map filters) throws SQLException; + Map getDeviceCountsByPlatforms(FilterSet filterSet) + throws InvalidParameterValueException, SQLException; Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; - Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException; + Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + throws InvalidParameterValueException, SQLException; Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, SQLException; - PaginationResult getDevicesWithDetails(Map filters, - int startIndex, int resultCount) throws InvalidParameterException, SQLException; + PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException; PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, int startIndex, int resultCount) - throws InvalidParameterException, SQLException; + FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; - List> getDevicesWithDetails(Map filters) throws SQLException; + List> getDevicesWithDetails(FilterSet filterSet) + throws InvalidParameterValueException, SQLException; List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException; + FilterSet filterSet) throws InvalidParameterValueException, 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/bean/ConnectivityStatus.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/ConnectivityStatus.java new file mode 100644 index 0000000000..1348b95577 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/ConnectivityStatus.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public enum ConnectivityStatus { + active, inactive, removed +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java new file mode 100644 index 0000000000..0f046db35d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public class FilterSet { + private String connectivityStatus; + private String potentialVulnerability; + private String platform; + private String ownership; + + public String getConnectivityStatus() { + return connectivityStatus; + } + + public void setConnectivityStatus(String connectivityStatus) { + this.connectivityStatus = connectivityStatus; + } + + public String getPotentialVulnerability() { + return potentialVulnerability; + } + + public void setPotentialVulnerability(String potentialVulnerability) { + this.potentialVulnerability = potentialVulnerability; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getOwnership() { + return ownership; + } + + public void setOwnership(String ownership) { + this.ownership = ownership; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java new file mode 100644 index 0000000000..15e1ad4795 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public enum Ownership { + byod, cope +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java new file mode 100644 index 0000000000..01d207ccd5 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public enum Platform { + android, ios, windows +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java new file mode 100644 index 0000000000..fe3ae5febc --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public enum PotentialVulnerability { + non_compliant, unmonitored +} \ No newline at end of file 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/InvalidParameterValueException.java similarity index 86% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterException.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/exception/InvalidParameterValueException.java index 74b0f26404..c36bf90e7c 100644 --- 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/InvalidParameterValueException.java @@ -22,7 +22,7 @@ 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 { +public class InvalidParameterValueException extends Exception { private String errorMessage; private static final long serialVersionUID = 2021891706072918864L; @@ -34,7 +34,7 @@ public class InvalidParameterException extends Exception { * @param nestedException Nested exception. */ @SuppressWarnings("unused") - public InvalidParameterException(String errorMessage, Exception nestedException) { + public InvalidParameterValueException(String errorMessage, Exception nestedException) { super(errorMessage, nestedException); setErrorMessage(errorMessage); } @@ -46,7 +46,7 @@ public class InvalidParameterException extends Exception { * @param cause Cause of this exception. */ @SuppressWarnings("unused") - public InvalidParameterException(String errorMessage, Throwable cause) { + public InvalidParameterValueException(String errorMessage, Throwable cause) { super(errorMessage, cause); setErrorMessage(errorMessage); } @@ -56,7 +56,7 @@ public class InvalidParameterException extends Exception { * * @param errorMessage Specific error message. */ - public InvalidParameterException(String errorMessage) { + public InvalidParameterValueException(String errorMessage) { super(errorMessage); setErrorMessage(errorMessage); } @@ -67,7 +67,7 @@ public class InvalidParameterException extends Exception { * @param cause Cause of this exception. */ @SuppressWarnings("unused") - public InvalidParameterException(Throwable cause) { + public InvalidParameterValueException(Throwable cause) { super(cause); } 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 c79d38e771..eb51abe721 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 @@ -21,7 +21,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.GadgetDataServiceDAOFactory; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -29,65 +30,84 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { @Override public int getTotalDeviceCount() throws SQLException { - return this.getDeviceCount(null); + try { + return this.getDeviceCount(null); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } @Override public int getActiveDeviceCount() throws SQLException { - Map filters = new HashMap<>(); - filters.put("CONNECTIVITY_STATUS", "ACTIVE"); - return this.getDeviceCount(filters); + FilterSet filterSet = new FilterSet(); + filterSet.setConnectivityStatus(ConnectivityStatus.active.toString()); + try { + return this.getDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } @Override public int getInactiveDeviceCount() throws SQLException { - Map filters = new HashMap<>(); - filters.put("CONNECTIVITY_STATUS", "INACTIVE"); - return this.getDeviceCount(filters); + FilterSet filterSet = new FilterSet(); + filterSet.setConnectivityStatus(ConnectivityStatus.inactive.toString()); + try { + return this.getDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } @Override public int getRemovedDeviceCount() throws SQLException { - Map filters = new HashMap<>(); - filters.put("CONNECTIVITY_STATUS", "REMOVED"); - return this.getDeviceCount(filters); + FilterSet filterSet = new FilterSet(); + filterSet.setConnectivityStatus(ConnectivityStatus.removed.toString()); + try { + return this.getDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } @Override public int getNonCompliantDeviceCount() throws SQLException { - Map filters = new HashMap<>(); - filters.put("IS_COMPLIANT", 0); - return this.getDeviceCount(filters); + FilterSet filterSet = new FilterSet(); + filterSet.setPotentialVulnerability(PotentialVulnerability.non_compliant.toString()); + try { + return this.getDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } @Override public int getUnmonitoredDeviceCount() throws SQLException { - Map filters = new HashMap<>(); - filters.put("POLICY_ID", -1); - return this.getDeviceCount(filters); + FilterSet filterSet = new FilterSet(); + filterSet.setPotentialVulnerability(PotentialVulnerability.unmonitored.toString()); + try { + return this.getDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterException, SQLException { + throws InvalidParameterValueException, SQLException { if (startIndex < 0) { - throw new InvalidParameterException("Start index (startIndex) should be " + - "equal to 0 or greater than that."); + throw new InvalidParameterValueException("Start index 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."); + throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that."); } Connection con; @@ -137,7 +157,10 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - public int getDeviceCount(Map filters) throws SQLException { + public int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { + + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -179,13 +202,15 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCount; } - public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) - throws InvalidParameterException, SQLException { + public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) + throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); } + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -193,7 +218,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { int filteredDeviceCount = 0; try { con = this.getConnection(); - String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; + String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + + "WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; // appending filters to support advanced filtering options // [1] appending filter columns if (filters != null && filters.size() > 0) { @@ -228,7 +254,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCount; } - public Map getDeviceCountsByPlatforms(Map filters) throws SQLException { + public Map getDeviceCountsByPlatforms(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { + + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -273,13 +303,14 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + - "should not be either null or empty."); + throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); } + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -324,7 +355,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCountsByPlatforms; } - public Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException { + public Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { + + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -369,13 +404,14 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + - "should not be either null or empty."); + throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); } + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -420,19 +456,19 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCountsByOwnershipTypes; } - public PaginationResult getDevicesWithDetails(Map filters, - int startIndex, int resultCount) throws InvalidParameterException, SQLException { + public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException { if (startIndex < 0) { - throw new InvalidParameterException("Start index (startIndex) should be " + - "equal to 0 or greater than that."); + throw new InvalidParameterValueException("Start index 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."); + throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that."); } + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -504,24 +540,23 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, int startIndex, int resultCount) - throws InvalidParameterException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + - "should not be either null or empty."); + throw new InvalidParameterValueException("Non-compliant feature code 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."); + throw new InvalidParameterValueException("Start index 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."); + throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that."); } + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -595,7 +630,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - public List> getDevicesWithDetails(Map filters) throws SQLException { + public List> getDevicesWithDetails(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { + + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -645,13 +684,14 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws InvalidParameterException, SQLException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + - "should not be either null or empty."); + throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); } + Map filters = this.extractDatabaseFiltersFromBean(filterSet); + Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -702,6 +742,67 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDevicesWithDetails; } + private Map extractDatabaseFiltersFromBean(FilterSet filterSet) + throws InvalidParameterValueException { + if (filterSet == null) { + return null; + } + + Map filters = new LinkedHashMap<>(); + + String connectivityStatus = filterSet.getConnectivityStatus(); + if (connectivityStatus != null) { + if (ConnectivityStatus.active.toString().equals(connectivityStatus) || + ConnectivityStatus.inactive.toString().equals(connectivityStatus) || + ConnectivityStatus.removed.toString().equals(connectivityStatus)) { + filters.put("CONNECTIVITY_STATUS", connectivityStatus.toUpperCase()); + } else { + throw new InvalidParameterValueException("Invalid use of value for platform. " + + "Value of platform could only be either android, ios or windows."); + } + } + + String potentialVulnerability = filterSet.getPotentialVulnerability(); + if (potentialVulnerability != null) { + if (PotentialVulnerability.non_compliant.toString().equals(potentialVulnerability) || + PotentialVulnerability.unmonitored.toString().equals(potentialVulnerability)) { + if (PotentialVulnerability.non_compliant.toString().equals(potentialVulnerability)) { + filters.put("IS_COMPLIANT", 0); + } else { + filters.put("POLICY_ID", -1); + } + } else { + throw new InvalidParameterValueException("Invalid use of value for potential vulnerability. " + + "Value of potential vulnerability could only be non_compliant or unmonitored."); + } + } + + String platform = filterSet.getPlatform(); + if (platform != null) { + if (Platform.android.toString().equals(platform) || + Platform.ios.toString().equals(platform) || + Platform.windows.toString().equals(platform)) { + filters.put("PLATFORM", platform); + } else { + throw new InvalidParameterValueException("Invalid use of value for platform. " + + "Value of platform could only be either android, ios or windows."); + } + } + + String ownership = filterSet.getOwnership(); + if (ownership != null) { + if (Ownership.byod.toString().equals(ownership) || + Ownership.cope.toString().equals(ownership)) { + filters.put("OWNERSHIP", ownership.toUpperCase()); + } else { + throw new InvalidParameterValueException("Invalid use of value for ownership. " + + "Value of ownership could only be either BYOD or COPE."); + } + } + + return filters; + } + private Connection getConnection() throws SQLException { return GadgetDataServiceDAOFactory.getConnection(); } 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 98ceb5d88f..4e8c3fca7d 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 @@ -20,8 +20,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.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.analytics.dashboard.dao.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; @@ -108,7 +108,7 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws SQLException, InvalidParameterException { + throws SQLException, InvalidParameterValueException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); @@ -121,11 +121,11 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getDeviceCount(Map filters) throws SQLException { + public int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { int deviceCount; try { GadgetDataServiceDAOFactory.openConnection(); - deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters); + deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -133,13 +133,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) - throws SQLException, InvalidParameterException { + public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) + throws InvalidParameterValueException, SQLException { int featureNonCompliantDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters); + getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -147,12 +147,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getDeviceCountsByPlatforms(Map filters) throws SQLException { + public Map getDeviceCountsByPlatforms(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { Map deviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDeviceCountsByPlatforms(filters); + getDeviceCountsByPlatforms(filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -161,12 +162,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { Map featureNonCompliantDeviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters); + getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -174,12 +175,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getDeviceCountsByOwnershipTypes(Map filters) throws SQLException { + public Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { Map deviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDeviceCountsByOwnershipTypes(filters); + getDeviceCountsByOwnershipTypes(filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -188,12 +190,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException { + FilterSet filterSet) throws SQLException, InvalidParameterValueException { Map featureNonCompliantDeviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters); + getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -201,13 +203,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public PaginationResult getDevicesWithDetails(Map filters, - int startIndex, int resultCount) throws InvalidParameterException, SQLException { + public PaginationResult getDevicesWithDetails(FilterSet filterSet, + int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDevicesWithDetails(filters, startIndex, resultCount); + getDevicesWithDetails(filterSet, startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -216,13 +218,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, int startIndex, int resultCount) - throws InvalidParameterException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, startIndex, resultCount); + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet, startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -230,11 +232,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List> getDevicesWithDetails(Map filters) throws SQLException { + public List> getDevicesWithDetails(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { List> devicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); - devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters); + devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -243,12 +246,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) throws SQLException, InvalidParameterException { + FilterSet filterSet) throws InvalidParameterValueException, SQLException { List> featureNonCompliantDevicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters); + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java index 7d1bc08c19..5dda71d849 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java @@ -72,14 +72,14 @@ public class GadgetDataServiceComponent { //do nothing } - public void setDataSourceService(DataSourceService dataSourceService) { + protected void setDataSourceService(DataSourceService dataSourceService) { if (log.isDebugEnabled()) { log.debug("Binding org.wso2.carbon.ndatasource.core.DataSourceService..."); } //do nothing } - public void unsetDataSourceService(DataSourceService dataSourceService) { + protected void unsetDataSourceService(DataSourceService dataSourceService) { if (log.isDebugEnabled()) { log.debug("Unbinding org.wso2.carbon.ndatasource.core.DataSourceService..."); } From 17e958d83813b46176bf41d0b741909957c42856 Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 8 May 2016 17:42:01 +0530 Subject: [PATCH 2/3] Adding inter-mediate development code bits for dashboard analytics feature --- .../dashboard/GadgetDataService.java | 36 +- .../dashboard/dao/GadgetDataServiceDAO.java | 62 +-- .../dao/bean/ConnectivityStatus.java | 23 - .../dashboard/dao/bean/FilterSet.java | 4 + .../dashboard/dao/bean/Ownership.java | 23 - .../dashboard/dao/bean/Platform.java | 23 - .../dao/bean/PotentialVulnerability.java | 23 - .../dao/impl/GadgetDataServiceDAOImpl.java | 425 ++++++++++-------- .../dashboard/impl/GadgetDataServiceImpl.java | 132 ++---- 9 files changed, 323 insertions(+), 428 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/ConnectivityStatus.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/bean/Ownership.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/bean/Platform.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/bean/PotentialVulnerability.java 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 22afb893da..c17dcfb263 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,13 +18,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; import java.util.List; -import java.util.Map; /** * To be updated... @@ -32,48 +31,39 @@ import java.util.Map; public interface GadgetDataService { @SuppressWarnings("unused") - int getTotalDeviceCount() throws SQLException; + DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - int getActiveDeviceCount() throws SQLException; + DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - int getInactiveDeviceCount() throws SQLException; + DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException; @SuppressWarnings("unused") - int getRemovedDeviceCount() throws SQLException; + List getDeviceCountsByConnectivityStatuses() throws SQLException; @SuppressWarnings("unused") - int getNonCompliantDeviceCount() throws SQLException; - - @SuppressWarnings("unused") - int getUnmonitoredDeviceCount() throws SQLException; + List getDeviceCountsByPotentialVulnerabilities() throws SQLException; @SuppressWarnings("unused") PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; - - @SuppressWarnings("unused") - int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; - - @SuppressWarnings("unused") - Map getDeviceCountsByPlatforms(FilterSet filterSet) + List getDeviceCountsByPlatforms(FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, + List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + List getDeviceCountsByOwnershipTypes(FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, + List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") @@ -86,11 +76,11 @@ public interface GadgetDataService { throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - List> getDevicesWithDetails(FilterSet filterSet) + List getDevicesWithDetails(FilterSet filterSet) throws InvalidParameterValueException, SQLException; @SuppressWarnings("unused") - List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, 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/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 04620a57a4..d95250f1bf 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,76 +18,44 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; import java.util.List; -import java.util.Map; public interface GadgetDataServiceDAO { - /** - * Method to get total filtered device count from a particular tenant. - * - * @return Total filtered device count. - */ - int getTotalDeviceCount() throws SQLException; + DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; - /** - * Method to get active device count from a particular tenant. - * - * @return active device count. - */ - int getActiveDeviceCount() throws SQLException; + DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, SQLException; /** - * Method to get inactive device count from a particular tenant. + * Method to get total device count from a particular tenant. * - * @return inactive device count. + * @return Total device count. */ - int getInactiveDeviceCount() throws SQLException; + DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException; - /** - * Method to get removed device count from a particular tenant. - * - * @return removed device count. - */ - int getRemovedDeviceCount() throws SQLException; + List getDeviceCountsByConnectivityStatuses() throws SQLException; - /** - * Method to get non-compliant device count from a particular tenant. - * - * @return Non-compliant device count. - */ - int getNonCompliantDeviceCount() throws SQLException; - - /** - * Method to get unmonitored device count from a particular tenant. - * - * @return Unmonitored device count. - */ - int getUnmonitoredDeviceCount() throws SQLException; + List getDeviceCountsByPotentialVulnerabilities() throws SQLException; PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; - int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException; - - int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException; - - Map getDeviceCountsByPlatforms(FilterSet filterSet) + List getDeviceCountsByPlatforms(FilterSet filterSet) throws InvalidParameterValueException, SQLException; - Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, + List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException; - Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + List getDeviceCountsByOwnershipTypes(FilterSet filterSet) throws InvalidParameterValueException, SQLException; - Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, + List getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException; PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) @@ -96,10 +64,10 @@ public interface GadgetDataServiceDAO { PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException; - List> getDevicesWithDetails(FilterSet filterSet) + List getDevicesWithDetails(FilterSet filterSet) throws InvalidParameterValueException, SQLException; - List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, 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/bean/ConnectivityStatus.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/ConnectivityStatus.java deleted file mode 100644 index 1348b95577..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/ConnectivityStatus.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; - -public enum ConnectivityStatus { - active, inactive, removed -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java index 0f046db35d..a9a775a08e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/FilterSet.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; public class FilterSet { + private String connectivityStatus; private String potentialVulnerability; private String platform; @@ -44,6 +45,7 @@ public class FilterSet { return platform; } + @SuppressWarnings("unused") public void setPlatform(String platform) { this.platform = platform; } @@ -52,7 +54,9 @@ public class FilterSet { return ownership; } + @SuppressWarnings("unused") public void setOwnership(String ownership) { this.ownership = ownership; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java deleted file mode 100644 index 15e1ad4795..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Ownership.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; - -public enum Ownership { - byod, cope -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java deleted file mode 100644 index 01d207ccd5..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/Platform.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; - -public enum Platform { - android, ios, windows -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java deleted file mode 100644 index fe3ae5febc..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/PotentialVulnerability.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * you may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; - -public enum PotentialVulnerability { - non_compliant, unmonitored -} \ No newline at end of file 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 eb51abe721..641783aceb 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 @@ -35,129 +35,36 @@ import java.util.*; public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { @Override - public int getTotalDeviceCount() throws SQLException { + public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { + int totalDeviceCount; try { - return this.getDeviceCount(null); + totalDeviceCount = this.getFilteredDeviceCount(null); } catch (InvalidParameterValueException e) { throw new AssertionError(e); } - } - - @Override - public int getActiveDeviceCount() throws SQLException { - FilterSet filterSet = new FilterSet(); - filterSet.setConnectivityStatus(ConnectivityStatus.active.toString()); - try { - return this.getDeviceCount(filterSet); - } catch (InvalidParameterValueException e) { - throw new AssertionError(e); - } - } - - @Override - public int getInactiveDeviceCount() throws SQLException { - FilterSet filterSet = new FilterSet(); - filterSet.setConnectivityStatus(ConnectivityStatus.inactive.toString()); - try { - return this.getDeviceCount(filterSet); - } catch (InvalidParameterValueException e) { - throw new AssertionError(e); - } - } - - @Override - public int getRemovedDeviceCount() throws SQLException { - FilterSet filterSet = new FilterSet(); - filterSet.setConnectivityStatus(ConnectivityStatus.removed.toString()); - try { - return this.getDeviceCount(filterSet); - } catch (InvalidParameterValueException e) { - throw new AssertionError(e); - } - } - @Override - public int getNonCompliantDeviceCount() throws SQLException { - FilterSet filterSet = new FilterSet(); - filterSet.setPotentialVulnerability(PotentialVulnerability.non_compliant.toString()); - try { - return this.getDeviceCount(filterSet); - } catch (InvalidParameterValueException e) { - throw new AssertionError(e); - } - } + DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry(); + deviceCountByGroupEntry.setGroup("total"); + deviceCountByGroupEntry.setDisplayNameForGroup("Total"); + deviceCountByGroupEntry.setDeviceCount(totalDeviceCount); - @Override - public int getUnmonitoredDeviceCount() throws SQLException { - FilterSet filterSet = new FilterSet(); - filterSet.setPotentialVulnerability(PotentialVulnerability.unmonitored.toString()); - try { - return this.getDeviceCount(filterSet); - } catch (InvalidParameterValueException e) { - throw new AssertionError(e); - } + return deviceCountByGroupEntry; } - @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { - if (startIndex < 0) { - throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); - } + int filteredDeviceCount = this.getFilteredDeviceCount(filterSet); - if (resultCount < 5) { - throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that."); - } + DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry(); + deviceCountByGroupEntry.setGroup("non-specific"); + deviceCountByGroupEntry.setDisplayNameForGroup("Non-specific"); + deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount); - Connection con; - PreparedStatement stmt = null; - ResultSet rs = null; - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - List> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>(); - int totalRecordsCount = 0; - try { - con = this.getConnection(); - String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + - "WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?"; - stmt = con.prepareStatement(sql); - stmt.setInt(1, tenantId); - stmt.setInt(2, startIndex); - stmt.setInt(3, resultCount); - - // executing query - rs = stmt.executeQuery(); - // fetching query results - Map filteredNonCompliantDeviceCountByFeature; - while (rs.next()) { - filteredNonCompliantDeviceCountByFeature = new HashMap<>(); - filteredNonCompliantDeviceCountByFeature.put("FEATURE_CODE", rs.getString("FEATURE_CODE")); - filteredNonCompliantDeviceCountByFeature.put("DEVICE_COUNT", rs.getInt("DEVICE_COUNT")); - filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature); - } - // fetching total records count - sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " + - "(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?)"; - - stmt = con.prepareStatement(sql); - stmt.setInt(1, tenantId); - - // executing query - rs = stmt.executeQuery(); - // fetching query results - while (rs.next()) { - totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); - } - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); - } - PaginationResult paginationResult = new PaginationResult(); - paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures); - paginationResult.setRecordsTotal(totalRecordsCount); - return paginationResult; + return deviceCountByGroupEntry; } - public int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { + private int getFilteredDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -202,8 +109,9 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCount; } - public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) - throws InvalidParameterValueException, SQLException { + @Override + public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty."); @@ -219,7 +127,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { try { con = this.getConnection(); String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + - "WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; + "WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; // appending filters to support advanced filtering options // [1] appending filter columns if (filters != null && filters.size() > 0) { @@ -251,10 +159,149 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } - return filteredDeviceCount; + + DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry(); + deviceCountByGroupEntry.setGroup("feature-non-compliant"); + deviceCountByGroupEntry.setDisplayNameForGroup("Feature-non-compliant"); + deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount); + + return deviceCountByGroupEntry; + } + + @Override + public List getDeviceCountsByConnectivityStatuses() throws SQLException { + Connection con; + PreparedStatement stmt = null; + ResultSet rs = null; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + List deviceCountsByConnectivityStatuses = new ArrayList<>(); + try { + con = this.getConnection(); + String sql = "SELECT CONNECTIVITY_STATUS, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 " + + "WHERE TENANT_ID = ? GROUP BY CONNECTIVITY_STATUS"; + stmt = con.prepareStatement(sql); + // [2] appending filter column values, if exist + stmt.setInt(1, tenantId); + // executing query + rs = stmt.executeQuery(); + // fetching query results + DeviceCountByGroupEntry deviceCountByConnectivityStatus; + while (rs.next()) { + deviceCountByConnectivityStatus = new DeviceCountByGroupEntry(); + deviceCountByConnectivityStatus.setGroup(rs.getString("CONNECTIVITY_STATUS")); + deviceCountByConnectivityStatus.setDisplayNameForGroup(rs.getString("CONNECTIVITY_STATUS")); + deviceCountByConnectivityStatus.setDeviceCount(rs.getInt("DEVICE_COUNT")); + deviceCountsByConnectivityStatuses.add(deviceCountByConnectivityStatus); + } + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + return deviceCountsByConnectivityStatuses; + } + + @Override + public List getDeviceCountsByPotentialVulnerabilities() throws SQLException { + // getting non-compliant device count + DeviceCountByGroupEntry nonCompliantDeviceCount = new DeviceCountByGroupEntry(); + nonCompliantDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); + nonCompliantDeviceCount.setDisplayNameForGroup("Non-compliant"); + nonCompliantDeviceCount.setDeviceCount(getNonCompliantDeviceCount()); + + // getting unmonitored device count + DeviceCountByGroupEntry unmonitoredDeviceCount = new DeviceCountByGroupEntry(); + unmonitoredDeviceCount.setGroup(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED); + unmonitoredDeviceCount.setDisplayNameForGroup("Unmonitored"); + unmonitoredDeviceCount.setDeviceCount(getUnmonitoredDeviceCount()); + + List deviceCountsByPotentialVulnerabilities = new ArrayList<>(); + deviceCountsByPotentialVulnerabilities.add(nonCompliantDeviceCount); + deviceCountsByPotentialVulnerabilities.add(unmonitoredDeviceCount); + + return deviceCountsByPotentialVulnerabilities; + } + + private int getNonCompliantDeviceCount() throws SQLException { + FilterSet filterSet = new FilterSet(); + filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT); + try { + return this.getFilteredDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } + } + + private int getUnmonitoredDeviceCount() throws SQLException { + FilterSet filterSet = new FilterSet(); + filterSet.setPotentialVulnerability(GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED); + try { + return this.getFilteredDeviceCount(filterSet); + } catch (InvalidParameterValueException e) { + throw new AssertionError(e); + } } - public Map getDeviceCountsByPlatforms(FilterSet filterSet) + @Override + public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException { + + if (startIndex < 0) { + throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that."); + } + + if (resultCount < 5) { + throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that."); + } + + Connection con; + PreparedStatement stmt = null; + ResultSet rs = null; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + List filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>(); + int totalRecordsCount = 0; + try { + con = this.getConnection(); + String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + + "WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?"; + stmt = con.prepareStatement(sql); + stmt.setInt(1, tenantId); + stmt.setInt(2, startIndex); + stmt.setInt(3, resultCount); + + // executing query + rs = stmt.executeQuery(); + // fetching query results + DeviceCountByGroupEntry filteredNonCompliantDeviceCountByFeature; + while (rs.next()) { + filteredNonCompliantDeviceCountByFeature = new DeviceCountByGroupEntry(); + filteredNonCompliantDeviceCountByFeature.setGroup(rs.getString("FEATURE_CODE")); + filteredNonCompliantDeviceCountByFeature.setDisplayNameForGroup(rs.getString("FEATURE_CODE")); + filteredNonCompliantDeviceCountByFeature.setDeviceCount(rs.getInt("DEVICE_COUNT")); + filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature); + } + // fetching total records count + sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " + + "(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?)"; + + stmt = con.prepareStatement(sql); + stmt.setInt(1, tenantId); + + // executing query + rs = stmt.executeQuery(); + // fetching query results + while (rs.next()) { + totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); + } + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + PaginationResult paginationResult = new PaginationResult(); + paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures); + paginationResult.setRecordsTotal(totalRecordsCount); + return paginationResult; + } + + @Override + public List getDeviceCountsByPlatforms(FilterSet filterSet) throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -263,7 +310,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceCountsByPlatforms = new HashMap<>(); + List filteredDeviceCountsByPlatforms = new ArrayList<>(); try { con = this.getConnection(); String sql, advancedSqlFiltering = ""; @@ -293,8 +340,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + DeviceCountByGroupEntry filteredDeviceCountByPlatform; while (rs.next()) { - filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); + filteredDeviceCountByPlatform = new DeviceCountByGroupEntry(); + filteredDeviceCountByPlatform.setGroup(rs.getString("PLATFORM")); + filteredDeviceCountByPlatform.setDisplayNameForGroup(rs.getString("PLATFORM").toUpperCase()); + filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT")); + filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform); } } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); @@ -302,7 +354,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCountsByPlatforms; } - public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, + @Override + public List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { @@ -315,7 +368,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceCountsByPlatforms = new HashMap<>(); + List filteredDeviceCountsByPlatforms = new ArrayList<>(); try { con = this.getConnection(); String sql, advancedSqlFiltering = ""; @@ -346,8 +399,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + DeviceCountByGroupEntry filteredDeviceCountByPlatform; while (rs.next()) { - filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); + filteredDeviceCountByPlatform = new DeviceCountByGroupEntry(); + filteredDeviceCountByPlatform.setGroup(rs.getString("PLATFORM")); + filteredDeviceCountByPlatform.setDisplayNameForGroup(rs.getString("PLATFORM").toUpperCase()); + filteredDeviceCountByPlatform.setDeviceCount(rs.getInt("DEVICE_COUNT")); + filteredDeviceCountsByPlatforms.add(filteredDeviceCountByPlatform); } } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); @@ -355,7 +413,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCountsByPlatforms; } - public Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) + @Override + public List getDeviceCountsByOwnershipTypes(FilterSet filterSet) throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -364,7 +423,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceCountsByOwnershipTypes = new HashMap<>(); + List filteredDeviceCountsByOwnershipTypes = new ArrayList<>(); try { con = this.getConnection(); String sql, advancedSqlFiltering = ""; @@ -394,8 +453,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + DeviceCountByGroupEntry filteredDeviceCountByOwnershipType; while (rs.next()) { - filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); + filteredDeviceCountByOwnershipType = new DeviceCountByGroupEntry(); + filteredDeviceCountByOwnershipType.setGroup(rs.getString("OWNERSHIP")); + filteredDeviceCountByOwnershipType.setDisplayNameForGroup(rs.getString("OWNERSHIP")); + filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT")); + filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType); } } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); @@ -403,7 +467,9 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCountsByOwnershipTypes; } - public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, + @Override + public List + getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { @@ -416,7 +482,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceCountsByOwnershipTypes = new HashMap<>(); + List filteredDeviceCountsByOwnershipTypes = new ArrayList<>(); try { con = this.getConnection(); String sql, advancedSqlFiltering = ""; @@ -447,8 +513,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + DeviceCountByGroupEntry filteredDeviceCountByOwnershipType; while (rs.next()) { - filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); + filteredDeviceCountByOwnershipType = new DeviceCountByGroupEntry(); + filteredDeviceCountByOwnershipType.setGroup(rs.getString("OWNERSHIP")); + filteredDeviceCountByOwnershipType.setDisplayNameForGroup(rs.getString("OWNERSHIP")); + filteredDeviceCountByOwnershipType.setDeviceCount(rs.getInt("DEVICE_COUNT")); + filteredDeviceCountsByOwnershipTypes.add(filteredDeviceCountByOwnershipType); } } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); @@ -456,6 +527,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDeviceCountsByOwnershipTypes; } + @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { @@ -473,7 +545,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - List> filteredDevicesWithDetails = new ArrayList<>(); + List filteredDevicesWithDetails = new ArrayList<>(); int totalRecordsCount = 0; try { con = this.getConnection(); @@ -509,15 +581,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results - Map filteredDeviceWithDetails; + DetailedDeviceEntry filteredDeviceWithDetails; while (rs.next()) { - filteredDeviceWithDetails = new HashMap<>(); - filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); - filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); - filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); - filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS")); + filteredDeviceWithDetails = new DetailedDeviceEntry(); + filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID")); + filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM")); + filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP")); + filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDevicesWithDetails.add(filteredDeviceWithDetails); } + // fetching total records count sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?"; @@ -539,6 +612,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } + @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet, int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { @@ -561,7 +635,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - List> filteredDevicesWithDetails = new ArrayList<>(); + List filteredDevicesWithDetails = new ArrayList<>(); int totalRecordsCount = 0; try { con = this.getConnection(); @@ -598,15 +672,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results - Map filteredDeviceWithDetails; + DetailedDeviceEntry filteredDeviceWithDetails; while (rs.next()) { - filteredDeviceWithDetails = new HashMap<>(); - filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); - filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); - filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); - filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS")); + filteredDeviceWithDetails = new DetailedDeviceEntry(); + filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID")); + filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM")); + filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP")); + filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDevicesWithDetails.add(filteredDeviceWithDetails); } + // fetching total records count sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + "WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; @@ -630,7 +705,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - public List> getDevicesWithDetails(FilterSet filterSet) + @Override + public List getDevicesWithDetails(FilterSet filterSet) throws InvalidParameterValueException, SQLException { Map filters = this.extractDatabaseFiltersFromBean(filterSet); @@ -639,7 +715,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - List> filteredDevicesWithDetails = new ArrayList<>(); + List filteredDevicesWithDetails = new ArrayList<>(); try { con = this.getConnection(); String sql; @@ -668,13 +744,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results - Map filteredDeviceWithDetails; + DetailedDeviceEntry filteredDeviceWithDetails; while (rs.next()) { - filteredDeviceWithDetails = new HashMap<>(); - filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); - filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); - filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); - filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS")); + filteredDeviceWithDetails = new DetailedDeviceEntry(); + filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID")); + filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM")); + filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP")); + filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDevicesWithDetails.add(filteredDeviceWithDetails); } } finally { @@ -683,7 +759,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return filteredDevicesWithDetails; } - public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + @Override + public List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, FilterSet filterSet) throws InvalidParameterValueException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { @@ -696,7 +773,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - List> filteredDevicesWithDetails = new ArrayList<>(); + List filteredDevicesWithDetails = new ArrayList<>(); try { con = this.getConnection(); String sql; @@ -727,13 +804,13 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results - Map filteredDeviceWithDetails; + DetailedDeviceEntry filteredDeviceWithDetails; while (rs.next()) { - filteredDeviceWithDetails = new HashMap<>(); - filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); - filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); - filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); - filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS")); + filteredDeviceWithDetails = new DetailedDeviceEntry(); + filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID")); + filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM")); + filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP")); + filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS")); filteredDevicesWithDetails.add(filteredDeviceWithDetails); } } finally { @@ -752,52 +829,34 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { String connectivityStatus = filterSet.getConnectivityStatus(); if (connectivityStatus != null) { - if (ConnectivityStatus.active.toString().equals(connectivityStatus) || - ConnectivityStatus.inactive.toString().equals(connectivityStatus) || - ConnectivityStatus.removed.toString().equals(connectivityStatus)) { - filters.put("CONNECTIVITY_STATUS", connectivityStatus.toUpperCase()); - } else { - throw new InvalidParameterValueException("Invalid use of value for platform. " + - "Value of platform could only be either android, ios or windows."); - } + filters.put("CONNECTIVITY_STATUS", connectivityStatus); } String potentialVulnerability = filterSet.getPotentialVulnerability(); if (potentialVulnerability != null) { - if (PotentialVulnerability.non_compliant.toString().equals(potentialVulnerability) || - PotentialVulnerability.unmonitored.toString().equals(potentialVulnerability)) { - if (PotentialVulnerability.non_compliant.toString().equals(potentialVulnerability)) { + if (GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT.equals(potentialVulnerability) || + GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED.equals(potentialVulnerability)) { + if (GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT.equals(potentialVulnerability)) { filters.put("IS_COMPLIANT", 0); } else { filters.put("POLICY_ID", -1); } } else { throw new InvalidParameterValueException("Invalid use of value for potential vulnerability. " + - "Value of potential vulnerability could only be non_compliant or unmonitored."); + "Value of potential vulnerability could only be either " + + GadgetDataServiceDAOConstants.PotentialVulnerability.NON_COMPLIANT + " or " + + GadgetDataServiceDAOConstants.PotentialVulnerability.UNMONITORED + "."); } } String platform = filterSet.getPlatform(); if (platform != null) { - if (Platform.android.toString().equals(platform) || - Platform.ios.toString().equals(platform) || - Platform.windows.toString().equals(platform)) { - filters.put("PLATFORM", platform); - } else { - throw new InvalidParameterValueException("Invalid use of value for platform. " + - "Value of platform could only be either android, ios or windows."); - } + filters.put("PLATFORM", platform); } String ownership = filterSet.getOwnership(); if (ownership != null) { - if (Ownership.byod.toString().equals(ownership) || - Ownership.cope.toString().equals(ownership)) { - filters.put("OWNERSHIP", ownership.toUpperCase()); - } else { - throw new InvalidParameterValueException("Invalid use of value for ownership. " + - "Value of ownership could only be either BYOD or COPE."); - } + filters.put("OWNERSHIP", ownership); } return filters; 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 4e8c3fca7d..7c3304bb9e 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 @@ -20,13 +20,12 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.impl; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; import java.util.List; -import java.util.Map; /** * To be updated... @@ -34,81 +33,72 @@ import java.util.Map; public class GadgetDataServiceImpl implements GadgetDataService { @Override - public int getTotalDeviceCount() throws SQLException { - int totalDeviceCount; + public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { + DeviceCountByGroupEntry filteredDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); - totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); + filteredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } - return totalDeviceCount; + return filteredDeviceCount; } @Override - public int getActiveDeviceCount() throws SQLException { - int activeDeviceCount; + public DeviceCountByGroupEntry getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) + throws InvalidParameterValueException, SQLException { + DeviceCountByGroupEntry featureNonCompliantDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); - activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount(); - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return activeDeviceCount; - } - - @Override - public int getInactiveDeviceCount() throws SQLException { - int inactiveDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount(); + featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. + getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } - return inactiveDeviceCount; + return featureNonCompliantDeviceCount; } @Override - public int getRemovedDeviceCount() throws SQLException { - int removedDeviceCount; + public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { + DeviceCountByGroupEntry totalDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); - removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount(); + totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); } finally { GadgetDataServiceDAOFactory.closeConnection(); } - return removedDeviceCount; + return totalDeviceCount; } @Override - public int getNonCompliantDeviceCount() throws SQLException { - int nonCompliantDeviceCount; + public List getDeviceCountsByConnectivityStatuses() throws SQLException { + List deviceCountsByConnectivityStatuses; try { GadgetDataServiceDAOFactory.openConnection(); - nonCompliantDeviceCount = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getNonCompliantDeviceCount(); + deviceCountsByConnectivityStatuses = GadgetDataServiceDAOFactory. + getGadgetDataServiceDAO().getDeviceCountsByConnectivityStatuses(); } finally { GadgetDataServiceDAOFactory.closeConnection(); } - return nonCompliantDeviceCount; + return deviceCountsByConnectivityStatuses; } @Override - public int getUnmonitoredDeviceCount() throws SQLException { - int unmonitoredDeviceCount; + public List getDeviceCountsByPotentialVulnerabilities() throws SQLException { + List deviceCountsByPotentialVulnerabilities; try { GadgetDataServiceDAOFactory.openConnection(); - unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(); + deviceCountsByPotentialVulnerabilities = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getDeviceCountsByPotentialVulnerabilities(); } finally { GadgetDataServiceDAOFactory.closeConnection(); } - return unmonitoredDeviceCount; + return deviceCountsByPotentialVulnerabilities; } @Override public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) - throws SQLException, InvalidParameterValueException { + throws SQLException, InvalidParameterValueException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); @@ -121,35 +111,9 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getDeviceCount(FilterSet filterSet) throws InvalidParameterValueException, SQLException { - int deviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filterSet); - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return deviceCount; - } - - @Override - public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, FilterSet filterSet) - throws InvalidParameterValueException, SQLException { - int featureNonCompliantDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filterSet); - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return featureNonCompliantDeviceCount; - } - - @Override - public Map getDeviceCountsByPlatforms(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { - Map deviceCountsByPlatforms; + public List getDeviceCountsByPlatforms(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { + List deviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). @@ -161,9 +125,9 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { - Map featureNonCompliantDeviceCountsByPlatforms; + public List getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, SQLException { + List featureNonCompliantDeviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). @@ -175,9 +139,9 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getDeviceCountsByOwnershipTypes(FilterSet filterSet) - throws InvalidParameterValueException, SQLException { - Map deviceCountsByOwnershipTypes; + public List getDeviceCountsByOwnershipTypes(FilterSet filterSet) + throws InvalidParameterValueException, SQLException { + List deviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). @@ -189,9 +153,10 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - FilterSet filterSet) throws SQLException, InvalidParameterValueException { - Map featureNonCompliantDeviceCountsByOwnershipTypes; + public List + getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, + FilterSet filterSet) throws SQLException, InvalidParameterValueException { + List featureNonCompliantDeviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). @@ -204,7 +169,7 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getDevicesWithDetails(FilterSet filterSet, - int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { + int startIndex, int resultCount) throws InvalidParameterValueException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); @@ -218,8 +183,8 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet, int startIndex, int resultCount) - throws InvalidParameterValueException, SQLException { + FilterSet filterSet, int startIndex, int resultCount) + throws InvalidParameterValueException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); @@ -232,12 +197,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List> getDevicesWithDetails(FilterSet filterSet) + public List getDevicesWithDetails(FilterSet filterSet) throws InvalidParameterValueException, SQLException { - List> devicesWithDetails; + List devicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); - devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); + devicesWithDetails = GadgetDataServiceDAOFactory. + getGadgetDataServiceDAO().getDevicesWithDetails(filterSet); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -245,9 +211,9 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - FilterSet filterSet) throws InvalidParameterValueException, SQLException { - List> featureNonCompliantDevicesWithDetails; + public List getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + FilterSet filterSet) throws InvalidParameterValueException, SQLException { + List featureNonCompliantDevicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). From a23e5785371993e941bc4107cf718df23c993eda Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 8 May 2016 17:43:05 +0530 Subject: [PATCH 3/3] Adding inter-mediate development code bits for dashboard analytics feature --- .../dao/bean/DetailedDeviceEntry.java | 64 +++++++++++++++++++ .../dao/bean/DeviceCountByGroupEntry.java | 53 +++++++++++++++ .../impl/GadgetDataServiceDAOConstants.java | 38 +++++++++++ 3 files changed, 155 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/bean/DetailedDeviceEntry.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOConstants.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/bean/DetailedDeviceEntry.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DetailedDeviceEntry.java new file mode 100644 index 0000000000..c8885b6833 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DetailedDeviceEntry.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public class DetailedDeviceEntry { + + private int deviceId; + private String platform; + private String ownershipType; + private String connectivityStatus; + + @SuppressWarnings("unused") + public int getDeviceId() { + return deviceId; + } + + public void setDeviceId(int deviceId) { + this.deviceId = deviceId; + } + + @SuppressWarnings("unused") + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + @SuppressWarnings("unused") + public String getOwnershipType() { + return ownershipType; + } + + public void setOwnershipType(String ownershipType) { + this.ownershipType = ownershipType; + } + + @SuppressWarnings("unused") + public String getConnectivityStatus() { + return connectivityStatus; + } + + public void setConnectivityStatus(String connectivityStatus) { + this.connectivityStatus = connectivityStatus; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java new file mode 100644 index 0000000000..e7dc9909f6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/bean/DeviceCountByGroupEntry.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean; + +public class DeviceCountByGroupEntry { + + private String group; + private String displayNameForGroup; + private int deviceCount; + + @SuppressWarnings("unused") + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + @SuppressWarnings("unused") + public String getDisplayNameForGroup() { + return displayNameForGroup; + } + + public void setDisplayNameForGroup(String displayNameForGroup) { + this.displayNameForGroup = displayNameForGroup; + } + + @SuppressWarnings("unused") + public int getDeviceCount() { + return deviceCount; + } + + public void setDeviceCount(int deviceCount) { + this.deviceCount = deviceCount; + } +} 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/GadgetDataServiceDAOConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOConstants.java new file mode 100644 index 0000000000..9caad2f3a8 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOConstants.java @@ -0,0 +1,38 @@ +/* + * 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.impl; + +public final class GadgetDataServiceDAOConstants { + + public static class PotentialVulnerability { + + // These constants do not hold actual database values + // These are just logical values defined and used @ Gadget Data Service DAO Implementation layer + public static final String NON_COMPLIANT = "NON_COMPLIANT"; + public static final String UNMONITORED = "UNMONITORED"; + + private PotentialVulnerability() { + throw new AssertionError(); + } + + } + + private GadgetDataServiceDAOConstants() { throw new AssertionError(); } + +}