DAO refactoring

revert-70aa11f8
prabathabey 10 years ago
commit 974a616737

@ -131,4 +131,19 @@ public class Device {
}
}
@Override
public String toString() {
return "Device[" +
"name=" + name + ";" +
"type=" + type + ";" +
"description=" + description + ";" +
"identifier=" + deviceIdentifier + ";" +
// "EnrolmentInfo[" +
// "owner=" + enrolmentInfo.getOwner() + ";" +
// "ownership=" + enrolmentInfo.getOwnership() + ";" +
// "status=" + enrolmentInfo.getStatus() + ";" +
// "]" +
"]";
}
}

@ -18,7 +18,10 @@
*/
package org.wso2.carbon.device.mgt.common.app.mgt;
public class Application {
import java.io.Serializable;
import java.util.Properties;
public class Application implements Serializable {
private int id;
private String packageName;
@ -29,6 +32,7 @@ public class Application {
private String imageUrl;
private String version;
private String type;
private Properties appProperties;
public String getType() {
return type;
@ -113,5 +117,12 @@ public class Application {
return packageName.equals(target.getPackageName());
}
public Properties getAppProperties() {
return appProperties;
}
public void setAppProperties(Properties appProperties) {
this.appProperties = appProperties;
}
}

@ -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;
}

@ -160,7 +160,6 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
return pluginRepository;
}
@Override
public void updateApplicationListInstallInDevice(
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException {

@ -60,4 +60,21 @@ public interface DeviceDAO {
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
int tenantId) throws DeviceManagementDAOException;
/**
* Get the list of devices that matches with the given device name.
*
* @param id Name of the device
* @param applications List of applications
* @throws DeviceManagementDAOException
*/
void addDeviceApplications(int id, Object applications) throws DeviceManagementDAOException;
/**
* Get the list of devices that matches with the given device name.
*
* @param deviceId device id of the device
* @return List of Applications that are installed on the given device.
* @throws DeviceManagementDAOException
*/
List<Application> getInstalledApplications(int deviceId) throws DeviceManagementDAOException;
}

@ -71,7 +71,7 @@ public class DeviceManagementDAOFactory {
conn.setAutoCommit(false);
currentConnection.set(conn);
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving datasource connection", e);
throw new DeviceManagementDAOException("Error occurred while retrieving config.datasource connection", e);
}
}
@ -79,7 +79,7 @@ public class DeviceManagementDAOFactory {
try {
currentConnection.set(dataSource.getConnection());
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while acquiring datasource connection", e);
throw new DeviceManagementDAOException("Error occurred while acquiring config.datasource connection", e);
}
}

@ -18,18 +18,21 @@
package org.wso2.carbon.device.mgt.core.dao.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.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.OwnerShip;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
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.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
@ -37,6 +40,8 @@ import java.util.List;
public class DeviceDAOImpl implements DeviceDAO {
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
@Override
public int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException {
Connection conn;
@ -115,8 +120,8 @@ public class DeviceDAOImpl implements DeviceDAO {
conn = this.getConnection();
String sql =
"SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, " +
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE dt WHERE " +
"dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?";
"t.NAME AS DEVICE_TYPE_NAME, d.DEVICE_IDENTIFICATION, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId());
@ -409,17 +414,61 @@ public class DeviceDAOImpl implements DeviceDAO {
}
}
@Override
public void addDeviceApplications(int id, Object applications) throws DeviceManagementDAOException {
}
@Override
public List<Application> getInstalledApplications(int deviceId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
List<Application> applications = new ArrayList<Application>();
Application application;
ByteArrayInputStream bais;
ObjectInputStream ois;
try {
conn = this.getConnection();
stmt = conn.prepareStatement(
"SELECT DEVICE_ID, APPLICATIONS FROM DM_DEVICE_APPLICATIONS WHERE DEVICE_ID = ?");
stmt.setInt(1, deviceId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
byte[] applicationDetails = rs.getBytes("APPLICATIONS");
bais = new ByteArrayInputStream(applicationDetails);
ois = new ObjectInputStream(bais);
application = (Application) ois.readObject();
applications.add(application);
}
}catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the Application object";
log.error(errorMsg, e);
throw new DeviceManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the Application object";
log.error(errorMsg, e);
throw new DeviceManagementDAOException(errorMsg, e);
} catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the list of Applications installed in device id '"
+ deviceId;
log.error(errorMsg, e);
throw new DeviceManagementDAOException(errorMsg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
return applications;
}
private Device loadDevice(ResultSet rs) throws SQLException {
Device device = new Device();
DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("ID"));
deviceType.setName(rs.getString("DEVICE_NAME"));
device.setId(rs.getInt("DEVICE_TYPE_ID"));
device.setId(rs.getInt("DEVICE_ID"));
device.setDescription(rs.getString("DESCRIPTION"));
device.setType(rs.getString("DEVICE_TYPE"));
device.setType(rs.getString("DEVICE_TYPE_NAME"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
device.setEnrolmentInfo(this.loadEnrolment(rs));
return device;
}

@ -24,12 +24,15 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
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.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
@ -57,6 +60,7 @@ public class OperationManagerImpl implements OperationManager {
private OperationMappingDAO operationMappingDAO;
private OperationDAO operationDAO;
private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@ -66,6 +70,7 @@ public class OperationManagerImpl implements OperationManager {
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
operationDAO = OperationManagementDAOFactory.getOperationDAO();
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
}
@Override
@ -169,6 +174,21 @@ public class OperationManagerImpl implements OperationManager {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
device = deviceDAO.getDevice(deviceId, tenantId);
if (device.getEnrolmentInfo().getStatus() !=null && !device.getEnrolmentInfo().getStatus().equals(
EnrolmentInfo.Status.ACTIVE)){
try {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.updateDeviceEnrolmentInfo(device,
EnrolmentInfo.Status.ACTIVE);
}catch (DeviceManagementException deviceMgtEx){
String errorMsg = "Error occurred while update enrol status: "+deviceId.toString();
log.error(errorMsg, deviceMgtEx);
throw new OperationManagementException(errorMsg, deviceMgtEx);
}
}
if (device == null) {
throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type:" + deviceId.getType());
@ -225,6 +245,20 @@ public class OperationManagerImpl implements OperationManager {
}
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
.getNextOperation(device.getId());
if (device.getEnrolmentInfo().getStatus() !=null && !device.getEnrolmentInfo().getStatus().equals(
EnrolmentInfo.Status.ACTIVE)){
try {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.updateDeviceEnrolmentInfo(device,
EnrolmentInfo.Status.ACTIVE);
}catch (DeviceManagementException deviceMgtEx){
String errorMsg = "Error occurred while update enrol status: "+deviceId.toString();
log.error(errorMsg, deviceMgtEx);
throw new OperationManagementException(errorMsg, deviceMgtEx);
}
}
if (dtoOperation != null) {
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND
.equals(dtoOperation.getType())) {

@ -74,7 +74,7 @@ public class OperationManagementDAOFactory {
try {
currentConnection.set(dataSource.getConnection());
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while retrieving datasource connection", e);
throw new OperationManagementDAOException("Error occurred while retrieving config.datasource connection", e);
}
}

@ -82,9 +82,22 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
* The method to get application list installed for the device.
*
* @param deviceIdentifier
* @return
* @return List of applications installed on the device
* @throws DeviceManagementException
*/
List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
/**
* The method to get application list installed for the device.
*
* @param deviceIdentifier device identifier of the device
* @param applications List of installed Applications
*
* @throws DeviceManagementException
*/
void updateInstalledApplicationListOfDevice(DeviceIdentifier deviceIdentifier, List<Application> applications)
throws DeviceManagementException;
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
}

@ -43,6 +43,7 @@ import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener {
@ -127,6 +128,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return status;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager dms =
@ -135,7 +138,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
int deviceId = deviceDAO.updateDevice(type.getId(), device, tenantId);
enrolmentDAO.updateEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
@ -161,8 +163,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
try {
Device device = deviceDAO.getDevice(deviceId,tenantId);
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while fetch device for device Identifier:";
log.error(errorMsg + deviceId.toString(),e);
throw new DeviceManagementException(errorMsg, e);
}
return dms.disenrollDevice(deviceId);
}
@ -635,7 +653,46 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws DeviceManagementException {
return null;
Device device = null;
try {
device = this.getDevice(deviceIdentifier);
return deviceDAO.getInstalledApplications(device.getId());
}catch (DeviceManagementDAOException deviceDaoEx){
String errorMsg = "Error occured while fetching the Application List of device : " + device.getId();
log.error(errorMsg, deviceDaoEx);
throw new DeviceManagementException(errorMsg, deviceDaoEx);
}
}
@Override
public void updateInstalledApplicationListOfDevice(DeviceIdentifier deviceIdentifier,
List<Application> applications)
throws DeviceManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
deviceDAO.addDeviceApplications(device.getId(), applications);
}catch (DeviceManagementDAOException deviceDaoEx){
String errorMsg = "Error occurred saving application list to the device";
log.error(errorMsg+":"+deviceIdentifier.toString());
throw new DeviceManagementException(errorMsg, deviceDaoEx);
}
}
@Override
public void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status status) throws DeviceManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
device.getEnrolmentInfo().setStatus(status);
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
}catch (DeviceManagementDAOException deviceDaoEx){
String errorMsg = "Error occured update device enrolment status : "+device.getId();
log.error(errorMsg, deviceDaoEx);
throw new DeviceManagementException(errorMsg, deviceDaoEx);
}
}
@Override

@ -30,6 +30,7 @@ import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;

@ -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;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.dao;
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.app.mgt.Application;
@ -80,4 +81,9 @@ public class ApplicationPersistenceDAOTests extends BaseDeviceManagementDAOTest
}
}
@BeforeClass
@Override
public void init() throws Exception {
this.initDatSource();
}
}

