mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Adding temporary development code bits for cdmf-product dashboard feature
This commit is contained in:
parent
a888cf39c0
commit
274aa0ecd3
@ -1,15 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
package org.wso2.carbon.device.mgt.analytics.dashboard;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be updated...
|
* To be updated...
|
||||||
*/
|
*/
|
||||||
public interface GadgetDataService {
|
public interface GadgetDataService {
|
||||||
@SuppressWarnings("unused")
|
|
||||||
int getTotalFilteredDeviceCount(String[] filters);
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
int getNonCompliantDeviceCount(String[] filters);
|
int getTotalDeviceCount(Map<String, Object> filters);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
int getUnmonitoredDeviceCount(String[] filters);
|
int getActiveDeviceCount();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
int getInactiveDeviceCount();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
int getRemovedDeviceCount();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
int getNonCompliantDeviceCount();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
int getUnmonitoredDeviceCount();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
|
||||||
|
|
||||||
public interface GadgetDataServiceDAO {
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
// Total devices related analytics
|
public interface GadgetDataServiceDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get total filtered device count from a particular tenant.
|
* Method to get total filtered device count from a particular tenant.
|
||||||
@ -12,37 +31,52 @@ public interface GadgetDataServiceDAO {
|
|||||||
*
|
*
|
||||||
* @return Total filtered device count.
|
* @return Total filtered device count.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
int getTotalDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
int getTotalFilteredDeviceCount(String[] filters) throws GadgetDataServiceDAOException;
|
|
||||||
|
|
||||||
// Security-concerns related analytics
|
@SuppressWarnings("unused")
|
||||||
|
int getFeatureNonCompliantDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
int getActiveDeviceCount() throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
int getInactiveDeviceCount() throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
int getRemovedDeviceCount() throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get non-compliant device count.
|
* Method to get non-compliant device count.
|
||||||
*
|
*
|
||||||
* @param filters List of filters to be applied in getting
|
|
||||||
* non-compliant device count.
|
|
||||||
*
|
|
||||||
* @return Non-compliant device count.
|
* @return Non-compliant device count.
|
||||||
*/
|
*/
|
||||||
int getNonCompliantDeviceCount(String[] filters);
|
@SuppressWarnings("unused")
|
||||||
|
int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
Map<String, Integer> getNonCompliantDeviceCountsByFeatures() throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get unmonitored device count.
|
* Method to get unmonitored device count.
|
||||||
*
|
*
|
||||||
* @param filters List of filters to be applied in getting
|
|
||||||
* unmonitored device count.
|
|
||||||
*
|
|
||||||
* @return Unmonitored device count.
|
* @return Unmonitored device count.
|
||||||
*/
|
*/
|
||||||
int getUnmonitoredDeviceCount(String[] filters);
|
@SuppressWarnings("unused")
|
||||||
|
int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException;
|
||||||
// Device Groupings related analytics
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
int getAndroidDeviceCount(String[] filters);
|
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
int getBYODDeviceCount(String[] filters);
|
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
int getCOPEDeviceCount(String[] filters);
|
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|||||||
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|||||||
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
@ -9,65 +27,336 @@ 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.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
|
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTotalFilteredDeviceCount(String[] filters) throws GadgetDataServiceDAOException {
|
public int getTotalDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 1;
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFeatureNonCompliantDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 2;
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getActiveDeviceCount() throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 1;
|
||||||
|
Map<String, Object> filters = new HashMap<>();
|
||||||
|
filters.put("CONNECTIVITY_STATUS", "ACTIVE");
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInactiveDeviceCount() throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 1;
|
||||||
|
Map<String, Object> filters = new HashMap<>();
|
||||||
|
filters.put("CONNECTIVITY_STATUS", "INACTIVE");
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRemovedDeviceCount() throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 1;
|
||||||
|
Map<String, Object> filters = new HashMap<>();
|
||||||
|
filters.put("CONNECTIVITY_STATUS", "REMOVED");
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 1;
|
||||||
|
Map<String, Object> filters = new HashMap<>();
|
||||||
|
filters.put("IS_COMPLIANT", 0);
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Integer> getNonCompliantDeviceCountsByFeatures() throws GadgetDataServiceDAOException {
|
||||||
Connection con;
|
Connection con;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
int totalFilteredDeviceCount = 0;
|
Map<String, Integer> filteredNonCompliantDeviceCountsByFeatures = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
con = this.getConnection();
|
con = this.getConnection();
|
||||||
String sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES WHERE TENANT_ID = ?";
|
String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 " +
|
||||||
if (filters.length > 0) {
|
"WHERE TENANT_ID = ? GROUP BY FEATURE_CODE";
|
||||||
|
|
||||||
}
|
|
||||||
stmt = con.prepareStatement(sql);
|
stmt = con.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
|
// executing query
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
// fetching query results
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
totalFilteredDeviceCount = rs.getInt("DEVICE_COUNT");
|
filteredNonCompliantDeviceCountsByFeatures.
|
||||||
|
put(rs.getString("FEATURE_CODE"), rs.getInt("DEVICE_COUNT"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new GadgetDataServiceDAOException("Error occurred while fetching the registered device types", e);
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
return totalFilteredDeviceCount;
|
return filteredNonCompliantDeviceCountsByFeatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNonCompliantDeviceCount(String[] filters) {
|
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
|
||||||
return 50;
|
int filteringViewID = 1;
|
||||||
|
Map<String, Object> filters = new HashMap<>();
|
||||||
|
filters.put("POLICY_ID", -1);
|
||||||
|
return this.getDeviceCount(filteringViewID, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUnmonitoredDeviceCount(String[] filters) {
|
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
return 60;
|
int filteringViewID = 1;
|
||||||
|
return this.getDeviceCountsByPlatforms(filteringViewID, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAndroidDeviceCount(String[] filters) {
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
return 0;
|
int filteringViewID = 2;
|
||||||
|
return this.getDeviceCountsByPlatforms(filteringViewID, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBYODDeviceCount(String[] filters) {
|
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
return 0;
|
int filteringViewID = 1;
|
||||||
|
return this.getDeviceCountsByOwnershipTypes(filteringViewID, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCOPEDeviceCount(String[] filters) {
|
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
return 0;
|
int filteringViewID = 2;
|
||||||
|
return this.getDeviceCountsByOwnershipTypes(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 1;
|
||||||
|
return this.getDevicesWithDetails(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
int filteringViewID = 2;
|
||||||
|
return this.getDevicesWithDetails(filteringViewID, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDeviceCount(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
Connection con;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
int filteredDeviceCount = 0;
|
||||||
|
try {
|
||||||
|
con = this.getConnection();
|
||||||
|
String sql;
|
||||||
|
if (filteringViewID == 1) {
|
||||||
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
||||||
|
} else {
|
||||||
|
// if filteringViewID == 2
|
||||||
|
sql = "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?";
|
||||||
|
}
|
||||||
|
// appending filters to support advanced filtering options
|
||||||
|
// [1] appending filter columns
|
||||||
|
if (filters != null && filters.size() > 0) {
|
||||||
|
for (String column : filters.keySet()) {
|
||||||
|
sql = sql + " AND " + column + " = ?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
// [2] appending filter column values
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// executing query
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
// fetching query results
|
||||||
|
while (rs.next()) {
|
||||||
|
filteredDeviceCount = rs.getInt("DEVICE_COUNT");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return filteredDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Integer> getDeviceCountsByPlatforms(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
Connection con;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
Map<String, Integer> filteredDeviceCountsByPlatforms = new HashMap<>();
|
||||||
|
try {
|
||||||
|
con = this.getConnection();
|
||||||
|
String sql, advancedSqlFiltering = "";
|
||||||
|
// appending filters if exist, to support advanced filtering options
|
||||||
|
// [1] appending filter columns
|
||||||
|
if (filters.size() > 0) {
|
||||||
|
for (String column : filters.keySet()) {
|
||||||
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filteringViewID == 1) {
|
||||||
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
|
||||||
|
advancedSqlFiltering + "GROUP BY PLATFORM";
|
||||||
|
} else {
|
||||||
|
// if filteringViewID == 2
|
||||||
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
|
||||||
|
advancedSqlFiltering + "GROUP BY PLATFORM";
|
||||||
|
}
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
// [2] appending filter column values
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
// executing query
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
// fetching query results
|
||||||
|
while (rs.next()) {
|
||||||
|
filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return filteredDeviceCountsByPlatforms;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Integer> getDeviceCountsByOwnershipTypes(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
Connection con;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
Map<String, Integer> filteredDeviceCountsByOwnershipTypes = new HashMap<>();
|
||||||
|
try {
|
||||||
|
con = this.getConnection();
|
||||||
|
String sql, advancedSqlFiltering = "";
|
||||||
|
// appending filters if exist, to support advanced filtering options
|
||||||
|
// [1] appending filter columns
|
||||||
|
if (filters.size() > 0) {
|
||||||
|
for (String column : filters.keySet()) {
|
||||||
|
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filteringViewID == 1) {
|
||||||
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
|
||||||
|
advancedSqlFiltering + "GROUP BY OWNERSHIP";
|
||||||
|
} else {
|
||||||
|
// if filteringViewID == 2
|
||||||
|
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
|
||||||
|
advancedSqlFiltering + "GROUP BY OWNERSHIP";
|
||||||
|
}
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
// [2] appending filter column values
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
// executing query
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
// fetching query results
|
||||||
|
while (rs.next()) {
|
||||||
|
filteredDeviceCountsByOwnershipTypes.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return filteredDeviceCountsByOwnershipTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> getDevicesWithDetails(int filteringViewID, Map<String, Object> filters) throws GadgetDataServiceDAOException {
|
||||||
|
Connection con;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
|
||||||
|
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
con = this.getConnection();
|
||||||
|
String sql;
|
||||||
|
if (filteringViewID == 1) {
|
||||||
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_1 WHERE TENANT_ID = ?";
|
||||||
|
} else {
|
||||||
|
// if filteringViewID == 2
|
||||||
|
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?";
|
||||||
|
}
|
||||||
|
// appending filters to support advanced filtering options
|
||||||
|
// [1] appending filter columns
|
||||||
|
if (filters.size() > 0) {
|
||||||
|
for (String column : filters.keySet()) {
|
||||||
|
sql = sql + " AND " + column + " = ?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
// [2] appending filter column values
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
// executing query
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
// fetching query results
|
||||||
|
while (rs.next()) {
|
||||||
|
filteredDeviceWithDetails.put("Device-ID", rs.getInt("DEVICE_ID"));
|
||||||
|
filteredDeviceWithDetails.put("Platform", rs.getString("PLATFORM"));
|
||||||
|
filteredDeviceWithDetails.put("Ownership", rs.getString("OWNERSHIP"));
|
||||||
|
filteredDeviceWithDetails.put("Connectivity-Details", rs.getString("CONNECTIVITY_STATUS"));
|
||||||
|
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
return filteredDevicesWithDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws SQLException {
|
private Connection getConnection() throws SQLException {
|
||||||
return GadgetDataServiceDAOFactory.getConnection();
|
return GadgetDataServiceDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.analytics.dashboard.internal;
|
package org.wso2.carbon.device.mgt.analytics.dashboard.internal;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|||||||
@ -1,33 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.analytics.dashboard.internal;
|
package org.wso2.carbon.device.mgt.analytics.dashboard.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
|
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
|
||||||
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
|
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be updated...
|
* To be updated...
|
||||||
*/
|
*/
|
||||||
class GadgetDataServiceImpl implements GadgetDataService {
|
class GadgetDataServiceImpl implements GadgetDataService {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static final Log log = LogFactory.getLog(GadgetDataServiceImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTotalFilteredDeviceCount(String[] filters) {
|
public int getTotalDeviceCount(Map<String, Object> filters) {
|
||||||
// default
|
int totalDeviceCount;
|
||||||
int totalFilteredDeviceCount = -1;
|
|
||||||
try {
|
try {
|
||||||
totalFilteredDeviceCount = GadgetDataServiceDAOFactory.
|
GadgetDataServiceDAOFactory.openConnection();
|
||||||
getGadgetDataServiceDAO().getTotalFilteredDeviceCount(filters);
|
totalDeviceCount = GadgetDataServiceDAOFactory.
|
||||||
} catch (GadgetDataServiceDAOException e) {
|
getGadgetDataServiceDAO().getTotalDeviceCount(filters);
|
||||||
return totalFilteredDeviceCount;
|
} catch (GadgetDataServiceDAOException | SQLException e) {
|
||||||
|
totalDeviceCount = -1;
|
||||||
|
return totalDeviceCount;
|
||||||
|
} finally {
|
||||||
|
GadgetDataServiceDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
return totalFilteredDeviceCount;
|
return totalDeviceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNonCompliantDeviceCount(String[] filters) {
|
public int getActiveDeviceCount() {
|
||||||
return GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount(filters);
|
int activeDeviceCount;
|
||||||
|
try {
|
||||||
|
GadgetDataServiceDAOFactory.openConnection();
|
||||||
|
activeDeviceCount = GadgetDataServiceDAOFactory.
|
||||||
|
getGadgetDataServiceDAO().getActiveDeviceCount();
|
||||||
|
} catch (GadgetDataServiceDAOException | SQLException e) {
|
||||||
|
activeDeviceCount = -1;
|
||||||
|
return activeDeviceCount;
|
||||||
|
} finally {
|
||||||
|
GadgetDataServiceDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return activeDeviceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUnmonitoredDeviceCount(String[] filters) {
|
public int getInactiveDeviceCount() {
|
||||||
return GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(filters);
|
int inactiveDeviceCount;
|
||||||
|
try {
|
||||||
|
GadgetDataServiceDAOFactory.openConnection();
|
||||||
|
inactiveDeviceCount = GadgetDataServiceDAOFactory.
|
||||||
|
getGadgetDataServiceDAO().getInactiveDeviceCount();
|
||||||
|
} catch (GadgetDataServiceDAOException | SQLException e) {
|
||||||
|
inactiveDeviceCount = -1;
|
||||||
|
return inactiveDeviceCount;
|
||||||
|
} finally {
|
||||||
|
GadgetDataServiceDAOFactory.closeConnection();
|
||||||
}
|
}
|
||||||
|
return inactiveDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRemovedDeviceCount() {
|
||||||
|
int removedDeviceCount;
|
||||||
|
try {
|
||||||
|
GadgetDataServiceDAOFactory.openConnection();
|
||||||
|
removedDeviceCount = GadgetDataServiceDAOFactory.
|
||||||
|
getGadgetDataServiceDAO().getRemovedDeviceCount();
|
||||||
|
} catch (GadgetDataServiceDAOException | SQLException e) {
|
||||||
|
removedDeviceCount = -1;
|
||||||
|
return removedDeviceCount;
|
||||||
|
} finally {
|
||||||
|
GadgetDataServiceDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return removedDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNonCompliantDeviceCount() {
|
||||||
|
int nonCompliantDeviceCount;
|
||||||
|
try {
|
||||||
|
GadgetDataServiceDAOFactory.openConnection();
|
||||||
|
nonCompliantDeviceCount = GadgetDataServiceDAOFactory.
|
||||||
|
getGadgetDataServiceDAO().getNonCompliantDeviceCount();
|
||||||
|
} catch (GadgetDataServiceDAOException | SQLException e) {
|
||||||
|
nonCompliantDeviceCount = -1;
|
||||||
|
return nonCompliantDeviceCount;
|
||||||
|
} finally {
|
||||||
|
GadgetDataServiceDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return nonCompliantDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getUnmonitoredDeviceCount() {
|
||||||
|
int unmonitoredDeviceCount;
|
||||||
|
try {
|
||||||
|
GadgetDataServiceDAOFactory.openConnection();
|
||||||
|
unmonitoredDeviceCount = GadgetDataServiceDAOFactory.
|
||||||
|
getGadgetDataServiceDAO().getUnmonitoredDeviceCount();
|
||||||
|
} catch (GadgetDataServiceDAOException | SQLException e) {
|
||||||
|
unmonitoredDeviceCount = -1;
|
||||||
|
return unmonitoredDeviceCount;
|
||||||
|
} finally {
|
||||||
|
GadgetDataServiceDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
return unmonitoredDeviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -485,7 +485,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
|
|||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE VIEW DEVICES_VIEW AS
|
CREATE VIEW DEVICES_VIEW_1 AS
|
||||||
SELECT
|
SELECT
|
||||||
DEVICE_INFO.DEVICE_ID,
|
DEVICE_INFO.DEVICE_ID,
|
||||||
DEVICE_INFO.PLATFORM,
|
DEVICE_INFO.PLATFORM,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user