revert-70aa11f8
geethkokila 9 years ago
commit f1aeb1a846

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>device-mgt</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Device Management Dashboard Analytics</name>
<description>WSO2 Carbon - Device Management Dashboard Analytics</description>
<url>http://wso2.org</url>
<dependencies>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi.services</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
<Bundle-Description>Device Management Dashboard Analytics Bundle</Bundle-Description>
<Private-Package>
org.wso2.carbon.device.mgt.analytics.dashboard.dao,
org.wso2.carbon.device.mgt.analytics.dashboard.internal
</Private-Package>
<Export-Package>
org.wso2.carbon.device.mgt.analytics.dashboard
</Export-Package>
<Import-Package>
org.osgi.framework,
org.osgi.service.component,
org.apache.commons.logging.*,
javax.sql,
org.wso2.carbon.context,
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.device.mgt.core.*,
org.wso2.carbon.ndatasource.core.*;
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,55 @@
/*
* 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;
import java.util.Map;
/**
* To be updated...
*/
public interface GadgetDataService {
@SuppressWarnings("unused")
int getTotalDeviceCount(Map<String, Object> filters);
@SuppressWarnings("unused")
int getActiveDeviceCount();
@SuppressWarnings("unused")
int getInactiveDeviceCount();
@SuppressWarnings("unused")
int getRemovedDeviceCount();
@SuppressWarnings("unused")
int getNonCompliantDeviceCount();
@SuppressWarnings("unused")
int getUnmonitoredDeviceCount();
@SuppressWarnings("unused")
Map<String, Integer> getNonCompliantDeviceCountsByFeatures();
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters);
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters);
}

@ -0,0 +1,82 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
import java.util.List;
import java.util.Map;
public interface GadgetDataServiceDAO {
/**
* Method to get total filtered device count from a particular tenant.
*
* @param filters List of filters to be applied in getting
* total filtered device count.
*
* @return Total filtered device count.
*/
int getTotalDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException;
@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.
*
* @return Non-compliant device count.
*/
@SuppressWarnings("unused")
int getNonCompliantDeviceCount() throws GadgetDataServiceDAOException;
@SuppressWarnings("unused")
Map<String, Integer> getNonCompliantDeviceCountsByFeatures() throws GadgetDataServiceDAOException;
/**
* Method to get unmonitored device count.
*
* @return Unmonitored device count.
*/
@SuppressWarnings("unused")
int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException;
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException;
@SuppressWarnings("unused")
Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException;
@SuppressWarnings("unused")
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;
}

