forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt into das-ext
commit
99a424b58b
@ -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;
|
||||
}
|
||||
|
||||
}
|
77
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java
77
components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
<%
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var uri = request.getRequestURI();
|
||||
var uriMatcher = new URIMatcher(String(uri));
|
||||
|
||||
var log = new Log("api/device-api.jag");
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
|
||||
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
var result;
|
||||
|
||||
response.contentType = 'application/json';
|
||||
|
||||
if (!user) {
|
||||
response.sendRedirect("/devicemgt/login?#login-required");
|
||||
exit();
|
||||
} else {
|
||||
if (uriMatcher.match("/{context}/api/groups")) {
|
||||
var url = request.getParameter("url");
|
||||
var draw = request.getParameter("draw");
|
||||
var length = request.getParameter("length");
|
||||
var start = request.getParameter("start");
|
||||
var search = request.getParameter("search[value]");
|
||||
var groupName = request.getParameter("columns[1][search][value]");
|
||||
var owner = request.getParameter("columns[2][search][value]");
|
||||
var targetURL;
|
||||
|
||||
function appendQueryParam(url, queryParam, value) {
|
||||
if (url.indexOf("?") > 0) {
|
||||
return url + "&" + queryParam + "=" + value;
|
||||
}
|
||||
return url + "?" + queryParam + "=" + value;
|
||||
}
|
||||
|
||||
targetURL = devicemgtProps.httpsURL + request.getParameter("url");
|
||||
targetURL = appendQueryParam(targetURL, "start", start);
|
||||
targetURL = appendQueryParam(targetURL, "length", length);
|
||||
|
||||
if (search && search !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "search", search);
|
||||
}
|
||||
|
||||
if (groupName && groupName !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "group-name", groupName);
|
||||
}
|
||||
|
||||
if (owner && owner !== "") {
|
||||
targetURL = appendQueryParam(targetURL, "user", owner);
|
||||
}
|
||||
|
||||
serviceInvokers.XMLHttp.get(
|
||||
targetURL, function (responsePayload) {
|
||||
response.status = 200;
|
||||
result = responsePayload;
|
||||
},
|
||||
function (responsePayload) {
|
||||
response.status = responsePayload.status;
|
||||
result = responsePayload.responseText;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (result) {
|
||||
print(result);
|
||||
}
|
||||
|
||||
%>
|
@ -1,124 +0,0 @@
|
||||
<%
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
var uri = request.getRequestURI();
|
||||
var uriMatcher = new URIMatcher(String(uri));
|
||||
|
||||
var log = new Log("api/stats-api.jag");
|
||||
|
||||
var from = request.getParameter("from");
|
||||
var to = request.getParameter("to");
|
||||
|
||||
var constants = require("/app/modules/constants.js");
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
|
||||
|
||||
var deviceCloudGroupService = devicemgtProps["httpsURL"] + "/common/group_manager";
|
||||
var deviceCloudDeviceService = devicemgtProps["httpsURL"] + "/common/device_manager";
|
||||
var deviceCloudStatsService = devicemgtProps["httpsURL"] + "/common/stats_manager";
|
||||
|
||||
var stats = {};
|
||||
var deviceId;
|
||||
var deviceType;
|
||||
|
||||
var responseProcessor = require('utils').response;
|
||||
response.contentType = 'application/json';
|
||||
|
||||
var user = session.get(constants.USER_SESSION_KEY);
|
||||
|
||||
if (!user) {
|
||||
response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized");
|
||||
} else {
|
||||
if (uriMatcher.match("/{context}/api/stats")) {
|
||||
deviceId = request.getParameter("deviceId");
|
||||
deviceType = request.getParameter("deviceType");
|
||||
|
||||
getDeviceData(deviceType, deviceId);
|
||||
|
||||
} else if (uriMatcher.match("/{context}/api/stats/group")) {
|
||||
var groupId = request.getParameter("groupId");
|
||||
|
||||
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all
|
||||
var endPoint = deviceCloudGroupService + "/group/id/" + groupId + "/device/all";
|
||||
var data = {"username": user};
|
||||
var devices = get(endPoint, data, "json").data;
|
||||
|
||||
for (var device in devices) {
|
||||
deviceId = devices[device].deviceIdentifier;
|
||||
deviceType = devices[device].type;
|
||||
getDeviceData(deviceType, deviceId);
|
||||
}
|
||||
}
|
||||
log.info(stats);
|
||||
// returning the result.
|
||||
if (stats) {
|
||||
print(stats);
|
||||
}
|
||||
}
|
||||
|
||||
function getDeviceData(deviceType, deviceId) {
|
||||
//URL: GET https://localhost:9443/devicecloud/device_manager/device/type/{type}/identifier/{identifier}
|
||||
var endPoint = deviceCloudDeviceService + "/device/type/" + deviceType + "/identifier/" + deviceId;
|
||||
var data = {"username": user};
|
||||
var device = get(endPoint, data, "json").data;
|
||||
log.info(device);
|
||||
if (!device) {
|
||||
return;
|
||||
}
|
||||
var uname = device.enrolmentInfo.owner;
|
||||
|
||||
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
|
||||
|
||||
if (analyticStreams) {
|
||||
var streamTableName;
|
||||
for (var stream in analyticStreams) {
|
||||
streamTableName = analyticStreams[stream]["table"];
|
||||
if (stats[streamTableName] == null) {
|
||||
stats[streamTableName] = [];
|
||||
}
|
||||
stats[streamTableName].push({
|
||||
"device": device.name,
|
||||
"stats": getSensorData(streamTableName, analyticStreams[stream]["ui_unit"]["data"][1]["column"]["name"], uname, device.type, device.deviceIdentifier, from, to),
|
||||
"stream": analyticStreams[stream]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSensorData(table, column, user, type, deviceIdentifier, from, to) {
|
||||
|
||||
var fetchedData = [];
|
||||
|
||||
try {
|
||||
///stats/device/type/{type}/identifier/{identifier}
|
||||
var endPoint = deviceCloudStatsService + "/stats/device/type/" + type + "/identifier/" + deviceIdentifier;
|
||||
var query = "?table=" + encodeURIComponent(table)
|
||||
+ "&column=" + encodeURIComponent(column)
|
||||
+ "&username=" + encodeURIComponent(user)
|
||||
+ "&from=" + from
|
||||
+ "&to=" + to;
|
||||
endPoint = endPoint + query;
|
||||
fetchedData = get(endPoint, {}, "json").data;
|
||||
return fetchedData;
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
%>
|
Loading…
Reference in new issue