@ -23,14 +23,12 @@ import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
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.TestUtils;
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.common.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import javax.sql.DataSource;
@ -43,44 +41,44 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class BaseDeviceManagementDAOTest {
public abstract class BaseDeviceManagementDAOTest {
private DataSource dataSource;
private static final Log log = LogFactory.getLog(BaseDeviceManagementDAOTest.class);
@BeforeSuite
public void setupDataSource() throws Exception {
this.dataSource = this.getDataSource(this.readDataSourceConfig());
this.initDatSource();
this.initSQLScript();
}
public void initDatSource() throws Exception {
this.dataSource = this.getDataSource(this.readDataSourceConfig());
DeviceManagementDAOFactory.init(dataSource);
}
private DataSource getDataSource(TestDBConfiguration config) {
@BeforeClass
public abstract void init() throws Exception;
private DataSource getDataSource(DataSourceConfig config) {
PoolProperties properties = new PoolProperties();
properties.setUrl(config.getConnectionUrl());
properties.setDriverClassName(config.getDriverClass());
properties.setUsername(config.getUserName());
properties.setPassword(config.getPwd());
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 TestDBConfiguration readDataSourceConfig() throws DeviceManagementDAOException,
DeviceManagementException {
File config = new File("src/test/resources/data-source-config.xml");
Document doc;
TestDBConfigurations dbConfigs;
doc = DeviceManagerUtil.convertToDocument(config);
JAXBContext testDBContext;
private DataSourceConfig readDataSourceConfig() throws DeviceManagementException {
try {
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
File file = new File("src/test/resources/config/datasource/data-source-config.xml");
Document doc = DeviceManagerUtil.convertToDocument(file);
JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class);
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
dbConfigs = (TestDBConfigurations) unmarshaller.unmarshal(doc);
return (DataSourceConfig) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new DeviceManagementDAOException("Error parsing test db configurations", e);
throw new DeviceManagementException("Error occurred while reading data source configuration", e);
}
}
private void initSQLScript() throws Exception {

@ -44,8 +44,9 @@ public class DeviceManagementDAOTests extends BaseDeviceManagementDAOTest {
private static final Log log = LogFactory.getLog(DeviceManagementDAOTests.class);
@BeforeClass
public void init() {
@Override
public void init() throws Exception {
initDatSource();
}
@Test
@ -142,6 +143,7 @@ public class DeviceManagementDAOTests extends BaseDeviceManagementDAOTest {
int id = -1;
try {
Assert.assertNotNull(getDataSource(), "Data Source is not initialized properly");
conn = getDataSource().getConnection();
String sql = "SELECT ID FROM DM_DEVICE WHERE DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
@ -169,6 +171,7 @@ public class DeviceManagementDAOTests extends BaseDeviceManagementDAOTest {
DeviceType deviceType = this.loadDummyDeviceType();
try {
Assert.assertNotNull(getDataSource(), "Data Source is not initialized properly");
conn = getDataSource().getConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceType.getName());
@ -188,6 +191,7 @@ public class DeviceManagementDAOTests extends BaseDeviceManagementDAOTest {
@Test(dependsOnMethods = "testAddDeviceTest")
public void testSetEnrolmentStatus() {
System.out.println("ENROLLLLLLLLLLLLLL");
Device device = this.loadDummyDevice();
try {
DeviceManagementDAOFactory.openConnection();
@ -247,6 +251,7 @@ public class DeviceManagementDAOTests extends BaseDeviceManagementDAOTest {
device.setEnrolmentInfo(enrolmentInfo);
device.setDescription("Test Description");
device.setDeviceIdentifier("1234");
device.setType(this.loadDummyDeviceType().getName());
return device;
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.dao;
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.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
@ -82,4 +83,9 @@ public class EnrolmentPersistenceDAOTests extends BaseDeviceManagementDAOTest {
}
}
@BeforeClass
@Override
public void init() throws Exception {
this.initDatSource();
}
}

@ -23,14 +23,12 @@
<parameter name="useDefaultListeners" value="false"/>
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="databaseType" value="H2"/>
<classes>
<class name="org.wso2.carbon.device.mgt.core.dao.BaseDeviceManagementDAOTest"/>
<class name="org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
<!--class name="org.wso2.carbon.device.mgt.core.DeviceOperationManagementTests"/-->
<class name="org.wso2.carbon.device.mgt.core.dao.ApplicationPersistenceDAOTests"/>
<!--class name="org.wso2.carbon.device.mgt.core.dao.EnrolmentPersistenceDAOTests"/-->
</classes>
</test>
</suite>

@ -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);
}
}

@ -140,9 +140,9 @@ public interface PolicyAdministratorPoint {
List<Profile> getProfiles() throws PolicyManagementException;
Feature addFeature(Feature feature) throws FeatureManagementException;
Feature updateFeature(Feature feature) throws FeatureManagementException;
// Feature addFeature(Feature feature) throws FeatureManagementException;
//
// Feature updateFeature(Feature feature) throws FeatureManagementException;
boolean deleteFeature(int featureId) throws FeatureManagementException;

@ -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;
}

@ -22,6 +22,9 @@ package org.wso2.carbon.policy.mgt.core;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
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.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
@ -34,9 +37,11 @@ import java.util.List;
public interface PolicyManagerService {
/*
Feature addFeature(Feature feature) throws FeatureManagementException;
Feature updateFeature(Feature feature) throws FeatureManagementException;
*/
Profile addProfile(Profile profile) throws PolicyManagementException;
@ -65,4 +70,11 @@ public interface PolicyManagerService {
PolicyEvaluationPoint getPEP() throws PolicyManagementException;
int getPolicyCount() throws PolicyManagementException;
List<ComplianceFeature> CheckPolicyCompliance(DeviceIdentifier deviceIdentifier, Object
deviceResponse) throws PolicyComplianceException;
boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object response) throws PolicyComplianceException;
ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
}

@ -27,9 +27,14 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.policy.mgt.common.*;
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.core.impl.PolicyAdministratorPointImpl;
import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
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.mgt.impl.MonitoringManagerImpl;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
import java.util.ArrayList;
@ -41,19 +46,11 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
private static final Log log = LogFactory.getLog(PolicyManagerServiceImpl.class);
PolicyAdministratorPointImpl policyAdministratorPoint;
MonitoringManager monitoringManager;
public PolicyManagerServiceImpl() {
policyAdministratorPoint = new PolicyAdministratorPointImpl();
}
@Override
public Feature addFeature(Feature feature) throws FeatureManagementException {
return policyAdministratorPoint.addFeature(feature);
}
@Override
public Feature updateFeature(Feature feature) throws FeatureManagementException {
return policyAdministratorPoint.updateFeature(feature);
monitoringManager = new MonitoringManagerImpl();
}
@Override
@ -144,7 +141,8 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
FeatureManagementException {
try {
List<ProfileFeature> effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().
List<ProfileFeature> effectiveFeatures = PolicyManagementDataHolder.getInstance()
.getPolicyEvaluationPoint().
getEffectiveFeatures(deviceIdentifier);
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<DeviceIdentifier>();
@ -211,4 +209,27 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
public int getPolicyCount() throws PolicyManagementException {
return policyAdministratorPoint.getPolicyCount();
}
@Override
public List<ComplianceFeature> CheckPolicyCompliance(DeviceIdentifier deviceIdentifier, Object
deviceResponse) throws PolicyComplianceException {
return monitoringManager.checkPolicyCompliance(deviceIdentifier, deviceResponse);
}
@Override
public boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object response) throws
PolicyComplianceException {
List<ComplianceFeature> complianceFeatures =
monitoringManager.checkPolicyCompliance(deviceIdentifier, response);
if (complianceFeatures == null || complianceFeatures.isEmpty()) {
return false;
}
return true;
}
@Override
public ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
return monitoringManager.getDevicePolicyCompliance(deviceIdentifier);
}
}

@ -27,11 +27,11 @@ import java.util.List;
public interface FeatureDAO {
Feature addFeature(Feature feature) throws FeatureManagerDAOException;
/* Feature addFeature(Feature feature) throws FeatureManagerDAOException;
List<Feature> addFeatures(List<Feature> feature) throws FeatureManagerDAOException;
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;*/
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;

@ -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);
}
}

@ -19,6 +19,7 @@
package org.wso2.carbon.policy.mgt.core.dao;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Criterion;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyCriterion;
@ -99,4 +100,8 @@ public interface PolicyDAO {
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;
int getPolicyCount() throws PolicyManagerDAOException;
int getAppliedPolicyId(int deviceId) throws PolicyManagerDAOException;
Policy getAppliedPolicy(int deviceId) throws PolicyManagerDAOException;
}

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOE
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.policy.mgt.core.dao.impl.FeatureDAOImpl;
import org.wso2.carbon.policy.mgt.core.dao.impl.MonitoringDAOImpl;
import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl;
import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl;
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
@ -67,6 +68,10 @@ public class PolicyManagementDAOFactory {
return new FeatureDAOImpl();
}
public static MonitoringDAO getMonitoringDAO() {
return new MonitoringDAOImpl();
}
/**
* Resolve data source from the data source definition
*
@ -107,7 +112,7 @@ public class PolicyManagementDAOFactory {
conn.setAutoCommit(false);
currentConnection.set(conn);
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while retrieving datasource connection", e);
throw new PolicyManagerDAOException("Error occurred while retrieving config.datasource connection", e);
}
}

@ -42,7 +42,7 @@ public class FeatureDAOImpl implements FeatureDAO {
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
@Override
/* @Override
public Feature addFeature(Feature feature) throws FeatureManagerDAOException {
Connection conn;
@ -75,9 +75,9 @@ public class FeatureDAOImpl implements FeatureDAO {
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
}
return feature;
}
}*/
@Override
/* @Override
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagerDAOException {
Connection conn;
@ -119,10 +119,10 @@ public class FeatureDAOImpl implements FeatureDAO {
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
}
return featureList;
}
}*/
@Override
/* @Override
public Feature updateFeature(Feature feature) throws FeatureManagerDAOException {
Connection conn;
@ -147,7 +147,7 @@ public class FeatureDAOImpl implements FeatureDAO {
}
return feature;
}
}*/
@Override
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
@ -466,7 +466,7 @@ public class FeatureDAOImpl implements FeatureDAO {
return PolicyManagementDAOFactory.getConnection();
} catch (PolicyManagerDAOException e) {
throw new FeatureManagerDAOException("Error occurred while obtaining a connection from the policy " +
"management metadata repository datasource", e);
"management metadata repository config.datasource", e);
}
}

@ -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.");
}
}
}

@ -21,16 +21,21 @@ 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.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.policy.mgt.common.Criterion;
import org.wso2.carbon.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyCriterion;
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
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.dao.util.PolicyManagementDAOUtil;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.Calendar;
@ -429,7 +434,8 @@ public class PolicyDAOImpl implements PolicyDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, CONTENT) VALUES (?, ?, ?, ?)";
String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, " +
"CONTENT) VALUES (?, ?, ?, ?)";
stmt = conn.prepareStatement(query);
for (PolicyCriterion criterion : policyCriteria) {
@ -517,7 +523,8 @@ public class PolicyDAOImpl implements PolicyDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ? WHERE ID = ?";
String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?" +
" WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getTenantId());
@ -740,7 +747,6 @@ public class PolicyDAOImpl implements PolicyDAO {
}
@Override
public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
throws PolicyManagerDAOException {
@ -1060,7 +1066,8 @@ public class PolicyDAOImpl implements PolicyDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE) VALUES (?, ?, ?, ?, ?, ?)";
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE)" +
" VALUES (?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, policy.getPolicyName());
@ -1191,4 +1198,95 @@ public class PolicyDAOImpl implements PolicyDAO {
}
}
@Override
public int getAppliedPolicyId(int deviceId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
return resultSet.getInt("POLICY_ID");
}
} catch (SQLException e) {
String msg = "Error occurred while getting the applied policy id.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
}
return 0;
}
@Override
public Policy getAppliedPolicy(int deviceId) throws PolicyManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
Policy policy = null;
try {
conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_POLICY_APPLIED WHERE DEVICE_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
resultSet = stmt.executeQuery();
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
byte[] contentBytes;
try {
contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT");
bais = new ByteArrayInputStream(contentBytes);
ois = new ObjectInputStream(bais);
policy = (Policy) ois.readObject();
} finally {
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
}
} catch (SQLException e) {
String msg = "Error occurred while getting the applied policy.";
log.error(msg, e);
throw new PolicyManagerDAOException(msg, e);
} catch (IOException e) {
String msg = "Unable to read the byte stream for content";
log.error(msg);
throw new PolicyManagerDAOException(msg, e);
} catch (ClassNotFoundException e) {
String msg = "Class not found while converting the object";
log.error(msg);
throw new PolicyManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
this.closeConnection();
}
return policy;
}
}