@ -0,0 +1,77 @@
/*
* 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;
@SuppressWarnings("unused")
/**
* Custom exception class for data access related exceptions.
*/
public class GadgetDataServiceDAOException extends Exception {
private String errorMessage;
private static final long serialVersionUID = 2021891706072918864L;
/**
* Constructs a new exception with the specific error message and nested exception.
*
* @param errorMessage specific error message.
* @param nestedException Nested exception.
*/
public GadgetDataServiceDAOException(String errorMessage, Exception nestedException) {
super(errorMessage, nestedException);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message and cause.
*
* @param errorMessage Specific error message.
* @param cause Cause of this exception.
*/
public GadgetDataServiceDAOException(String errorMessage, Throwable cause) {
super(errorMessage, cause);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message.
*
* @param errorMessage Specific error message.
*/
public GadgetDataServiceDAOException(String errorMessage) {
super(errorMessage);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message and cause.
*
* @param cause Cause of this exception.
*/
public GadgetDataServiceDAOException(Throwable cause) {
super(cause);
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

@ -0,0 +1,133 @@
/*
* 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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.List;
@SuppressWarnings("unused")
public class GadgetDataServiceDAOFactory {
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOFactory.class);
private static DataSource dataSource;
private static String databaseEngine;
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
public static GadgetDataServiceDAO getGadgetDataServiceDAO() {
return new GadgetDataServiceDAOImpl();
}
public static void init(DataSourceConfig config) {
dataSource = resolveDataSource(config);
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
}
public static void init(DataSource dtSource) {
dataSource = dtSource;
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
}
public static void openConnection() throws SQLException {
Connection conn = currentConnection.get();
if (conn != null) {
throw new IllegalTransactionStateException("A transaction is already active within the context of " +
"this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
"transaction is already active is a sign of improper transaction handling");
}
conn = dataSource.getConnection();
currentConnection.set(conn);
}
public static Connection getConnection() throws SQLException {
Connection conn = currentConnection.get();
if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods");
}
return conn;
}
public static void closeConnection() {
Connection conn = currentConnection.get();
if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " +
"'beginTransaction'/'openConnection' methods");
}
try {
conn.close();
} catch (SQLException e) {
log.warn("Error occurred while close the connection");
}
currentConnection.remove();
}
/**
* Resolve data source from the data source definition
*
* @param config data source configuration
* @return data source resolved from the data source definition
*/
private static DataSource resolveDataSource(DataSourceConfig config) {
DataSource dataSource = null;
if (config == null) {
throw new RuntimeException(
"Device Management Repository data source configuration " + "is null and " +
"thus, is not initialized");
}
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
if (jndiConfig != null) {
if (log.isDebugEnabled()) {
log.debug("Initializing Device Management Repository data source using the JNDI " +
"Lookup Definition");
}
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<>();
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
jndiProperties.put(prop.getName(), prop.getValue());
}
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
} else {
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
}
}
return dataSource;
}
}

@ -0,0 +1,368 @@
/*
* 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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
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.HashMap;
import java.util.List;
import java.util.Map;
class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@SuppressWarnings("unused")
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
@Override
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;
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Map<String, Integer> filteredNonCompliantDeviceCountsByFeatures = new HashMap<>();
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";
stmt = con.prepareStatement(sql);
stmt.setInt(1, tenantId);
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
filteredNonCompliantDeviceCountsByFeatures.
put(rs.getString("FEATURE_CODE"), 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 filteredNonCompliantDeviceCountsByFeatures;
}
@Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
int filteringViewID = 1;
Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1);
return this.getDeviceCount(filteringViewID, filters);
}
@Override
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
int filteringViewID = 1;
return this.getDeviceCountsByPlatforms(filteringViewID, filters);
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(Map<String, Object> filters) throws GadgetDataServiceDAOException {
int filteringViewID = 2;
return this.getDeviceCountsByPlatforms(filteringViewID, filters);
}
@Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
int filteringViewID = 1;
return this.getDeviceCountsByOwnershipTypes(filteringViewID, filters);
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(Map<String, Object> filters) throws GadgetDataServiceDAOException {
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, 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++;
}
}
// 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 exist
if (filters != null && 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, 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++;
}
}
// 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 exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
}
}
if (filteringViewID == 1) {
sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
advancedSqlFiltering + "GROUP BY OWNERSHIP";
} else {
// if filteringViewID == 2
sql = "SELECT OWNERSHIP, 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, 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++;
}
}
// executing query
rs = stmt.executeQuery();
// fetching query results
while (rs.next()) {
filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
} 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 exist
if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) {
sql = sql + " AND " + column + " = ?";
}
}
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++;
}
}
// 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 {
return GadgetDataServiceDAOFactory.getConnection();
}
}

@ -0,0 +1,80 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.internal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.ndatasource.core.DataSourceService;
@SuppressWarnings("unused")
/**
* @scr.component name="org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService" immediate="true"
* @scr.reference name="org.wso2.carbon.ndatasource"
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDataSourceService"
* unbind="unsetDataSourceService"
*/
public class GadgetDataServiceComponent {
private static final Log log = LogFactory.getLog(GadgetDataServiceComponent.class);
protected void activate(ComponentContext componentContext) {
if (log.isDebugEnabled()) {
log.debug("Starting Device Management Dashboard Analytics Bundle...");
}
try {
DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementConfig config =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
GadgetDataServiceDAOFactory.init(dsConfig);
//Register GadgetDataService to expose corresponding data to external parties.
componentContext.getBundleContext().
registerService(GadgetDataService.class.getName(), new GadgetDataServiceImpl(), null);
if (log.isDebugEnabled()) {
log.debug("Device Management Dashboard Analytics Bundle has been started successfully");
}
} catch (Throwable e) {
log.error("Error occurred while initializing the bundle", e);
}
}
protected void deactivate(ComponentContext componentContext) {
if (log.isDebugEnabled()) {
log.debug("Deactivating Device Management Dashboard Analytics Bundle...");
}
//do nothing
}
public void setDataSourceService(DataSourceService dataSourceService){
}
public void unsetDataSourceService(DataSourceService dataSourceService){
}
}

@ -0,0 +1,179 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.internal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
import java.sql.SQLException;
import java.util.Map;
/**
* To be updated...
*/
class GadgetDataServiceImpl implements GadgetDataService {
@SuppressWarnings("unused")
private static final Log log = LogFactory.getLog(GadgetDataServiceImpl.class);
@Override
public int getTotalDeviceCount(Map<String, Object> filters) {
int totalDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
totalDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getTotalDeviceCount(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
totalDeviceCount = -1;
return totalDeviceCount;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return totalDeviceCount;
}
@Override
public int getActiveDeviceCount() {
int activeDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
activeDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getActiveDeviceCount();
} catch (GadgetDataServiceDAOException | SQLException e) {
activeDeviceCount = -1;
return activeDeviceCount;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return activeDeviceCount;
}
@Override
public int getInactiveDeviceCount() {
int inactiveDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
inactiveDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getInactiveDeviceCount();
} catch (GadgetDataServiceDAOException | SQLException e) {
inactiveDeviceCount = -1;
return inactiveDeviceCount;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return inactiveDeviceCount;
}
@Override
public int getRemovedDeviceCount() {
int removedDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
removedDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getRemovedDeviceCount();
} catch (GadgetDataServiceDAOException | SQLException e) {
removedDeviceCount = -1;
return removedDeviceCount;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return removedDeviceCount;
}
@Override
public int getNonCompliantDeviceCount() {
int nonCompliantDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
nonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getNonCompliantDeviceCount();
} catch (GadgetDataServiceDAOException | SQLException e) {
nonCompliantDeviceCount = -1;
return nonCompliantDeviceCount;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return nonCompliantDeviceCount;
}
@Override
public int getUnmonitoredDeviceCount() {
int unmonitoredDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
unmonitoredDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getUnmonitoredDeviceCount();
} catch (GadgetDataServiceDAOException | SQLException e) {
unmonitoredDeviceCount = -1;
return unmonitoredDeviceCount;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return unmonitoredDeviceCount;
}
@Override
public Map<String, Integer> getNonCompliantDeviceCountsByFeatures() {
Map<String, Integer> nonCompliantDeviceCountsByFeatures = null;
try {
GadgetDataServiceDAOFactory.openConnection();
nonCompliantDeviceCountsByFeatures =
GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCountsByFeatures();
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return nonCompliantDeviceCountsByFeatures;
}
@Override
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) {
Map<String, Integer> deviceCountsByPlatforms = null;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDeviceCountsByPlatforms(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) {
Map<String, Integer> deviceCountsByOwnershipTypes = null;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDeviceCountsByOwnershipTypes(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByOwnershipTypes;
}
}

@ -28,7 +28,6 @@ var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var userModule = require("/app/modules/user.js").userModule;
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
var user = session.get(constants.USER_SESSION_KEY);
var result;
@ -38,107 +37,41 @@ if (!user) {
response.sendRedirect("/devicemgt/login?#login-required");
exit();
} else {
if (uriMatcher.match("/{context}/api/devices/sketch/download/{downloadId}")) {
downloadId = uriMatcher.elements().downloadId;
//Just download the already created zip archive
var sketchFolder = "repository/resources/sketches";
var archivesPath = "file://" + CarbonUtils.getCarbonHome() + "/" + sketchFolder + "/archives/" +
downloadId + ".zip";
var zipFile = new File(archivesPath);
response.addHeader('Content-type', "application/zip, application/octet-stream");
response.addHeader('Cache-Control', 'public,max-age=12960000');
response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadId + ".zip\"");
try {
zipFile.open('r');
var stream = zipFile.getStream();
print(stream);
} catch (err) {
} finally {
if (zipFile != null) {
zipFile.close();
}
}
} else if (uriMatcher.match("/{context}/api/devices/sketch/download")) {
//Create a new zip archive and register user calling endpoint
/* This should match with $CARBON_HOME/repository/resources/sketches/{sketchType} */
sketchType = request.getParameter("sketchType");
/* This should be registered device type of the CDMF(Connected Device Management Framework) */
deviceType = request.getParameter("deviceType");
deviceName = request.getParameter("deviceName");
if (!sketchType) {
log.error("Sketch Type is empty!");
// HTTP status code 400 refers to - Bad request.
result = 400;
if (uriMatcher.match("/{context}/api/devices/sketch/download")) {
// works as a proxy to pass the relavant query string to back end api.
var queryString = request.getQueryString();
if (!queryString) {
queryString = "";
} else {
/**
URL: {serverURL}/{deviceType}/{downloadAgentUri}?owner={username}&deviceName={deviceName}
{serverURL} - devicemgt/app/conf/config.json
{deviceType} - from the request
{downloadAgentUri} - device_type_specific_unit/private/conf/device-type.json
{username} - from request
{deviceName} - from request
**/
var sketchDownloadEndPoint = devicemgtProps["httpsURL"] + "/" + deviceType + "/devices/download";
deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentUri) {
sketchDownloadEndPoint = deviceTypeConfig.deviceType.downloadAgentUri;
}
var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER);
if (tokenPair) {
response.addHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + tokenPair.accessToken);
response.sendRedirect(sketchDownloadEndPoint + "?sketchType=" + sketchType + "&deviceName="
+ deviceName);
} else {
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
exit();
}
queryString = "?" + queryString;
}
} else if (uriMatcher.match("/{context}/api/devices/sketch/generate_link")) {
var contents = request.getContent();
sketchType = contents.sketchType;
deviceType = contents.deviceType;
deviceName = contents.deviceName;
generateLink = contents.generateLink;
if (!sketchType) {
log.error("Sketch Type is empty!");
// HTTP status code 400 refers to - Bad request.
result = 400;
var deviceType = request.getParameter("deviceType"); // need a better solution here
deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentUri) {
sketchDownloadEndPoint = devicemgtProps["httpsURL"] + "/" + deviceTypeConfig.deviceType.downloadAgentUri;
serviceInvokers.HttpClient.get(sketchDownloadEndPoint + queryString, function (responsePayload, responseHeaders) {
if (responseHeaders) {
for (var i = 0; i < responseHeaders.length; i++) {
var header = responseHeaders[i]
var headerName = String(header.getName());
var headerValue = String(header.getValue());
response.addHeader(headerName, headerValue);
}
var streamObject = new Stream(responsePayload);
print(streamObject);
} else {
return responsePayload;
}
}, function (responsePayload) {
log.error(responsePayload)
var response = {};
response["status"] = "error";
return response;
}
);
} else {
/**
URL: {serverURL}/{deviceType}/{downloadAgentUri}?owner={username}&deviceName={deviceName}
{serverURL} - devicemgt/app/conf/config.json
{deviceType} - from the request
{downloadAgentUri} - device_type_specific_unit/private/conf/device-type.json
{username} - from request
{deviceName} - from request
**/
deviceManagerService = devicemgtProps["httpsURL"] + "/" + deviceType + "_mgt" + "/manager";
sketchGenerateLinkEndPoint = deviceManagerService + "/device/" + sketchType + "/generate_link";
var deviceTypeConfig = utility.getDeviceTypeConfig(deviceType);
//replace download endpoint
if (deviceTypeConfig && deviceTypeConfig.deviceType.downloadAgentLinkGenUri) {
sketchGenerateLinkEndPoint = devicemgtProps["httpsURL"] + "/" + deviceType + "_mgt" +
"/" + deviceTypeConfig.deviceType.downloadAgentLinkGenUri;
}
var fileId = get(sketchGenerateLinkEndPoint + "?owner=" + user.username + "&deviceName=" +
deviceName, null, "text");
result = "curl -k " + devicemgtProps["httpsURL"] + constants.WEB_APP_CONTEXT +
"/api/devices/sketch/download/" + fileId.data;
result = 400;
}
} else if (uriMatcher.match("/{context}/api/devices/all")) {
result = deviceModule.getOwnDevices();

@ -162,21 +162,28 @@ var backendServiceInvoker = function () {
}
}
var stringRequestEntity = new StringRequestEntity(stringify(payload));
httpMethodObject.setRequestEntity(stringRequestEntity);
if (payload) {
var stringRequestEntity = new StringRequestEntity(stringify(payload));
httpMethodObject.setRequestEntity(stringRequestEntity);
}
var client = new HttpClient();
try {
client.executeMethod(httpMethodObject);
var status = httpMethodObject.getStatusCode();
if (status == 200) {
return successCallback(httpMethodObject.getResponseBody());
var responseContentTypeHeader = httpMethodObject.getResponseHeader(constants.CONTENT_TYPE_IDENTIFIER);
if (responseContentTypeHeader && responseContentTypeHeader.getValue() == constants.APPLICATION_ZIP) {
return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders());
} else {
return successCallback(httpMethodObject.getResponseBody());
}
} else {
return errorCallback(httpMethodObject.getResponseBody());
}
} catch (e) {
return errorCallback(response);
} finally {
method.releaseConnection();
httpMethodObject.releaseConnection();
}
};

@ -62,6 +62,7 @@ var ACCESS_TOKEN_PAIR_IDENTIFIER = "accessTokenPair";
var ENCODED_CLIENT_KEYS_IDENTIFIER = "encodedClientKey";
var CONTENT_TYPE_IDENTIFIER = "Content-Type";
var APPLICATION_JSON = "application/json";
var APPLICATION_ZIP = "application/zip";
var ACCEPT_IDENTIFIER = "Accept";
var AUTHORIZATION_HEADER= "Authorization";
var BEARER_PREFIX = "Bearer ";

@ -28,7 +28,6 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>device-mgt</artifactId>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Management Component</name>
@ -39,6 +38,7 @@
<module>org.wso2.carbon.device.mgt.common</module>
<module>org.wso2.carbon.device.mgt.extensions</module>
<module>org.wso2.carbon.device.mgt.ui</module>
<module>org.wso2.carbon.device.mgt.analytics.dashboard</module>
<module>org.wso2.carbon.device.mgt.api</module>
<module>org.wso2.carbon.device.mgt.analytics.data.publisher</module>
<module>org.wso2.carbon.device.mgt.etc</module>

@ -85,9 +85,14 @@ public class PermissionBasedScopeValidator extends OAuth2ScopeValidator {
int tenantId = OAuthExtUtils.getTenantId(authzUser.getTenantDomain());
UserRealm userRealm = OAuthExtensionsDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId);
if (userRealm != null && userRealm.getAuthorizationManager() != null) {
status = userRealm.getAuthorizationManager()
.isUserAuthorized(userStore +"/"+ username, permission.getPath(),
PermissionMethod.UI_EXECUTE);
if (userStore != null) {
status = userRealm.getAuthorizationManager()
.isUserAuthorized(userStore + "/" + username, permission.getPath(),
PermissionMethod.UI_EXECUTE);
} else {
status = userRealm.getAuthorizationManager()
.isUserAuthorized(username, permission.getPath(), PermissionMethod.UI_EXECUTE);
}
}
}
} catch (PermissionManagementException e) {

@ -22,29 +22,34 @@ public final class PolicyManagementConstants {
public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml";
public static final String ANY = "ANY";
public static final String POLICY_BUNDLE = "POLICY_BUNDLE";
// public static final String POLICY_BUNDLE = "POLICY_BUNDLE";
public static final String TENANT_ID = "TENANT_ID";
public static final String MONITOR = "MONITOR";
// public static final String MONITOR = "MONITOR";
public static final String ENFORCE = "ENFORCE";
public static final String WARN = "WARN";
public static final String BLOCK = "BLOCK";
public static final String MONITORING_TASK_TYPE = "MONITORING_TASK";
public static final String MONITORING_TASK_NAME = "MONITORING";
public static final String MONITORING_TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.task.MonitoringTask";
public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER";
public static final String DM_CACHE = "DM_CACHE";
// public static final String DM_CACHE = "DM_CACHE";
public static final String DM_CACHE_LIST = "DM_CACHE_LIST";
public static final String DELEGATION_TASK_TYPE = "DELEGATION__TASK";
public static final String DELEGATION_TASK_NAME = "DELEGATION";
public static final String DELEGATION_TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask";
/**
Caller would reference the constants using PolicyManagementConstants.DEVICE_CONFIG_XML_NAME,
and so on. Any caller should be prevented from constructing objects of
this class, thus declaring this private constructor.
*/
private PolicyManagementConstants() {
throw new AssertionError();
}
}

@ -28,7 +28,6 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>policy-mgt</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
@ -43,7 +42,6 @@
<module>org.wso2.carbon.complex.policy.decision.point</module>
</modules>
<build>
<pluginManagement>
<plugins>

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>device-mgt-feature</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard.feature</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WSO2 Carbon - Device Management Dashboard Analytics Feature</name>
<description>WSO2 Carbon - Device Management Dashboard Analytics Feature</description>
<url>http://wso2.org</url>
<dependencies>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<version>${carbon.p2.plugin.version}</version>
<executions>
<execution>
<id>p2-feature-generation</id>
<phase>package</phase>
<goals>
<goal>p2-feature-gen</goal>
</goals>
<configuration>
<id>org.wso2.carbon.device.mgt.analytics.dashboard</id>
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
<adviceFile>
<properties>
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
</properties>
</adviceFile>
<bundles>
<bundleDef>
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.analytics.dashboard:${carbon.device.mgt.version}
</bundleDef>
</bundles>
<importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
</importFeatureDef>
</importFeatures>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -507,3 +507,31 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
);
-- END OF POLICY AND DEVICE GROUP MAPPING --
CREATE VIEW DEVICES_VIEW_1 AS
SELECT
DEVICE_INFO.DEVICE_ID,
DEVICE_INFO.PLATFORM,
DEVICE_INFO.OWNERSHIP,
DEVICE_INFO.CONNECTIVITY_STATUS,
IFNULL(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID,
IFNULL(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 AS OWNERSHIP,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_DEVICE.TENANT_ID AS 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;

@ -39,6 +39,7 @@
<module>org.wso2.carbon.device.mgt.feature</module>
<module>org.wso2.carbon.device.mgt.extensions.feature</module>
<module>org.wso2.carbon.device.mgt.analytics.data.publisher.feature</module>
<module>org.wso2.carbon.device.mgt.analytics.dashboard.feature</module>
</modules>
</project>

@ -269,6 +269,11 @@
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.analytics.dashboard</artifactId>
<version>${carbon.device.mgt.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.server.feature</artifactId>

Loading…
Cancel
Save