revert-70aa11f8
hasuniea 9 years ago
commit 5f8a41eb12

@ -58,6 +58,8 @@
<Bundle-Description>Device Management Dashboard Analytics Bundle</Bundle-Description> <Bundle-Description>Device Management Dashboard Analytics Bundle</Bundle-Description>
<Private-Package> <Private-Package>
org.wso2.carbon.device.mgt.analytics.dashboard.dao, 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 org.wso2.carbon.device.mgt.analytics.dashboard.internal
</Private-Package> </Private-Package>
<Export-Package> <Export-Package>

@ -30,58 +30,61 @@ import java.util.Map;
public interface GadgetDataService { public interface GadgetDataService {
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getTotalDeviceCount(); int getTotalDeviceCount() throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getActiveDeviceCount(); int getActiveDeviceCount() throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getInactiveDeviceCount(); int getInactiveDeviceCount() throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getRemovedDeviceCount(); int getRemovedDeviceCount() throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getNonCompliantDeviceCount(); int getNonCompliantDeviceCount() throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getUnmonitoredDeviceCount(); int getUnmonitoredDeviceCount() throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest); PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getDeviceCount(Map<String, Object> filters); int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters); int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters); Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters); Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters); Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters); Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getDevicesWithDetails(Map<String, Object> filters, PaginationRequest paginationRequest); PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters, PaginationRequest paginationRequest); Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters); List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceException;
@SuppressWarnings("unused") @SuppressWarnings("unused")
List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters); Map<String, Object> filters) throws GadgetDataServiceException;
} }

@ -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;
}
}

