From d568c6e8bd90b9f7b7ee64354af8204b699f21bc Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 5 May 2016 16:12:15 +0530 Subject: [PATCH] Adding temporary development code bits for dashboard analytics feature --- .../dashboard/GadgetDataService.java | 7 +- .../dashboard/dao/GadgetDataServiceDAO.java | 7 +- .../dao/impl/GadgetDataServiceDAOImpl.java | 89 +++++++++---------- .../dashboard/impl/GadgetDataServiceImpl.java | 12 +-- 4 files changed, 52 insertions(+), 63 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java index 0c8d6bf9f9..3931e72fc2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.analytics.dashboard; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException; -import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; @@ -50,7 +49,7 @@ public interface GadgetDataService { int getUnmonitoredDeviceCount() throws SQLException; @SuppressWarnings("unused") - PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") @@ -76,11 +75,11 @@ public interface GadgetDataService { @SuppressWarnings("unused") PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException; + int startIndex, int resultCount) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) + Map filters, int startIndex, int resultCount) throws InvalidParameterException, SQLException; @SuppressWarnings("unused") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java index ac14fd177d..f166fedf7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAO.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException; -import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import java.sql.SQLException; @@ -70,7 +69,7 @@ public interface GadgetDataServiceDAO { */ int getUnmonitoredDeviceCount() throws SQLException; - PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterException, SQLException; int getDeviceCount(Map filters) throws SQLException; @@ -89,10 +88,10 @@ public interface GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException; PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException; + int startIndex, int resultCount) throws InvalidParameterException, SQLException; PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) + Map filters, int startIndex, int resultCount) throws InvalidParameterException, SQLException; List> getDevicesWithDetails(Map filters) throws SQLException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java index 034c3e0858..c79d38e771 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java @@ -22,7 +22,6 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterException; -import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -78,21 +77,17 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws InvalidParameterException, SQLException { - if (paginationRequest == null) { - throw new InvalidParameterException("PaginationRequest object should not be null."); + if (startIndex < 0) { + throw new InvalidParameterException("Start index (startIndex) should be " + + "equal to 0 or greater than that."); } - if (paginationRequest.getStartIndex() < 0) { - throw new InvalidParameterException("startIndex of PaginationRequest object " + - "should be equal to 0 or greater than that."); - } - - if (paginationRequest.getRowCount() < 5) { - throw new InvalidParameterException("rowCount of PaginationRequest object " + - "should be equal to 5 or greater than that."); + if (resultCount < 5) { + throw new InvalidParameterException("Result count (resultCount) should be " + + "equal to 5 or greater than that."); } Connection con; @@ -107,8 +102,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { "WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?"; stmt = con.prepareStatement(sql); stmt.setInt(1, tenantId); - stmt.setInt(2, paginationRequest.getStartIndex()); - stmt.setInt(3, paginationRequest.getRowCount()); + stmt.setInt(2, startIndex); + stmt.setInt(3, resultCount); // executing query rs = stmt.executeQuery(); @@ -281,7 +276,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } Connection con; @@ -376,7 +372,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } Connection con; @@ -424,20 +421,16 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException { - - if (paginationRequest == null) { - throw new InvalidParameterException("PaginationRequest object should not be null."); - } + int startIndex, int resultCount) throws InvalidParameterException, SQLException { - if (paginationRequest.getStartIndex() < 0) { - throw new InvalidParameterException("startIndex of PaginationRequest object " + - "should be equal to 0 or greater than that."); + if (startIndex < 0) { + throw new InvalidParameterException("Start index (startIndex) should be " + + "equal to 0 or greater than that."); } - if (paginationRequest.getRowCount() < 5) { - throw new InvalidParameterException("rowCount of PaginationRequest object " + - "should be equal to 5 or greater than that."); + if (resultCount < 5) { + throw new InvalidParameterException("Result count (resultCount) should be " + + "equal to 5 or greater than that."); } Connection con; @@ -471,11 +464,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } i++; } - stmt.setInt(i, paginationRequest.getStartIndex()); - stmt.setInt(++i, paginationRequest.getRowCount()); + stmt.setInt(i, startIndex); + stmt.setInt(++i, resultCount); } else { - stmt.setInt(2, paginationRequest.getStartIndex()); - stmt.setInt(3, paginationRequest.getRowCount()); + stmt.setInt(2, startIndex); + stmt.setInt(3, resultCount); } // executing query rs = stmt.executeQuery(); @@ -511,25 +504,22 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) - throws InvalidParameterException, SQLException { + Map filters, int startIndex, int resultCount) + throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } - if (paginationRequest == null) { - throw new InvalidParameterException("PaginationRequest object should not be null."); + if (startIndex < 0) { + throw new InvalidParameterException("Start index (startIndex) should be " + + "equal to 0 or greater than that."); } - if (paginationRequest.getStartIndex() < 0) { - throw new InvalidParameterException("startIndex of PaginationRequest object " + - "should be equal to 0 or greater than that."); - } - - if (paginationRequest.getRowCount() < 5) { - throw new InvalidParameterException("rowCount of PaginationRequest object " + - "should be equal to 5 or greater than that."); + if (resultCount < 5) { + throw new InvalidParameterException("Result count (resultCount) should be " + + "equal to 5 or greater than that."); } Connection con; @@ -564,11 +554,11 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } i++; } - stmt.setInt(i, paginationRequest.getStartIndex()); - stmt.setInt(++i, paginationRequest.getRowCount()); + stmt.setInt(i, startIndex); + stmt.setInt(++i, resultCount); } else { - stmt.setInt(3, paginationRequest.getStartIndex()); - stmt.setInt(4, paginationRequest.getRowCount()); + stmt.setInt(3, startIndex); + stmt.setInt(4, resultCount); } // executing query rs = stmt.executeQuery(); @@ -658,7 +648,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { Map filters) throws InvalidParameterException, SQLException { if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) { - throw new InvalidParameterException("nonCompliantFeatureCode should not be either null or empty."); + throw new InvalidParameterException("Non-compliant feature code (nonCompliantFeatureCode) " + + "should not be either null or empty."); } Connection con; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java index 16eded439c..98ceb5d88f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java @@ -107,13 +107,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount) throws SQLException, InvalidParameterException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getNonCompliantDeviceCountsByFeatures(paginationRequest); + getNonCompliantDeviceCountsByFeatures(startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -202,12 +202,12 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getDevicesWithDetails(Map filters, - PaginationRequest paginationRequest) throws InvalidParameterException, SQLException { + int startIndex, int resultCount) throws InvalidParameterException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDevicesWithDetails(filters, paginationRequest); + getDevicesWithDetails(filters, startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -216,13 +216,13 @@ public class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) + Map filters, int startIndex, int resultCount) throws InvalidParameterException, SQLException { PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest); + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, startIndex, resultCount); } finally { GadgetDataServiceDAOFactory.closeConnection(); }