hasuniea 9 years ago
commit c98a162174

@ -16,23 +16,25 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
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.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.*; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException;
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;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO {
@Override @Override
public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException { public DeviceCountByGroupEntry getTotalDeviceCount() throws SQLException {
@ -51,14 +53,15 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return deviceCountByGroupEntry; return deviceCountByGroupEntry;
} }
@Override
public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet) public DeviceCountByGroupEntry getDeviceCount(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
int filteredDeviceCount = this.getFilteredDeviceCount(filterSet); int filteredDeviceCount = this.getFilteredDeviceCount(filterSet);
DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry(); DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
deviceCountByGroupEntry.setGroup("non-specific"); deviceCountByGroupEntry.setGroup("filtered");
deviceCountByGroupEntry.setDisplayNameForGroup("Non-specific"); deviceCountByGroupEntry.setDisplayNameForGroup("Filtered");
deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount); deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount);
return deviceCountByGroupEntry; return deviceCountByGroupEntry;
@ -161,8 +164,8 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry(); DeviceCountByGroupEntry deviceCountByGroupEntry = new DeviceCountByGroupEntry();
deviceCountByGroupEntry.setGroup("feature-non-compliant"); deviceCountByGroupEntry.setGroup("feature-non-compliant-and-filtered");
deviceCountByGroupEntry.setDisplayNameForGroup("Feature-non-compliant"); deviceCountByGroupEntry.setDisplayNameForGroup("Feature-non-compliant-and-filtered");
deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount); deviceCountByGroupEntry.setDeviceCount(filteredDeviceCount);
return deviceCountByGroupEntry; return deviceCountByGroupEntry;
@ -240,66 +243,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
} }
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DeviceCountByGroupEntry> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
// executing query
rs = stmt.executeQuery();
// fetching query results
DeviceCountByGroupEntry filteredNonCompliantDeviceCountByFeature;
while (rs.next()) {
filteredNonCompliantDeviceCountByFeature = new DeviceCountByGroupEntry();
filteredNonCompliantDeviceCountByFeature.setGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDisplayNameForGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature);
}
// fetching total records count
sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " +
"(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?)";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override @Override
public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet) public List<DeviceCountByGroupEntry> getDeviceCountsByPlatforms(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
@ -527,184 +470,6 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDeviceCountsByOwnershipTypes; return filteredDeviceCountsByOwnershipTypes;
} }
@Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 " +
"WHERE TENANT_ID = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
if (filters != null && filters.values().size() > 0) {
int i = 2;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
}
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
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 ?, ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
if (filters != null && filters.values().size() > 0) {
int i = 3;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(3, startIndex);
stmt.setInt(4, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override @Override
public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet) public List<DetailedDeviceEntry> getDevicesWithDetails(FilterSet filterSet)
throws InvalidParameterValueException, SQLException { throws InvalidParameterValueException, SQLException {
@ -819,7 +584,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filteredDevicesWithDetails; return filteredDevicesWithDetails;
} }
private Map<String, Object> extractDatabaseFiltersFromBean(FilterSet filterSet) protected Map<String, Object> extractDatabaseFiltersFromBean(FilterSet filterSet)
throws InvalidParameterValueException { throws InvalidParameterValueException {
if (filterSet == null) { if (filterSet == null) {
return null; return null;
@ -862,7 +627,7 @@ public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return filters; return filters;
} }
private Connection getConnection() throws SQLException { protected Connection getConnection() throws SQLException {
return GadgetDataServiceDAOFactory.getConnection(); return GadgetDataServiceDAOFactory.getConnection();
} }

@ -16,14 +16,14 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
public final class GadgetDataServiceDAOConstants { public final class GadgetDataServiceDAOConstants {
public static class PotentialVulnerability { public static class PotentialVulnerability {
// These constants do not hold actual database values // These constants do not hold actual database values
// These are just logical values defined and used @ Gadget Data Service DAO Implementation layer // These are just abstract values defined and used @ Gadget Data Service DAO Implementation layer
public static final String NON_COMPLIANT = "NON_COMPLIANT"; public static final String NON_COMPLIANT = "NON_COMPLIANT";
public static final String UNMONITORED = "UNMONITORED"; public static final String UNMONITORED = "UNMONITORED";

@ -20,8 +20,12 @@ 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.analytics.dashboard.dao.impl.GenericGadgetDataServiceDAOImpl;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl.OracleGadgetDataServiceDAOImpl;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl.PostgreSQLGadgetDataServiceDAOImpl;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException;
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;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -41,7 +45,23 @@ public class GadgetDataServiceDAOFactory {
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>(); private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
public static GadgetDataServiceDAO getGadgetDataServiceDAO() { public static GadgetDataServiceDAO getGadgetDataServiceDAO() {
return new GadgetDataServiceDAOImpl(); if (databaseEngine != null) {
switch (databaseEngine) {
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
return new GenericGadgetDataServiceDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericGadgetDataServiceDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
// to be added
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new PostgreSQLGadgetDataServiceDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleGadgetDataServiceDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
} }
public static void init(DataSourceConfig config) { public static void init(DataSourceConfig config) {

@ -0,0 +1,279 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class GenericGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO {
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DeviceCountByGroupEntry> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
// executing query
rs = stmt.executeQuery();
// fetching query results
DeviceCountByGroupEntry filteredNonCompliantDeviceCountByFeature;
while (rs.next()) {
filteredNonCompliantDeviceCountByFeature = new DeviceCountByGroupEntry();
filteredNonCompliantDeviceCountByFeature.setGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDisplayNameForGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature);
}
// fetching total records count
sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " +
"(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?) NON_COMPLIANT_FEATURE_CODE";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 " +
"WHERE TENANT_ID = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
if (filters != null && filters.values().size() > 0) {
int i = 2;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
}
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
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 ?, ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
if (filters != null && filters.values().size() > 0) {
int i = 3;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(3, startIndex);
stmt.setInt(4, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
}

@ -0,0 +1,281 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class OracleGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO {
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DeviceCountByGroupEntry> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql = "SELECT * FROM (SELECT ROWNUM offset, rs.* FROM (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) rs) WHERE offset >= ? AND ROWNUM <= ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
// executing query
rs = stmt.executeQuery();
// fetching query results
DeviceCountByGroupEntry filteredNonCompliantDeviceCountByFeature;
while (rs.next()) {
filteredNonCompliantDeviceCountByFeature = new DeviceCountByGroupEntry();
filteredNonCompliantDeviceCountByFeature.setGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDisplayNameForGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature);
}
// fetching total records count
sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " +
"(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?) NON_COMPLIANT_FEATURE_CODE";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
sql = "SELECT * FROM (SELECT ROWNUM offset, rs.* FROM (SELECT DEVICE_ID, PLATFORM, OWNERSHIP, " +
"CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " + advancedSqlFiltering +
"ORDER BY DEVICE_ID ASC) rs) WHERE offset >= ? AND ROWNUM <= ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
if (filters != null && filters.values().size() > 0) {
int i = 2;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
}
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
sql = "SELECT * FROM (SELECT ROWNUM offset, rs.* FROM (SELECT DEVICE_ID, PLATFORM, OWNERSHIP, " +
"CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? AND FEATURE_CODE = ? " +
advancedSqlFiltering + "ORDER BY DEVICE_ID ASC) rs) WHERE offset >= ? AND ROWNUM <= ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
if (filters != null && filters.values().size() > 0) {
int i = 3;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(3, startIndex);
stmt.setInt(4, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
}

@ -0,0 +1,279 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.AbstractGadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DetailedDeviceEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.DeviceCountByGroupEntry;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.bean.FilterSet;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.exception.InvalidParameterValueException;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PostgreSQLGadgetDataServiceDAOImpl extends AbstractGadgetDataServiceDAO {
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DeviceCountByGroupEntry> filteredNonCompliantDeviceCountsByFeatures = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC OFFSET ? LIMIT ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
// executing query
rs = stmt.executeQuery();
// fetching query results
DeviceCountByGroupEntry filteredNonCompliantDeviceCountByFeature;
while (rs.next()) {
filteredNonCompliantDeviceCountByFeature = new DeviceCountByGroupEntry();
filteredNonCompliantDeviceCountByFeature.setGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDisplayNameForGroup(rs.getString("FEATURE_CODE"));
filteredNonCompliantDeviceCountByFeature.setDeviceCount(rs.getInt("DEVICE_COUNT"));
filteredNonCompliantDeviceCountsByFeatures.add(filteredNonCompliantDeviceCountByFeature);
}
// fetching total records count
sql = "SELECT COUNT(FEATURE_CODE) AS NON_COMPLIANT_FEATURE_COUNT FROM " +
"(SELECT DISTINCT FEATURE_CODE FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?) NON_COMPLIANT_FEATURE_CODE";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredNonCompliantDeviceCountsByFeatures);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getDevicesWithDetails(FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 " +
"WHERE TENANT_ID = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC OFFSET ? LIMIT ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
if (filters != null && filters.values().size() > 0) {
int i = 2;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(2, startIndex);
stmt.setInt(3, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
@Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
FilterSet filterSet, int startIndex, int resultCount)
throws InvalidParameterValueException, SQLException {
if (nonCompliantFeatureCode == null || "".equals(nonCompliantFeatureCode)) {
throw new InvalidParameterValueException("Non-compliant feature code should not be either null or empty.");
}
if (startIndex < 0) {
throw new InvalidParameterValueException("Start index should be equal to 0 or greater than that.");
}
if (resultCount < 5) {
throw new InvalidParameterValueException("Result count should be equal to 5 or greater than that.");
}
Map<String, Object> filters = this.extractDatabaseFiltersFromBean(filterSet);
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
List<DetailedDeviceEntry> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
con = this.getConnection();
String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options
// [1] appending filter columns, if exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? AND FEATURE_CODE = ? " + advancedSqlFiltering +
"ORDER BY DEVICE_ID ASC OFFSET ? LIMIT ?";
stmt = con.prepareStatement(sql);
// [2] appending filter column values, if exist
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
if (filters != null && filters.values().size() > 0) {
int i = 3;
for (Object value : filters.values()) {
if (value instanceof Integer) {
stmt.setInt(i, (Integer) value);
} else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
}
stmt.setInt(i, startIndex);
stmt.setInt(++i, resultCount);
} else {
stmt.setInt(3, startIndex);
stmt.setInt(4, resultCount);
}
// executing query
rs = stmt.executeQuery();
// fetching query results
DetailedDeviceEntry filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new DetailedDeviceEntry();
filteredDeviceWithDetails.setDeviceId(rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.setPlatform(rs.getString("PLATFORM"));
filteredDeviceWithDetails.setOwnershipType(rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.setConnectivityStatus(rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
// fetching total records count
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " +
"WHERE TENANT_ID = ? AND FEATURE_CODE = ?";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, nonCompliantFeatureCode);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(filteredDevicesWithDetails);
paginationResult.setRecordsTotal(totalRecordsCount);
return paginationResult;
}
}

@ -97,7 +97,7 @@ public class DeviceManagementDAOFactory {
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>(); private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
public static DeviceDAO getDeviceDAO() { public static DeviceDAO getDeviceDAO() {
if(databaseEngine != null) { if (databaseEngine != null) {
switch (databaseEngine) { switch (databaseEngine) {
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE: case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleDeviceDAOImpl(); return new OracleDeviceDAOImpl();
@ -112,7 +112,7 @@ public class DeviceManagementDAOFactory {
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
} }
} }
throw new RuntimeException("Database engine has not initialized properly."); throw new IllegalStateException("Database engine has not initialized properly.");
} }
public static DeviceTypeDAO getDeviceTypeDAO() { public static DeviceTypeDAO getDeviceTypeDAO() {

@ -1,13 +1,12 @@
{{#zone "topCss"}} {{#zone "topCss"}}
{{css "css/analytics.css"}} {{css "css/analytics.css"}}
{{css "css/daterangepicker.css"}}
{{css "css/graph.css"}}
{{/zone}} {{/zone}}
{{unit "cdmf.unit.ui.title" pageTitle="Analytics"}} {{unit "cdmf.unit.ui.title" pageTitle="Analytics"}}
{{unit "cdmf.unit.ui.content.title" pageHeader=title}} {{unit "cdmf.unit.ui.content.title" pageHeader=title}}
{{unit "cdmf.unit.lib.service-invoker-utility"}} {{unit "cdmf.unit.lib.service-invoker-utility"}}
{{unit "cdmf.unit.lib.handlebars"}} {{unit "cdmf.unit.lib.handlebars"}}
{{unit "cdmf.unit.lib.rickshaw-graph"}}
{{#zone "breadcrumbs"}} {{#zone "breadcrumbs"}}
<li> <li>
@ -15,18 +14,6 @@
<i class="icon fw fw-home"></i> <i class="icon fw fw-home"></i>
</a> </a>
</li> </li>
{{#if groupName}}
<li>
<a href="{{@app.context}}/groups">
Groups
</a>
</li>
<li>
<a href="{{@app.context}}/devices?groupId={{groupId}}&groupName={{groupName}}">
{{groupName}}
</a>
</li>
{{else}}
<li> <li>
<a href="{{@app.context}}/devices"> <a href="{{@app.context}}/devices">
Devices Devices
@ -37,7 +24,6 @@
{{deviceName}} {{deviceName}}
</a> </a>
</li> </li>
{{/if}}
<li> <li>
<a href="#"> <a href="#">
Analytics Analytics
@ -52,28 +38,7 @@
<div class="col-lg-3 margin-top-double"> <div class="col-lg-3 margin-top-double">
<h1 class="grey ">{{deviceName}} Analytics</h1> <h1 class="grey ">{{deviceName}} Analytics</h1>
</div> </div>
<div id="rangeSliderWrapper" class="pull-right col-lg-9"> {{unit "cdmf.unit.analytics.date-range-picker"}}
<div id="dateRangePickerContainer">
<div class="btn-group" role="group">
<button id="hour-btn" type="button"
class="btn btn-default date-range">Hour
</button>
<button id="h12-btn" type="button"
class="btn btn-default date-range">12 Hours
</button>
<button id="h24-btn" type="button"
class="btn btn-default date-range">24 Hours
</button>
<button id="h48-btn" type="button"
class="btn btn-default date-range">48 Hours
</button>
<button id="date-range" type="button"
class="btn btn-default date-range last-child"
data-toggle="popup"
title="Click to set custom date range"></button>
</div>
</div>
</div>
</div> </div>
<hr> <hr>
<div class="clear"></div> <div class="clear"></div>
@ -83,7 +48,3 @@
</div> </div>
</div> </div>
{{/zone}} {{/zone}}
{{#zone "bottomJs"}}
{{js "js/jquery.daterangepicker.js"}}
{{js "js/graph_util.js"}}
{{/zone}}

@ -18,33 +18,12 @@
function onRequest(context) { function onRequest(context) {
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) { var deviceType = context.uriParams.deviceType;
if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters");
}
if (lvalue != rvalue) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
var groupName = request.getParameter("groupName");
var groupId = request.getParameter("groupId");
var deviceName = request.getParameter("deviceName"); var deviceName = request.getParameter("deviceName");
var deviceId = request.getParameter("deviceId"); var deviceId = request.getParameter("deviceId");
var deviceType = context.uriParams.deviceType;
var title = "Analytics";
if (groupName) {
title = "Group " + title;
} else {
title = "Device " + title;
}
return { return {
"deviceAnalyticsViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "analytics-view"), "deviceAnalyticsViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "analytics-view"),
"deviceType": deviceType, "deviceType": deviceType,
"title": title,
"groupName": groupName,
"groupId": groupId,
"deviceName": deviceName, "deviceName": deviceName,
"deviceId": deviceId "deviceId": deviceId
}; };

@ -54,10 +54,3 @@
margin-right: 20px; margin-right: 20px;
margin-left: 20px; margin-left: 20px;
} }
.date-range{
border: 1px solid #ccc;
}
#dateRangePickerContainer button.active{
background-color: #e6e6e6 !important;
}

@ -0,0 +1,52 @@
{{#zone "topCss"}}
{{css "css/analytics.css"}}
{{/zone}}
{{unit "cdmf.unit.ui.title" pageTitle="Analytics"}}
{{unit "cdmf.unit.ui.content.title" pageHeader=title}}
{{unit "cdmf.unit.lib.service-invoker-utility"}}
{{unit "cdmf.unit.lib.handlebars"}}
{{unit "cdmf.unit.lib.rickshaw-graph"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/groups">
Groups
</a>
</li>
<li>
<a href="{{@app.context}}/devices?groupOwner={{groupOwner}}&groupName={{groupName}}">
{{groupName}}
</a>
</li>
<li>
<a href="#">
Analytics
</a>
</li>
{{/zone}}
{{#zone "content"}}
<div class="container container-bg white-bg">
<div class=" margin-top-double">
<div class="row padding-top-double padding-bottom-double margin-bottom-double">
<div class="col-lg-3 margin-top-double">
<h1 class="grey ">{{groupName}} Analytics</h1>
</div>
{{unit "cdmf.unit.analytics.date-range-picker" deviceTypes=deviceTypes}}
</div>
<hr>
<div class="clear"></div>
<div id="div-chart">
{{#each deviceTypes}}
{{unit deviceAnalyticsViewUnitName devices=devices}}
{{/each}}
</div>
</div>
</div>
{{/zone}}

@ -0,0 +1,51 @@
/*
* 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.
*/
function onRequest(context) {
var utility = require("/app/modules/utility.js").utility;
var groupModule = require("/app/modules/group.js").groupModule;
var groupName = context.uriParams.name;
var groupOwner = context.uriParams.owner;
var deviceTypes = [];
var devices = groupModule.getGroupDevices(groupName, groupOwner).data;
for (var i = 0; i < devices.length; i++) {
var hasDeviceType = false;
for (var j = 0; j < deviceTypes.length; j++) {
if (deviceTypes[j].type === devices[i].type) {
deviceTypes[j].devices.push(devices[i]);
hasDeviceType = true;
break;
}
}
if (!hasDeviceType) {
var deviceType = {};
deviceType.type = devices[i].type;
deviceType.devices = [];
deviceType.devices.push(devices[i]);
deviceType.deviceAnalyticsViewUnitName = utility.getTenantedDeviceUnitName(deviceType.type, "analytics-view");
deviceTypes.push(deviceType);
}
}
return {
"groupName": groupName,
"groupOwner": groupOwner,
"deviceTypes": deviceTypes
};
}

@ -0,0 +1,5 @@
{
"version": "1.0.0",
"uri": "/group/{owner}/{name}/analytics",
"layout": "cdmf.layout.default"
}

@ -0,0 +1,63 @@
/*
* 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.
*/
#rangeSliderWrapper {
margin-top: 25px;
}
#chart {
display: inline-block;
}
#legend {
display: inline-block;
position: relative;
left: 8px;
}
#legend_container {
position: absolute;
right: 0;
bottom: 26px;
width: 0;
}
#chart_container {
float: left;
position: relative;
}
.ast-container {
padding-bottom: 30px;
}
.container {
width: auto;
}
.shrink {
margin-right: 20px;
margin-left: 20px;
}
.date-range{
border: 1px solid #ccc;
}
#dateRangePickerContainer button.active{
background-color: #e6e6e6 !important;
}

@ -142,7 +142,7 @@ function loadGroups() {
'<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="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>'; '<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">' + html += '<a href="group/' + row.owner + '/' + row.name + '/analytics" 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="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>'; '<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>';

@ -1,62 +0,0 @@
{{#each groups}}
<tr data-type="selectable" data-group-name="{{name}}" data-group-owner="{{owner}}">
<td class="remove-padding icon-only content-fill">
<div class="thumbnail icon">
<img class="square-element text fw "
src="public/cdmf.page.groups/images/group-icon.png"/>
</div>
</td>
<td class="fade-edge">
<h4>{{name}}</h4>
</td>
<td class="fade-edge remove-padding-top" data-search="{{owner}}"
data-display="{{owner}}"
data-grid-label="Owner">{{owner}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<a href="devices?groupName={{name}}&groupOwner={{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>
<a href="analytics?groupName={{name}}&groupOwner={{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>
<a href="#" data-click-event="remove-form"
class="btn padding-reduce-on-grid-view share-group-link"
data-group-name="{{name}}" data-group-owner="{{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>
<a href="#" data-click-event="remove-form"
class="btn padding-reduce-on-grid-view edit-group-link"
data-group-name="{{name}}" data-group-owner="{{owner}}"
data-group-description="{{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>
<a href="#" data-click-event="remove-form"
class="btn padding-reduce-on-grid-view remove-group-link"
data-group-name="{{name}}" data-group-owner="{{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>
</td>
</tr>
{{/each}}

@ -0,0 +1,31 @@
{{#zone "topCss"}}
{{css "css/daterangepicker.css"}}
{{/zone}}
<span id="device-type-details" data-devicetypes="{{deviceTypes}}"></span>
<div id="rangeSliderWrapper" class="pull-right col-lg-9">
<div id="dateRangePickerContainer">
<div class="btn-group" role="group">
<button id="hour-btn" type="button"
class="btn btn-default date-range">Hour
</button>
<button id="h12-btn" type="button"
class="btn btn-default date-range">12 Hours
</button>
<button id="h24-btn" type="button"
class="btn btn-default date-range">24 Hours
</button>
<button id="h48-btn" type="button"
class="btn btn-default date-range">48 Hours
</button>
<button id="date-range" type="button"
class="btn btn-default date-range last-child"
data-toggle="popup"
title="Click to set custom date range"></button>
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "js/moment.js"}}
{{js "js/jquery.daterangepicker.js"}}
{{js "js/date-picker.js"}}
{{/zone}}

@ -0,0 +1,32 @@
/*
* 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.
*/
function onRequest(context) {
var deviceTypes = context.unit.params.deviceTypes;
var deviceType = context.uriParams.deviceType;
var deviceTypesList = [];
if (deviceTypes) {
for (var i = 0; i < deviceTypes.length; i++) {
deviceTypesList.push(deviceTypes[i].type);
}
} else if (deviceType) {
deviceTypesList.push(deviceType);
}
return {"deviceTypes": stringify(deviceTypesList)};
}

@ -346,3 +346,16 @@ input.hour-range, input.minute-range {
#dateRangePickerContainer { #dateRangePickerContainer {
float: right; float: right;
} }
.date-range {
border: 1px solid #ccc;
}
#dateRangePickerContainer button.active {
background-color: #e6e6e6 !important;
}
#dateRangePickerContainer .btn-default:hover {
background-color: #b2b2b2;
border-color: #000000;
}

@ -28,9 +28,26 @@ var DateRange = convertDate(startDate) + " to " + convertDate(endDate);
$(document).ready(function () { $(document).ready(function () {
initDate(); initDate();
var configObject = {
startOfWeek: 'monday',
separator: ' to ',
format: 'YYYY-MM-DD HH:mm',
autoClose: false,
time: {
enabled: true
},
shortcuts: 'hide',
endDate: currentDay,
maxDays: 2,
getValue: function () {
return this.value;
},
setValue: function (s) {
this.value = s;
}
};
$('#date-range').html(DateRange); $('#date-range').html(DateRange);
$('#date-range').dateRangePicker() $('#date-range').dateRangePicker(configObject)
.bind('datepicker-apply', function (event, dateRange) { .bind('datepicker-apply', function (event, dateRange) {
$(this).addClass('active'); $(this).addClass('active');
$(this).siblings().removeClass('active'); $(this).siblings().removeClass('active');
@ -83,8 +100,11 @@ function setDateTime(from, to) {
from += tzOffset; from += tzOffset;
to += tzOffset; to += tzOffset;
// the relevant import units needs to implement this. // Implement drawGraph_<device type name> method in your UI unit for analytics.
drawGraph(parseInt(from / 1000), parseInt(to / 1000)); var deviceTypes = $("#device-type-details").data("devicetypes");
for (var i = 0; i < deviceTypes.length; i++){
window["drawGraph_" + deviceTypes](parseInt(from / 1000), parseInt(to / 1000));
}
} }
function convertDate(date) { function convertDate(date) {

@ -1,20 +1,3 @@
/*
* 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.
*/
(function ($) { (function ($) {
/* /*

@ -1,21 +1,3 @@
/*
* 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.
*/
// daterangepicker.js // daterangepicker.js
// version : 0.0.5 // version : 0.0.5
// author : Chunlong Liu // author : Chunlong Liu

@ -232,6 +232,13 @@
position: relative; position: relative;
left: 40px; left: 40px;
height: 30px; height: 30px;
width: 97%;
top: 20px;
text-align: right;
}
.chartWrapper {
padding-top: 50px;
} }
/*detail*/ /*detail*/

@ -0,0 +1,8 @@
{{#zone "topCss"}}
{{css "css/graph.css"}}
{{/zone}}
{{#zone "bottomJs"}}
{{js "js/d3.min.js"}}
{{js "js/rickshaw.min.js"}}
{{/zone}}

@ -502,14 +502,16 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID , ID) REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
-- END OF POLICY AND DEVICE GROUP MAPPING -- -- END OF POLICY AND DEVICE GROUP MAPPING --
-- DASHBOARD RELATED VIEWS --
CREATE VIEW DEVICES_VIEW_1 AS CREATE VIEW DEVICES_VIEW_1 AS
SELECT SELECT
DEVICE_INFO.DEVICE_ID, DEVICE_INFO.DEVICE_ID,
@ -560,3 +562,5 @@ DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND
DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID; ORDER BY TENANT_ID, DEVICE_ID;
-- END OF DASHBOARD RELATED VIEWS --

@ -2,7 +2,18 @@ CREATE TABLE DM_DEVICE_TYPE (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
NAME VARCHAR(300) DEFAULT NULL, NAME VARCHAR(300) DEFAULT NULL,
PROVIDER_TENANT_ID INTEGER DEFAULT 0, PROVIDER_TENANT_ID INTEGER DEFAULT 0,
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, SHARED_WITH_ALL_TENANTS INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (ID)
);
CREATE TABLE DM_GROUP (
ID INTEGER IDENTITY NOT NULL,
GROUP_NAME VARCHAR(100) DEFAULT NULL,
DESCRIPTION VARCHAR(max) DEFAULT NULL,
DATE_OF_CREATE BIGINT DEFAULT NULL,
DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL,
OWNER VARCHAR(45) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
@ -18,7 +29,7 @@ CREATE TABLE DM_DEVICE (
ID INTEGER identity NOT NULL, ID INTEGER identity NOT NULL,
DESCRIPTION VARCHAR(max) DEFAULT NULL, DESCRIPTION VARCHAR(max) DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL,
DEVICE_TYPE_ID INT DEFAULT NULL, DEVICE_TYPE_ID INTEGER DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0, TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID), PRIMARY KEY (ID),
@ -26,6 +37,18 @@ CREATE TABLE DM_DEVICE (
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
CREATE TABLE DM_DEVICE_GROUP_MAP (
ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INTEGER DEFAULT NULL,
GROUP_ID INTEGER DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
REFERENCES DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE DM_OPERATION ( CREATE TABLE DM_OPERATION (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
TYPE VARCHAR(50) NOT NULL, TYPE VARCHAR(50) NOT NULL,
@ -77,7 +100,7 @@ CREATE TABLE DM_ENROLMENT (
STATUS VARCHAR(50) NULL, STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT DATETIME2(0) DEFAULT NULL, DATE_OF_ENROLMENT DATETIME2(0) DEFAULT NULL,
DATE_OF_LAST_UPDATE DATETIME2(0) DEFAULT NULL, DATE_OF_LAST_UPDATE DATETIME2(0) DEFAULT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
@ -113,10 +136,10 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
CREATE TABLE DM_PROFILE ( CREATE TABLE DM_PROFILE (
ID INT NOT NULL IDENTITY , ID INTEGER NOT NULL IDENTITY ,
PROFILE_NAME VARCHAR(45) NOT NULL , PROFILE_NAME VARCHAR(45) NOT NULL ,
TENANT_ID INT NOT NULL , TENANT_ID INTEGER NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL , DEVICE_TYPE_ID INTEGER NOT NULL ,
CREATED_TIME DATETIME2(0) NOT NULL , CREATED_TIME DATETIME2(0) NOT NULL ,
UPDATED_TIME DATETIME2(0) NOT NULL , UPDATED_TIME DATETIME2(0) NOT NULL ,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
@ -132,16 +155,16 @@ CREATE TABLE DM_PROFILE (
CREATE TABLE DM_POLICY ( CREATE TABLE DM_POLICY (
ID INT NOT NULL IDENTITY , ID INTEGER NOT NULL IDENTITY ,
NAME VARCHAR(45) DEFAULT NULL , NAME VARCHAR(45) DEFAULT NULL ,
DESCRIPTION VARCHAR(1000) NULL, DESCRIPTION VARCHAR(1000) NULL,
TENANT_ID INT NOT NULL , TENANT_ID INTEGER NOT NULL ,
PROFILE_ID INT NOT NULL , PROFILE_ID INTEGER NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL, OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL, COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL, PRIORITY INTEGER NOT NULL,
ACTIVE INT NOT NULL, ACTIVE INTEGER NOT NULL,
UPDATED INT NULL, UPDATED INTEGER NULL,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_PROFILE_DM_POLICY CONSTRAINT FK_DM_PROFILE_DM_POLICY
FOREIGN KEY (PROFILE_ID ) FOREIGN KEY (PROFILE_ID )
@ -154,11 +177,11 @@ CREATE TABLE DM_POLICY (
CREATE TABLE DM_DEVICE_POLICY ( CREATE TABLE DM_DEVICE_POLICY (
ID INT NOT NULL IDENTITY , ID INTEGER NOT NULL IDENTITY ,
DEVICE_ID INT NOT NULL , DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INT NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
DEVICE VARBINARY(max) NOT NULL, DEVICE VARBINARY(max) NOT NULL,
POLICY_ID INT NOT NULL , POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT FK_POLICY_DEVICE_POLICY CONSTRAINT FK_POLICY_DEVICE_POLICY
FOREIGN KEY (POLICY_ID ) FOREIGN KEY (POLICY_ID )
@ -176,9 +199,9 @@ CREATE TABLE DM_DEVICE_POLICY (
CREATE TABLE DM_DEVICE_TYPE_POLICY ( CREATE TABLE DM_DEVICE_TYPE_POLICY (
ID INT NOT NULL , ID INTEGER NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL , DEVICE_TYPE_ID INTEGER NOT NULL ,
POLICY_ID INT NOT NULL , POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT FK_DEVICE_TYPE_POLICY CONSTRAINT FK_DEVICE_TYPE_POLICY
FOREIGN KEY (POLICY_ID ) FOREIGN KEY (POLICY_ID )
@ -197,11 +220,11 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY (
CREATE TABLE DM_PROFILE_FEATURES ( CREATE TABLE DM_PROFILE_FEATURES (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
PROFILE_ID INT NOT NULL, PROFILE_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL, DEVICE_TYPE_ID INTEGER NOT NULL,
TENANT_ID INT NOT NULL , TENANT_ID INTEGER NOT NULL ,
CONTENT VARBINARY(max) NULL DEFAULT NULL, CONTENT VARBINARY(max) NULL DEFAULT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
@ -215,9 +238,9 @@ CREATE TABLE DM_PROFILE_FEATURES (
CREATE TABLE DM_ROLE_POLICY ( CREATE TABLE DM_ROLE_POLICY (
ID INT NOT NULL IDENTITY , ID INTEGER NOT NULL IDENTITY ,
ROLE_NAME VARCHAR(45) NOT NULL , ROLE_NAME VARCHAR(45) NOT NULL ,
POLICY_ID INT NOT NULL , POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT FK_ROLE_POLICY_POLICY CONSTRAINT FK_ROLE_POLICY_POLICY
FOREIGN KEY (POLICY_ID ) FOREIGN KEY (POLICY_ID )
@ -230,8 +253,8 @@ CREATE TABLE DM_ROLE_POLICY (
CREATE TABLE DM_USER_POLICY ( CREATE TABLE DM_USER_POLICY (
ID INT NOT NULL IDENTITY , ID INTEGER NOT NULL IDENTITY ,
POLICY_ID INT NOT NULL , POLICY_ID INTEGER NOT NULL ,
USERNAME VARCHAR(45) NOT NULL , USERNAME VARCHAR(45) NOT NULL ,
PRIMARY KEY (ID) , PRIMARY KEY (ID) ,
CONSTRAINT DM_POLICY_USER_POLICY CONSTRAINT DM_POLICY_USER_POLICY
@ -243,12 +266,12 @@ CREATE TABLE DM_USER_POLICY (
CREATE TABLE DM_DEVICE_POLICY_APPLIED ( CREATE TABLE DM_DEVICE_POLICY_APPLIED (
ID INT NOT NULL IDENTITY , ID INTEGER NOT NULL IDENTITY ,
DEVICE_ID INT NOT NULL , DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INT NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INT NOT NULL , POLICY_ID INTEGER NOT NULL ,
POLICY_CONTENT VARBINARY(max) NULL , POLICY_CONTENT VARBINARY(max) NULL ,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
APPLIED SMALLINT NULL , APPLIED SMALLINT NULL ,
CREATED_TIME DATETIME2(0) NULL , CREATED_TIME DATETIME2(0) NULL ,
UPDATED_TIME DATETIME2(0) NULL , UPDATED_TIME DATETIME2(0) NULL ,
@ -264,8 +287,8 @@ CREATE TABLE DM_USER_POLICY (
CREATE TABLE DM_CRITERIA ( CREATE TABLE DM_CRITERIA (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
NAME VARCHAR(50) NULL, NAME VARCHAR(50) NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
@ -273,9 +296,9 @@ CREATE TABLE DM_CRITERIA (
CREATE TABLE DM_POLICY_CRITERIA ( CREATE TABLE DM_POLICY_CRITERIA (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
CRITERIA_ID INT NOT NULL, CRITERIA_ID INTEGER NOT NULL,
POLICY_ID INT NOT NULL, POLICY_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
FOREIGN KEY (CRITERIA_ID) FOREIGN KEY (CRITERIA_ID)
@ -290,8 +313,8 @@ CREATE TABLE DM_POLICY_CRITERIA (
); );
CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES ( CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
POLICY_CRITERION_ID INT NOT NULL, POLICY_CRITERION_ID INTEGER NOT NULL,
PROP_KEY VARCHAR(45) NULL, PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL, PROP_VALUE VARCHAR(100) NULL,
CONTENT VARBINARY(max) NULL , CONTENT VARBINARY(max) NULL ,
@ -304,35 +327,35 @@ CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
); );
CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE DM_POLICY_COMPLIANCE_STATUS (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
DEVICE_ID INT NOT NULL, DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INT NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INT NOT NULL, POLICY_ID INTEGER NOT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
STATUS INT NULL, STATUS INTEGER NULL,
LAST_SUCCESS_TIME DATETIME2(0) NULL, LAST_SUCCESS_TIME DATETIME2(0) NULL,
LAST_REQUESTED_TIME DATETIME2(0) NULL, LAST_REQUESTED_TIME DATETIME2(0) NULL,
LAST_FAILED_TIME DATETIME2(0) NULL, LAST_FAILED_TIME DATETIME2(0) NULL,
ATTEMPTS INT NULL, ATTEMPTS INTEGER NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
CREATE TABLE DM_POLICY_CHANGE_MGT ( CREATE TABLE DM_POLICY_CHANGE_MGT (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
POLICY_ID INT NOT NULL, POLICY_ID INTEGER NOT NULL,
DEVICE_TYPE_ID INT NOT NULL, DEVICE_TYPE_ID INTEGER NOT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
COMPLIANCE_STATUS_ID INT NOT NULL, COMPLIANCE_STATUS_ID INTEGER NOT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL,
STATUS INT NULL, STATUS INTEGER NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
FOREIGN KEY (COMPLIANCE_STATUS_ID) FOREIGN KEY (COMPLIANCE_STATUS_ID)
@ -342,10 +365,10 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
); );
CREATE TABLE DM_DEVICE_GROUP_POLICY ( CREATE TABLE DM_DEVICE_GROUP_POLICY (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
DEVICE_GROUP_ID INT NOT NULL, DEVICE_GROUP_ID INTEGER NOT NULL,
POLICY_ID INT NOT NULL, POLICY_ID INTEGER NOT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID) FOREIGN KEY (DEVICE_GROUP_ID)
@ -353,8 +376,8 @@ CREATE TABLE DM_DEVICE_GROUP_POLICY (
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID , ID) REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
@ -370,7 +393,7 @@ CREATE TABLE DM_APPLICATION (
LOCATION_URL VARCHAR(100) DEFAULT NULL, LOCATION_URL VARCHAR(100) DEFAULT NULL,
IMAGE_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL,
APP_PROPERTIES VARBINARY(max) NULL, APP_PROPERTIES VARBINARY(max) NULL,
MEMORY_USAGE INTEGER(10) NULL, MEMORY_USAGE INTEGER NULL,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
); );
@ -405,12 +428,12 @@ CREATE TABLE DM_NOTIFICATION (
); );
-- NOTIFICATION TABLE END -- -- NOTIFICATION TABLE END --
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'DM_DEVICE_INFO' and type = 'u')
DROP TABLE IF EXISTS DM_DEVICE_INFO; DROP TABLE DM_DEVICE_INFO;
CREATE TABLE DM_DEVICE_INFO ( CREATE TABLE DM_DEVICE_INFO (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INT NULL, DEVICE_ID INTEGER 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),
@ -423,11 +446,12 @@ CREATE TABLE DM_DEVICE_INFO (
CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC); CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC);
DROP TABLE IF EXISTS DM_DEVICE_LOCATION; IF EXISTS (SELECT * FROM sys.objects WHERE name = 'DM_DEVICE_LOCATION' and type = 'u')
DROP TABLE DM_DEVICE_LOCATION;
CREATE TABLE DM_DEVICE_LOCATION ( CREATE TABLE DM_DEVICE_LOCATION (
ID INTEGER IDENTITY NOT NULL, ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INT NULL, DEVICE_ID INTEGER NULL,
LATITUDE FLOAT NULL, LATITUDE FLOAT NULL,
LONGITUDE FLOAT NULL, LONGITUDE FLOAT NULL,
STREET1 VARCHAR(45) NULL, STREET1 VARCHAR(45) NULL,
@ -447,11 +471,12 @@ CREATE TABLE 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);
DROP TABLE IF EXISTS DM_DEVICE_DETAIL; IF EXISTS (SELECT * FROM sys.objects WHERE name = 'DM_DEVICE_DETAIL' and type = 'u')
DROP TABLE DM_DEVICE_DETAIL;
CREATE TABLE DM_DEVICE_DETAIL ( CREATE TABLE DM_DEVICE_DETAIL (
ID INT NOT NULL IDENTITY, ID INTEGER NOT NULL IDENTITY,
DEVICE_ID INT NOT NULL, DEVICE_ID INTEGER NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL, DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL,
@ -465,7 +490,7 @@ CREATE TABLE 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 NULL, PLUGGED_IN INTEGER NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL, UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -423,8 +423,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID , ID) REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB; )ENGINE = InnoDB;
@ -493,8 +493,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
) )
ENGINE = InnoDB; ENGINE = InnoDB;
DROP TABLE IF EXISTS DM_DEVICE_DETAIL ; DROP TABLE IF EXISTS DM_DEVICE_DETAIL ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
@ -524,3 +522,64 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ON UPDATE NO ACTION) ON UPDATE NO ACTION)
ENGINE = InnoDB; ENGINE = InnoDB;
-- DASHBOARD RELATED VIEWS --
CREATE VIEW DEVICE_INFO_VIEW AS
SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_DEVICE.TENANT_ID
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID;
CREATE VIEW DEVICE_WITH_POLICY_INFO_VIEW AS
SELECT
DEVICE_ID,
POLICY_ID,
STATUS AS IS_COMPLIANT
FROM DM_POLICY_COMPLIANCE_STATUS;
CREATE VIEW DEVICES_VIEW_1 AS
SELECT
DEVICE_INFO_VIEW.DEVICE_ID,
DEVICE_INFO_VIEW.PLATFORM,
DEVICE_INFO_VIEW.OWNERSHIP,
DEVICE_INFO_VIEW.CONNECTIVITY_STATUS,
IFNULL(DEVICE_WITH_POLICY_INFO_VIEW.POLICY_ID, -1) AS POLICY_ID,
IFNULL(DEVICE_WITH_POLICY_INFO_VIEW.IS_COMPLIANT, -1) AS IS_COMPLIANT,
DEVICE_INFO_VIEW.TENANT_ID
FROM
DEVICE_INFO_VIEW
LEFT JOIN
DEVICE_WITH_POLICY_INFO_VIEW
ON DEVICE_INFO_VIEW.DEVICE_ID = DEVICE_WITH_POLICY_INFO_VIEW.DEVICE_ID
ORDER BY DEVICE_INFO_VIEW.DEVICE_ID;
CREATE VIEW DEVICES_VIEW_2 AS
SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE_DETAIL.DEVICE_MODEL,
DM_DEVICE_DETAIL.VENDOR,
DM_DEVICE_DETAIL.OS_VERSION,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.OWNER,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_POLICY_COMPLIANCE_STATUS.POLICY_ID,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_POLICY_COMPLIANCE_FEATURES.FEATURE_CODE,
DM_POLICY_COMPLIANCE_FEATURES.STATUS AS IS_COMPLAINT,
DM_DEVICE.TENANT_ID
FROM
DM_POLICY_COMPLIANCE_FEATURES, DM_POLICY_COMPLIANCE_STATUS, DM_ENROLMENT, DM_DEVICE, DM_DEVICE_TYPE, DM_DEVICE_DETAIL
WHERE
DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID AND
DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID AND
DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND
DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID;
-- END OF DASHBOARD RELATED VIEWS --

@ -2,7 +2,7 @@ CREATE TABLE DM_DEVICE_TYPE (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
NAME VARCHAR2(300) DEFAULT NULL, NAME VARCHAR2(300) DEFAULT NULL,
PROVIDER_TENANT_ID INTEGER DEFAULT 0, PROVIDER_TENANT_ID INTEGER DEFAULT 0,
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL,
CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID) CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID)
) )
/ /
@ -20,6 +20,31 @@ WHEN (NEW.ID IS NULL)
END; END;
/ /
CREATE TABLE DM_GROUP (
ID NUMBER(10) NOT NULL,
DESCRIPTION CLOB DEFAULT NULL,
GROUP_NAME VARCHAR2(100) DEFAULT NULL,
DATE_OF_ENROLLMENT TIMESTAMP(0) DEFAULT NULL,
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
OWNER VARCHAR2(45) DEFAULT NULL,
TENANT_ID NUMBER(10) DEFAULT 0,
CONSTRAINT PK_DM_GROUP PRIMARY KEY (ID)
)
/
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_GROUP_seq START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER DM_GROUP_seq_tr
BEFORE INSERT
ON DM_GROUP
REFERENCING NEW AS NEW
FOR EACH ROW
WHEN (NEW.ID IS NULL)
BEGIN
SELECT DM_GROUP_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
/
CREATE TABLE DM_DEVICE_CERTIFICATE ( CREATE TABLE DM_DEVICE_CERTIFICATE (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL,
@ -65,6 +90,29 @@ WHEN (NEW.ID IS NULL)
END; END;
/ /
CREATE TABLE DM_DEVICE_GROUP_MAP (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) DEFAULT NULL,
GROUP_ID NUMBER(10) DEFAULT NULL,
TENANT_ID NUMBER(10) DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEV_GROUP_MAP_DM_DEV2 FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID),
CONSTRAINT fk_DM_DEV_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
REFERENCES DM_GROUP (ID)
);
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_GROUP_MAP_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_MAP_seq_tr
BEFORE INSERT ON DM_DEVICE_GROUP_MAP FOR EACH ROW
WHEN (NEW.ID IS NULL)
BEGIN
SELECT DM_DEVICE_GROUP_MAP_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
/
CREATE TABLE DM_OPERATION ( CREATE TABLE DM_OPERATION (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
TYPE VARCHAR2(50) NOT NULL, TYPE VARCHAR2(50) NOT NULL,
@ -580,19 +628,19 @@ CREATE TABLE DM_DEVICE_GROUP_POLICY (
REFERENCES DM_GROUP (ID) REFERENCES DM_GROUP (ID)
, ,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID , ID) REFERENCES DM_POLICY (ID)
) ; ) ;
-- Generate ID using sequence and trigger -- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr
BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
@ -691,7 +739,7 @@ WHEN (NEW.NOTIFICATION_ID IS NULL)
BEGIN BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO'; EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO';
EXCEPTION EXCEPTION
WHEN OTHERS THEN NULL; WHEN OTHERS THEN NULL;
END; END;
/ /
@ -713,20 +761,16 @@ CREATE TABLE DM_DEVICE_INFO (
CREATE SEQUENCE DM_DEVICE_INFO_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_DEVICE_INFO_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_INFO_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_INFO_seq_tr
BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC);
BEGIN BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION'; EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION';
EXCEPTION EXCEPTION
WHEN OTHERS THEN NULL; WHEN OTHERS THEN NULL;
END; END;
/ /
@ -755,20 +799,16 @@ CREATE TABLE DM_DEVICE_LOCATION (
CREATE SEQUENCE DM_DEVICE_LOCATION_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_DEVICE_LOCATION_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_LOCATION_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_LOCATION_seq_tr
BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC);
BEGIN BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL'; EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL';
EXCEPTION EXCEPTION
WHEN OTHERS THEN NULL; WHEN OTHERS THEN NULL;
END; END;
/ /
@ -801,12 +841,65 @@ CREATE TABLE DM_DEVICE_DETAIL (
CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_DETAIL_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_DETAIL_seq_tr
BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); -- DASHBOARD RELATED VIEWS --
CREATE VIEW DEVICES_VIEW_1 AS
SELECT
DEVICE_INFO.DEVICE_ID,
DEVICE_INFO.PLATFORM,
DEVICE_INFO.OWNERSHIP,
DEVICE_INFO.CONNECTIVITY_STATUS,
NVL(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID,
NVL(DEVICE_WITH_POLICY_INFO.IS_COMPLIANT, -1) AS IS_COMPLIANT,
DEVICE_INFO.TENANT_ID
FROM
(SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_DEVICE.TENANT_ID
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO
LEFT JOIN
(SELECT
DEVICE_ID,
POLICY_ID,
STATUS AS IS_COMPLIANT
FROM DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
ORDER BY DEVICE_INFO.DEVICE_ID;
CREATE VIEW DEVICES_VIEW_2 AS
SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE_DETAIL.DEVICE_MODEL,
DM_DEVICE_DETAIL.VENDOR,
DM_DEVICE_DETAIL.OS_VERSION,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.OWNER,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_POLICY_COMPLIANCE_STATUS.POLICY_ID,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_POLICY_COMPLIANCE_FEATURES.FEATURE_CODE,
DM_POLICY_COMPLIANCE_FEATURES.STATUS AS IS_COMPLAINT,
DM_DEVICE.TENANT_ID
FROM
DM_POLICY_COMPLIANCE_FEATURES, DM_POLICY_COMPLIANCE_STATUS, DM_ENROLMENT, DM_DEVICE, DM_DEVICE_TYPE, DM_DEVICE_DETAIL
WHERE
DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID AND
DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID AND
DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND
DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID;
-- END OF DASHBOARD RELATED VIEWS --

@ -8,8 +8,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
ID BIGSERIAL NOT NULL PRIMARY KEY, ID BIGSERIAL NOT NULL PRIMARY KEY,
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
CERTIFICATE BYTEA DEFAULT NULL CERTIFICATE BYTEA DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0, TENANT_ID INTEGER DEFAULT 0
); );
CREATE TABLE IF NOT EXISTS DM_DEVICE ( CREATE TABLE IF NOT EXISTS DM_DEVICE (
@ -292,10 +292,9 @@ 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 ( CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_GROUP_POLICY_seq'), ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_GROUP_ID INT NOT NULL, DEVICE_GROUP_ID INT NOT NULL,
POLICY_ID INT NOT NULL, POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL, TENANT_ID INT NOT NULL,
@ -306,8 +305,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID , ID) REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION ON UPDATE NO ACTION
); );
@ -373,11 +372,10 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_INFO_seq') NOT NULL, ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INT 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) ,
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)
@ -385,11 +383,9 @@ 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);
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_LOCATION_seq') NOT NULL, ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INT NULL, DEVICE_ID INT NULL,
LATITUDE DOUBLE PRECISION NULL, LATITUDE DOUBLE PRECISION NULL,
LONGITUDE DOUBLE PRECISION NULL, LONGITUDE DOUBLE PRECISION NULL,
@ -400,7 +396,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
STATE VARCHAR(45) NULL, STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL, UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID) ,
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)
@ -408,13 +403,9 @@ 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);
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 BIGSERIAL NOT NULL PRIMARY KEY,
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,
@ -431,7 +422,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL, PLUGGED_IN INT NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL, 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)
@ -439,5 +429,58 @@ 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); -- DASHBOARD RELATED VIEWS --
CREATE VIEW DEVICES_VIEW_1 AS
SELECT
DEVICE_INFO.DEVICE_ID,
DEVICE_INFO.PLATFORM,
DEVICE_INFO.OWNERSHIP,
DEVICE_INFO.CONNECTIVITY_STATUS,
COALESCE(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID,
COALESCE(DEVICE_WITH_POLICY_INFO.IS_COMPLIANT, -1) AS IS_COMPLIANT,
DEVICE_INFO.TENANT_ID
FROM
(SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_DEVICE.TENANT_ID
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO
LEFT JOIN
(SELECT
DEVICE_ID,
POLICY_ID,
STATUS AS IS_COMPLIANT
FROM DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
ORDER BY DEVICE_INFO.DEVICE_ID;
CREATE VIEW DEVICES_VIEW_2 AS
SELECT
DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE_DETAIL.DEVICE_MODEL,
DM_DEVICE_DETAIL.VENDOR,
DM_DEVICE_DETAIL.OS_VERSION,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.OWNER,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_POLICY_COMPLIANCE_STATUS.POLICY_ID,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_POLICY_COMPLIANCE_FEATURES.FEATURE_CODE,
DM_POLICY_COMPLIANCE_FEATURES.STATUS AS IS_COMPLAINT,
DM_DEVICE.TENANT_ID
FROM
DM_POLICY_COMPLIANCE_FEATURES, DM_POLICY_COMPLIANCE_STATUS, DM_ENROLMENT, DM_DEVICE, DM_DEVICE_TYPE, DM_DEVICE_DETAIL
WHERE
DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID AND
DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID AND
DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND
DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID;
-- END OF DASHBOARD RELATED VIEWS --

Loading…
Cancel
Save