revert-70aa11f8
hasuniea 9 years ago
commit 5f8a41eb12

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

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

@ -0,0 +1,82 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard;
/**
* Custom exception class for GadgetDataService layer.
*/
public class GadgetDataServiceException extends Exception {
private String errorMessage;
private static final long serialVersionUID = 2021891706072918864L;
/**
* Constructs a new exception with the specific error message and nested exception.
*
* @param errorMessage specific error message.
* @param nestedException Nested exception.
*/
public GadgetDataServiceException(String errorMessage, Exception nestedException) {
super(errorMessage, nestedException);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message and cause.
*
* @param errorMessage Specific error message.
* @param cause Cause of this exception.
*/
@SuppressWarnings("unused")
public GadgetDataServiceException(String errorMessage, Throwable cause) {
super(errorMessage, cause);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message.
*
* @param errorMessage Specific error message.
*/
@SuppressWarnings("unused")
public GadgetDataServiceException(String errorMessage) {
super(errorMessage);
setErrorMessage(errorMessage);
}
/**
* Constructs a new exception with the specific error message and cause.
*
* @param cause Cause of this exception.
*/
@SuppressWarnings("unused")
public GadgetDataServiceException(Throwable cause) {
super(cause);
}
@SuppressWarnings("unused")
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

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

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl.GadgetDataServiceDAOImpl;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
@ -33,6 +34,7 @@ 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;
@ -47,7 +49,7 @@ public class GadgetDataServiceDAOFactory {
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
log.error("Error occurred while retrieving config.datasource connection.", e);
}
}
@ -56,7 +58,7 @@ public class GadgetDataServiceDAOFactory {
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
log.error("Error occurred while retrieving config.datasource connection.", e);
}
}
@ -65,7 +67,7 @@ public class GadgetDataServiceDAOFactory {
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");
"transaction is already active is a sign of improper transaction handling.");
}
conn = dataSource.getConnection();
currentConnection.set(conn);
@ -76,7 +78,7 @@ public class GadgetDataServiceDAOFactory {
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");
"'beginTransaction'/'openConnection' methods.");
}
return conn;
}
@ -86,35 +88,34 @@ public class GadgetDataServiceDAOFactory {
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");
"'beginTransaction'/'openConnection' methods.");
}
try {
conn.close();
} catch (SQLException e) {
log.warn("Error occurred while close the connection");
log.warn("Error occurred while close the connection.");
}
currentConnection.remove();
}
/**
* Resolve data source from the data source definition
* Resolve data source from the data source definition.
*
* @param config data source configuration
* @return data source resolved 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");
"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");
log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition.");
}
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
if (jndiPropertyList != null) {

@ -16,11 +16,12 @@
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.dao;
package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
@ -34,9 +35,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@SuppressWarnings("unused")
private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class);
public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
@Override
public int getTotalDeviceCount() throws GadgetDataServiceDAOException {
@ -72,7 +71,15 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
}
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) throws GadgetDataServiceDAOException {
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1);
return this.getDeviceCount(filters);
}
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceDAOException {
Connection con;
PreparedStatement stmt = null;
ResultSet rs = null;
@ -112,7 +119,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT");
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting non compliant device counts by features.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -122,13 +130,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
return paginationResult;
}
@Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException {
Map<String, Object> filters = new HashMap<>();
filters.put("POLICY_ID", -1);
return this.getDeviceCount(filters);
}
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceDAOException {
Connection con;
PreparedStatement stmt = null;
@ -166,7 +167,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCount = rs.getInt("DEVICE_COUNT");
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered device count.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -211,7 +213,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDeviceCount = rs.getInt("DEVICE_COUNT");
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered device count, " +
"non compliant by a particular feature.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -257,7 +261,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of device counts by platforms.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -304,7 +309,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a set of feature non-compliant device counts by platforms.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -350,7 +356,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of device counts by ownership types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -398,7 +405,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of feature " +
"non-compliant device counts by ownership types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -469,7 +478,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of devices " +
"with details when pagination is enabled.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -485,7 +496,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
PreparedStatement stmt = null;
ResultSet rs = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Map<String, Object> filteredDeviceWithDetails = new HashMap<>();
List<Map<String, Object>> filteredDevicesWithDetails = new ArrayList<>();
int totalRecordsCount = 0;
try {
@ -523,7 +533,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
// executing query
rs = stmt.executeQuery();
// fetching query results
Map<String, Object> filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new HashMap<>();
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
@ -545,7 +557,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
totalRecordsCount = rs.getInt("DEVICE_COUNT");
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of feature non-compliant devices " +
"with details when pagination is enabled.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -599,7 +613,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting a filtered set of devices with details.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
@ -612,7 +627,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
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();
@ -644,7 +658,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
// executing query
rs = stmt.executeQuery();
// fetching query results
Map<String, Object> filteredDeviceWithDetails;
while (rs.next()) {
filteredDeviceWithDetails = new HashMap<>();
filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
@ -652,7 +668,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
filteredDevicesWithDetails.add(filteredDeviceWithDetails);
}
} catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " +
"execute relevant SQL queries for getting filtered set of feature non-compliant devices with details.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}

@ -0,0 +1,363 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.analytics.dashboard.impl;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataServiceException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
/**
* To be updated...
*/
public class GadgetDataServiceImpl implements GadgetDataService {
@Override
public int getTotalDeviceCount() throws GadgetDataServiceException {
int totalDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for total device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return totalDeviceCount;
}
@Override
public int getActiveDeviceCount() throws GadgetDataServiceException {
int activeDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for active device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return activeDeviceCount;
}
@Override
public int getInactiveDeviceCount() throws GadgetDataServiceException {
int inactiveDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for inactive device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return inactiveDeviceCount;
}
@Override
public int getRemovedDeviceCount() throws GadgetDataServiceException {
int removedDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for removed device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return removedDeviceCount;
}
@Override
public int getNonCompliantDeviceCount() throws GadgetDataServiceException {
int nonCompliantDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
nonCompliantDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for non-compliant device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return nonCompliantDeviceCount;
}
@Override
public int getUnmonitoredDeviceCount() throws GadgetDataServiceException {
int unmonitoredDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount();
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for unmonitored device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return unmonitoredDeviceCount;
}
@Override
public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest)
throws GadgetDataServiceException {
PaginationResult paginationResult;
try {
GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getNonCompliantDeviceCountsByFeatures(paginationRequest);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for non-compliant device counts by features.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return paginationResult;
}
@Override
public int getDeviceCount(Map<String, Object> filters) throws GadgetDataServiceException {
int deviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in calling DAO function for getting a filtered device count.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCount;
}
@Override
public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map<String, Object> filters)
throws GadgetDataServiceException {
int featureNonCompliantDeviceCount;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting a filtered device count, non compliant by a particular feature.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDeviceCount;
}
@Override
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters)
throws GadgetDataServiceException {
Map<String, Integer> deviceCountsByPlatforms;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByPlatforms(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by platforms.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
Map<String, Integer> featureNonCompliantDeviceCountsByPlatforms;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by platforms, non compliant by a particular feature.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDeviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters)
throws GadgetDataServiceException {
Map<String, Integer> deviceCountsByOwnershipTypes;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDeviceCountsByOwnershipTypes(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by ownership types.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByOwnershipTypes;
}
@Override
public Map<String, Integer> getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
Map<String, Integer> featureNonCompliantDeviceCountsByOwnershipTypes;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDeviceCountsByOwnershipTypes =
GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection.", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered device counts by ownership types, non compliant by a particular feature.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDeviceCountsByOwnershipTypes;
}
@Override
public PaginationResult getDevicesWithDetails(Map<String, Object> filters,
PaginationRequest paginationRequest) throws GadgetDataServiceException {
PaginationResult paginationResult;
try {
GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getDevicesWithDetails(filters, paginationRequest);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details when pagination is enabled.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return paginationResult;
}
@Override
public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters, PaginationRequest paginationRequest) throws GadgetDataServiceException {
PaginationResult paginationResult;
try {
GadgetDataServiceDAOFactory.openConnection();
paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details, non compliant by feature when pagination is enabled.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return paginationResult;
}
@Override
public List<Map<String, Object>> getDevicesWithDetails(Map<String, Object> filters)
throws GadgetDataServiceException {
List<Map<String, Object>> devicesWithDetails;
try {
GadgetDataServiceDAOFactory.openConnection();
devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return devicesWithDetails;
}
@Override
public List<Map<String, Object>> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode,
Map<String, Object> filters) throws GadgetDataServiceException {
List<Map<String, Object>> featureNonCompliantDevicesWithDetails;
try {
GadgetDataServiceDAOFactory.openConnection();
featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().
getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters);
} catch (SQLException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " +
"in opening database connection", e);
} catch (GadgetDataServiceDAOException e) {
throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " +
"for getting filtered devices with details, non compliant by feature.", e);
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return featureNonCompliantDevicesWithDetails;
}
}

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService;
import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory;
import org.wso2.carbon.device.mgt.analytics.dashboard.impl.GadgetDataServiceImpl;
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;
@ -39,6 +40,7 @@ import org.wso2.carbon.ndatasource.core.DataSourceService;
* unbind="unsetDataSourceService"
*/
public class GadgetDataServiceComponent {
private static final Log log = LogFactory.getLog(GadgetDataServiceComponent.class);
protected void activate(ComponentContext componentContext) {
@ -56,10 +58,10 @@ public class GadgetDataServiceComponent {
componentContext.getBundleContext().
registerService(GadgetDataService.class.getName(), new GadgetDataServiceImpl(), null);
if (log.isDebugEnabled()) {
log.debug("Device Management Dashboard Analytics Bundle has been started successfully");
log.debug("Device Management Dashboard Analytics Bundle has been started successfully.");
}
} catch (Throwable e) {
log.error("Error occurred while initializing the bundle", e);
log.error("Error occurred while initializing the bundle.", e);
}
}
@ -71,10 +73,17 @@ public class GadgetDataServiceComponent {
}
public void setDataSourceService(DataSourceService dataSourceService) {
if (log.isDebugEnabled()) {
log.debug("Binding org.wso2.carbon.ndatasource.core.DataSourceService...");
}
//do nothing
}
public void unsetDataSourceService(DataSourceService dataSourceService) {
if (log.isDebugEnabled()) {
log.debug("Unbinding org.wso2.carbon.ndatasource.core.DataSourceService...");
}
//do nothing
}
}

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

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

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

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

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

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

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

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

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

