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 32721655887..cbc22f06c9c 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 @@ -58,6 +58,8 @@ Device Management Dashboard Analytics Bundle org.wso2.carbon.device.mgt.analytics.dashboard.dao, + org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl, + org.wso2.carbon.device.mgt.analytics.dashboard.impl, org.wso2.carbon.device.mgt.analytics.dashboard.internal 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 d34bd4c2e5a..7c5b2038e66 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 @@ -30,58 +30,61 @@ import java.util.Map; public interface GadgetDataService { @SuppressWarnings("unused") - int getTotalDeviceCount(); + int getTotalDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getActiveDeviceCount(); + int getActiveDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getInactiveDeviceCount(); + int getInactiveDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getRemovedDeviceCount(); + int getRemovedDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getNonCompliantDeviceCount(); + int getNonCompliantDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getUnmonitoredDeviceCount(); + int getUnmonitoredDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest); + PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + throws GadgetDataServiceException; @SuppressWarnings("unused") - int getDeviceCount(Map filters); + int getDeviceCount(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters); + int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, + Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - Map getDeviceCountsByPlatforms(Map filters); + Map getDeviceCountsByPlatforms(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters); + Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - Map getDeviceCountsByOwnershipTypes(Map filters); + Map getDeviceCountsByOwnershipTypes(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters); + Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - PaginationResult getDevicesWithDetails(Map filters, PaginationRequest paginationRequest); + PaginationResult getDevicesWithDetails(Map filters, + PaginationRequest paginationRequest) throws GadgetDataServiceException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest); + Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceException; @SuppressWarnings("unused") - List> getDevicesWithDetails(Map filters); + List> getDevicesWithDetails(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters); + Map filters) throws GadgetDataServiceException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java new file mode 100644 index 00000000000..32ebef29f0e --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * you may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.analytics.dashboard; + +/** + * Custom exception class for GadgetDataService layer. + */ +public class GadgetDataServiceException extends Exception { + + private String errorMessage; + private static final long serialVersionUID = 2021891706072918864L; + + /** + * Constructs a new exception with the specific error message and nested exception. + * + * @param errorMessage specific error message. + * @param nestedException Nested exception. + */ + public GadgetDataServiceException(String errorMessage, Exception nestedException) { + super(errorMessage, nestedException); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message and cause. + * + * @param errorMessage Specific error message. + * @param cause Cause of this exception. + */ + @SuppressWarnings("unused") + public GadgetDataServiceException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message. + * + * @param errorMessage Specific error message. + */ + @SuppressWarnings("unused") + public GadgetDataServiceException(String errorMessage) { + super(errorMessage); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message and cause. + * + * @param cause Cause of this exception. + */ + @SuppressWarnings("unused") + public GadgetDataServiceException(Throwable cause) { + super(cause); + } + + @SuppressWarnings("unused") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java index 3ebf841f130..adb1917c1eb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java @@ -18,11 +18,11 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; -@SuppressWarnings("unused") /** - * Custom exception class for data access related exceptions. + * Custom exception class for GadgetDataServiceDAO layer. */ public class GadgetDataServiceDAOException extends Exception { + private String errorMessage; private static final long serialVersionUID = 2021891706072918864L; @@ -43,6 +43,7 @@ public class GadgetDataServiceDAOException extends Exception { * @param errorMessage Specific error message. * @param cause Cause of this exception. */ + @SuppressWarnings("unused") public GadgetDataServiceDAOException(String errorMessage, Throwable cause) { super(errorMessage, cause); setErrorMessage(errorMessage); @@ -53,6 +54,7 @@ public class GadgetDataServiceDAOException extends Exception { * * @param errorMessage Specific error message. */ + @SuppressWarnings("unused") public GadgetDataServiceDAOException(String errorMessage) { super(errorMessage); setErrorMessage(errorMessage); @@ -63,10 +65,12 @@ public class GadgetDataServiceDAOException extends Exception { * * @param cause Cause of this exception. */ + @SuppressWarnings("unused") public GadgetDataServiceDAOException(Throwable cause) { super(cause); } + @SuppressWarnings("unused") public String getErrorMessage() { return errorMessage; } @@ -74,4 +78,5 @@ public class GadgetDataServiceDAOException extends Exception { public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java index bb2d44ac636..c5a6097f3fa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl.GadgetDataServiceDAOImpl; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; @@ -33,6 +34,7 @@ import java.util.List; @SuppressWarnings("unused") public class GadgetDataServiceDAOFactory { + private static final Log log = LogFactory.getLog(GadgetDataServiceDAOFactory.class); private static DataSource dataSource; private static String databaseEngine; @@ -47,7 +49,7 @@ public class GadgetDataServiceDAOFactory { try { databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); } catch (SQLException e) { - log.error("Error occurred while retrieving config.datasource connection", e); + log.error("Error occurred while retrieving config.datasource connection.", e); } } @@ -56,7 +58,7 @@ public class GadgetDataServiceDAOFactory { try { databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); } catch (SQLException e) { - log.error("Error occurred while retrieving config.datasource connection", e); + log.error("Error occurred while retrieving config.datasource connection.", e); } } @@ -64,8 +66,8 @@ public class GadgetDataServiceDAOFactory { Connection conn = currentConnection.get(); if (conn != null) { throw new IllegalTransactionStateException("A transaction is already active within the context of " + - "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + - "transaction is already active is a sign of improper transaction handling"); + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling."); } conn = dataSource.getConnection(); currentConnection.set(conn); @@ -75,8 +77,8 @@ public class GadgetDataServiceDAOFactory { Connection conn = currentConnection.get(); if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + - "This might have ideally been caused by not properly initiating the transaction via " + - "'beginTransaction'/'openConnection' methods"); + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods."); } return conn; } @@ -85,36 +87,35 @@ public class GadgetDataServiceDAOFactory { Connection conn = currentConnection.get(); if (conn == null) { throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + - "This might have ideally been caused by not properly initiating the transaction via " + - "'beginTransaction'/'openConnection' methods"); + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods."); } try { conn.close(); } catch (SQLException e) { - log.warn("Error occurred while close the connection"); + log.warn("Error occurred while close the connection."); } currentConnection.remove(); } /** - * Resolve data source from the data source definition + * Resolve data source from the data source definition. * - * @param config data source configuration - * @return data source resolved from the data source definition + * @param config data source configuration. + * @return data source resolved from the data source definition. */ private static DataSource resolveDataSource(DataSourceConfig config) { DataSource dataSource = null; if (config == null) { throw new RuntimeException( - "Device Management Repository data source configuration " + "is null and " + - "thus, is not initialized"); + "Device Management Repository data source configuration " + "is null and " + + "thus, is not initialized."); } JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); if (jndiConfig != null) { if (log.isDebugEnabled()) { - log.debug("Initializing Device Management Repository data source using the JNDI " + - "Lookup Definition"); + log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition."); } List jndiPropertyList = jndiConfig.getJndiProperties(); if (jndiPropertyList != null) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/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 similarity index 90% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java rename to 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 fabd43ec8eb..9f2250d3cf4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/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 @@ -16,11 +16,12 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao; +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -34,9 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { - @SuppressWarnings("unused") - private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class); +public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { @Override public int getTotalDeviceCount() throws GadgetDataServiceDAOException { @@ -72,7 +71,15 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { + public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException { + Map filters = new HashMap<>(); + filters.put("POLICY_ID", -1); + return this.getDeviceCount(filters); + } + + @Override + public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + throws GadgetDataServiceDAOException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -82,7 +89,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { 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 ?, ?"; + "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()); @@ -112,7 +119,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting non compliant device counts by features.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -122,13 +130,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - @Override - public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException { - Map filters = new HashMap<>(); - filters.put("POLICY_ID", -1); - return this.getDeviceCount(filters); - } - public int getDeviceCount(Map filters) throws GadgetDataServiceDAOException { Connection con; PreparedStatement stmt = null; @@ -166,7 +167,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered device count.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -211,7 +213,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered device count, " + + "non compliant by a particular feature.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -257,7 +261,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of device counts by platforms.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -304,7 +309,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a set of feature non-compliant device counts by platforms.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -350,7 +356,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of device counts by ownership types.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -398,7 +405,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of feature " + + "non-compliant device counts by ownership types.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -469,7 +478,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of devices " + + "with details when pagination is enabled.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -485,7 +496,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceWithDetails = new HashMap<>(); List> filteredDevicesWithDetails = new ArrayList<>(); int totalRecordsCount = 0; try { @@ -499,7 +509,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } } sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " + - "WHERE TENANT_ID = ? AND FEATURE_CODE = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?"; + "WHERE TENANT_ID = ? AND FEATURE_CODE = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?"; stmt = con.prepareStatement(sql); // [2] appending filter column values, if exist stmt.setInt(1, tenantId); @@ -523,7 +533,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + Map 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")); @@ -545,7 +557,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of feature non-compliant devices " + + "with details when pagination is enabled.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -599,7 +613,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDevicesWithDetails.add(filteredDeviceWithDetails); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of devices with details.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -612,13 +627,12 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceWithDetails = new HashMap<>(); List> filteredDevicesWithDetails = new ArrayList<>(); try { con = this.getConnection(); String sql; sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS 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 exist if (filters != null && filters.size() > 0) { @@ -644,7 +658,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + Map 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")); @@ -652,7 +668,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDevicesWithDetails.add(filteredDeviceWithDetails); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting filtered set of feature non-compliant devices with details.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java new file mode 100644 index 00000000000..eb01fa3ae2b --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java @@ -0,0 +1,363 @@ +/* + * 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.impl; + +import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; +import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataServiceException; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; + +import java.sql.SQLException; +import java.util.List; +import java.util.Map; + +/** + * To be updated... + */ +public class GadgetDataServiceImpl implements GadgetDataService { + + @Override + public int getTotalDeviceCount() throws GadgetDataServiceException { + int totalDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for total device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return totalDeviceCount; + } + + @Override + public int getActiveDeviceCount() throws GadgetDataServiceException { + int activeDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount(); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for active device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return activeDeviceCount; + } + + @Override + public int getInactiveDeviceCount() throws GadgetDataServiceException { + int inactiveDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount(); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for inactive device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return inactiveDeviceCount; + } + + @Override + public int getRemovedDeviceCount() throws GadgetDataServiceException { + int removedDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount(); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for removed device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return removedDeviceCount; + } + + @Override + public int getNonCompliantDeviceCount() throws GadgetDataServiceException { + int nonCompliantDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + nonCompliantDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount(); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for non-compliant device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return nonCompliantDeviceCount; + } + + @Override + public int getUnmonitoredDeviceCount() throws GadgetDataServiceException { + int unmonitoredDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for unmonitored device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return unmonitoredDeviceCount; + } + + @Override + public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + throws GadgetDataServiceException { + PaginationResult paginationResult; + try { + GadgetDataServiceDAOFactory.openConnection(); + paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getNonCompliantDeviceCountsByFeatures(paginationRequest); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for non-compliant device counts by features.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return paginationResult; + } + + @Override + public int getDeviceCount(Map filters) throws GadgetDataServiceException { + int deviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for getting a filtered device count.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return deviceCount; + } + + @Override + public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) + throws GadgetDataServiceException { + int featureNonCompliantDeviceCount; + try { + GadgetDataServiceDAOFactory.openConnection(); + featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. + getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting a filtered device count, non compliant by a particular feature.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return featureNonCompliantDeviceCount; + } + + @Override + public Map getDeviceCountsByPlatforms(Map filters) + throws GadgetDataServiceException { + Map deviceCountsByPlatforms; + try { + GadgetDataServiceDAOFactory.openConnection(); + deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getDeviceCountsByPlatforms(filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by platforms.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return deviceCountsByPlatforms; + } + + @Override + public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, + Map filters) throws GadgetDataServiceException { + Map featureNonCompliantDeviceCountsByPlatforms; + try { + GadgetDataServiceDAOFactory.openConnection(); + featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory. + getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by platforms, non compliant by a particular feature.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return featureNonCompliantDeviceCountsByPlatforms; + } + + @Override + public Map getDeviceCountsByOwnershipTypes(Map filters) + throws GadgetDataServiceException { + Map deviceCountsByOwnershipTypes; + try { + GadgetDataServiceDAOFactory.openConnection(); + deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getDeviceCountsByOwnershipTypes(filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by ownership types.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return deviceCountsByOwnershipTypes; + } + + @Override + public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, + Map filters) throws GadgetDataServiceException { + Map featureNonCompliantDeviceCountsByOwnershipTypes; + try { + GadgetDataServiceDAOFactory.openConnection(); + featureNonCompliantDeviceCountsByOwnershipTypes = + GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by ownership types, non compliant by a particular feature.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return featureNonCompliantDeviceCountsByOwnershipTypes; + } + + @Override + public PaginationResult getDevicesWithDetails(Map filters, + PaginationRequest paginationRequest) throws GadgetDataServiceException { + PaginationResult paginationResult; + try { + GadgetDataServiceDAOFactory.openConnection(); + paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getDevicesWithDetails(filters, paginationRequest); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details when pagination is enabled.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return paginationResult; + } + + @Override + public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceException { + PaginationResult paginationResult; + try { + GadgetDataServiceDAOFactory.openConnection(); + paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details, non compliant by feature when pagination is enabled.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return paginationResult; + } + + @Override + public List> getDevicesWithDetails(Map filters) + throws GadgetDataServiceException { + List> devicesWithDetails; + try { + GadgetDataServiceDAOFactory.openConnection(); + devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return devicesWithDetails; + } + + @Override + public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, + Map filters) throws GadgetDataServiceException { + List> featureNonCompliantDevicesWithDetails; + try { + GadgetDataServiceDAOFactory.openConnection(); + featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). + getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters); + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details, non compliant by feature.", e); + } finally { + GadgetDataServiceDAOFactory.closeConnection(); + } + return featureNonCompliantDevicesWithDetails; + } + +} 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 193afc92da6..7d1bc08c197 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 @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; 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.impl.GadgetDataServiceImpl; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; @@ -39,6 +40,7 @@ import org.wso2.carbon.ndatasource.core.DataSourceService; * unbind="unsetDataSourceService" */ public class GadgetDataServiceComponent { + private static final Log log = LogFactory.getLog(GadgetDataServiceComponent.class); protected void activate(ComponentContext componentContext) { @@ -56,10 +58,10 @@ public class GadgetDataServiceComponent { componentContext.getBundleContext(). registerService(GadgetDataService.class.getName(), new GadgetDataServiceImpl(), null); if (log.isDebugEnabled()) { - log.debug("Device Management Dashboard Analytics Bundle has been started successfully"); + log.debug("Device Management Dashboard Analytics Bundle has been started successfully."); } } catch (Throwable e) { - log.error("Error occurred while initializing the bundle", e); + log.error("Error occurred while initializing the bundle.", e); } } @@ -70,11 +72,18 @@ public class GadgetDataServiceComponent { //do nothing } - public void setDataSourceService(DataSourceService dataSourceService){ - + public void setDataSourceService(DataSourceService dataSourceService) { + if (log.isDebugEnabled()) { + log.debug("Binding org.wso2.carbon.ndatasource.core.DataSourceService..."); + } + //do nothing } - public void unsetDataSourceService(DataSourceService dataSourceService){ - + public void unsetDataSourceService(DataSourceService dataSourceService) { + if (log.isDebugEnabled()) { + log.debug("Unbinding org.wso2.carbon.ndatasource.core.DataSourceService..."); + } + //do nothing } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java deleted file mode 100644 index 2f31b84f403..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java +++ /dev/null @@ -1,301 +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.internal; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException; -import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; -import org.wso2.carbon.device.mgt.common.PaginationRequest; -import org.wso2.carbon.device.mgt.common.PaginationResult; - -import java.sql.SQLException; -import java.util.List; -import java.util.Map; - -/** - * To be updated... - */ -class GadgetDataServiceImpl implements GadgetDataService { - - @SuppressWarnings("unused") - private static final Log log = LogFactory.getLog(GadgetDataServiceImpl.class); - - @Override - public int getTotalDeviceCount() { - int totalDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - totalDeviceCount = -1; - return totalDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return totalDeviceCount; - } - - @Override - public int getActiveDeviceCount() { - int activeDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - activeDeviceCount = -1; - return activeDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return activeDeviceCount; - } - - @Override - public int getInactiveDeviceCount() { - int inactiveDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - inactiveDeviceCount = -1; - return inactiveDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return inactiveDeviceCount; - } - - @Override - public int getRemovedDeviceCount() { - int removedDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - removedDeviceCount = -1; - return removedDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return removedDeviceCount; - } - - @Override - public int getNonCompliantDeviceCount() { - int nonCompliantDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - nonCompliantDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - nonCompliantDeviceCount = -1; - return nonCompliantDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return nonCompliantDeviceCount; - } - - @Override - public int getUnmonitoredDeviceCount() { - int unmonitoredDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - unmonitoredDeviceCount = -1; - return unmonitoredDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return unmonitoredDeviceCount; - } - - @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) { - PaginationResult paginationResult = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getNonCompliantDeviceCountsByFeatures(paginationRequest); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return paginationResult; - } - - @Override - public int getDeviceCount(Map filters) { - int deviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - deviceCount = -1; - return deviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return deviceCount; - } - - @Override - public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) { - int featureNonCompliantDeviceCount; - try { - GadgetDataServiceDAOFactory.openConnection(); - featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - featureNonCompliantDeviceCount = -1; - return featureNonCompliantDeviceCount; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return featureNonCompliantDeviceCount; - } - - @Override - public Map getDeviceCountsByPlatforms(Map filters) { - Map deviceCountsByPlatforms = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDeviceCountsByPlatforms(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return deviceCountsByPlatforms; - } - - @Override - public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) { - Map featureNonCompliantDeviceCountsByPlatforms = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory. - getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return featureNonCompliantDeviceCountsByPlatforms; - } - - @Override - public Map getDeviceCountsByOwnershipTypes(Map filters) { - Map deviceCountsByOwnershipTypes = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDeviceCountsByOwnershipTypes(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return deviceCountsByOwnershipTypes; - } - - @Override - public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) { - Map featureNonCompliantDeviceCountsByOwnershipTypes = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - featureNonCompliantDeviceCountsByOwnershipTypes = - GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return featureNonCompliantDeviceCountsByOwnershipTypes; - } - - @Override - public PaginationResult getDevicesWithDetails(Map filters, PaginationRequest paginationRequest) { - PaginationResult paginationResult = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getDevicesWithDetails(filters, paginationRequest); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return paginationResult; - } - - @Override - public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) { - PaginationResult paginationResult = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return paginationResult; - } - - @Override - public List> getDevicesWithDetails(Map filters) { - List> devicesWithDetails = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return devicesWithDetails; - } - - @Override - public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) { - List> featureNonCompliantDevicesWithDetails = null; - try { - GadgetDataServiceDAOFactory.openConnection(); - featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). - getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; - } finally { - GadgetDataServiceDAOFactory.closeConnection(); - } - return featureNonCompliantDevicesWithDetails; - } - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index dc6bcd886a8..92af0d4544e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.common.device.details; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -51,6 +52,7 @@ public class DeviceInfo implements Serializable { private Double totalRAMMemory; private Double availableRAMMemory; private boolean pluggedIn; + private Date updatedTime; private Map deviceDetailsMap = new HashMap<>(); @@ -290,6 +292,17 @@ public class DeviceInfo implements Serializable { this.pluggedIn = pluggedIn; } + public Date getUpdatedTime() { + if(updatedTime.equals(null)){ + updatedTime = new Date(); + } + return updatedTime; + } + + public void setUpdatedTime(Date updatedTime) { + this.updatedTime = updatedTime; + } + public void setDeviceDetailsMap(Map deviceDetailsMap) { this.deviceDetailsMap = deviceDetailsMap; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java index 0b05406522a..1368b92806a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java @@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.common.device.details; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; +import java.util.Date; public class DeviceLocation implements Serializable { @@ -39,6 +40,7 @@ public class DeviceLocation implements Serializable { private String state; private String zip; private String country; + private Date updatedTime; public int getDeviceId() { return deviceId; @@ -119,5 +121,16 @@ public class DeviceLocation implements Serializable { public void setCountry(String country) { this.country = country; } + + public Date getUpdatedTime() { + if(updatedTime.equals(null)){ + updatedTime = new Date(); + } + return updatedTime; + } + + public void setUpdatedTime(Date updatedTime) { + this.updatedTime = updatedTime; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 5f141c44d5b..3496bacb8c8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -31,7 +31,11 @@ public class Operation implements Serializable { } public enum Status { - IN_PROGRESS, PENDING, COMPLETED, ERROR + IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED + } + + public enum Control { + REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } private String code; @@ -39,11 +43,13 @@ public class Operation implements Serializable { private Type type; private int id; private Status status; + private Control control; private String receivedTimeStamp; private String createdTimeStamp; private boolean isEnabled; private Object payLoad; private String operationResponse; + private String activityId; @Override public boolean equals(Object o) { @@ -87,6 +93,11 @@ public class Operation implements Serializable { if (status != operation.status) { return false; } + + if(control != operation.control){ + return false; + } + if (type != operation.type) { return false; } @@ -151,6 +162,14 @@ public class Operation implements Serializable { this.status = status; } + public Control getControl() { + return control; + } + + public void setControl(Control control) { + this.control = control; + } + public String getReceivedTimeStamp() { return receivedTimeStamp; } @@ -191,6 +210,14 @@ public class Operation implements Serializable { this.operationResponse = operationResponse; } + public String getActivityId() { + return activityId; + } + + public void setActivityId(String activityId) { + this.activityId = activityId; + } + @Override public String toString() { return "Operation{" + @@ -198,6 +225,7 @@ public class Operation implements Serializable { ", type=" + type + ", id=" + id + ", status=" + status + + ", control=" + control + ", receivedTimeStamp='" + receivedTimeStamp + '\'' + ", createdTimeStamp='" + createdTimeStamp + '\'' + ", isEnabled=" + isEnabled + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index 1d86b618f8e..26ed93bddb0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -85,4 +85,6 @@ public interface OperationManager { Operation getOperation(int operationId) throws OperationManagementException; + Operation getOperationByActivityId(String activity) throws OperationManagementException; + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index ad4a8e64ee2..379ca8c3d6c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -75,4 +75,9 @@ public final class DeviceManagementConstants { public static final String DOWNLOAD_URL = "download-url"; } + public static final class OperationAttributes { + private OperationAttributes() {throw new AssertionError(); } + public static final String ACTIVITY = "ACTIVITY_"; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index cd901b22385..3b392cc8200 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -50,8 +50,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " + "VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " + "EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " + - "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setInt(1, deviceInfo.getDeviceId()); stmt.setString(2, deviceInfo.getDeviceModel()); @@ -68,6 +68,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setDouble(13, deviceInfo.getTotalRAMMemory()); stmt.setDouble(14, deviceInfo.getAvailableRAMMemory()); stmt.setBoolean(15, deviceInfo.isPluggedIn()); + stmt.setLong(16, System.currentTimeMillis()); stmt.execute(); @@ -144,6 +145,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); } deviceInfo.setDeviceId(deviceId); @@ -226,7 +228,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { try { conn = this.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " + - "STREET2, CITY, ZIP, STATE, COUNTRY) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "STREET2, CITY, ZIP, STATE, COUNTRY, UPDATE_TIMESTAMP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setInt(1, deviceLocation.getDeviceId()); stmt.setDouble(2, deviceLocation.getLatitude()); stmt.setDouble(3, deviceLocation.getLongitude()); @@ -236,6 +238,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(7, deviceLocation.getZip()); stmt.setString(8, deviceLocation.getState()); stmt.setString(9, deviceLocation.getCountry()); + stmt.setLong(10, System.currentTimeMillis()); stmt.execute(); } catch (SQLException e) { throw new DeviceDetailsMgtDAOException("Error occurred while adding the device location to database.", e); @@ -268,6 +271,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { location.setZip(rs.getString("ZIP")); location.setState(rs.getString("STATE")); location.setCountry(rs.getString("COUNTRY")); + location.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); } location.setDeviceId(deviceId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java index 28c43cd6bdf..bc132a9b209 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java @@ -34,4 +34,8 @@ public class CommandOperation extends Operation { return Type.COMMAND; } + public Control getControl(){ + return Control.NO_REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java index bd4fc50ae60..c2be65a3724 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java @@ -77,4 +77,9 @@ public class ConfigOperation extends Operation { return Type.CONFIG; } + + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java index 37e0736eb50..360deb868ae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -18,8 +18,6 @@ */ package org.wso2.carbon.device.mgt.core.dto.operation.mgt; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Properties; @@ -30,7 +28,11 @@ public class Operation implements Serializable { } public enum Status { - IN_PROGRESS, PENDING, COMPLETED, ERROR + IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED + } + + public enum Control { + REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } private String code; @@ -38,6 +40,7 @@ public class Operation implements Serializable { private Type type; private int id; private Status status; + private Control control; private String receivedTimeStamp; private String createdTimeStamp; private boolean isEnabled; @@ -84,6 +87,14 @@ public class Operation implements Serializable { this.status = status; } + public Control getControl() { + return control; + } + + public void setControl(Control control) { + this.control = control; + } + public String getReceivedTimeStamp() { return receivedTimeStamp; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java index f1d97a0dd01..dc6ae4dd785 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java @@ -31,4 +31,8 @@ public class PolicyOperation extends Operation{ private List profileOperations; + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java index 61bb18d6988..107cf091d70 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java @@ -26,4 +26,9 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Type.PROFILE; } + + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java index 28a0a2345db..7051d72f51c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java @@ -72,8 +72,8 @@ public class DeviceTaskManagerServiceComponent { @SuppressWarnings("unused") protected void deactivate(ComponentContext componentContext) { try { - DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl(); - taskManagerService.stopTask(); +// DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl(); +// taskManagerService.stopTask(); } catch (Throwable e) { log.error("Error occurred while destroying the device details retrieving task manager service.", e); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java index 852142c1b87..3a9ecefca33 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java @@ -35,5 +35,8 @@ public class CommandOperation extends Operation { public Type getType() { return Type.COMMAND; } + public Control getControl(){ + return Control.NO_REPEAT; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java index 83cfd0e6127..69d8aafc4a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -78,4 +78,8 @@ public class ConfigOperation extends Operation { return Type.CONFIG; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 265dd02f8c1..9e156618b68 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -109,6 +109,12 @@ public class OperationManagerImpl implements OperationManager { OperationDAOUtil.convertOperation(operation); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); for (EnrolmentInfo enrolmentInfo : enrolments) { + if(operationDto.getControl() == + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT){ + operationDAO.updateEnrollmentOperationsStatus(enrolmentInfo.getId(), operationDto.getCode(), + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED); + } operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId()); } OperationManagementDAOFactory.commitTransaction(); @@ -613,7 +619,7 @@ public class OperationManagerImpl implements OperationManager { public Operation getOperation(int operationId) throws OperationManagementException { Operation operation; try { - OperationManagementDAOFactory.getConnection(); + OperationManagementDAOFactory.openConnection(); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. getOperation(operationId); if (dtoOperation == null) { @@ -648,6 +654,17 @@ public class OperationManagerImpl implements OperationManager { return operation; } + @Override + public Operation getOperationByActivityId(String activity) throws OperationManagementException { + // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. + int operationId = Integer.parseInt( + activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); + if(operationId == 0){ + throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); + } + return this.getOperation(operationId); + } + private OperationDAO lookupOperationDAO(Operation operation) { if (operation instanceof CommandOperation) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java index 0740728be0d..6b36492a83a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java @@ -33,4 +33,8 @@ public class PolicyOperation extends Operation { this.profileOperations = profileOperations; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java index 6c9abbed4c4..f984fdfb0c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java @@ -26,4 +26,8 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Type.PROFILE; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index c24887d1bfd..92349538299 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -52,6 +52,9 @@ public interface OperationDAO { void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status) throws OperationManagementDAOException; + void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, + Operation.Status newStatus) throws OperationManagementDAOException; + void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index b866285ff01..592be91c71f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -105,6 +105,41 @@ public class GenericOperationDAOImpl implements OperationDAO { } } + @Override + public void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, + Operation.Status newStatus) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + String query = "SELECT EOM.ID FROM DM_ENROLMENT_OP_MAPPING AS EOM INNER JOIN DM_OPERATION DM " + + "ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? " + + "AND EOM.STATUS = ?;"; + stmt = connection.prepareStatement(query); + stmt.setInt(1, enrolmentId); + stmt.setString(2, operationCode); + stmt.setString(3, existingStatus.toString()); + // This will return only one result always. + rs = stmt.executeQuery(); + int id = 0; + while (rs.next()){ + id = rs.getInt("ID"); + } + if (id != 0){ + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS = ? WHERE ID = ?"); + stmt.setString(1, newStatus.toString()); + stmt.setInt(2, id); + stmt.executeUpdate(); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while update device mapping operation status " + + "metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt); + } + } + @Override public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 44a93761a7d..6625ceab894 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.util; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*; public class OperationDAOUtil { @@ -94,6 +95,8 @@ public class OperationDAOUtil { operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); operation.setEnabled(dtoOperation.isEnabled()); operation.setProperties(dtoOperation.getProperties()); + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); + return operation; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java index 88affab4772..4c7058be020 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java @@ -28,4 +28,6 @@ import java.util.List; public interface Processor { List execute(SearchContext searchContext) throws SearchMgtException; + + List getUpdatedDevices(long epochTime) throws SearchMgtException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java index db028edc192..c3e912fcb83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java @@ -38,4 +38,6 @@ public interface QueryBuilder { List processORProperties(List conditions) throws InvalidOperatorException; + String processUpdatedDevices(long epochTime) throws InvalidOperatorException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java index ad78ca171fa..554ecfc0f97 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java @@ -27,5 +27,7 @@ import java.util.List; public interface SearchManagerService { List search(SearchContext searchContext) throws SearchMgtException; + + List getUpdated(long epochTime) throws SearchMgtException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java index e80da381675..ac8f670b7ae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java @@ -34,7 +34,9 @@ import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import java.sql.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SearchDAOImpl implements SearchDAO { @@ -52,61 +54,62 @@ public class SearchDAOImpl implements SearchDAO { PreparedStatement stmt = null; ResultSet rs; List devices = new ArrayList<>(); + Map devs = new HashMap<>(); try { conn = this.getConnection(); stmt = conn.prepareStatement(query); rs = stmt.executeQuery(); while (rs.next()) { - - Device device = new Device(); - device.setId(rs.getInt("ID")); - device.setDescription(rs.getString("DESCRIPTION")); - device.setName("NAME"); - device.setType(rs.getString("DEVICE_TYPE_NAME")); - device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceIdentifier identifier = new DeviceIdentifier(); - identifier.setType(rs.getString("DEVICE_TYPE_NAME")); - identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setDeviceId(rs.getInt("ID")); - deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); - deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); - deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); - deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); - deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); - deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setIMEI(rs.getString("IMEI")); -// deviceInfo.setIMSI(rs.getString("IMSI")); - deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); -// deviceInfo.setOperator(rs.getString("OPERATOR")); - deviceInfo.setOsVersion(rs.getString("OS_VERSION")); - deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); - deviceInfo.setSsid(rs.getString("SSID")); - deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); - deviceInfo.setVendor(rs.getString("VENDOR")); - - DeviceLocation deviceLocation = new DeviceLocation(); - deviceLocation.setLatitude(rs.getDouble("LATITUDE")); - deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); - deviceLocation.setStreet1(rs.getString("STREET1")); - deviceLocation.setStreet2(rs.getString("STREET2")); - deviceLocation.setCity(rs.getString("CITY")); - deviceLocation.setState(rs.getString("STATE")); - deviceLocation.setZip(rs.getString("ZIP")); - deviceLocation.setCountry(rs.getString("COUNTRY")); - deviceLocation.setDeviceId(rs.getInt("ID")); - - DeviceWrapper wrapper = new DeviceWrapper(); - wrapper.setDevice(device); - wrapper.setDeviceInfo(deviceInfo); - wrapper.setDeviceLocation(deviceLocation); - wrapper.setDeviceIdentifier(identifier); - devices.add(wrapper); + if(!devs.containsKey(rs.getInt("ID"))) { + Device device = new Device(); + device.setId(rs.getInt("ID")); + device.setDescription(rs.getString("DESCRIPTION")); + device.setName("NAME"); + device.setType(rs.getString("DEVICE_TYPE_NAME")); + device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setType(rs.getString("DEVICE_TYPE_NAME")); + identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setDeviceId(rs.getInt("ID")); + deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); + deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); + deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); + deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); + deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); + deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setOsVersion(rs.getString("OS_VERSION")); + deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); + deviceInfo.setSsid(rs.getString("SSID")); + deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); + deviceInfo.setVendor(rs.getString("VENDOR")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); + + DeviceLocation deviceLocation = new DeviceLocation(); + deviceLocation.setLatitude(rs.getDouble("LATITUDE")); + deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); + deviceLocation.setStreet1(rs.getString("STREET1")); + deviceLocation.setStreet2(rs.getString("STREET2")); + deviceLocation.setCity(rs.getString("CITY")); + deviceLocation.setState(rs.getString("STATE")); + deviceLocation.setZip(rs.getString("ZIP")); + deviceLocation.setCountry(rs.getString("COUNTRY")); + deviceLocation.setDeviceId(rs.getInt("ID")); + deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); + + DeviceWrapper wrapper = new DeviceWrapper(); + wrapper.setDevice(device); + wrapper.setDeviceInfo(deviceInfo); + wrapper.setDeviceLocation(deviceLocation); + wrapper.setDeviceIdentifier(identifier); + devices.add(wrapper); + devs.put(device.getId(), device.getId()); + } } } catch (SQLException e) { @@ -134,61 +137,63 @@ public class SearchDAOImpl implements SearchDAO { PreparedStatement stmt = null; ResultSet rs; List devices = new ArrayList<>(); + Map devs = new HashMap<>(); try { conn = this.getConnection(); stmt = conn.prepareStatement(query); rs = stmt.executeQuery(); while (rs.next()) { - - Device device = new Device(); - device.setId(rs.getInt("ID")); - device.setDescription(rs.getString("DESCRIPTION")); - device.setName(rs.getString("NAME")); - device.setType(rs.getString("DEVICE_TYPE_NAME")); - device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceIdentifier identifier = new DeviceIdentifier(); - identifier.setType(rs.getString("DEVICE_TYPE_NAME")); - identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setDeviceId(rs.getInt("ID")); - deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); - deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); - deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); - deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); - deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); - deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setIMEI(rs.getString("IMEI")); -// deviceInfo.setIMSI(rs.getString("IMSI")); - deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); -// deviceInfo.setOperator(rs.getString("OPERATOR")); - deviceInfo.setOsVersion(rs.getString("OS_VERSION")); - deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); - deviceInfo.setSsid(rs.getString("SSID")); - deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); - deviceInfo.setVendor(rs.getString("VENDOR")); - - DeviceLocation deviceLocation = new DeviceLocation(); - deviceLocation.setLatitude(rs.getDouble("LATITUDE")); - deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); - deviceLocation.setStreet1(rs.getString("STREET1")); - deviceLocation.setStreet2(rs.getString("STREET2")); - deviceLocation.setCity(rs.getString("CITY")); - deviceLocation.setState(rs.getString("STATE")); - deviceLocation.setZip(rs.getString("ZIP")); - deviceLocation.setCountry(rs.getString("COUNTRY")); - deviceLocation.setDeviceId(rs.getInt("ID")); - - DeviceWrapper wrapper = new DeviceWrapper(); - wrapper.setDevice(device); - wrapper.setDeviceInfo(deviceInfo); - wrapper.setDeviceLocation(deviceLocation); - wrapper.setDeviceIdentifier(identifier); - devices.add(wrapper); + if(!devs.containsKey(rs.getInt("ID"))) { + Device device = new Device(); + device.setId(rs.getInt("ID")); + device.setDescription(rs.getString("DESCRIPTION")); + device.setName(rs.getString("NAME")); + device.setType(rs.getString("DEVICE_TYPE_NAME")); + device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setType(rs.getString("DEVICE_TYPE_NAME")); + identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setDeviceId(rs.getInt("ID")); + deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); + deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); + deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); + deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); + deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); + deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setOsVersion(rs.getString("OS_VERSION")); + deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); + deviceInfo.setSsid(rs.getString("SSID")); + deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); + deviceInfo.setVendor(rs.getString("VENDOR")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); + + DeviceLocation deviceLocation = new DeviceLocation(); + deviceLocation.setLatitude(rs.getDouble("LATITUDE")); + deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); + deviceLocation.setStreet1(rs.getString("STREET1")); + deviceLocation.setStreet2(rs.getString("STREET2")); + deviceLocation.setCity(rs.getString("CITY")); + deviceLocation.setState(rs.getString("STATE")); + deviceLocation.setZip(rs.getString("ZIP")); + deviceLocation.setCountry(rs.getString("COUNTRY")); + deviceLocation.setDeviceId(rs.getInt("ID")); + deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); + + DeviceWrapper wrapper = new DeviceWrapper(); + wrapper.setDevice(device); + wrapper.setDeviceInfo(deviceInfo); + wrapper.setDeviceLocation(deviceLocation); + wrapper.setDeviceIdentifier(identifier); + + devices.add(wrapper); + devs.put(device.getId(), device.getId()); + } } } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java index 4a97f1fdbe6..55b377d4f57 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java @@ -94,6 +94,28 @@ public class ProcessorImpl implements Processor { return aggregator.aggregate(deviceWrappers); } + @Override + public List getUpdatedDevices(long epochTime) throws SearchMgtException { + + if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) { + epochTime = epochTime * 1000; + } + QueryBuilder queryBuilder = new QueryBuilderImpl(); + try { + String query = queryBuilder.processUpdatedDevices(epochTime); + DeviceManagementDAOFactory.openConnection(); + return searchDAO.searchDeviceDetailsTable(query); + } catch (InvalidOperatorException e) { + throw new SearchMgtException("Invalid operator was provided, so cannot execute the search.", e); + } catch (SQLException e) { + throw new SearchMgtException("Error occurred while managing database transactions.", e); + } catch (SearchDAOException e) { + throw new SearchMgtException("Error occurred while running the search operations for given time.", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + private List processANDSearch(List> deLists) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java index eaca48451f2..5864966f0c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java @@ -114,7 +114,7 @@ public class QueryBuilderImpl implements QueryBuilder { for (Condition con : conditions) { if (Utils.checkDeviceDetailsColumns(con.getKey())) { querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + - con.getOperator() + con.getValue(); + con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); } else if (Utils.checkDeviceLocationColumns(con.getKey())) { querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + con.getOperator() + con.getValue(); @@ -132,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder { for (Condition con : conditions) { if (Utils.checkDeviceDetailsColumns(con.getKey())) { querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + - con.getOperator() + con.getValue(); + con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); } else if (Utils.checkDeviceLocationColumns(con.getKey())) { querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + con.getOperator() + con.getValue(); @@ -158,6 +158,12 @@ public class QueryBuilderImpl implements QueryBuilder { return this.getQueryList(conditions); } + @Override + public String processUpdatedDevices(long epochTime) throws InvalidOperatorException { + return this.getGenericQueryPart() + " AND ( DD.UPDATE_TIMESTAMP > " + epochTime + + " OR DL.UPDATE_TIMESTAMP > " + epochTime + " )"; + } + private List getQueryList(List conditions) { List queryList = new ArrayList<>(); for (Condition con : conditions) { @@ -189,8 +195,9 @@ public class QueryBuilderImpl implements QueryBuilder { "DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + - "DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + - "DL.STATE, DL.COUNTRY FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " + + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP " + + "FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " + "DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -205,8 +212,9 @@ public class QueryBuilderImpl implements QueryBuilder { "DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + - "DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + - "DL.STATE, DL.COUNTRY, DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " + + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, " + + "DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " + "DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" + "DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java index 888f3edc36b..cc9a51d9191 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java @@ -40,5 +40,10 @@ public class SearchManagerServiceImpl implements SearchManagerService { public List search(SearchContext searchContext) throws SearchMgtException { return processor.execute(searchContext); } + + @Override + public List getUpdated(long epochTime) throws SearchMgtException { + return processor.getUpdatedDevices(epochTime); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java index bc69e76033c..3522228511f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java @@ -60,6 +60,41 @@ public class Utils { } + public static boolean checkColumnType(String column) { + + boolean bool = false; + + switch (column) { + case "deviceModel": + bool = true; + break; + case "vendor": + bool = true; + break; + case "osVersion": + bool = true; + break; + case "connectionType": + bool = true; + break; + case "ssid": + bool = true; + break; + default: bool =false; + break; + } + + return bool; + } + + public static String getConvertedValue(String column, String value) { + + if(checkColumnType(column)){ + return "\'" + value + "\'"; + } else return value; + + } + public static Map getDeviceDetailsColumnNames() { return genericColumnsMap; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 88bd74cdaa3..9d5e6b46d5c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -867,6 +867,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId); } + @Override + public Operation getOperationByActivityId(String activity) throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByActivityId(activity); + } + @Override public List getDevicesOfUser(String username) throws DeviceManagementException { List devices = new ArrayList<>(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java index 88acffe514c..93c15914ad4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java @@ -93,62 +93,91 @@ public class SearchDevice extends BaseDeviceManagementTest { } -// @Test -// public void doValidLocationSearch() throws Exception{ -// -// SearchContext context = new SearchContext(); -// List conditions = new ArrayList<>(); -// -// Condition cond = new Condition(); -// cond.setKey("LOCATION"); -// cond.setOperator("="); -// cond.setValue("Karan"); -// cond.setState(Condition.State.AND); -// conditions.add(cond); -// -// context.setConditions(conditions); -// -// SearchManagerService service = new SearchManagerServiceImpl(); -// List deviceWrappers = service.search(context); -// -// Gson gson = new Gson(); -// String bbbb = gson.toJson(deviceWrappers); -// log.info("Valid Search " + bbbb); -// -// -// for (DeviceWrapper dw : deviceWrappers) { -// log.debug(dw.getDevice().getDescription()); -// log.debug(dw.getDevice().getDeviceIdentifier()); -// } -// } -// -// @Test -// public void doInvalidLocationSearch() throws Exception{ -// -// SearchContext context = new SearchContext(); -// List conditions = new ArrayList<>(); -// -// Condition cond = new Condition(); -// cond.setKey("LOCATION"); -// cond.setOperator("="); -// cond.setValue("Colombo"); -// cond.setState(Condition.State.AND); -// conditions.add(cond); -// -// context.setConditions(conditions); -// -// SearchManagerService service = new SearchManagerServiceImpl(); -// List deviceWrappers = service.search(context); -// -// Gson gson = new Gson(); -// String bbbb = gson.toJson(deviceWrappers); -// log.info("Invalid Search " + bbbb); -// -// -// for (DeviceWrapper dw : deviceWrappers) { -// log.debug(dw.getDevice().getDescription()); -// log.debug(dw.getDevice().getDeviceIdentifier()); -// } -// } + @Test + public void doValidLocationSearch() throws Exception{ + + SearchContext context = new SearchContext(); + List conditions = new ArrayList<>(); + + Condition cond = new Condition(); + cond.setKey("LOCATION"); + cond.setOperator("="); + cond.setValue("Karan"); + cond.setState(Condition.State.AND); + conditions.add(cond); + + context.setConditions(conditions); + + SearchManagerService service = new SearchManagerServiceImpl(); + List deviceWrappers = service.search(context); + + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info("Valid Search " + bbbb); + + + for (DeviceWrapper dw : deviceWrappers) { + log.debug(dw.getDevice().getDescription()); + log.debug(dw.getDevice().getDeviceIdentifier()); + } + } + + @Test + public void doInvalidLocationSearch() throws Exception{ + + SearchContext context = new SearchContext(); + List conditions = new ArrayList<>(); + + Condition cond = new Condition(); + cond.setKey("LOCATION"); + cond.setOperator("="); + cond.setValue("Colombo"); + cond.setState(Condition.State.AND); + conditions.add(cond); + + context.setConditions(conditions); + + SearchManagerService service = new SearchManagerServiceImpl(); + List deviceWrappers = service.search(context); + + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info("Invalid Search " + bbbb); + + + for (DeviceWrapper dw : deviceWrappers) { + log.debug(dw.getDevice().getDescription()); + log.debug(dw.getDevice().getDeviceIdentifier()); + } + } + + @Test + public void doStringSearch() throws Exception{ + + SearchContext context = new SearchContext(); + List conditions = new ArrayList<>(); + + Condition cond = new Condition(); + cond.setKey("deviceModel"); + cond.setOperator("="); + cond.setValue("SM-T520"); + cond.setState(Condition.State.AND); + conditions.add(cond); + + context.setConditions(conditions); + + SearchManagerService service = new SearchManagerServiceImpl(); + List deviceWrappers = service.search(context); + + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info("Invalid Search " + bbbb); + + + for (DeviceWrapper dw : deviceWrappers) { + log.debug(dw.getDevice().getDescription()); + log.debug(dw.getDevice().getDeviceIdentifier()); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 23a88af804a..7d6159a87f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag index e64ad14d168..4d5bd9973f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag @@ -80,4 +80,8 @@ if (!user) { } } +if (result) { + print(result); +} + %> \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs index 2e9690071bd..259daf255fb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs @@ -37,7 +37,7 @@
{{#if groupCount}} -
+
@@ -270,9 +270,6 @@ {{/zone}} {{#zone "bottomJs"}} - {{#if groupCount}} {{js "js/listing.js"}} {{/if}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index a2d95a3c4e8..9d4b89a8f0e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -97,48 +97,97 @@ function toTitleCase(str) { function loadGroups() { var groupListing = $("#group-listing"); - var groupListingSrc = groupListing.attr("src"); var currentUser = groupListing.data("currentUser"); - $.template("group-listing", groupListingSrc, function (template) { - - var successCallback = function (data) { - data = JSON.parse(data); - var viewModel = {}; - viewModel.groups = data.data; - $('#group-grid').removeClass('hidden'); - var content = template(viewModel); - $("#ast-container").html(content); - - /* - * On group checkbox select add parent selected style class - */ - $(groupCheckbox).click(function () { - addGroupSelectedClass(this); - }); - attachEvents(); + var serviceURL; + if ($.hasPermission("LIST_ALL_GROUPS")) { + serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000"; + } else if ($.hasPermission("LIST_GROUPS")) { + //Get authenticated users groups + serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000"; + } else { + $("#loading-content").remove(); + $('#device-table').addClass('hidden'); + $('#device-listing-status-msg').text('Permission denied.'); + $("#device-listing-status").removeClass(' hidden'); + return; + } - $('#group-grid').datatables_extended(); + $('#group-grid').datatables_extended ({ + serverSide: true, + processing: false, + searching: true, + ordering: false, + filter: false, + pageLength : 16, + ajax: { url : '/devicemgt/api/groups', data : {url : serviceURL}, + dataSrc: function ( json ) { + $('#group-grid').removeClass('hidden'); + var $list = $("#group-listing :input[type='search']"); + $list.each(function(){ + $(this).addClass("hidden"); + }); + return json.data; + } + }, + columnDefs: [ + { targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) { + return '
'; + }}, + { targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) { + return '

' + name + '

'; + }}, + { targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'}, + { targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' , + render: function ( id, type, row, meta ) { + var html; + html = '' + + '' + + ''; + + html += '' + + '' + + ''; + + html += ''; + + html += '' + + ''; + + html += '' + + ''; + + return html; + }} + ], + "createdRow": function( row, data, dataIndex ) { + $(row).attr('data-type', 'selectable'); + $(row).attr('data-groupid', data.id); + $.each($('td', row), function (colIndex) { + switch(colIndex) { + case 1: + $(this).attr('data-grid-label', "Name"); + $(this).attr('data-search', data.name); + $(this).attr('data-display', data.name); + break; + case 2: + $(this).attr('data-grid-label', "Owner"); + $(this).attr('data-search', data.owner); + $(this).attr('data-display', data.owner); + break; + } + }); + }, + "fnDrawCallback": function( oSettings ) { $(".icon .text").res_text(0.2); - }; - - var serviceURL; - if ($.hasPermission("LIST_ALL_GROUPS")) { - serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000"; - } else if ($.hasPermission("LIST_GROUPS")) { - //Get authenticated users groups - serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000"; - } else { - $("#loading-content").remove(); - $('#device-table').addClass('hidden'); - $('#device-listing-status-msg').text('Permission denied.'); - $("#device-listing-status").removeClass(' hidden'); - return; + attachEvents(); } - - invokerUtil.get(serviceURL, successCallback, function (message) { - displayErrors(message.content); - }); - + }); + $(groupCheckbox).click(function () { + addGroupSelectedClass(this); }); } diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index a40e30b63ff..c08f1274042 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -88,6 +88,7 @@ org.wso2.carbon.device.mgt.* org.wso2.carbon.identity.application.common.model, org.wso2.carbon.identity.oauth.callback, + org.wso2.carbon.identity.oauth.common, org.wso2.carbon.identity.oauth2, org.wso2.carbon.identity.oauth2.model, org.wso2.carbon.identity.oauth2.validators, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 23a88af804a..7d6159a87f0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index 879efecd805..6b40e2022b8 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -60,7 +60,7 @@ public class CertificateAuthenticator implements WebappAuthenticator { if (request.getHeader(MUTUAL_AUTH_HEADER) != null) { X509Certificate[] clientCertificate = (X509Certificate[]) request. getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE); - if (clientCertificate[0] != null) { + if (clientCertificate != null && clientCertificate[0] != null) { CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance(). getCertificateManagementService().verifyPEMSignature(clientCertificate[0]); if (certificateResponse == null) { @@ -86,6 +86,9 @@ public class CertificateAuthenticator implements WebappAuthenticator { "but the serial number is missing in the database."); } + } else { + authenticationInfo.setStatus(Status.FAILURE); + authenticationInfo.setMessage("No client certificate is present"); } } else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) { diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml index 5baa363c69f..d32ff3e50a2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml @@ -29,7 +29,7 @@ Ex - Multiple Receiver Groups with two receivers each {tcp://localhost:7612/,tcp://localhost:7613},{tcp://localhost:7712/,tcp://localhost:7713/} --> - true + falsetcp://localhost:7611adminadmin diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 3067b300304..deabce47563 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 69989f51689..6101c9e5a88 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -341,6 +341,24 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); +CREATE TABLE DM_DEVICE_GROUP_POLICY ( + ID INT NOT NULL IDENTITY, + DEVICE_GROUP_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) + REFERENCES DM_POLICY (ID , ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + CREATE TABLE DM_APPLICATION ( ID INTEGER IDENTITY NOT NULL, NAME VARCHAR(150) NOT NULL, @@ -390,13 +408,12 @@ CREATE TABLE DM_NOTIFICATION ( DROP TABLE IF EXISTS DM_DEVICE_INFO; -CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( - ID INTEGER AUTO_INCREMENT NOT NULL, - DEVICE_ID INTEGER NULL, +CREATE TABLE DM_DEVICE_INFO ( + ID INTEGER IDENTITY NOT NULL, + DEVICE_ID INT NULL, KEY_FIELD VARCHAR(45) NULL, VALUE_FIELD VARCHAR(100) NULL, PRIMARY KEY (ID), - INDEX DM_DEVICE_INFO_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT DM_DEVICE_INFO_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) @@ -404,23 +421,23 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( ON UPDATE NO ACTION ); - +CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC); DROP TABLE IF EXISTS DM_DEVICE_LOCATION; -CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( - ID INTEGER AUTO_INCREMENT NOT NULL, - DEVICE_ID INTEGER NULL, - LATITUDE DOUBLE NULL, - LONGITUDE DOUBLE NULL, +CREATE TABLE DM_DEVICE_LOCATION ( + ID INTEGER IDENTITY NOT NULL, + DEVICE_ID INT NULL, + LATITUDE FLOAT NULL, + LONGITUDE FLOAT NULL, STREET1 VARCHAR(45) NULL, STREET2 VARCHAR(45) NULL, CITY VARCHAR(45) NULL, ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), - INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) @@ -428,11 +445,12 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ON UPDATE NO ACTION ); +CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); -DROP TABLE IF EXISTS DM_DEVICE_DETAIL ; +DROP TABLE IF EXISTS DM_DEVICE_DETAIL; -CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( - ID INT NOT NULL AUTO_INCREMENT, +CREATE TABLE DM_DEVICE_DETAIL ( + ID INT NOT NULL IDENTITY, DEVICE_ID INT NOT NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, @@ -447,9 +465,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CPU_USAGE DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, - PLUGGED_IN INT(1) NULL, + PLUGGED_IN INT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), - INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) @@ -457,3 +475,5 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ON UPDATE NO ACTION ); +CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 066e59c8c2a..7d3eada22ec 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -482,6 +482,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT DM_DEVICE_LOCATION_DEVICE @@ -513,6 +514,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index e47cd114401..fa9ac2e783e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -568,6 +568,34 @@ WHEN (NEW.ID IS NULL) END; / + +CREATE TABLE DM_DEVICE_GROUP_POLICY ( + ID NUMBER(10) NOT NULL, + DEVICE_GROUP_ID NUMBER(10) NOT NULL, + POLICY_ID NUMBER(10) NOT NULL, + TENANT_ID NUMBER(10) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + , + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) + REFERENCES DM_POLICY (ID , ID) +) ; + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr + BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW + WHEN (NEW.ID IS NULL) +BEGIN + SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ + + CREATE TABLE DM_APPLICATION ( ID NUMBER(10) NOT NULL, NAME VARCHAR2(150) NOT NULL, @@ -714,6 +742,7 @@ CREATE TABLE DM_DEVICE_LOCATION ( ZIP VARCHAR2(10) NULL, STATE VARCHAR2(45) NULL, COUNTRY VARCHAR2(45) NULL, + UPDATE_TIMESTAMP NUMBER(19) NOT NULL, PRIMARY KEY (ID) , CONSTRAINT DM_DEVICE_LOCATION_DEVICE @@ -751,23 +780,22 @@ CREATE TABLE DM_DEVICE_DETAIL ( VENDOR VARCHAR2(45) NULL, OS_VERSION VARCHAR2(45) NULL, BATTERY_LEVEL NUMBER(4) NULL, - INTERNAL_TOTAL_MEMORY NUMBER(30) NULL, - INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, - EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL, - EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, + INTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL, + EXTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL, CONNECTION_TYPE VARCHAR2(10) NULL, SSID VARCHAR2(45) NULL, CPU_USAGE NUMBER(5) NULL, - TOTAL_RAM_MEMORY NUMBER(30) NULL, - AVAILABLE_RAM_MEMORY NUMBER(30) NULL, + TOTAL_RAM_MEMORY NUMBER(30,3) NULL, + AVAILABLE_RAM_MEMORY NUMBER(30,3) NULL, PLUGGED_IN NUMBER(10) NULL, - PRIMARY KEY (ID) - , + UPDATE_TIMESTAMP NUMBER(19) NOT NULL, + PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) - ) - ; +); -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1; @@ -782,4 +810,3 @@ END; CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 431fe0e40a3..5fcf3f99ac9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -292,6 +292,26 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); +CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq; + +CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( + ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_GROUP_POLICY_seq'), + DEVICE_GROUP_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) + REFERENCES DM_POLICY (ID , ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, @@ -379,6 +399,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID) , CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -390,6 +411,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); +CREATE SEQUENCE DM_DEVICE_DETAIL_seq; + CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'), DEVICE_ID INT NOT NULL, @@ -407,7 +430,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT NULL, - PRIMARY KEY (ID) , + UPDATE_TIMESTAMP BIGINT NOT NULL, + PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID)