forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
285c870d6a
249
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/AbstractGadgetDataServiceDAO.java
249
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/AbstractGadgetDataServiceDAO.java
4
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOConstants.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOConstants.java
4
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOConstants.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOConstants.java
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
@ -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)};
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"version": "1.0.0"
|
||||
}
|
13
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/css/daterangepicker.css → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/css/daterangepicker.css
13
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/css/daterangepicker.css → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/css/daterangepicker.css
28
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/js/graph_util.js → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/date-picker.js
28
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/js/graph_util.js → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/date-picker.js
17
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/js/jquery-ui-timepicker-addon.js → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/jquery-ui-timepicker-addon.js
vendored
17
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/js/jquery-ui-timepicker-addon.js → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/jquery-ui-timepicker-addon.js
vendored
@ -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 ($) {
|
||||
|
||||
/*
|
18
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/js/jquery.daterangepicker.js → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/jquery.daterangepicker.js
18
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/js/jquery.daterangepicker.js → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.analytics.date-range-picker/public/js/jquery.daterangepicker.js
@ -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
|
||||
// version : 0.0.5
|
||||
// author : Chunlong Liu
|
File diff suppressed because it is too large
Load Diff
7
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/css/graph.css → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.rickshaw-graph/public/css/graph.css
7
components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.analytics/public/css/graph.css → components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.rickshaw-graph/public/css/graph.css
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,8 @@
|
||||
{{#zone "topCss"}}
|
||||
{{css "css/graph.css"}}
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "bottomJs"}}
|
||||
{{js "js/d3.min.js"}}
|
||||
{{js "js/rickshaw.min.js"}}
|
||||
{{/zone}}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"index": 30
|
||||
}
|
Loading…
Reference in new issue