@ -279,7 +279,7 @@ public class ProfileDAOImpl implements ProfileDAO {
return PolicyManagementDAOFactory.getConnection();
} catch (PolicyManagerDAOException e) {
throw new ProfileManagerDAOException("Error occurred while obtaining a connection from the policy " +
"management metadata repository datasource", e);
"management metadata repository config.datasource", e);
}
}

@ -188,7 +188,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
}
}
@Override
/* @Override
public Feature addFeature(Feature feature) throws FeatureManagementException {
return featureManager.addFeature(feature);
}
@ -197,7 +197,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
public Feature updateFeature(Feature feature) throws FeatureManagementException {
return featureManager.updateFeature(feature);
}
}*/
@Override
public boolean deleteFeature(int featureId) throws FeatureManagementException {

@ -21,9 +21,12 @@ package org.wso2.carbon.policy.mgt.core.internal;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;
import java.util.Map;
public class PolicyManagementDataHolder {
private RealmService realmService;
@ -31,6 +34,8 @@ public class PolicyManagementDataHolder {
private PolicyEvaluationPoint policyEvaluationPoint;
private PolicyInformationPoint policyInformationPoint;
private DeviceManagementProviderService deviceManagementService;
private Map<String, PolicyMonitoringService> policyMonitoringServiceMap;
private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder();
private PolicyManagementDataHolder() {}
@ -82,4 +87,16 @@ public class PolicyManagementDataHolder {
public void setDeviceManagementService(DeviceManagementProviderService deviceManagementService) {
this.deviceManagementService = deviceManagementService;
}
public PolicyMonitoringService getPolicyMonitoringService(String deviceType) {
return policyMonitoringServiceMap.get(deviceType);
}
public void setPolicyMonitoringService(String deviceType, PolicyMonitoringService policyMonitoringService) {
this.policyMonitoringServiceMap.put(deviceType, policyMonitoringService);
}
public void unsetPolicyMonitoringService(String deviceType) {
this.policyMonitoringServiceMap.remove(deviceType);
}
}

@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
@ -51,6 +52,12 @@ import org.wso2.carbon.user.core.service.RealmService;
* policy="dynamic"
* bind="setDeviceManagementService"
* unbind="unsetDeviceManagementService"
* @scr.reference name="org.wso2.carbon.policy.mgt.common.policy.monitor"
* interface="org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService"
* cardinality="0..n"
* policy="dynamic"
* bind="setPolicyMonitoringService"
* unbind="unsetPolicyMonitoringService"
*/
@SuppressWarnings("unused")
public class PolicyManagementServiceComponent {
@ -143,4 +150,21 @@ public class PolicyManagementServiceComponent {
PolicyManagementDataHolder.getInstance().setDeviceManagementService(null);
}
protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
if (log.isDebugEnabled()) {
log.debug("Setting Policy Monitoring Service");
}
// TODO: FIX THE device type by taking from properties
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService("", policyMonitoringService);
}
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
if (log.isDebugEnabled()) {
log.debug("Setting Policy Monitoring Service");
}
// TODO: FIX THE device type by taking from properties
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService("");
}
}

@ -29,11 +29,11 @@ import java.util.List;
public interface FeatureManager {
Feature addFeature(Feature feature) throws FeatureManagementException;
/*Feature addFeature(Feature feature) throws FeatureManagementException;
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagementException;
Feature updateFeature(Feature feature) throws FeatureManagementException;
Feature updateFeature(Feature feature) throws FeatureManagementException;*/
boolean deleteFeature(Feature feature) throws FeatureManagementException;

@ -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;
}

@ -68,4 +68,6 @@ public interface PolicyManager {
boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
int getPolicyCount() throws PolicyManagementException;
Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
}

@ -41,7 +41,7 @@ public class FeatureManagerImpl implements FeatureManager {
featureDAO = PolicyManagementDAOFactory.getFeatureDAO();
}
@Override
/*@Override
public Feature addFeature(Feature feature) throws FeatureManagementException {
try {
PolicyManagementDAOFactory.beginTransaction();
@ -68,9 +68,9 @@ public class FeatureManagerImpl implements FeatureManager {
throw new FeatureManagementException(msg, e);
}
return feature;
}
}*/
@Override
/*@Override
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagementException {
try {
PolicyManagementDAOFactory.beginTransaction();
@ -98,9 +98,9 @@ public class FeatureManagerImpl implements FeatureManager {
}
return features;
}
}*/
@Override
/* @Override
public Feature updateFeature(Feature feature) throws FeatureManagementException {
try {
PolicyManagementDAOFactory.beginTransaction();
@ -127,7 +127,7 @@ public class FeatureManagerImpl implements FeatureManager {
throw new FeatureManagementException(msg, e);
}
return feature;
}
}*/
@Override
public boolean deleteFeature(Feature feature) throws FeatureManagementException {

@ -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;
}
}

@ -30,6 +30,7 @@ import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.dao.*;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
import java.sql.Timestamp;
import java.util.ArrayList;
@ -288,7 +289,7 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addPolicy(policy);
}
List<Device> deviceList = new ArrayList<Device>();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = PolicyManagerUtil.getTenantId();
for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) {
deviceList.add(deviceDAO.getDevice(deviceIdentifier, tenantId));
}
@ -517,7 +518,7 @@ public class PolicyManagerImpl implements PolicyManager {
List<Integer> policyIdList;
List<Policy> policies = new ArrayList<Policy>();
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
policyIdList = policyDAO.getPolicyIdsOfDevice(device);
List<Policy> tempPolicyList = this.getPolicies();
@ -632,7 +633,7 @@ public class PolicyManagerImpl implements PolicyManager {
List<Integer> deviceIds;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = PolicyManagerUtil.getTenantId();
deviceIds = policyDAO.getPolicyAppliedDevicesIds(policyId);
for (int deviceId : deviceIds) {
//TODO FIX ME
@ -654,9 +655,10 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
PolicyManagementException {
int deviceId = -1;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
deviceId = device.getId();
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
@ -690,7 +692,7 @@ public class PolicyManagerImpl implements PolicyManager {
boolean exist;
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
exist = policyDAO.checkPolicyAvailable(device.getId());
} catch (PolicyManagerDAOException e) {
@ -709,7 +711,7 @@ public class PolicyManagerImpl implements PolicyManager {
public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
policyDAO.setPolicyApplied(device.getId());
return true;
@ -727,6 +729,7 @@ public class PolicyManagerImpl implements PolicyManager {
@Override
public int getPolicyCount() throws PolicyManagementException {
int policyCount = 0;
try {
policyCount = policyDAO.getPolicyCount();
@ -737,4 +740,26 @@ public class PolicyManagerImpl implements PolicyManager {
throw new PolicyManagementException(msg, e);
}
}
@Override
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
Policy policy;
try {
int tenantId = PolicyManagerUtil.getTenantId();
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
int policyId = policyDAO.getAppliedPolicyId(device.getId());
policy = policyDAO.getPolicy(policyId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while getting device id.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (PolicyManagerDAOException e) {
String msg = "Error occurred while getting policy id or policy.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
}
return policy;
}
}

@ -21,6 +21,9 @@ package org.wso2.carbon.policy.mgt.core.service;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
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.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
@ -42,15 +45,6 @@ public class PolicyManagementService implements PolicyManagerService {
policyManagerService = new PolicyManagerServiceImpl();
}
@Override
public Feature addFeature(Feature feature) throws FeatureManagementException {
return policyManagerService.addFeature(feature);
}
@Override
public Feature updateFeature(Feature feature) throws FeatureManagementException {
return policyManagerService.updateFeature(feature);
}
@Override
public Profile addProfile(Profile profile) throws PolicyManagementException {
@ -122,4 +116,20 @@ public class PolicyManagementService implements PolicyManagerService {
public int getPolicyCount() throws PolicyManagementException {
return policyManagerService.getPolicyCount();
}
@Override
public List<ComplianceFeature> CheckPolicyCompliance(DeviceIdentifier deviceIdentifier, Object
deviceResponse) throws PolicyComplianceException {
return policyManagerService.CheckPolicyCompliance(deviceIdentifier, deviceResponse);
}
@Override
public boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object response) throws PolicyComplianceException {
return policyManagerService.checkCompliance(deviceIdentifier, response);
}
@Override
public ComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
return policyManagerService.getDeviceCompliance(deviceIdentifier);
}
}

@ -90,17 +90,12 @@ public class PolicyManagerUtil {
//TODO: Get the tenant id proper way. This is has to be fix for test to run.
int tenantId;
tenantId = MultitenantConstants.SUPER_TENANT_ID;
/* try {
if (PrivilegedCarbonContext.getThreadLocalCarbonContext() != null) {
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
} else {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
}
} catch (Exception e) {
}*/
if ("Super".equalsIgnoreCase(System.getProperty("GetTenantIDForTest"))) {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
} else {
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
}
return tenantId;
}
}

@ -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;
}
}

@ -15,30 +15,21 @@
* 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.Parameters;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Feature;
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.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.policy.mgt.common.*;
import org.wso2.carbon.policy.mgt.core.common.DBTypes;
import org.wso2.carbon.policy.mgt.core.common.TestDBConfiguration;
import org.wso2.carbon.policy.mgt.core.common.TestDBConfigurations;
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.impl.PolicyAdministratorPointImpl;
import org.wso2.carbon.policy.mgt.core.mgt.FeatureManager;
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
@ -48,21 +39,12 @@ import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
import org.wso2.carbon.policy.mgt.core.mgt.impl.ProfileManagerImpl;
import org.wso2.carbon.policy.mgt.core.util.*;
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;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class PolicyDAOTestCase {
public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
private static DataSource dataSource;
private List<Feature> featureList;
private List<ProfileFeature> profileFeatureList;
private Profile profile;
@ -71,100 +53,13 @@ public class PolicyDAOTestCase {
private static final Log log = LogFactory.getLog(PolicyDAOTestCase.class);
@BeforeClass
@Parameters("dbType")
public void setUpDB(String dbTypeStr) throws Exception {
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
TestDBConfiguration dbConfig = getTestDBConfiguration(dbType);
PoolProperties properties = new PoolProperties();
log.info("Database Type : " + dbTypeStr);
switch (dbType) {
case MySql:
log.info("Mysql Called..................................................." + dbTypeStr);
properties.setUrl(dbConfig.getConnectionUrl());
properties.setDriverClassName(dbConfig.getDriverClass());
properties.setUsername(dbConfig.getUserName());
properties.setPassword(dbConfig.getPwd());
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
PolicyManagementDAOFactory.init(dataSource);
DeviceManagementDAOFactory.init(dataSource);
break;
case H2:
properties.setUrl(dbConfig.getConnectionUrl());
properties.setDriverClassName(dbConfig.getDriverClass());
properties.setUsername(dbConfig.getUserName());
properties.setPassword(dbConfig.getPwd());
dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
this.initH2SQLScript();
PolicyManagementDAOFactory.init(dataSource);
DeviceManagementDAOFactory.init(dataSource);
break;
default:
}
}
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws PolicyManagerDAOException,
PolicyManagementException {
File deviceMgtConfig = new File("src/test/resources/data-source-config.xml");
Document doc;
TestDBConfigurations dbConfigs;
doc = PolicyManagerUtil.convertToDocument(deviceMgtConfig);
JAXBContext testDBContext;
try {
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
dbConfigs = (TestDBConfigurations) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new PolicyManagerDAOException("Error parsing test db configurations", e);
}
for (TestDBConfiguration config : dbConfigs.getDbTypesList()) {
if (config.getDbType().equals(dbType.toString())) {
return config;
}
}
return null;
}
private void initH2SQLScript() 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);
}
}
private void initMySQlSQLScript() throws Exception {
Connection conn = null;
Statement stmt = null;
try {
conn = this.getDataSource().getConnection();
stmt = conn.createStatement();
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateMySqlTestDB.sql'");
} finally {
TestUtils.cleanupResources(conn, stmt, null);
}
}
private DataSource getDataSource() {
return dataSource;
@Override
public void init() throws Exception {
initDatSource();
}
@Test
public void addDeviceType() throws DeviceManagementDAOException {
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
deviceTypeDAO.addDeviceType(DeviceTypeCreator.getDeviceType());
}

@ -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;
}
}

@ -17,17 +17,9 @@
~ under the License.
-->
<DeviceMgtTestDBConfigurations>
<DBType typeName="MySql">
<connectionurl>jdbc:mysql://localhost:3306/WSO2CDM</connectionurl>
<driverclass>com.mysql.jdbc.Driver</driverclass>
<userName>root</userName>
<pwd></pwd>
</DBType>
<DBType typeName="H2">
<connectionurl>jdbc:h2:mem:WSO2_TEST_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</connectionurl>
<driverclass>org.h2.Driver</driverclass>
<userName>wso2carbon</userName>
<pwd>wso2carbon</pwd>
</DBType>
</DeviceMgtTestDBConfigurations>
<DataSourceConfig>
<Url>jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1</Url>
<DriverClassName>org.h2.Driver</DriverClassName>
<User>wso2carbon</User>
<Password>wso2carbon</Password>
</DataSourceConfig>

@ -1,49 +1,105 @@
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID INT auto_increment NOT NULL,
NAME VARCHAR(300) NULL DEFAULT NULL,
PRIMARY KEY (ID)
);
-- -----------------------------------------------------
-- Table DM_DEVICE_TYPE
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_DEVICE (
ID INTEGER auto_increment NOT NULL,
DESCRIPTION TEXT NULL DEFAULT NULL,
NAME VARCHAR(100) NULL DEFAULT NULL,
DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL,
DATE_OF_LAST_UPDATE BIGINT NULL DEFAULT NULL,
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
STATUS VARCHAR(15) NULL DEFAULT NULL,
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL,
OWNER VARCHAR(45) NULL DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID INT(11) AUTO_INCREMENT ,
NAME VARCHAR(300) NULL DEFAULT NULL ,
PRIMARY KEY (ID) )
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
;
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
--INSERT INTO DM_DEVICE_TYPE (NAME) VALUES ('ANDROID');
--INSERT INTO DM_DEVICE_TYPE (NAME) VALUES ('IOS');
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_DEVICE
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BLOB DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE (
ID INT(11) AUTO_INCREMENT NOT NULL ,
DESCRIPTION TEXT NULL DEFAULT NULL ,
NAME VARCHAR(100) NULL DEFAULT NULL ,
DATE_OF_ENROLLMENT BIGINT(20) NULL DEFAULT NULL ,
DATE_OF_LAST_UPDATE BIGINT(20) NULL DEFAULT NULL ,
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL ,
STATUS VARCHAR(15) NULL DEFAULT NULL ,
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL ,
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL ,
OWNER VARCHAR(45) NULL DEFAULT NULL ,
TENANT_ID INT(11) NULL DEFAULT '0' ,
PRIMARY KEY (ID) ,
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_response_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
;
CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATIONS (
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
APPLICATIONS BLOB DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_applications_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
);
--- POLICY RELATED TABLES ----
-- -----------------------------------------------------
-- Table DM_PROFILE
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_PROFILE (
@ -58,13 +114,11 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE (
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_POLICY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_POLICY (
@ -80,14 +134,10 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
FOREIGN KEY (PROFILE_ID )
REFERENCES DM_PROFILE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_DEVICE_POLICY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
@ -104,14 +154,10 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
FOREIGN KEY (DEVICE_ID )
REFERENCES DM_DEVICE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_DEVICE_TYPE_POLICY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
@ -128,15 +174,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_PROFILE_FEATURES
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
@ -150,14 +192,10 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
FOREIGN KEY (PROFILE_ID)
REFERENCES DM_PROFILE (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_ROLE_POLICY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
@ -169,15 +207,11 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table .DM_USER_POLICY
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
ID INT NOT NULL AUTO_INCREMENT ,
@ -188,10 +222,10 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
ID INT NOT NULL AUTO_INCREMENT ,
DEVICE_ID INT NOT NULL ,
@ -211,14 +245,10 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
;
ON UPDATE NO ACTION
);
-- -----------------------------------------------------
-- Table DM_CRITERIA
-- -----------------------------------------------------
DROP TABLE IF EXISTS DM_CRITERIA ;
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
ID INT NOT NULL AUTO_INCREMENT,
@ -228,10 +258,6 @@ CREATE TABLE IF NOT EXISTS DM_CRITERIA (
);
-- -----------------------------------------------------
-- Table DM_POLICY_CRITERIA
-- -----------------------------------------------------
DROP TABLE IF EXISTS DM_POLICY_CRITERIA ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ID INT NOT NULL AUTO_INCREMENT,
@ -251,10 +277,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
);
-- -----------------------------------------------------
-- Table DM_POLICY_CRITERIA_PROPERTIES
-- -----------------------------------------------------
DROP TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES ;
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT,
@ -271,3 +293,9 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
);
-- POLICY RELATED TABLES FINISHED --
-- TO:DO - Remove this INSERT sql statement.
--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');
--Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (2, 'ios');

@ -25,7 +25,7 @@
<test name="DAO Unit Tests" preserve-order="true">
<parameter name="dbType" value="H2"/>
<classes>
<!--class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/-->
<!--<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>-->
</classes>
</test>
</suite>

@ -61,8 +61,8 @@ public class SimpleEvaluationImpl implements SimpleEvaluation {
return null;
}
//TODO : UNCOMMENT THE FOLLOWING CASE
// policyAdministratorPoint = policyManagerService.getPAP();
// policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy);
policyAdministratorPoint = policyManagerService.getPAP();
policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy);
}

Loading…
Cancel
Save