@ -18,11 +18,11 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao; 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 { public class GadgetDataServiceDAOException extends Exception {
private String errorMessage; private String errorMessage;
private static final long serialVersionUID = 2021891706072918864L; private static final long serialVersionUID = 2021891706072918864L;
@ -43,6 +43,7 @@ public class GadgetDataServiceDAOException extends Exception {
* @param errorMessage Specific error message. * @param errorMessage Specific error message.
* @param cause Cause of this exception. * @param cause Cause of this exception.
*/ */
@SuppressWarnings("unused")
public GadgetDataServiceDAOException(String errorMessage, Throwable cause) { public GadgetDataServiceDAOException(String errorMessage, Throwable cause) {
super(errorMessage, cause); super(errorMessage, cause);
setErrorMessage(errorMessage); setErrorMessage(errorMessage);
@ -53,6 +54,7 @@ public class GadgetDataServiceDAOException extends Exception {
* *
* @param errorMessage Specific error message. * @param errorMessage Specific error message.
*/ */
@SuppressWarnings("unused")
public GadgetDataServiceDAOException(String errorMessage) { public GadgetDataServiceDAOException(String errorMessage) {
super(errorMessage); super(errorMessage);
setErrorMessage(errorMessage); setErrorMessage(errorMessage);
@ -63,10 +65,12 @@ public class GadgetDataServiceDAOException extends Exception {
* *
* @param cause Cause of this exception. * @param cause Cause of this exception.
*/ */
@SuppressWarnings("unused")
public GadgetDataServiceDAOException(Throwable cause) { public GadgetDataServiceDAOException(Throwable cause) {
super(cause); super(cause);
} }
@SuppressWarnings("unused")
public String getErrorMessage() { public String getErrorMessage() {
return errorMessage; return errorMessage;
} }
@ -74,4 +78,5 @@ public class GadgetDataServiceDAOException extends Exception {
public void setErrorMessage(String errorMessage) { public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
} }
} }

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
@ -33,6 +34,7 @@ import java.util.List;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class GadgetDataServiceDAOFactory { public class GadgetDataServiceDAOFactory {
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOFactory.class); private static final Log log = LogFactory.getLog(GadgetDataServiceDAOFactory.class);
private static DataSource dataSource; private static DataSource dataSource;
private static String databaseEngine; private static String databaseEngine;
@ -47,7 +49,7 @@ public class GadgetDataServiceDAOFactory {
try { try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) { } 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 { try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) { } 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(); Connection conn = currentConnection.get();
if (conn != null) { if (conn != null) {
throw new IllegalTransactionStateException("A transaction is already active within the context of " + throw new IllegalTransactionStateException("A transaction is already active within the context of " +
"this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
"transaction is already active is a sign of improper transaction handling"); "transaction is already active is a sign of improper transaction handling.");
} }
conn = dataSource.getConnection(); conn = dataSource.getConnection();
currentConnection.set(conn); currentConnection.set(conn);
@ -75,8 +77,8 @@ public class GadgetDataServiceDAOFactory {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn == null) { if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " + "This might have ideally been caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods"); "'beginTransaction'/'openConnection' methods.");
} }
return conn; return conn;
} }
@ -85,36 +87,35 @@ public class GadgetDataServiceDAOFactory {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn == null) { if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " + "This might have ideally been caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods"); "'beginTransaction'/'openConnection' methods.");
} }
try { try {
conn.close(); conn.close();
} catch (SQLException e) { } catch (SQLException e) {
log.warn("Error occurred while close the connection"); log.warn("Error occurred while close the connection.");
} }
currentConnection.remove(); currentConnection.remove();
} }
/** /**
* Resolve data source from the data source definition * Resolve data source from the data source definition.
* *
* @param config data source configuration * @param config data source configuration.
* @return data source resolved from the data source definition * @return data source resolved from the data source definition.
*/ */
private static DataSource resolveDataSource(DataSourceConfig config) { private static DataSource resolveDataSource(DataSourceConfig config) {
DataSource dataSource = null; DataSource dataSource = null;
if (config == null) { if (config == null) {
throw new RuntimeException( throw new RuntimeException(
"Device Management Repository data source configuration " + "is null and " + "Device Management Repository data source configuration " + "is null and " +
"thus, is not initialized"); "thus, is not initialized.");
} }
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
if (jndiConfig != null) { if (jndiConfig != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI " + log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition.");
"Lookup Definition");
} }
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties(); List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
if (jndiPropertyList != null) { if (jndiPropertyList != null) {

@ -16,11 +16,12 @@
* under the License. * 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.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.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; 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.List;
import java.util.Map; import java.util.Map;
class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@SuppressWarnings("unused")
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
@Override @Override
public int getTotalDeviceCount() throws GadgetDataServiceDAOException { public int getTotalDeviceCount() throws GadgetDataServiceDAOException {
@ -72,7 +71,15 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
@Override @Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1);
return this.getDeviceCount(filters);
}
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceDAOException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -82,7 +89,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
try { try {
con = this.getConnection(); con = this.getConnection();
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + 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 = con.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setInt(2, paginationRequest.getStartIndex()); stmt.setInt(2, paginationRequest.getStartIndex());
@ -112,7 +119,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -122,13 +130,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult; return paginationResult;
} }
@Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1);
return this.getDeviceCount(filters);
}
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException { public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
Connection con; Connection con;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -166,7 +167,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCount = rs.getInt("DEVICE_COUNT"); filteredDeviceCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -211,7 +213,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCount = rs.getInt("DEVICE_COUNT"); filteredDeviceCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -257,7 +261,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -304,7 +309,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -350,7 +356,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -398,7 +405,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -469,7 +478,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -485,7 +496,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>(); List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0; int totalRecordsCount = 0;
try { try {
@ -499,7 +509,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
} }
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " + 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); stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist // [2] appending filter column values, if exist
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
@ -523,7 +533,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
// fetching query results // fetching query results
Map<String, Object> filteredDeviceWithDetails;
while (rs.next()) { while (rs.next()) {
filteredDeviceWithDetails = new HashMap<>();
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
@ -545,7 +557,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
totalRecordsCount = rs.getInt("DEVICE_COUNT"); totalRecordsCount = rs.getInt("DEVICE_COUNT");
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -599,7 +613,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -612,13 +627,12 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>(); List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
try { try {
con = this.getConnection(); con = this.getConnection();
String sql; String sql;
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " + 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 // appending filters to support advanced filtering options
// [1] appending filter columns, if exist // [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) { if (filters != null && filters.size() > 0) {
@ -644,7 +658,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
// fetching query results // fetching query results
Map<String, Object> filteredDeviceWithDetails;
while (rs.next()) { while (rs.next()) {
filteredDeviceWithDetails = new HashMap<>();
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
@ -652,7 +668,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) { } 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 { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }

@ -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<String, Object> 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<String, Object> 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<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters)
throws GadgetDataServiceException {
Map<String, Integer> deviceCountsByPlatforms;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPlatforms(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by platforms.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
Map<String, Integer> featureNonCompliantDeviceCountsByPlatforms;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by platforms, non compliant by a particular feature.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDeviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters)
throws GadgetDataServiceException {
Map<String, Integer> deviceCountsByOwnershipTypes;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByOwnershipTypes(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by ownership types.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByOwnershipTypes;
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
Map<String, Integer> 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<String, Object> 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<String, Object> 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<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters)
throws GadgetDataServiceException {
List<Map<String, Object>> devicesWithDetails;
try {
GadgetDataServiceDAOFactory.openConnection();
devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return devicesWithDetails;
}
@Override
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
List<Map<String, Object>> featureNonCompliantDevicesWithDetails;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details, non compliant by feature.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDevicesWithDetails;
}
}

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.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.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
@ -39,6 +40,7 @@ import org.wso2.carbon.ndatasource.core.DataSourceService;
* unbind="unsetDataSourceService" * unbind="unsetDataSourceService"
*/ */
public class GadgetDataServiceComponent { public class GadgetDataServiceComponent {
private static final Log log = LogFactory.getLog(GadgetDataServiceComponent.class); private static final Log log = LogFactory.getLog(GadgetDataServiceComponent.class);
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
@ -56,10 +58,10 @@ public class GadgetDataServiceComponent {
componentContext.getBundleContext(). componentContext.getBundleContext().
registerService(GadgetDataService.class.getName(), new GadgetDataServiceImpl(), null); registerService(GadgetDataService.class.getName(), new GadgetDataServiceImpl(), null);
if (log.isDebugEnabled()) { 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) { } 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 //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
} }
} }

@ -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<String, Object> 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<String, Object> 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<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) {
Map<String, Integer> deviceCountsByPlatforms = null;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPlatforms(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) {
Map<String, Integer> 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<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) {
Map<String, Integer> deviceCountsByOwnershipTypes = null;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByOwnershipTypes(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByOwnershipTypes;
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) {
Map<String, Integer> 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<String, Object> 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<String, Object> 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<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) {
List<Map<String, Object>> devicesWithDetails = null;
try {
GadgetDataServiceDAOFactory.openConnection();
devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return devicesWithDetails;
}
@Override
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) {
List<Map<String, Object>> featureNonCompliantDevicesWithDetails = null;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDevicesWithDetails;
}
}

@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.common.device.details;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -51,6 +52,7 @@ public class DeviceInfo implements Serializable {
private Double totalRAMMemory; private Double totalRAMMemory;
private Double availableRAMMemory; private Double availableRAMMemory;
private boolean pluggedIn; private boolean pluggedIn;
private Date updatedTime;
private Map<String, String> deviceDetailsMap = new HashMap<>(); private Map<String, String> deviceDetailsMap = new HashMap<>();
@ -290,6 +292,17 @@ public class DeviceInfo implements Serializable {
this.pluggedIn = pluggedIn; 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<String, String> deviceDetailsMap) { public void setDeviceDetailsMap(Map<String, String> deviceDetailsMap) {
this.deviceDetailsMap = deviceDetailsMap; this.deviceDetailsMap = deviceDetailsMap;
} }

@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.common.device.details;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
public class DeviceLocation implements Serializable { public class DeviceLocation implements Serializable {
@ -39,6 +40,7 @@ public class DeviceLocation implements Serializable {
private String state; private String state;
private String zip; private String zip;
private String country; private String country;
private Date updatedTime;
public int getDeviceId() { public int getDeviceId() {
return deviceId; return deviceId;
@ -119,5 +121,16 @@ public class DeviceLocation implements Serializable {
public void setCountry(String country) { public void setCountry(String country) {
this.country = country; this.country = country;
} }
public Date getUpdatedTime() {
if(updatedTime.equals(null)){
updatedTime = new Date();
}
return updatedTime;
}
public void setUpdatedTime(Date updatedTime) {
this.updatedTime = updatedTime;
}
} }

@ -31,7 +31,11 @@ public class Operation implements Serializable {
} }
public enum Status { 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; private String code;
@ -39,11 +43,13 @@ public class Operation implements Serializable {
private Type type; private Type type;
private int id; private int id;
private Status status; private Status status;
private Control control;
private String receivedTimeStamp; private String receivedTimeStamp;
private String createdTimeStamp; private String createdTimeStamp;
private boolean isEnabled; private boolean isEnabled;
private Object payLoad; private Object payLoad;
private String operationResponse; private String operationResponse;
private String activityId;
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
@ -87,6 +93,11 @@ public class Operation implements Serializable {
if (status != operation.status) { if (status != operation.status) {
return false; return false;
} }
if(control != operation.control){
return false;
}
if (type != operation.type) { if (type != operation.type) {
return false; return false;
} }
@ -151,6 +162,14 @@ public class Operation implements Serializable {
this.status = status; this.status = status;
} }
public Control getControl() {
return control;
}
public void setControl(Control control) {
this.control = control;
}
public String getReceivedTimeStamp() { public String getReceivedTimeStamp() {
return receivedTimeStamp; return receivedTimeStamp;
} }
@ -191,6 +210,14 @@ public class Operation implements Serializable {
this.operationResponse = operationResponse; this.operationResponse = operationResponse;
} }
public String getActivityId() {
return activityId;
}
public void setActivityId(String activityId) {
this.activityId = activityId;
}
@Override @Override
public String toString() { public String toString() {
return "Operation{" + return "Operation{" +
@ -198,6 +225,7 @@ public class Operation implements Serializable {
", type=" + type + ", type=" + type +
", id=" + id + ", id=" + id +
", status=" + status + ", status=" + status +
", control=" + control +
", receivedTimeStamp='" + receivedTimeStamp + '\'' + ", receivedTimeStamp='" + receivedTimeStamp + '\'' +
", createdTimeStamp='" + createdTimeStamp + '\'' + ", createdTimeStamp='" + createdTimeStamp + '\'' +
", isEnabled=" + isEnabled + ", isEnabled=" + isEnabled +

@ -85,4 +85,6 @@ public interface OperationManager {
Operation getOperation(int operationId) throws OperationManagementException; Operation getOperation(int operationId) throws OperationManagementException;
Operation getOperationByActivityId(String activity) throws OperationManagementException;
} }

@ -75,4 +75,9 @@ public final class DeviceManagementConstants {
public static final String DOWNLOAD_URL = "download-url"; public static final String DOWNLOAD_URL = "download-url";
} }
public static final class OperationAttributes {
private OperationAttributes() {throw new AssertionError(); }
public static final String ACTIVITY = "ACTIVITY_";
}
} }

@ -50,8 +50,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " + stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " +
"VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " + "VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " +
"EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " + "EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " +
"SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " + "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setInt(1, deviceInfo.getDeviceId()); stmt.setInt(1, deviceInfo.getDeviceId());
stmt.setString(2, deviceInfo.getDeviceModel()); stmt.setString(2, deviceInfo.getDeviceModel());
@ -68,6 +68,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setDouble(13, deviceInfo.getTotalRAMMemory()); stmt.setDouble(13, deviceInfo.getTotalRAMMemory());
stmt.setDouble(14, deviceInfo.getAvailableRAMMemory()); stmt.setDouble(14, deviceInfo.getAvailableRAMMemory());
stmt.setBoolean(15, deviceInfo.isPluggedIn()); stmt.setBoolean(15, deviceInfo.isPluggedIn());
stmt.setLong(16, System.currentTimeMillis());
stmt.execute(); stmt.execute();
@ -144,6 +145,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
} }
deviceInfo.setDeviceId(deviceId); deviceInfo.setDeviceId(deviceId);
@ -226,7 +228,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " + 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.setInt(1, deviceLocation.getDeviceId());
stmt.setDouble(2, deviceLocation.getLatitude()); stmt.setDouble(2, deviceLocation.getLatitude());
stmt.setDouble(3, deviceLocation.getLongitude()); stmt.setDouble(3, deviceLocation.getLongitude());
@ -236,6 +238,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setString(7, deviceLocation.getZip()); stmt.setString(7, deviceLocation.getZip());
stmt.setString(8, deviceLocation.getState()); stmt.setString(8, deviceLocation.getState());
stmt.setString(9, deviceLocation.getCountry()); stmt.setString(9, deviceLocation.getCountry());
stmt.setLong(10, System.currentTimeMillis());
stmt.execute(); stmt.execute();
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceDetailsMgtDAOException("Error occurred while adding the device location to database.", 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.setZip(rs.getString("ZIP"));
location.setState(rs.getString("STATE")); location.setState(rs.getString("STATE"));
location.setCountry(rs.getString("COUNTRY")); location.setCountry(rs.getString("COUNTRY"));
location.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
} }
location.setDeviceId(deviceId); location.setDeviceId(deviceId);

@ -34,4 +34,8 @@ public class CommandOperation extends Operation {
return Type.COMMAND; return Type.COMMAND;
} }
public Control getControl(){
return Control.NO_REPEAT;
}
} }

@ -77,4 +77,9 @@ public class ConfigOperation extends Operation {
return Type.CONFIG; return Type.CONFIG;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -18,8 +18,6 @@
*/ */
package org.wso2.carbon.device.mgt.core.dto.operation.mgt; 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.io.Serializable;
import java.util.Properties; import java.util.Properties;
@ -30,7 +28,11 @@ public class Operation implements Serializable {
} }
public enum Status { 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; private String code;
@ -38,6 +40,7 @@ public class Operation implements Serializable {
private Type type; private Type type;
private int id; private int id;
private Status status; private Status status;
private Control control;
private String receivedTimeStamp; private String receivedTimeStamp;
private String createdTimeStamp; private String createdTimeStamp;
private boolean isEnabled; private boolean isEnabled;
@ -84,6 +87,14 @@ public class Operation implements Serializable {
this.status = status; this.status = status;
} }
public Control getControl() {
return control;
}
public void setControl(Control control) {
this.control = control;
}
public String getReceivedTimeStamp() { public String getReceivedTimeStamp() {
return receivedTimeStamp; return receivedTimeStamp;
} }

@ -31,4 +31,8 @@ public class PolicyOperation extends Operation{
private List<ProfileOperation> profileOperations; private List<ProfileOperation> profileOperations;
public Control getControl(){
return Control.REPEAT;
}
} }

@ -26,4 +26,9 @@ public class ProfileOperation extends ConfigOperation implements Serializable {
return Type.PROFILE; return Type.PROFILE;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -72,8 +72,8 @@ public class DeviceTaskManagerServiceComponent {
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected void deactivate(ComponentContext componentContext) { protected void deactivate(ComponentContext componentContext) {
try { try {
DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl(); // DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl();
taskManagerService.stopTask(); // taskManagerService.stopTask();
} catch (Throwable e) { } catch (Throwable e) {
log.error("Error occurred while destroying the device details retrieving task manager service.", e); log.error("Error occurred while destroying the device details retrieving task manager service.", e);
} }

@ -35,5 +35,8 @@ public class CommandOperation extends Operation {
public Type getType() { public Type getType() {
return Type.COMMAND; return Type.COMMAND;
} }
public Control getControl(){
return Control.NO_REPEAT;
}
} }

@ -78,4 +78,8 @@ public class ConfigOperation extends Operation {
return Type.CONFIG; return Type.CONFIG;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -109,6 +109,12 @@ public class OperationManagerImpl implements OperationManager {
OperationDAOUtil.convertOperation(operation); OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
for (EnrolmentInfo enrolmentInfo : enrolments) { 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()); operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
} }
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
@ -613,7 +619,7 @@ public class OperationManagerImpl implements OperationManager {
public Operation getOperation(int operationId) throws OperationManagementException { public Operation getOperation(int operationId) throws OperationManagementException {
Operation operation; Operation operation;
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getOperation(operationId); getOperation(operationId);
if (dtoOperation == null) { if (dtoOperation == null) {
@ -648,6 +654,17 @@ public class OperationManagerImpl implements OperationManager {
return operation; 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) { private OperationDAO lookupOperationDAO(Operation operation) {
if (operation instanceof CommandOperation) { if (operation instanceof CommandOperation) {

@ -33,4 +33,8 @@ public class PolicyOperation extends Operation {
this.profileOperations = profileOperations; this.profileOperations = profileOperations;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -26,4 +26,8 @@ public class ProfileOperation extends ConfigOperation implements Serializable {
return Type.PROFILE; return Type.PROFILE;
} }
public Control getControl(){
return Control.REPEAT;
}
} }

@ -52,6 +52,9 @@ public interface OperationDAO {
void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status) void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
throws OperationManagementDAOException; throws OperationManagementDAOException;
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
Operation.Status newStatus) throws OperationManagementDAOException;
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; throws OperationManagementDAOException;

@ -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 @Override
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException { throws OperationManagementDAOException {

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.util; 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.*; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*;
public class OperationDAOUtil { public class OperationDAOUtil {
@ -94,6 +95,8 @@ public class OperationDAOUtil {
operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp());
operation.setEnabled(dtoOperation.isEnabled()); operation.setEnabled(dtoOperation.isEnabled());
operation.setProperties(dtoOperation.getProperties()); operation.setProperties(dtoOperation.getProperties());
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId());
return operation; return operation;
} }

@ -28,4 +28,6 @@ import java.util.List;
public interface Processor { public interface Processor {
List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException; List<DeviceWrapper> execute(SearchContext searchContext) throws SearchMgtException;
List<DeviceWrapper> getUpdatedDevices(long epochTime) throws SearchMgtException;
} }

@ -38,4 +38,6 @@ public interface QueryBuilder {
List<String> processORProperties(List<Condition> conditions) throws InvalidOperatorException; List<String> processORProperties(List<Condition> conditions) throws InvalidOperatorException;
String processUpdatedDevices(long epochTime) throws InvalidOperatorException;
} }

@ -27,5 +27,7 @@ import java.util.List;
public interface SearchManagerService { public interface SearchManagerService {
List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException; List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException;
List<DeviceWrapper> getUpdated(long epochTime) throws SearchMgtException;
} }

@ -34,7 +34,9 @@ import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class SearchDAOImpl implements SearchDAO { public class SearchDAOImpl implements SearchDAO {
@ -52,61 +54,62 @@ public class SearchDAOImpl implements SearchDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>(); List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
if(!devs.containsKey(rs.getInt("ID"))) {
Device device = new Device(); Device device = new Device();
device.setId(rs.getInt("ID")); device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION")); device.setDescription(rs.getString("DESCRIPTION"));
device.setName("NAME"); device.setName("NAME");
device.setType(rs.getString("DEVICE_TYPE_NAME")); device.setType(rs.getString("DEVICE_TYPE_NAME"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
DeviceIdentifier identifier = new DeviceIdentifier(); DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setType(rs.getString("DEVICE_TYPE_NAME")); identifier.setType(rs.getString("DEVICE_TYPE_NAME"));
identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); identifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceId(rs.getInt("ID")); deviceInfo.setDeviceId(rs.getInt("ID"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
// deviceInfo.setIMEI(rs.getString("IMEI")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); deviceInfo.setSsid(rs.getString("SSID"));
// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); DeviceLocation deviceLocation = new DeviceLocation();
deviceInfo.setVendor(rs.getString("VENDOR")); deviceLocation.setLatitude(rs.getDouble("LATITUDE"));
deviceLocation.setLongitude(rs.getDouble("LONGITUDE"));
DeviceLocation deviceLocation = new DeviceLocation(); deviceLocation.setStreet1(rs.getString("STREET1"));
deviceLocation.setLatitude(rs.getDouble("LATITUDE")); deviceLocation.setStreet2(rs.getString("STREET2"));
deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); deviceLocation.setCity(rs.getString("CITY"));
deviceLocation.setStreet1(rs.getString("STREET1")); deviceLocation.setState(rs.getString("STATE"));
deviceLocation.setStreet2(rs.getString("STREET2")); deviceLocation.setZip(rs.getString("ZIP"));
deviceLocation.setCity(rs.getString("CITY")); deviceLocation.setCountry(rs.getString("COUNTRY"));
deviceLocation.setState(rs.getString("STATE")); deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setZip(rs.getString("ZIP")); deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
deviceLocation.setCountry(rs.getString("COUNTRY"));
deviceLocation.setDeviceId(rs.getInt("ID")); DeviceWrapper wrapper = new DeviceWrapper();
wrapper.setDevice(device);
DeviceWrapper wrapper = new DeviceWrapper(); wrapper.setDeviceInfo(deviceInfo);
wrapper.setDevice(device); wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceInfo(deviceInfo); wrapper.setDeviceIdentifier(identifier);
wrapper.setDeviceLocation(deviceLocation); devices.add(wrapper);
wrapper.setDeviceIdentifier(identifier); devs.put(device.getId(), device.getId());
devices.add(wrapper); }
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -134,61 +137,63 @@ public class SearchDAOImpl implements SearchDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs; ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>(); List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
if(!devs.containsKey(rs.getInt("ID"))) {
Device device = new Device(); Device device = new Device();
device.setId(rs.getInt("ID")); device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION")); device.setDescription(rs.getString("DESCRIPTION"));
device.setName(rs.getString("NAME")); device.setName(rs.getString("NAME"));
device.setType(rs.getString("DEVICE_TYPE_NAME")); device.setType(rs.getString("DEVICE_TYPE_NAME"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
DeviceIdentifier identifier = new DeviceIdentifier(); DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setType(rs.getString("DEVICE_TYPE_NAME")); identifier.setType(rs.getString("DEVICE_TYPE_NAME"));
identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); identifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
DeviceInfo deviceInfo = new DeviceInfo(); DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setDeviceId(rs.getInt("ID")); deviceInfo.setDeviceId(rs.getInt("ID"));
deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY"));
deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
// deviceInfo.setIMEI(rs.getString("IMEI")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); deviceInfo.setSsid(rs.getString("SSID"));
// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); DeviceLocation deviceLocation = new DeviceLocation();
deviceInfo.setVendor(rs.getString("VENDOR")); deviceLocation.setLatitude(rs.getDouble("LATITUDE"));
deviceLocation.setLongitude(rs.getDouble("LONGITUDE"));
DeviceLocation deviceLocation = new DeviceLocation(); deviceLocation.setStreet1(rs.getString("STREET1"));
deviceLocation.setLatitude(rs.getDouble("LATITUDE")); deviceLocation.setStreet2(rs.getString("STREET2"));
deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); deviceLocation.setCity(rs.getString("CITY"));
deviceLocation.setStreet1(rs.getString("STREET1")); deviceLocation.setState(rs.getString("STATE"));
deviceLocation.setStreet2(rs.getString("STREET2")); deviceLocation.setZip(rs.getString("ZIP"));
deviceLocation.setCity(rs.getString("CITY")); deviceLocation.setCountry(rs.getString("COUNTRY"));
deviceLocation.setState(rs.getString("STATE")); deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setZip(rs.getString("ZIP")); deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
deviceLocation.setCountry(rs.getString("COUNTRY"));
deviceLocation.setDeviceId(rs.getInt("ID")); DeviceWrapper wrapper = new DeviceWrapper();
wrapper.setDevice(device);
DeviceWrapper wrapper = new DeviceWrapper(); wrapper.setDeviceInfo(deviceInfo);
wrapper.setDevice(device); wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceInfo(deviceInfo); wrapper.setDeviceIdentifier(identifier);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier); devices.add(wrapper);
devices.add(wrapper); devs.put(device.getId(), device.getId());
}
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -94,6 +94,28 @@ public class ProcessorImpl implements Processor {
return aggregator.aggregate(deviceWrappers); return aggregator.aggregate(deviceWrappers);
} }
@Override
public List<DeviceWrapper> 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<DeviceWrapper> processANDSearch(List<List<DeviceWrapper>> deLists) { private List<DeviceWrapper> processANDSearch(List<List<DeviceWrapper>> deLists) {

@ -114,7 +114,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) { for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) { if (Utils.checkDeviceDetailsColumns(con.getKey())) {
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(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())) { } else if (Utils.checkDeviceLocationColumns(con.getKey())) {
querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue(); con.getOperator() + con.getValue();
@ -132,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) { for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) { if (Utils.checkDeviceDetailsColumns(con.getKey())) {
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(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())) { } else if (Utils.checkDeviceLocationColumns(con.getKey())) {
querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue(); con.getOperator() + con.getValue();
@ -158,6 +158,12 @@ public class QueryBuilderImpl implements QueryBuilder {
return this.getQueryList(conditions); 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<String> getQueryList(List<Condition> conditions) { private List<String> getQueryList(List<Condition> conditions) {
List<String> queryList = new ArrayList<>(); List<String> queryList = new ArrayList<>();
for (Condition con : conditions) { 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.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.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.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" + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, 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, " + "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 = " + "DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); 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.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.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.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" + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, 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, " + "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 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 = " + "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(); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

@ -40,5 +40,10 @@ public class SearchManagerServiceImpl implements SearchManagerService {
public List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException { public List<DeviceWrapper> search(SearchContext searchContext) throws SearchMgtException {
return processor.execute(searchContext); return processor.execute(searchContext);
} }
@Override
public List<DeviceWrapper> getUpdated(long epochTime) throws SearchMgtException {
return processor.getUpdatedDevices(epochTime);
}
} }

@ -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<String, String> getDeviceDetailsColumnNames() { public static Map<String, String> getDeviceDetailsColumnNames() {
return genericColumnsMap; return genericColumnsMap;
} }

@ -867,6 +867,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId); return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId);
} }
@Override
public Operation getOperationByActivityId(String activity) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByActivityId(activity);
}
@Override @Override
public List<Device> getDevicesOfUser(String username) throws DeviceManagementException { public List<Device> getDevicesOfUser(String username) throws DeviceManagementException {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();

@ -93,62 +93,91 @@ public class SearchDevice extends BaseDeviceManagementTest {
} }
// @Test @Test
// public void doValidLocationSearch() throws Exception{ public void doValidLocationSearch() throws Exception{
//
// SearchContext context = new SearchContext(); SearchContext context = new SearchContext();
// List<Condition> conditions = new ArrayList<>(); List<Condition> conditions = new ArrayList<>();
//
// Condition cond = new Condition(); Condition cond = new Condition();
// cond.setKey("LOCATION"); cond.setKey("LOCATION");
// cond.setOperator("="); cond.setOperator("=");
// cond.setValue("Karan"); cond.setValue("Karan");
// cond.setState(Condition.State.AND); cond.setState(Condition.State.AND);
// conditions.add(cond); conditions.add(cond);
//
// context.setConditions(conditions); context.setConditions(conditions);
//
// SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
// List<DeviceWrapper> deviceWrappers = service.search(context); List<DeviceWrapper> deviceWrappers = service.search(context);
//
// Gson gson = new Gson(); Gson gson = new Gson();
// String bbbb = gson.toJson(deviceWrappers); String bbbb = gson.toJson(deviceWrappers);
// log.info("Valid Search " + bbbb); log.info("Valid Search " + bbbb);
//
//
// for (DeviceWrapper dw : deviceWrappers) { for (DeviceWrapper dw : deviceWrappers) {
// log.debug(dw.getDevice().getDescription()); log.debug(dw.getDevice().getDescription());
// log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(dw.getDevice().getDeviceIdentifier());
// } }
// } }
//
// @Test @Test
// public void doInvalidLocationSearch() throws Exception{ public void doInvalidLocationSearch() throws Exception{
//
// SearchContext context = new SearchContext(); SearchContext context = new SearchContext();
// List<Condition> conditions = new ArrayList<>(); List<Condition> conditions = new ArrayList<>();
//
// Condition cond = new Condition(); Condition cond = new Condition();
// cond.setKey("LOCATION"); cond.setKey("LOCATION");
// cond.setOperator("="); cond.setOperator("=");
// cond.setValue("Colombo"); cond.setValue("Colombo");
// cond.setState(Condition.State.AND); cond.setState(Condition.State.AND);
// conditions.add(cond); conditions.add(cond);
//
// context.setConditions(conditions); context.setConditions(conditions);
//
// SearchManagerService service = new SearchManagerServiceImpl(); SearchManagerService service = new SearchManagerServiceImpl();
// List<DeviceWrapper> deviceWrappers = service.search(context); List<DeviceWrapper> deviceWrappers = service.search(context);
//
// Gson gson = new Gson(); Gson gson = new Gson();
// String bbbb = gson.toJson(deviceWrappers); String bbbb = gson.toJson(deviceWrappers);
// log.info("Invalid Search " + bbbb); log.info("Invalid Search " + bbbb);
//
//
// for (DeviceWrapper dw : deviceWrappers) { for (DeviceWrapper dw : deviceWrappers) {
// log.debug(dw.getDevice().getDescription()); log.debug(dw.getDevice().getDescription());
// log.debug(dw.getDevice().getDeviceIdentifier()); log.debug(dw.getDevice().getDeviceIdentifier());
// } }
// } }
@Test
public void doStringSearch() throws Exception{
SearchContext context = new SearchContext();
List<Condition> 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<DeviceWrapper> 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());
}
}
} }

@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL, ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)

@ -37,7 +37,7 @@
<div> <div>
<span id="permission" data-permission="{{permissions.list}}"></span> <span id="permission" data-permission="{{permissions.list}}"></span>
{{#if groupCount}} {{#if groupCount}}
<div class="container-fluid"> <div class="container-fluid" id="group-listing" data-current-user="{{currentUser.username}}">
<table class="table table-striped table-hover list-table display responsive nowrap data-table table-selectable grid-view" <table class="table table-striped table-hover list-table display responsive nowrap data-table table-selectable grid-view"
id="group-grid"> id="group-grid">
<thead> <thead>
@ -270,9 +270,6 @@
{{/zone}} {{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
<script id="group-listing" data-current-user="{{currentUser.username}}"
src="{{@page.publicUri}}/templates/listing.hbs"
type="text/x-handlebars-template"></script>
{{#if groupCount}} {{#if groupCount}}
{{js "js/listing.js"}} {{js "js/listing.js"}}
{{/if}} {{/if}}

@ -97,48 +97,97 @@ function toTitleCase(str) {
function loadGroups() { function loadGroups() {
var groupListing = $("#group-listing"); var groupListing = $("#group-listing");
var groupListingSrc = groupListing.attr("src");
var currentUser = groupListing.data("currentUser"); var currentUser = groupListing.data("currentUser");
$.template("group-listing", groupListingSrc, function (template) { var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) {
var successCallback = function (data) { serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000";
data = JSON.parse(data); } else if ($.hasPermission("LIST_GROUPS")) {
var viewModel = {}; //Get authenticated users groups
viewModel.groups = data.data; serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000";
$('#group-grid').removeClass('hidden'); } else {
var content = template(viewModel); $("#loading-content").remove();
$("#ast-container").html(content); $('#device-table').addClass('hidden');
$('#device-listing-status-msg').text('Permission denied.');
/* $("#device-listing-status").removeClass(' hidden');
* On group checkbox select add parent selected style class return;
*/ }
$(groupCheckbox).click(function () {
addGroupSelectedClass(this);
});
attachEvents();
$('#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 '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
}},
{ targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) {
return '<h4 data-groupid="' + row.id + '">' + name + '</h4>';
}},
{ 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 = '<a href="devices?groupName=' + row.name + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
html += '<a href="analytics?groupName=' + row.name + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
'<i class="fw fw-edit fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">Edit</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x"></i>' +
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
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); $(".icon .text").res_text(0.2);
}; 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;
} }
});
invokerUtil.get(serviceURL, successCallback, function (message) { $(groupCheckbox).click(function () {
displayErrors(message.content); addGroupSelectedClass(this);
});
}); });
} }

@ -88,6 +88,7 @@
org.wso2.carbon.device.mgt.* org.wso2.carbon.device.mgt.*
org.wso2.carbon.identity.application.common.model, org.wso2.carbon.identity.application.common.model,
org.wso2.carbon.identity.oauth.callback, org.wso2.carbon.identity.oauth.callback,
org.wso2.carbon.identity.oauth.common,
org.wso2.carbon.identity.oauth2, org.wso2.carbon.identity.oauth2,
org.wso2.carbon.identity.oauth2.model, org.wso2.carbon.identity.oauth2.model,
org.wso2.carbon.identity.oauth2.validators, org.wso2.carbon.identity.oauth2.validators,

@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL, ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)

@ -60,7 +60,7 @@ public class CertificateAuthenticator implements WebappAuthenticator {
if (request.getHeader(MUTUAL_AUTH_HEADER) != null) { if (request.getHeader(MUTUAL_AUTH_HEADER) != null) {
X509Certificate[] clientCertificate = (X509Certificate[]) request. X509Certificate[] clientCertificate = (X509Certificate[]) request.
getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE); getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE);
if (clientCertificate[0] != null) { if (clientCertificate != null && clientCertificate[0] != null) {
CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance(). CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance().
getCertificateManagementService().verifyPEMSignature(clientCertificate[0]); getCertificateManagementService().verifyPEMSignature(clientCertificate[0]);
if (certificateResponse == null) { if (certificateResponse == null) {
@ -86,6 +86,9 @@ public class CertificateAuthenticator implements WebappAuthenticator {
"but the serial number is missing in the database."); "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) { } else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) {

@ -29,7 +29,7 @@
Ex - Multiple Receiver Groups with two receivers each Ex - Multiple Receiver Groups with two receivers each
{tcp://localhost:7612/,tcp://localhost:7613},{tcp://localhost:7712/,tcp://localhost:7713/} {tcp://localhost:7612/,tcp://localhost:7613},{tcp://localhost:7712/,tcp://localhost:7713/}
--> -->
<Enabled>true</Enabled> <Enabled>false</Enabled>
<ReceiverServerUrl>tcp://localhost:7611</ReceiverServerUrl> <ReceiverServerUrl>tcp://localhost:7611</ReceiverServerUrl>
<AdminUsername>admin</AdminUsername> <AdminUsername>admin</AdminUsername>
<AdminPassword>admin</AdminPassword> <AdminPassword>admin</AdminPassword>

@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL, ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)

@ -341,6 +341,24 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION 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 ( CREATE TABLE DM_APPLICATION (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
NAME VARCHAR(150) NOT NULL, NAME VARCHAR(150) NOT NULL,
@ -390,13 +408,12 @@ CREATE TABLE DM_NOTIFICATION (
DROP TABLE IF EXISTS DM_DEVICE_INFO; DROP TABLE IF EXISTS DM_DEVICE_INFO;
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( CREATE TABLE DM_DEVICE_INFO (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INTEGER NULL, DEVICE_ID INT NULL,
KEY_FIELD VARCHAR(45) NULL, KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL, VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX DM_DEVICE_INFO_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT DM_DEVICE_INFO_DEVICE CONSTRAINT DM_DEVICE_INFO_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)
@ -404,23 +421,23 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ON UPDATE NO ACTION 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; DROP TABLE IF EXISTS DM_DEVICE_LOCATION;
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( CREATE TABLE DM_DEVICE_LOCATION (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INTEGER NULL, DEVICE_ID INT NULL,
LATITUDE DOUBLE NULL, LATITUDE FLOAT NULL,
LONGITUDE DOUBLE NULL, LONGITUDE FLOAT NULL,
STREET1 VARCHAR(45) NULL, STREET1 VARCHAR(45) NULL,
STREET2 VARCHAR(45) NULL, STREET2 VARCHAR(45) NULL,
CITY VARCHAR(45) NULL, CITY VARCHAR(45) NULL,
ZIP VARCHAR(10) NULL, ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)
@ -428,11 +445,12 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ON UPDATE NO ACTION 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 ( CREATE TABLE DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL IDENTITY,
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
@ -447,9 +465,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
CPU_USAGE DECIMAL(5) NULL, CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_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), PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)
@ -457,3 +475,5 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC);

@ -482,6 +482,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL, ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC), INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
@ -513,6 +514,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL, PLUGGED_IN INT(1) NULL,
UPDATE_TIMESTAMP BIGINT(15) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -568,6 +568,34 @@ WHEN (NEW.ID IS NULL)
END; 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 ( CREATE TABLE DM_APPLICATION (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
NAME VARCHAR2(150) NOT NULL, NAME VARCHAR2(150) NOT NULL,
@ -714,6 +742,7 @@ CREATE TABLE DM_DEVICE_LOCATION (
ZIP VARCHAR2(10) NULL, ZIP VARCHAR2(10) NULL,
STATE VARCHAR2(45) NULL, STATE VARCHAR2(45) NULL,
COUNTRY VARCHAR2(45) NULL, COUNTRY VARCHAR2(45) NULL,
UPDATE_TIMESTAMP NUMBER(19) NOT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
, ,
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
@ -751,23 +780,22 @@ CREATE TABLE DM_DEVICE_DETAIL (
VENDOR VARCHAR2(45) NULL, VENDOR VARCHAR2(45) NULL,
OS_VERSION VARCHAR2(45) NULL, OS_VERSION VARCHAR2(45) NULL,
BATTERY_LEVEL NUMBER(4) NULL, BATTERY_LEVEL NUMBER(4) NULL,
INTERNAL_TOTAL_MEMORY NUMBER(30) NULL, INTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, INTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL,
EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL, EXTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, EXTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL,
CONNECTION_TYPE VARCHAR2(10) NULL, CONNECTION_TYPE VARCHAR2(10) NULL,
SSID VARCHAR2(45) NULL, SSID VARCHAR2(45) NULL,
CPU_USAGE NUMBER(5) NULL, CPU_USAGE NUMBER(5) NULL,
TOTAL_RAM_MEMORY NUMBER(30) NULL, TOTAL_RAM_MEMORY NUMBER(30,3) NULL,
AVAILABLE_RAM_MEMORY NUMBER(30) NULL, AVAILABLE_RAM_MEMORY NUMBER(30,3) NULL,
PLUGGED_IN NUMBER(10) NULL, PLUGGED_IN NUMBER(10) NULL,
PRIMARY KEY (ID) UPDATE_TIMESTAMP NUMBER(19) NOT NULL,
, PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)
) );
;
-- Generate ID using sequence and trigger -- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1; 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); CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC);

@ -292,6 +292,26 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION 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 ( CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID BIGSERIAL NOT NULL PRIMARY KEY, ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL, DEVICE_ID INTEGER NOT NULL,
@ -379,6 +399,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL, ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID) 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 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 ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'), ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'),
DEVICE_ID INT NOT NULL, DEVICE_ID INT NOT NULL,
@ -407,7 +430,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL, PLUGGED_IN INT NULL,
PRIMARY KEY (ID) , UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)

Loading…
Cancel
Save