@ -18,8 +18,6 @@
*/
package org.wso2.carbon.device.mgt.core.dto.operation.mgt;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Properties;
@ -30,7 +28,11 @@ public class Operation implements Serializable {
}
public enum Status {
IN_PROGRESS, PENDING, COMPLETED, ERROR
IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED
}
public enum Control {
REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE
}
private String code;
@ -38,6 +40,7 @@ public class Operation implements Serializable {
private Type type;
private int id;
private Status status;
private Control control;
private String receivedTimeStamp;
private String createdTimeStamp;
private boolean isEnabled;
@ -84,6 +87,14 @@ public class Operation implements Serializable {
this.status = status;
}
public Control getControl() {
return control;
}
public void setControl(Control control) {
this.control = control;
}
public String getReceivedTimeStamp() {
return receivedTimeStamp;
}

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

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

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

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

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

@ -109,6 +109,12 @@ public class OperationManagerImpl implements OperationManager {
OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
for (EnrolmentInfo enrolmentInfo : enrolments) {
if(operationDto.getControl() ==
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT){
operationDAO.updateEnrollmentOperationsStatus(enrolmentInfo.getId(), operationDto.getCode(),
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED);
}
operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
}
OperationManagementDAOFactory.commitTransaction();
@ -613,7 +619,7 @@ public class OperationManagerImpl implements OperationManager {
public Operation getOperation(int operationId) throws OperationManagementException {
Operation operation;
try {
OperationManagementDAOFactory.getConnection();
OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
getOperation(operationId);
if (dtoOperation == null) {
@ -648,6 +654,17 @@ public class OperationManagerImpl implements OperationManager {
return operation;
}
@Override
public Operation getOperationByActivityId(String activity) throws OperationManagementException {
// This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer.
int operationId = Integer.parseInt(
activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
if(operationId == 0){
throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
}
return this.getOperation(operationId);
}
private OperationDAO lookupOperationDAO(Operation operation) {
if (operation instanceof CommandOperation) {

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

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

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

@ -105,6 +105,41 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
}
@Override
public void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
Operation.Status newStatus) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Connection connection = OperationManagementDAOFactory.getConnection();
String query = "SELECT EOM.ID FROM DM_ENROLMENT_OP_MAPPING AS EOM INNER JOIN DM_OPERATION DM " +
"ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? " +
"AND EOM.STATUS = ?;";
stmt = connection.prepareStatement(query);
stmt.setInt(1, enrolmentId);
stmt.setString(2, operationCode);
stmt.setString(3, existingStatus.toString());
// This will return only one result always.
rs = stmt.executeQuery();
int id = 0;
while (rs.next()){
id = rs.getInt("ID");
}
if (id != 0){
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS = ? WHERE ID = ?");
stmt.setString(1, newStatus.toString());
stmt.setInt(2, id);
stmt.executeUpdate();
}
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
"metadata", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt);
}
}
@Override
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException {

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

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

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

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

@ -34,7 +34,9 @@ import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SearchDAOImpl implements SearchDAO {
@ -52,12 +54,13 @@ public class SearchDAOImpl implements SearchDAO {
PreparedStatement stmt = null;
ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement(query);
rs = stmt.executeQuery();
while (rs.next()) {
if(!devs.containsKey(rs.getInt("ID"))) {
Device device = new Device();
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
@ -78,17 +81,14 @@ public class SearchDAOImpl implements SearchDAO {
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
DeviceLocation deviceLocation = new DeviceLocation();
deviceLocation.setLatitude(rs.getDouble("LATITUDE"));
@ -100,6 +100,7 @@ public class SearchDAOImpl implements SearchDAO {
deviceLocation.setZip(rs.getString("ZIP"));
deviceLocation.setCountry(rs.getString("COUNTRY"));
deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
DeviceWrapper wrapper = new DeviceWrapper();
wrapper.setDevice(device);
@ -107,6 +108,8 @@ public class SearchDAOImpl implements SearchDAO {
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
devs.put(device.getId(), device.getId());
}
}
} catch (SQLException e) {
@ -134,12 +137,13 @@ public class SearchDAOImpl implements SearchDAO {
PreparedStatement stmt = null;
ResultSet rs;
List<DeviceWrapper> devices = new ArrayList<>();
Map<Integer, Integer> devs = new HashMap<>();
try {
conn = this.getConnection();
stmt = conn.prepareStatement(query);
rs = stmt.executeQuery();
while (rs.next()) {
if(!devs.containsKey(rs.getInt("ID"))) {
Device device = new Device();
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
@ -160,17 +164,14 @@ public class SearchDAOImpl implements SearchDAO {
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));
deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
DeviceLocation deviceLocation = new DeviceLocation();
deviceLocation.setLatitude(rs.getDouble("LATITUDE"));
@ -182,13 +183,17 @@ public class SearchDAOImpl implements SearchDAO {
deviceLocation.setZip(rs.getString("ZIP"));
deviceLocation.setCountry(rs.getString("COUNTRY"));
deviceLocation.setDeviceId(rs.getInt("ID"));
deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP")));
DeviceWrapper wrapper = new DeviceWrapper();
wrapper.setDevice(device);
wrapper.setDeviceInfo(deviceInfo);
wrapper.setDeviceLocation(deviceLocation);
wrapper.setDeviceIdentifier(identifier);
devices.add(wrapper);
devs.put(device.getId(), device.getId());
}
}
} catch (SQLException e) {

@ -94,6 +94,28 @@ public class ProcessorImpl implements Processor {
return aggregator.aggregate(deviceWrappers);
}
@Override
public List<DeviceWrapper> getUpdatedDevices(long epochTime) throws SearchMgtException {
if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) {
epochTime = epochTime * 1000;
}
QueryBuilder queryBuilder = new QueryBuilderImpl();
try {
String query = queryBuilder.processUpdatedDevices(epochTime);
DeviceManagementDAOFactory.openConnection();
return searchDAO.searchDeviceDetailsTable(query);
} catch (InvalidOperatorException e) {
throw new SearchMgtException("Invalid operator was provided, so cannot execute the search.", e);
} catch (SQLException e) {
throw new SearchMgtException("Error occurred while managing database transactions.", e);
} catch (SearchDAOException e) {
throw new SearchMgtException("Error occurred while running the search operations for given time.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
private List<DeviceWrapper> processANDSearch(List<List<DeviceWrapper>> deLists) {

@ -114,7 +114,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) {
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue());
} else if (Utils.checkDeviceLocationColumns(con.getKey())) {
querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
@ -132,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder {
for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) {
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue());
} else if (Utils.checkDeviceLocationColumns(con.getKey())) {
querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) +
con.getOperator() + con.getValue();
@ -158,6 +158,12 @@ public class QueryBuilderImpl implements QueryBuilder {
return this.getQueryList(conditions);
}
@Override
public String processUpdatedDevices(long epochTime) throws InvalidOperatorException {
return this.getGenericQueryPart() + " AND ( DD.UPDATE_TIMESTAMP > " + epochTime +
" OR DL.UPDATE_TIMESTAMP > " + epochTime + " )";
}
private List<String> getQueryList(List<Condition> conditions) {
List<String> queryList = new ArrayList<>();
for (Condition con : conditions) {
@ -189,8 +195,9 @@ public class QueryBuilderImpl implements QueryBuilder {
"DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" +
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " +
"DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP " +
"FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " +
"DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -205,8 +212,9 @@ public class QueryBuilderImpl implements QueryBuilder {
"DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" +
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY, DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " +
"DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, " +
"DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " +
"DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" +
"DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

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

@ -60,6 +60,41 @@ public class Utils {
}
public static boolean checkColumnType(String column) {
boolean bool = false;
switch (column) {
case "deviceModel":
bool = true;
break;
case "vendor":
bool = true;
break;
case "osVersion":
bool = true;
break;
case "connectionType":
bool = true;
break;
case "ssid":
bool = true;
break;
default: bool =false;
break;
}
return bool;
}
public static String getConvertedValue(String column, String value) {
if(checkColumnType(column)){
return "\'" + value + "\'";
} else return value;
}
public static Map<String, String> getDeviceDetailsColumnNames() {
return genericColumnsMap;
}

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

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

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

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

@ -97,30 +97,7 @@ function toTitleCase(str) {
function loadGroups() {
var groupListing = $("#group-listing");
var groupListingSrc = groupListing.attr("src");
var currentUser = groupListing.data("currentUser");
$.template("group-listing", groupListingSrc, function (template) {
var successCallback = function (data) {
data = JSON.parse(data);
var viewModel = {};
viewModel.groups = data.data;
$('#group-grid').removeClass('hidden');
var content = template(viewModel);
$("#ast-container").html(content);
/*
* On group checkbox select add parent selected style class
*/
$(groupCheckbox).click(function () {
addGroupSelectedClass(this);
});
attachEvents();
$('#group-grid').datatables_extended();
$(".icon .text").res_text(0.2);
};
var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000";
@ -135,10 +112,82 @@ function loadGroups() {
return;
}
invokerUtil.get(serviceURL, successCallback, function (message) {
displayErrors(message.content);
$('#group-grid').datatables_extended ({
serverSide: true,
processing: false,
searching: true,
ordering: false,
filter: false,
pageLength : 16,
ajax: { url : '/devicemgt/api/groups', data : {url : serviceURL},
dataSrc: function ( json ) {
$('#group-grid').removeClass('hidden');
var $list = $("#group-listing :input[type='search']");
$list.each(function(){
$(this).addClass("hidden");
});
return json.data;
}
},
columnDefs: [
{ targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) {
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
}},
{ targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) {
return '<h4 data-groupid="' + row.id + '">' + name + '</h4>';
}},
{ targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'},
{ targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
render: function ( id, type, row, meta ) {
var html;
html = '<a href="devices?groupName=' + row.name + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
html += '<a href="analytics?groupName=' + row.name + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-statistics fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Analytics</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view share-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-share fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
'<i class="fw fw-edit fw-stack-1x"></i></span><span class="hidden-xs hidden-on-grid-view">Edit</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x"></i>' +
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
return html;
}}
],
"createdRow": function( row, data, dataIndex ) {
$(row).attr('data-type', 'selectable');
$(row).attr('data-groupid', data.id);
$.each($('td', row), function (colIndex) {
switch(colIndex) {
case 1:
$(this).attr('data-grid-label', "Name");
$(this).attr('data-search', data.name);
$(this).attr('data-display', data.name);
break;
case 2:
$(this).attr('data-grid-label', "Owner");
$(this).attr('data-search', data.owner);
$(this).attr('data-display', data.owner);
break;
}
});
},
"fnDrawCallback": function( oSettings ) {
$(".icon .text").res_text(0.2);
attachEvents();
}
});
$(groupCheckbox).click(function () {
addGroupSelectedClass(this);
});
}

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

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

@ -60,7 +60,7 @@ public class CertificateAuthenticator implements WebappAuthenticator {
if (request.getHeader(MUTUAL_AUTH_HEADER) != null) {
X509Certificate[] clientCertificate = (X509Certificate[]) request.
getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE);
if (clientCertificate[0] != null) {
if (clientCertificate != null && clientCertificate[0] != null) {
CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance().
getCertificateManagementService().verifyPEMSignature(clientCertificate[0]);
if (certificateResponse == null) {
@ -86,6 +86,9 @@ public class CertificateAuthenticator implements WebappAuthenticator {
"but the serial number is missing in the database.");
}
} else {
authenticationInfo.setStatus(Status.FAILURE);
authenticationInfo.setMessage("No client certificate is present");
}
} else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) {

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

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

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

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

@ -568,6 +568,34 @@ WHEN (NEW.ID IS NULL)
END;
/
CREATE TABLE DM_DEVICE_GROUP_POLICY (
ID NUMBER(10) NOT NULL,
DEVICE_GROUP_ID NUMBER(10) NOT NULL,
POLICY_ID NUMBER(10) NOT NULL,
TENANT_ID NUMBER(10) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID)
REFERENCES DM_GROUP (ID)
,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID)
REFERENCES DM_POLICY (ID , ID)
) ;
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr
BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW
WHEN (NEW.ID IS NULL)
BEGIN
SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
/
CREATE TABLE DM_APPLICATION (
ID NUMBER(10) NOT NULL,
NAME VARCHAR2(150) NOT NULL,
@ -714,6 +742,7 @@ CREATE TABLE DM_DEVICE_LOCATION (
ZIP VARCHAR2(10) NULL,
STATE VARCHAR2(45) NULL,
COUNTRY VARCHAR2(45) NULL,
UPDATE_TIMESTAMP NUMBER(19) NOT NULL,
PRIMARY KEY (ID)
,
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
@ -751,23 +780,22 @@ CREATE TABLE DM_DEVICE_DETAIL (
VENDOR VARCHAR2(45) NULL,
OS_VERSION VARCHAR2(45) NULL,
BATTERY_LEVEL NUMBER(4) NULL,
INTERNAL_TOTAL_MEMORY NUMBER(30) NULL,
INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL,
EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL,
EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL,
INTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL,
EXTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL,
CONNECTION_TYPE VARCHAR2(10) NULL,
SSID VARCHAR2(45) NULL,
CPU_USAGE NUMBER(5) NULL,
TOTAL_RAM_MEMORY NUMBER(30) NULL,
AVAILABLE_RAM_MEMORY NUMBER(30) NULL,
TOTAL_RAM_MEMORY NUMBER(30,3) NULL,
AVAILABLE_RAM_MEMORY NUMBER(30,3) NULL,
PLUGGED_IN NUMBER(10) NULL,
PRIMARY KEY (ID)
,
UPDATE_TIMESTAMP NUMBER(19) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID)
)
;
);
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1;
@ -782,4 +810,3 @@ END;
CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC);

@ -292,6 +292,26 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION
);
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq;
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_GROUP_POLICY_seq'),
DEVICE_GROUP_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID)
REFERENCES DM_GROUP (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID)
REFERENCES DM_POLICY (ID , ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
@ -379,6 +399,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
ZIP VARCHAR(10) NULL,
STATE VARCHAR(45) NULL,
COUNTRY VARCHAR(45) NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID) ,
CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID)
@ -390,6 +411,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC);
CREATE SEQUENCE DM_DEVICE_DETAIL_seq;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'),
DEVICE_ID INT NOT NULL,
@ -407,6 +430,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID)

Loading…
Cancel
Save