forked from community/device-mgt-core
commit
974a616737
@ -1,14 +1,7 @@
|
||||
package org.wso2.carbon.device.mgt.core.api.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApplicationManagementProviderService extends ApplicationManager {
|
||||
|
||||
void updateApplicationListInstallInDevice(DeviceIdentifier deviceIdentifier, List<Application> applications)
|
||||
throws ApplicationManagementException;
|
||||
}
|
||||
|
@ -1,105 +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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.common.DBTypes;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDBConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class DeviceManagementBaseTest {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementBaseTest.class);
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
@Parameters("dbType")
|
||||
public void setupDatabase(String dbTypeName) throws Exception {
|
||||
DBTypes type = DBTypes.valueOf(dbTypeName);
|
||||
TestDBConfiguration config = getTestDBConfiguration(type);
|
||||
switch (type) {
|
||||
case H2:
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(config.getConnectionUrl());
|
||||
properties.setDriverClassName(config.getDriverClass());
|
||||
properties.setUsername(config.getUserName());
|
||||
properties.setPassword(config.getPwd());
|
||||
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
|
||||
this.initSQLScript();
|
||||
default:
|
||||
}
|
||||
}
|
||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws DeviceManagementDAOException,
|
||||
DeviceManagementException {
|
||||
File dbConfig = new File("src/test/resources/data-source-config.xml");
|
||||
Document doc = DeviceManagerUtil.convertToDocument(dbConfig);
|
||||
TestDBConfigurations dbConfigs;
|
||||
JAXBContext testDBContext;
|
||||
|
||||
try {
|
||||
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||
dbConfigs = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
||||
for (TestDBConfiguration config : dbConfigs.getDbTypesList()) {
|
||||
if (config.getDbType().equals(dbType.toString())) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementDAOException("Error parsing test db configurations", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initSQLScript() throws Exception {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
conn = this.getDataSource().getConnection();
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'");
|
||||
} catch(Exception e){
|
||||
log.error(e);
|
||||
throw e;
|
||||
}finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
@ -1,104 +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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceOperationManagementTests extends DeviceManagementBaseTest {
|
||||
|
||||
private OperationManager operationManager;
|
||||
private static final Log log = LogFactory.getLog(DeviceOperationManagementTests.class);
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void init() throws Exception{
|
||||
OperationManagementDAOFactory.init(this.getDataSource());
|
||||
this.initOperationManager();
|
||||
this.setupData();
|
||||
}
|
||||
|
||||
private void setupData() throws Exception {
|
||||
String deviceSql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " +
|
||||
"OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " +
|
||||
"VALUES ('Galaxy Tab', 'Samsung', 1425467382, 1425467382, 'BYOD', 'ACTIVE', 1, " +
|
||||
"'4892813d-0b18-4a02-b7b1-61775257400e', 'admin@wso2.com', '-1234');";
|
||||
String typeSql = "Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');";
|
||||
this.getDataSource().getConnection().createStatement().execute(typeSql);
|
||||
this.getDataSource().getConnection().createStatement().execute(deviceSql);
|
||||
}
|
||||
|
||||
private void initOperationManager() {
|
||||
this.operationManager = new OperationManagerImpl();
|
||||
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(new DeviceManagementProviderServiceImpl());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testAddOperation() throws Exception {
|
||||
// CommandOperation op = new CommandOperation();
|
||||
// op.setEnabled(true);
|
||||
// op.setType(Operation.Type.COMMAND);
|
||||
// op.setCode("OPCODE1");
|
||||
//
|
||||
// List<DeviceIdentifier> deviceIds = new ArrayList<DeviceIdentifier>();
|
||||
// DeviceIdentifier deviceId = new DeviceIdentifier();
|
||||
// deviceId.setId("4892813d-0b18-4a02-b7b1-61775257400e");
|
||||
// deviceId.setType("android");
|
||||
// deviceIds.add(deviceId);
|
||||
//
|
||||
// try {
|
||||
// boolean isAdded = operationManager.addOperation(op, deviceIds);
|
||||
// Assert.assertTrue(isAdded);
|
||||
// } catch (OperationManagementException e) {
|
||||
// e.printStackTrace();
|
||||
// throw new Exception(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void testGetOperations() {
|
||||
try {
|
||||
//TODO:- operationManager.getOperations is not implemented
|
||||
DeviceIdentifier deviceId = new DeviceIdentifier();
|
||||
deviceId.setId("4892813d-0b18-4a02-b7b1-61775257400e");
|
||||
deviceId.setType("android");
|
||||
List<? extends Operation> operations = operationManager.getOperations(deviceId);
|
||||
Assert.assertNotNull(operations);
|
||||
boolean notEmpty = operations.size() > 0;
|
||||
Assert.assertTrue(notEmpty);
|
||||
} catch (OperationManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.core.common;
|
||||
|
||||
|
||||
public enum DBTypes {
|
||||
Oracle("Oracle"),H2("H2"),MySql("MySql");
|
||||
|
||||
String dbName ;
|
||||
DBTypes(String dbStrName) {
|
||||
dbName = dbStrName;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DataSourceConfig")
|
||||
public class DataSourceConfig {
|
||||
|
||||
private String url;
|
||||
private String driverClassName;
|
||||
private String user;
|
||||
private String password;
|
||||
|
||||
@Override public String toString() {
|
||||
return "DataSourceConfig[" +
|
||||
" Url ='" + url + '\'' +
|
||||
", DriverClassName ='" + driverClassName + '\'' +
|
||||
", UserName ='" + user + '\'' +
|
||||
", Password ='" + password + '\'' +
|
||||
"]";
|
||||
}
|
||||
|
||||
@XmlElement(name = "Url", nillable = false)
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DriverClassName", nillable = false)
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
|
||||
public void setDriverClassName(String driverClassName) {
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "User", nillable = false)
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Password", nillable = false)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DBType")
|
||||
public class TestDBConfiguration {
|
||||
|
||||
private String connectionUrl;
|
||||
private String driverClass;
|
||||
private String userName;
|
||||
private String pwd;
|
||||
|
||||
@Override public String toString() {
|
||||
return "TestDBConfiguration{" +
|
||||
"connectionUrl='" + connectionUrl + '\'' +
|
||||
", driverClass='" + driverClass + '\'' +
|
||||
", userName='" + userName + '\'' +
|
||||
", pwd='" + pwd + '\'' +
|
||||
", dbType='" + dbType + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
private String dbType;
|
||||
|
||||
@XmlElement(name = "connectionurl", nillable = false)
|
||||
public String getConnectionUrl() {
|
||||
return connectionUrl;
|
||||
}
|
||||
|
||||
public void setConnectionUrl(String connectionUrl) {
|
||||
this.connectionUrl = connectionUrl;
|
||||
}
|
||||
|
||||
@XmlElement(name = "driverclass", nillable = false)
|
||||
public String getDriverClass() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
public void setDriverClass(String driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
||||
@XmlElement(name = "userName", nillable = false)
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "pwd", nillable = false)
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "typeName")
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "DeviceMgtTestDBConfigurations")
|
||||
public class TestDBConfigurations {
|
||||
|
||||
private List<TestDBConfiguration> dbTypesList;
|
||||
|
||||
@XmlElement(name = "DBType")
|
||||
public List<TestDBConfiguration> getDbTypesList() {
|
||||
return dbTypesList;
|
||||
}
|
||||
|
||||
public void setDbTypesList(List<TestDBConfiguration> dbTypesList) {
|
||||
this.dbTypesList = dbTypesList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common.Monitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ComplianceData {
|
||||
|
||||
private int id;
|
||||
private int deviceId;
|
||||
private int policyId;
|
||||
List<ComplianceFeature> complianceFeatures;
|
||||
private boolean status;
|
||||
private String message;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(int deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public int getPolicyId() {
|
||||
return policyId;
|
||||
}
|
||||
|
||||
public void setPolicyId(int policyId) {
|
||||
this.policyId = policyId;
|
||||
}
|
||||
|
||||
public List<ComplianceFeature> getComplianceFeatures() {
|
||||
return complianceFeatures;
|
||||
}
|
||||
|
||||
public void setComplianceFeatures(List<ComplianceFeature> complianceFeatures) {
|
||||
this.complianceFeatures = complianceFeatures;
|
||||
}
|
||||
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common.Monitor;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
|
||||
public class ComplianceFeature {
|
||||
|
||||
private ProfileFeature feature;
|
||||
private String featureCode;
|
||||
private boolean compliance;
|
||||
private String message;
|
||||
|
||||
|
||||
public ProfileFeature getFeature() {
|
||||
return feature;
|
||||
}
|
||||
|
||||
public void setFeature(ProfileFeature feature) {
|
||||
this.feature = feature;
|
||||
}
|
||||
|
||||
public String getFeatureCode() {
|
||||
return featureCode;
|
||||
}
|
||||
|
||||
public void setFeatureCode(String featureCode) {
|
||||
this.featureCode = featureCode;
|
||||
}
|
||||
|
||||
public boolean isCompliance() {
|
||||
return compliance;
|
||||
}
|
||||
|
||||
public void setCompliance(boolean compliance) {
|
||||
this.compliance = compliance;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common.Monitor;
|
||||
|
||||
public class PolicyComplianceException extends Exception {
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public PolicyComplianceException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyComplianceException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyComplianceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyComplianceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PolicyComplianceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common.spi;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyMonitoringService {
|
||||
|
||||
List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
|
||||
throws PolicyComplianceException;
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceData;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceFeature;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MonitoringDAO {
|
||||
|
||||
int setDeviceAsNoneCompliance(int deviceId, int policyId) throws MonitoringDAOException;
|
||||
|
||||
void setDeviceAsCompliance(int deviceId, int policyId) throws MonitoringDAOException;
|
||||
|
||||
void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature> complianceFeatures)
|
||||
throws MonitoringDAOException;
|
||||
|
||||
ComplianceData getCompliance(int deviceId) throws MonitoringDAOException;
|
||||
|
||||
List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException;
|
||||
|
||||
void deleteNoneComplianceData(int deviceId) throws MonitoringDAOException;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao;
|
||||
|
||||
public class MonitoringDAOException extends Exception{
|
||||
|
||||
private String monitoringDAOErrorMessage;
|
||||
|
||||
public String getMonitoringDAOErrorMessage() {
|
||||
return monitoringDAOErrorMessage;
|
||||
}
|
||||
|
||||
public void setMonitoringDAOErrorMessage(String monitoringDAOErrorMessage) {
|
||||
this.monitoringDAOErrorMessage = monitoringDAOErrorMessage;
|
||||
}
|
||||
|
||||
public MonitoringDAOException(String message) {
|
||||
super(message);
|
||||
setMonitoringDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public MonitoringDAOException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setMonitoringDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public MonitoringDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setMonitoringDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public MonitoringDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public MonitoringDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceData;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MonitoringDAOImpl.class);
|
||||
|
||||
@Override
|
||||
public int setDeviceAsNoneCompliance(int deviceId, int policyId) throws MonitoringDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS) VALUES" +
|
||||
" (?, ?, ?) ";
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(2, policyId);
|
||||
stmt.setInt(3, 0);
|
||||
stmt.executeUpdate();
|
||||
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
if (generatedKeys.next()) {
|
||||
return generatedKeys.getInt(1);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the none compliance to the database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceAsCompliance(int deviceId, int policyId) throws MonitoringDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, deviceId);
|
||||
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting the none compliance to the database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
|
||||
complianceFeatures) throws MonitoringDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS) " +
|
||||
"VALUES" +
|
||||
" (?, ?, ?) ";
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
for (ComplianceFeature feature : complianceFeatures) {
|
||||
stmt.setInt(1, policyComplianceStatusId);
|
||||
stmt.setString(2, feature.getFeatureCode());
|
||||
stmt.setString(3, String.valueOf(feature.isCompliance()));
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the none compliance features to the database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComplianceData getCompliance(int deviceId) throws MonitoringDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
ComplianceData complianceData = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, deviceId);
|
||||
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
complianceData.setId(resultSet.getInt("ID"));
|
||||
complianceData.setDeviceId(resultSet.getInt("DEVICE_ID"));
|
||||
complianceData.setPolicyId(resultSet.getInt("POLICY_ID"));
|
||||
complianceData.setStatus(resultSet.getBoolean("STATUS"));
|
||||
}
|
||||
return complianceData;
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to retrieve compliance data from database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
this.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws
|
||||
MonitoringDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
List<ComplianceFeature> complianceFeatures = new ArrayList<ComplianceFeature>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, policyComplianceStatusId);
|
||||
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
ComplianceFeature feature = new ComplianceFeature();
|
||||
feature.setFeatureCode(resultSet.getString("FEATURE_CODE"));
|
||||
feature.setMessage(resultSet.getString("STATUS"));
|
||||
complianceFeatures.add(feature);
|
||||
}
|
||||
return complianceFeatures;
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to retrieve compliance features data from database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
this.closeConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteNoneComplianceData(int deviceId) throws MonitoringDAOException {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to delete compliance data from database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Connection getConnection() throws MonitoringDAOException {
|
||||
try {
|
||||
return PolicyManagementDAOFactory.getConnection();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
throw new MonitoringDAOException("Error occurred while obtaining a connection from the policy " +
|
||||
"management metadata repository config.datasource", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void closeConnection() {
|
||||
try {
|
||||
PolicyManagementDAOFactory.closeConnection();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
log.warn("Unable to close the database connection.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceData;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.PolicyComplianceException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MonitoringManager {
|
||||
|
||||
List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object deviceResponse)
|
||||
throws PolicyComplianceException;
|
||||
|
||||
|
||||
boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
|
||||
|
||||
ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
|
||||
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceData;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.Monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MonitoringManagerImpl implements MonitoringManager {
|
||||
|
||||
private PolicyDAO policyDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
private MonitoringDAO monitoringDAO;
|
||||
|
||||
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
|
||||
|
||||
public MonitoringManagerImpl() {
|
||||
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ComplianceFeature> checkPolicyCompliance(DeviceIdentifier deviceIdentifier,
|
||||
Object deviceResponse) throws PolicyComplianceException {
|
||||
|
||||
List<ComplianceFeature> complianceFeatures;
|
||||
try {
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
Policy policy = policyDAO.getAppliedPolicy(device.getId());
|
||||
PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance().
|
||||
getPolicyMonitoringService(deviceIdentifier.getType());
|
||||
|
||||
complianceFeatures = monitoringService.checkPolicyCompliance(deviceIdentifier,
|
||||
policy, deviceResponse);
|
||||
|
||||
if (!complianceFeatures.isEmpty()) {
|
||||
int complianceId = monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId());
|
||||
monitoringDAO.addNoneComplianceFeatures(complianceId, device.getId(), complianceFeatures);
|
||||
|
||||
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
|
||||
for (ComplianceFeature compFeature : complianceFeatures) {
|
||||
for (ProfileFeature profFeature : profileFeatures) {
|
||||
if (profFeature.getFeatureCode().equalsIgnoreCase(compFeature.getFeatureCode())) {
|
||||
compFeature.setFeature(profFeature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
monitoringDAO.setDeviceAsCompliance(device.getId(), policy.getId());
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Unable tor retrieve device data from DB for " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Unable tor retrieve policy data from DB for device " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
} catch (MonitoringDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Unable to add the none compliance features to database for device " + deviceIdentifier.
|
||||
getId() + " - " + deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
return complianceFeatures;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
ComplianceData complianceData = monitoringDAO.getCompliance(device.getId());
|
||||
if (complianceData == null || !complianceData.isStatus()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Unable to retrieve device data for " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
|
||||
} catch (MonitoringDAOException e) {
|
||||
String msg = "Unable to retrieve compliance status for " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws
|
||||
PolicyComplianceException {
|
||||
|
||||
ComplianceData complianceData;
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
complianceData = monitoringDAO.getCompliance(device.getId());
|
||||
List<ComplianceFeature> complianceFeatures =
|
||||
monitoringDAO.getNoneComplianceFeatures(complianceData.getId());
|
||||
complianceData.setComplianceFeatures(complianceFeatures);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Unable to retrieve device data for " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
|
||||
} catch (MonitoringDAOException e) {
|
||||
String msg = "Unable to retrieve compliance data for " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
return complianceData;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.policy.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.common.DataSourceConfig;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
public abstract class BasePolicyManagementDAOTest {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(BasePolicyManagementDAOTest.class);
|
||||
|
||||
@BeforeSuite
|
||||
public void setupDataSource() throws Exception {
|
||||
this.initDatSource();
|
||||
this.initSQLScript();
|
||||
}
|
||||
|
||||
public void initDatSource() throws Exception {
|
||||
this.dataSource = this.getDataSource(this.readDataSourceConfig());
|
||||
DeviceManagementDAOFactory.init(dataSource);
|
||||
PolicyManagementDAOFactory.init(dataSource);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public abstract void init() throws Exception;
|
||||
|
||||
private DataSource getDataSource(DataSourceConfig config) {
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl(config.getUrl());
|
||||
properties.setDriverClassName(config.getDriverClassName());
|
||||
properties.setUsername(config.getUser());
|
||||
properties.setPassword(config.getPassword());
|
||||
return new org.apache.tomcat.jdbc.pool.DataSource(properties);
|
||||
}
|
||||
|
||||
private DataSourceConfig readDataSourceConfig() throws PolicyManagementException {
|
||||
try {
|
||||
File file = new File("src/test/resources/config/datasource/data-source-config.xml");
|
||||
Document doc = PolicyManagerUtil.convertToDocument(file);
|
||||
JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class);
|
||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||
return (DataSourceConfig) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new PolicyManagementException("Error occurred while reading data source configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initSQLScript() throws Exception {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
conn = this.getDataSource().getConnection();
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.policy.mgt.core.common;
|
||||
|
||||
|
||||
public enum DBTypes {
|
||||
Oracle("Oracle"),H2("H2"),MySql("MySql");
|
||||
|
||||
String dbName ;
|
||||
DBTypes(String dbStrName) {
|
||||
dbName = dbStrName;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.policy.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DataSourceConfig")
|
||||
public class DataSourceConfig {
|
||||
|
||||
private String url;
|
||||
private String driverClassName;
|
||||
private String user;
|
||||
private String password;
|
||||
|
||||
@Override public String toString() {
|
||||
return "DataSourceConfig[" +
|
||||
" Url ='" + url + '\'' +
|
||||
", DriverClassName ='" + driverClassName + '\'' +
|
||||
", UserName ='" + user + '\'' +
|
||||
", Password ='" + password + '\'' +
|
||||
"]";
|
||||
}
|
||||
|
||||
@XmlElement(name = "Url", nillable = false)
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@XmlElement(name = "DriverClassName", nillable = false)
|
||||
public String getDriverClassName() {
|
||||
return driverClassName;
|
||||
}
|
||||
|
||||
public void setDriverClassName(String driverClassName) {
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "User", nillable = false)
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Password", nillable = false)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.policy.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DBType")
|
||||
public class TestDBConfiguration {
|
||||
|
||||
private String connectionUrl;
|
||||
private String driverClass;
|
||||
private String userName;
|
||||
private String pwd;
|
||||
|
||||
@Override public String toString() {
|
||||
return "TestDBConfiguration{" +
|
||||
"connectionUrl='" + connectionUrl + '\'' +
|
||||
", driverClass='" + driverClass + '\'' +
|
||||
", userName='" + userName + '\'' +
|
||||
", pwd='" + pwd + '\'' +
|
||||
", dbType='" + dbType + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
private String dbType;
|
||||
|
||||
@XmlElement(name = "connectionurl", nillable = false)
|
||||
public String getConnectionUrl() {
|
||||
return connectionUrl;
|
||||
}
|
||||
|
||||
public void setConnectionUrl(String connectionUrl) {
|
||||
this.connectionUrl = connectionUrl;
|
||||
}
|
||||
|
||||
@XmlElement(name = "driverclass", nillable = false)
|
||||
public String getDriverClass() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
public void setDriverClass(String driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
||||
@XmlElement(name = "userName", nillable = false)
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "pwd", nillable = false)
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "typeName")
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, 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.policy.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "DeviceMgtTestDBConfigurations")
|
||||
public class TestDBConfigurations {
|
||||
|
||||
private List<TestDBConfiguration> dbTypesList;
|
||||
|
||||
@XmlElement(name = "DBType")
|
||||
public List<TestDBConfiguration> getDbTypesList() {
|
||||
return dbTypesList;
|
||||
}
|
||||
|
||||
public void setDbTypesList(List<TestDBConfiguration> dbTypesList) {
|
||||
this.dbTypesList = dbTypesList;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue