forked from community/device-mgt-core
commit
232ef4bd90
@ -1,57 +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.common;
|
||||
|
||||
public class DeviceManagementServiceException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -8933146283800122640L;
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public DeviceManagementServiceException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public DeviceManagementServiceException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public DeviceManagementServiceException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public DeviceManagementServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DeviceManagementServiceException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FeatureManager {
|
||||
|
||||
boolean addFeature(Feature feature) throws DeviceManagementException;
|
||||
|
||||
boolean getFeature(String name) throws DeviceManagementException;
|
||||
|
||||
List<Feature> getFeatures() throws DeviceManagementException;
|
||||
|
||||
boolean removeFeature(String name) throws DeviceManagementException;
|
||||
|
||||
}
|
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
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.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
||||
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.operation.mgt.OperationManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagementServiceProviderImpl implements DeviceManagementService {
|
||||
|
||||
private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
private DeviceManagementRepository pluginRepository;
|
||||
private OperationManager operationManager;
|
||||
private LicenseManager licenseManager;
|
||||
|
||||
public DeviceManagementServiceProviderImpl(DeviceManagementRepository pluginRepository) {
|
||||
this.pluginRepository = pluginRepository;
|
||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
this.operationManager = new OperationManagerImpl();
|
||||
this.licenseManager = new LicenseManagerImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||
boolean status = dms.enrollDevice(device);
|
||||
try {
|
||||
org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice(device);
|
||||
DeviceType deviceType = this.getDeviceTypeDAO().getDeviceType(device.getType());
|
||||
deviceDto.setStatus(Status.ACTIVE);
|
||||
deviceDto.setDeviceTypeId(deviceType.getId());
|
||||
this.getDeviceDAO().addDevice(deviceDto);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while enrolling the device " +
|
||||
"'" + device.getId() + "'", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||
boolean status = dms.modifyEnrollment(device);
|
||||
try {
|
||||
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while modifying the device " +
|
||||
"'" + device.getId() + "'", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.disenrollDevice(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.isEnrolled(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.isActive(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.setActive(deviceId, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
||||
DeviceManager dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
||||
List<Device> devicesList = new ArrayList<Device>();
|
||||
try {
|
||||
DeviceType dt = this.getDeviceTypeDAO().getDeviceType(type);
|
||||
List<org.wso2.carbon.device.mgt.core.dto.Device> devices =
|
||||
this.getDeviceDAO().getDevices(dt.getId());
|
||||
|
||||
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
||||
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
||||
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
||||
DeviceIdentifier deviceIdentifier =
|
||||
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
||||
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
||||
if (dmsDevice != null) {
|
||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
||||
}
|
||||
devicesList.add(convertedDevice);
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while obtaining the device for type " +
|
||||
"'" + type + "'", e);
|
||||
}
|
||||
return devicesList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
Device convertedDevice = null;
|
||||
try {
|
||||
DeviceType deviceType =
|
||||
this.getDeviceTypeDAO().getDeviceType(deviceId.getType());
|
||||
org.wso2.carbon.device.mgt.core.dto.Device device =
|
||||
this.getDeviceDAO().getDevice(deviceId);
|
||||
if (device != null) {
|
||||
convertedDevice = DeviceManagementDAOUtil
|
||||
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceType.getId()));
|
||||
Device dmsDevice = dms.getDevice(deviceId);
|
||||
if (dmsDevice != null) {
|
||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
|
||||
"'" + deviceId.getId() + "'", e);
|
||||
}
|
||||
return convertedDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||
return dms.updateDeviceInfo(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.setOwnership(deviceId, ownershipType);
|
||||
}
|
||||
|
||||
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
||||
return operationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
||||
return licenseManager.getLicense(deviceType, languageCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLicense(String type, License license) throws LicenseManagementException {
|
||||
return licenseManager.addLicense(type, license);
|
||||
}
|
||||
|
||||
public DeviceDAO getDeviceDAO() {
|
||||
return deviceDAO;
|
||||
}
|
||||
|
||||
public DeviceTypeDAO getDeviceTypeDAO() {
|
||||
return deviceTypeDAO;
|
||||
}
|
||||
|
||||
public DeviceManagementRepository getPluginRepository() {
|
||||
return pluginRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOperation(Operation operation,
|
||||
List<DeviceIdentifier> devices) throws OperationManagementException {
|
||||
return operationManager.addOperation(operation, devices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return operationManager.getOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return operationManager.getPendingOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
|
||||
return operationManager.getFeatures(deviceType);
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +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;
|
||||
|
||||
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.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Proxy class for all Device Management related operations that take the corresponding plugin type in
|
||||
* and resolve the appropriate plugin implementation
|
||||
*/
|
||||
public interface DeviceManager {
|
||||
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException;
|
||||
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException;
|
||||
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException;
|
||||
|
||||
public List<Device> getAllDevices(String type) throws DeviceManagementException;
|
||||
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException;
|
||||
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException;
|
||||
|
||||
public OperationManager getOperationManager(String type) throws DeviceManagementException;
|
||||
|
||||
}
|
@ -1,206 +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;
|
||||
|
||||
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.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
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.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagerImpl implements DeviceManager {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
|
||||
private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
private DeviceManagementConfig config;
|
||||
private DeviceManagementRepository pluginRepository;
|
||||
|
||||
public DeviceManagerImpl(DeviceManagementConfig config,
|
||||
DeviceManagementRepository pluginRepository) {
|
||||
this.config = config;
|
||||
this.pluginRepository = pluginRepository;
|
||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||
boolean status = dms.enrollDevice(device);
|
||||
try {
|
||||
org.wso2.carbon.device.mgt.core.dto.Device deviceDto =
|
||||
DeviceManagementDAOUtil.convertDevice(device);
|
||||
Integer deviceTypeId =
|
||||
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(device.getType());
|
||||
deviceDto.setStatus(Status.ACTIVE);
|
||||
deviceDto.setDeviceTypeId(deviceTypeId);
|
||||
this.getDeviceDAO().addDevice(deviceDto);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while enrolling the device '" + device.getId() + "'",
|
||||
e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||
boolean status = dms.modifyEnrollment(device);
|
||||
try {
|
||||
this.getDeviceDAO().updateDevice(DeviceManagementDAOUtil.convertDevice(device));
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while modifying the device '" + device.getId() + "'",
|
||||
e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.disenrollDevice(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.isEnrolled(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.isActive(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.setActive(deviceId, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
||||
List<Device> devicesList = new ArrayList<Device>();
|
||||
try {
|
||||
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
|
||||
List<org.wso2.carbon.device.mgt.core.dto.Device> devices =
|
||||
this.getDeviceDAO().getDevices(deviceTypeId);
|
||||
|
||||
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
|
||||
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
|
||||
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
|
||||
DeviceIdentifier deviceIdentifier =
|
||||
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
|
||||
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
||||
if (dmsDevice != null) {
|
||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
||||
}
|
||||
devicesList.add(convertedDevice);
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while obtaining the device for type '" + type + "'", e);
|
||||
}
|
||||
return devicesList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
Device convertedDevice = null;
|
||||
try {
|
||||
Integer deviceTypeId =
|
||||
this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
|
||||
org.wso2.carbon.device.mgt.core.dto.Device device =
|
||||
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
|
||||
if (device != null) {
|
||||
convertedDevice = DeviceManagementDAOUtil
|
||||
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
|
||||
Device dmsDevice = dms.getDevice(deviceId);
|
||||
if (dmsDevice != null) {
|
||||
convertedDevice.setProperties(dmsDevice.getProperties());
|
||||
convertedDevice.setFeatures(dmsDevice.getFeatures());
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'",
|
||||
e);
|
||||
}
|
||||
return convertedDevice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(device.getType());
|
||||
return dms.updateDeviceInfo(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
DeviceManagerService dms =
|
||||
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
|
||||
return dms.setOwnership(deviceId, ownershipType);
|
||||
}
|
||||
|
||||
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
||||
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
|
||||
return dms.getOperationManager();
|
||||
}
|
||||
|
||||
public DeviceDAO getDeviceDAO() {
|
||||
return deviceDAO;
|
||||
}
|
||||
|
||||
public DeviceTypeDAO getDeviceTypeDAO() {
|
||||
return deviceTypeDAO;
|
||||
}
|
||||
|
||||
public DeviceManagementRepository getPluginRepository() {
|
||||
return pluginRepository;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.license.mgt;
|
||||
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
|
||||
import org.wso2.carbon.registry.api.Registry;
|
||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GenericArtifactManagerFactory {
|
||||
|
||||
private static Map<Integer, GenericArtifactManager> tenantArtifactManagers =
|
||||
new HashMap<Integer, GenericArtifactManager>();
|
||||
private static final Object lock = new Object();
|
||||
|
||||
public static GenericArtifactManager getTenantAwareGovernanceArtifactManager() throws
|
||||
LicenseManagementException {
|
||||
Registry registry;
|
||||
int tenantId;
|
||||
try {
|
||||
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
registry =
|
||||
DeviceManagementDataHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(
|
||||
tenantId);
|
||||
} catch (RegistryException e) {
|
||||
throw new LicenseManagementException("Error occurred while initializing tenant system registry " +
|
||||
"to be used to manipulate License artifacts", e);
|
||||
}
|
||||
|
||||
try {
|
||||
GenericArtifactManager artifactManager;
|
||||
synchronized (lock) {
|
||||
artifactManager =
|
||||
tenantArtifactManagers.get(tenantId);
|
||||
if (artifactManager == null) {
|
||||
/* Hack, to fix https://wso2.org/jira/browse/REGISTRY-2427 */
|
||||
//GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
|
||||
artifactManager =
|
||||
new GenericArtifactManager((org.wso2.carbon.registry.core.Registry) registry,
|
||||
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY);
|
||||
tenantArtifactManagers.put(tenantId, artifactManager);
|
||||
}
|
||||
}
|
||||
return artifactManager;
|
||||
} catch (RegistryException e) {
|
||||
throw new LicenseManagementException("Error occurred while initializing GovernanceArtifactManager " +
|
||||
"associated with tenant '" + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* 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
|
||||
* 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
|
||||
* 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.
|
||||
* 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.license.mgt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
|
||||
import org.wso2.carbon.device.mgt.core.config.license.License;
|
||||
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.governance.api.exception.GovernanceException;
|
||||
import org.wso2.carbon.governance.api.generic.GenericArtifactFilter;
|
||||
import org.wso2.carbon.governance.api.generic.GenericArtifactManager;
|
||||
import org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LicenseManagerImpl implements LicenseManager {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
|
||||
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
|
||||
|
||||
@Override
|
||||
public License getLicense(final String deviceType, final String languageCode)
|
||||
throws LicenseManagementException {
|
||||
License deviceLicense = new License();
|
||||
LicenseConfig licenseConfig = DeviceManagementDataHolder.getInstance().getLicenseConfig();
|
||||
for (License license : licenseConfig.getLicenses()) {
|
||||
if ((deviceType.equals(license.getName())) &&
|
||||
(languageCode.equals(license.getLanguage()))) {
|
||||
deviceLicense = license;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return deviceLicense;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(License license) throws LicenseManagementException {
|
||||
|
||||
}
|
||||
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class);
|
||||
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
|
||||
|
||||
@Override
|
||||
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
|
||||
GenericArtifactManager artifactManager =
|
||||
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
|
||||
try {
|
||||
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
|
||||
@Override
|
||||
public boolean matches(GenericArtifact artifact) throws GovernanceException {
|
||||
String attributeNameVal = artifact.getAttribute(
|
||||
DeviceManagementConstants.LicenseProperties.NAME);
|
||||
String attributeLangVal = artifact.getAttribute(
|
||||
DeviceManagementConstants.LicenseProperties.LANGUAGE);
|
||||
return (attributeNameVal != null && attributeLangVal != null && attributeNameVal.equals
|
||||
(deviceType) && attributeLangVal.equals(languageCode));
|
||||
}
|
||||
});
|
||||
if (artifacts == null || artifacts.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
return this.populateLicense(artifacts[0]);
|
||||
} catch (GovernanceException e) {
|
||||
throw new LicenseManagementException("Error occurred while retrieving license corresponding to " +
|
||||
"device type '" + deviceType + "'");
|
||||
} catch (ParseException e) {
|
||||
throw new LicenseManagementException("Error occurred while parsing the ToDate/FromDate date string " +
|
||||
"of the license configured upon the device type '" + deviceType + "'");
|
||||
}
|
||||
}
|
||||
|
||||
private License populateLicense(GenericArtifact artifact) throws GovernanceException, ParseException {
|
||||
License license = new License();
|
||||
license.setName(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.NAME));
|
||||
license.setProvider(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER));
|
||||
license.setVersion(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.VERSION));
|
||||
license.setLanguage(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE));
|
||||
license.setText(artifact.getAttribute(DeviceManagementConstants.LicenseProperties.TEXT));
|
||||
license.setValidFrom(format.parse(artifact.getAttribute(
|
||||
DeviceManagementConstants.LicenseProperties.VALID_FROM)));
|
||||
license.setValidTo(format.parse(artifact.getAttribute(
|
||||
DeviceManagementConstants.LicenseProperties.VALID_TO)));
|
||||
return license;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLicense(String deviceType, License license) throws LicenseManagementException {
|
||||
GenericArtifactManager artifactManager =
|
||||
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
|
||||
try {
|
||||
GenericArtifact artifact =
|
||||
artifactManager.newGovernanceArtifact(new QName("http://www.wso2.com",
|
||||
DeviceManagementConstants.LicenseProperties.LICENSE_REGISTRY_KEY));
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.NAME, license.getName());
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VERSION, license.getVersion());
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.PROVIDER, license.getProvider());
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.LANGUAGE, license.getLanguage());
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.TEXT, license.getText());
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_TO,
|
||||
license.getValidTo().toString());
|
||||
artifact.setAttribute(DeviceManagementConstants.LicenseProperties.VALID_FROM,
|
||||
license.getValidFrom().toString());
|
||||
artifactManager.addGenericArtifact(artifact);
|
||||
return true;
|
||||
} catch (GovernanceException e) {
|
||||
throw new LicenseManagementException("Error occurred while adding license for device type " +
|
||||
deviceType + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.operation.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
|
||||
public class CommandOperation extends Operation {
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.operation.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigOperation extends Operation {
|
||||
|
||||
private List<Property> properties;
|
||||
|
||||
public ConfigOperation() {
|
||||
properties = new ArrayList<Property>();
|
||||
}
|
||||
|
||||
public List<Property> getConfigProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void addConfigProperty(String name, Object value, Class<?> type) {
|
||||
properties.add(new Property(name, value, type));
|
||||
}
|
||||
|
||||
public class Property {
|
||||
private String name;
|
||||
private Object value;
|
||||
private Class<?> type;
|
||||
|
||||
public Property(String name, Object value, Class<?> type) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Class<?> type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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.operation.mgt;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
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.DeviceManagementDAOFactory;
|
||||
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;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class implements all the functionalities exposed as part of the OperationManager. Any transaction initiated
|
||||
* upon persisting information related to operation state, etc has to be managed, demarcated and terminated via the
|
||||
* methods available in OperationManagementDAOFactory.
|
||||
*/
|
||||
public class OperationManagerImpl implements OperationManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(OperationManagerImpl.class);
|
||||
|
||||
private OperationDAO commandOperationDAO;
|
||||
private OperationDAO configOperationDAO;
|
||||
private OperationDAO simpleOperationDAO;
|
||||
private OperationMappingDAO operationMappingDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
|
||||
public OperationManagerImpl() {
|
||||
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
||||
configOperationDAO = OperationManagementDAOFactory.getConfigOperationDAO();
|
||||
simpleOperationDAO = OperationManagementDAOFactory.getSimpleOperationDAO();
|
||||
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
|
||||
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOperation(Operation operation,
|
||||
List<DeviceIdentifier> devices) throws OperationManagementException {
|
||||
try {
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
int operationId = this.lookupOperationDAO(operation).addOperation(operation);
|
||||
operationMappingDAO.addOperationMapping(operationId, null);
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
return true;
|
||||
} catch (OperationManagementDAOException e) {
|
||||
try {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
} catch (OperationManagementDAOException e1) {
|
||||
log.warn("Error occurred while roll-backing the transaction", e1);
|
||||
}
|
||||
throw new OperationManagementException("Error occurred while adding operation", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private OperationDAO lookupOperationDAO(Operation operation) {
|
||||
if (operation instanceof CommandOperation) {
|
||||
return commandOperationDAO;
|
||||
} else if (operation instanceof ConfigOperation) {
|
||||
return configOperationDAO;
|
||||
} else {
|
||||
return simpleOperationDAO;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.operation.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
|
||||
public class SimpleOperation extends Operation {
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OperationDAO {
|
||||
|
||||
int addOperation(Operation operation) throws OperationManagementDAOException;
|
||||
|
||||
int updateOperation(Operation operation) throws OperationManagementDAOException;
|
||||
|
||||
int deleteOperation(int id) throws OperationManagementDAOException;
|
||||
|
||||
Operation getOperation(int id) throws OperationManagementDAOException;
|
||||
|
||||
List<Operation> getOperations() throws OperationManagementDAOException;
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao;
|
||||
|
||||
public class OperationManagementDAOException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070299L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public OperationManagementDAOException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OperationManagementDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public OperationManagementDAOException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OperationManagementDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public OperationManagementDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.CommandOperationDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.ConfigOperationDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.OperationMappingDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.SimpleOperationDAOImpl;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class OperationManagementDAOFactory {
|
||||
|
||||
private static DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class);
|
||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||
|
||||
public static OperationDAO getCommandOperationDAO() {
|
||||
return new CommandOperationDAOImpl();
|
||||
}
|
||||
|
||||
public static OperationDAO getConfigOperationDAO() {
|
||||
return new ConfigOperationDAOImpl();
|
||||
}
|
||||
|
||||
public static OperationDAO getSimpleOperationDAO() {
|
||||
return new SimpleOperationDAOImpl();
|
||||
}
|
||||
|
||||
public static OperationMappingDAO getOperationMappingDAO() {
|
||||
return new OperationMappingDAOImpl();
|
||||
}
|
||||
|
||||
public static void init(DataSource dtSource) {
|
||||
dataSource = dtSource;
|
||||
}
|
||||
|
||||
public static void beginTransaction() throws OperationManagementDAOException {
|
||||
try {
|
||||
currentConnection.set(dataSource.getConnection());
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while retrieving datasource connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() {
|
||||
return currentConnection.get();
|
||||
}
|
||||
|
||||
public static void commitTransaction() throws OperationManagementDAOException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.commit();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||
"has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while committing the transaction", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void rollbackTransaction() throws OperationManagementDAOException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.rollback();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
||||
"has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while rollbacking the transaction", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve data source from the data source definition
|
||||
*
|
||||
* @param config data source configuration
|
||||
* @return data source resolved from the data source definition
|
||||
*/
|
||||
private static DataSource resolveDataSource(DataSourceConfig config) {
|
||||
DataSource dataSource = null;
|
||||
if (config == null) {
|
||||
throw new RuntimeException(
|
||||
"Device Management Repository data source configuration " + "is null and " +
|
||||
"thus, is not initialized");
|
||||
}
|
||||
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
||||
if (jndiConfig != null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
||||
"Lookup Definition");
|
||||
}
|
||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
||||
jndiConfig.getJndiProperties();
|
||||
if (jndiPropertyList != null) {
|
||||
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||
jndiProperties.put(prop.getName(), prop.getValue());
|
||||
}
|
||||
dataSource = DeviceManagementDAOUtil
|
||||
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||
} else {
|
||||
dataSource =
|
||||
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||
}
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public static DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class OperationManagementDAOUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(OperationManagementDAOUtil.class);
|
||||
|
||||
public static void cleanupResources(Statement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing the result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing the statement", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OperationMappingDAO {
|
||||
|
||||
void addOperationMapping(int operationId, List<Integer> deviceIds) throws OperationManagementDAOException;
|
||||
|
||||
void removeOperationMapping(int operationId, List<Integer> deviceIds) throws OperationManagementDAOException;
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.*;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class AbstractOperationDAO implements OperationDAO {
|
||||
|
||||
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement(
|
||||
"INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS) VALUES (?, ?, ?, ?)");
|
||||
stmt.setString(1, operation.getType().toString());
|
||||
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
|
||||
stmt.setTimestamp(3, null);
|
||||
stmt.setBoolean(4, false);
|
||||
stmt.executeUpdate();
|
||||
|
||||
rs = stmt.getGeneratedKeys();
|
||||
int id = -1;
|
||||
if (rs.next()) {
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
return id;
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandOperationDAOImpl extends AbstractOperationDAO {
|
||||
|
||||
@Override
|
||||
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
||||
int operationId = super.addOperation(operation);
|
||||
CommandOperation commandOp = (CommandOperation) operation;
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_COMMAND_OPERATION(OPERATION_ID, ENABLED) VALUES(?, ?)");
|
||||
stmt.setInt(1, operationId);
|
||||
stmt.setBoolean(2, commandOp.isEnabled());
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while adding command operation", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOperation(int id) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations() throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigOperationDAOImpl extends AbstractOperationDAO {
|
||||
|
||||
@Override
|
||||
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOperation(int id) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations() throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class OperationMappingDAOImpl implements OperationMappingDAO {
|
||||
|
||||
@Override
|
||||
public void addOperationMapping(int operationId, List<Integer> deviceIds) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "INSERT INTO DEVICE_OPERATION_MAPPING(DEVICE_ID, OPERATION_ID) VALUES(?, ?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, 0);
|
||||
stmt.setInt(2, operationId);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeOperationMapping(int operationId,
|
||||
List<Integer> deviceIds) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, 0);
|
||||
stmt.setInt(2, operationId);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.operation.mgt.dao.impl;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleOperationDAOImpl extends AbstractOperationDAO {
|
||||
|
||||
@Override
|
||||
public int updateOperation(Operation operation) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOperation(int id) throws OperationManagementDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations() throws OperationManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.*;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
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.core.internal.DeviceManagementDataHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
|
||||
@Override
|
||||
public String getProviderType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().enrollDevice(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().modifyEnrollment(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().disenrollDevice(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isEnrolled(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().isActive(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().setActive(deviceId, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getAllDevices(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementException{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId)
|
||||
throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getDevice(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().updateDeviceInfo(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().setOwnership(deviceId,
|
||||
ownershipType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getLicense(deviceType,
|
||||
languageCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addLicense(String type, License license) throws LicenseManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addLicense(type, license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOperation(Operation operation,
|
||||
List<DeviceIdentifier> devices) throws OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().addOperation(operation, devices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Operation> getPendingOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getPendingOperations(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().getFeatures(deviceType);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.testng.Assert;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class DeviceManagementBaseTest {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
public void init() {
|
||||
this.initDataSource();
|
||||
try {
|
||||
this.initDeviceManagementDatabaseSchema();
|
||||
} catch (SQLException e) {
|
||||
Assert.fail("Error occurred while initializing database schema", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initDeviceManagementDatabaseSchema() throws SQLException {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
if (dataSource == null) {
|
||||
Assert.fail("Device management datasource is not initialized peroperly");
|
||||
}
|
||||
conn = dataSource.getConnection();
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'");
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void initDataSource() {
|
||||
PoolProperties properties = new PoolProperties();
|
||||
properties.setUrl("jdbc:h2:mem:MDM_DB;DB_CLOSE_DELAY=-1");
|
||||
properties.setDriverClassName("org.h2.Driver");
|
||||
properties.setUsername("wso2carbon");
|
||||
properties.setPassword("wso2carbon");
|
||||
this.dataSource = new org.apache.tomcat.jdbc.pool.DataSource(properties);
|
||||
}
|
||||
|
||||
protected DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.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.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.*;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceOperationManagementTests extends DeviceManagementBaseTest {
|
||||
|
||||
private OperationManager operationManager;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void init() {
|
||||
super.init();
|
||||
this.initOperationManager();
|
||||
OperationManagementDAOFactory.init(this.getDataSource());
|
||||
}
|
||||
|
||||
public void initOperationManager() {
|
||||
this.operationManager = new OperationManagerImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddOperation() throws Exception {
|
||||
|
||||
CommandOperation op = new CommandOperation();
|
||||
op.setEnabled(true);
|
||||
op.setType(Operation.Type.COMMAND);
|
||||
|
||||
List<DeviceIdentifier> deviceIds = new ArrayList<DeviceIdentifier>();
|
||||
DeviceIdentifier deviceId = new DeviceIdentifier();
|
||||
deviceId.setId("Test");
|
||||
deviceId.setType("Android");
|
||||
deviceIds.add(deviceId);
|
||||
|
||||
try {
|
||||
operationManager.addOperation(op, deviceIds);
|
||||
} catch (OperationManagementException e) {
|
||||
e.printStackTrace();
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetOperations() {
|
||||
try {
|
||||
operationManager.getOperations(null);
|
||||
} catch (OperationManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||
ID INT auto_increment NOT NULL,
|
||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
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,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
PRIMARY KEY (ID)
|
||||
)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
|
||||
OPERATION_ID INTEGER NOT 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 INTEGER NOT NULL DEFAULT 0,
|
||||
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
|
||||
)
|
||||
|
||||
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,
|
||||
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
|
||||
)
|
||||
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class Profile {
|
||||
|
||||
private int profileId;
|
||||
private String profileName;
|
||||
private int tenantId;
|
||||
private DeviceType deviceType;
|
||||
private Timestamp createdDate;
|
||||
private Timestamp updatedDate;
|
||||
private List<Feature> featuresList; // Features included in the policies.
|
||||
|
||||
public DeviceType getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(DeviceType deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public List<Feature> getFeaturesList() {
|
||||
return featuresList;
|
||||
}
|
||||
|
||||
public void setFeaturesList(List<Feature> featuresList) {
|
||||
this.featuresList = featuresList;
|
||||
}
|
||||
|
||||
public int getProfileId() {
|
||||
return profileId;
|
||||
}
|
||||
|
||||
public void setProfileId(int profileId) {
|
||||
this.profileId = profileId;
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public void setProfileName(String profileName) {
|
||||
this.profileName = profileName;
|
||||
}
|
||||
|
||||
public Timestamp getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(Timestamp createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
public Timestamp getUpdatedDate() {
|
||||
return updatedDate;
|
||||
}
|
||||
|
||||
public void setUpdatedDate(Timestamp updatedDate) {
|
||||
this.updatedDate = updatedDate;
|
||||
}
|
||||
}
|
@ -1,81 +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.common.impl;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorService;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
|
||||
public class PolicyManagement implements PolicyAdministratorService {
|
||||
@Override
|
||||
public int addPolicy(Policy policy) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ;
|
||||
USE `WSO2CDM` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
|
||||
`ID` VARCHAR(20) 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`) ,
|
||||
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_PROFILE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`TENANT_ID` INT NOT NULL ,
|
||||
`CREATED_TIME` DATETIME NOT NULL ,
|
||||
`UPDATED_TIME` DATETIME NOT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NOT NULL ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`DEVICE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(256) NOT NULL ,
|
||||
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_POLICY_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
`FEATURE_ID` INT(11) NOT NULL ,
|
||||
`CONTENT` BLOB NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_FEATURES` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_ROLE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`ROLE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_ROLE_POLICY_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_LOCATION`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` (
|
||||
`LAT` VARCHAR(45) NOT NULL ,
|
||||
`LONG` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_TIME`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` (
|
||||
`STARTING_TIME` DATETIME NOT NULL ,
|
||||
`ENDING_TIME` DATETIME NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_TIME`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
@ -1,54 +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.wos2.carbon.policy.mgt.common;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wos2.carbon.policy.mgt.common.utils.PolicyCreator;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.impl.PolicyManagement;
|
||||
|
||||
public class PolicyManagementTestCase {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyManagementTestCase.class);
|
||||
|
||||
Policy policy = PolicyCreator.createPolicy();
|
||||
|
||||
private PolicyManagement policyManagement = new PolicyManagement();
|
||||
|
||||
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device")
|
||||
public void testAddPolicy() throws FeatureManagementException, PolicyManagementException {
|
||||
Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0);
|
||||
}
|
||||
|
||||
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device type")
|
||||
public void testAddPolicyToDeviceType() throws FeatureManagementException, PolicyManagementException {
|
||||
Assert.assertEquals(policyManagement.addPolicyToDeviceType("MD", policy), 0);
|
||||
}
|
||||
|
||||
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a user Role")
|
||||
public void testAddPolicyToRole() throws FeatureManagementException, PolicyManagementException {
|
||||
Assert.assertEquals(policyManagement.addPolicyToRole("Admin", policy), 0);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyManager {
|
||||
|
||||
Feature addFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
Feature updateFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
Profile addProfile(Profile profile) throws PolicyManagementException;
|
||||
|
||||
Profile updateProfile(Profile profile) throws PolicyManagementException;
|
||||
|
||||
Policy addPolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||
|
||||
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||
|
||||
Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException;
|
||||
|
||||
List<Policy> getPolicies(String deviceType) throws PolicyManagementException;
|
||||
|
||||
List<Feature> getFeatures() throws FeatureManagementException;
|
||||
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.core.impl.PolicyAdministratorPointImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyManagerImpl implements PolicyManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyManagerImpl.class);
|
||||
|
||||
PolicyAdministratorPointImpl policyAdministratorPoint;
|
||||
|
||||
public PolicyManagerImpl() {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile addProfile(Profile profile) throws PolicyManagementException {
|
||||
return policyAdministratorPoint.addProfile(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile updateProfile(Profile profile) throws PolicyManagementException {
|
||||
return policyAdministratorPoint.updateProfile(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
||||
return policyAdministratorPoint.addPolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
||||
return policyAdministratorPoint.updatePolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPolicies(String deviceType) throws PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws FeatureManagementException {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -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.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FeatureDAO {
|
||||
|
||||
Feature addFeature(Feature feature) throws FeatureManagerDAOException;
|
||||
|
||||
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;
|
||||
|
||||
List<Feature> getAllFeatures() throws FeatureManagerDAOException;
|
||||
|
||||
List<Feature> getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException;
|
||||
|
||||
void deleteFeature(int featureId) throws FeatureManagerDAOException;
|
||||
|
||||
void deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException;
|
||||
|
||||
}
|
@ -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.core.dao;
|
||||
|
||||
public class FeatureManagerDAOException extends Exception {
|
||||
|
||||
private String featureDAOErrorMessage;
|
||||
|
||||
public String getFeatureDAOErrorMessage() {
|
||||
return featureDAOErrorMessage;
|
||||
}
|
||||
|
||||
public void setFeatureDAOErrorMessage(String featureDAOErrorMessage) {
|
||||
this.featureDAOErrorMessage = featureDAOErrorMessage;
|
||||
}
|
||||
|
||||
public FeatureManagerDAOException(String message) {
|
||||
super(message);
|
||||
setFeatureDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public FeatureManagerDAOException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setFeatureDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public FeatureManagerDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setFeatureDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public FeatureManagerDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FeatureManagerDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.Profile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProfileDAO {
|
||||
|
||||
Profile addProfile(Profile profile) throws ProfileManagerDAOException;
|
||||
|
||||
Profile updateProfile(Profile profile) throws ProfileManagerDAOException;
|
||||
|
||||
void deleteProfile(Profile profile) throws ProfileManagerDAOException;
|
||||
|
||||
List<Profile> getAllProfiles() throws ProfileManagerDAOException;
|
||||
|
||||
List<Profile> getProfilesOfDeviceType(String deviceType) throws ProfileManagerDAOException;
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 ProfileManagerDAOException extends Exception{
|
||||
|
||||
private String profileDAOErrorMessage;
|
||||
|
||||
public String getProfileDAOErrorMessage() {
|
||||
return profileDAOErrorMessage;
|
||||
}
|
||||
|
||||
public void setProfileDAOErrorMessage(String profileDAOErrorMessage) {
|
||||
this.profileDAOErrorMessage = profileDAOErrorMessage;
|
||||
}
|
||||
|
||||
public ProfileManagerDAOException(String message) {
|
||||
super(message);
|
||||
setProfileDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public ProfileManagerDAOException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setProfileDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public ProfileManagerDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setProfileDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public ProfileManagerDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProfileManagerDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||
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 FeatureDAOImpl implements FeatureDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
|
||||
|
||||
|
||||
@Override
|
||||
public Feature addFeature(Feature feature) throws FeatureManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION, EVALUVATION_RULE) VALUES (?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS);
|
||||
stmt.setString(1, feature.getName());
|
||||
stmt.setString(2, feature.getCode());
|
||||
stmt.setString(3, feature.getDescription());
|
||||
stmt.setString(4, feature.getRuleValue());
|
||||
|
||||
int affectedRows = stmt.executeUpdate();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(affectedRows + " Features are added.");
|
||||
}
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
while (generatedKeys.next()) {
|
||||
feature.setId(generatedKeys.getInt(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding feature to the database.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Feature updateFeature(Feature feature) throws FeatureManagerDAOException {
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "DELETE FROM DM_PROFILE_FEATURES WHERE PROFILE_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profile.getProfileId());
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting the feature related to a profile.";
|
||||
log.error(msg);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Feature> getAllFeatures() throws FeatureManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "SELECT ID, NAME, CODE, EVALUVATION_RULE FROM DM_FEATURES";
|
||||
stmt = conn.prepareStatement(query);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
Feature feature = new Feature();
|
||||
feature.setId(resultSet.getInt("ID"));
|
||||
feature.setCode(resultSet.getString("CODE"));
|
||||
feature.setName(resultSet.getString("NAME"));
|
||||
feature.setRuleValue(resultSet.getString("EVALUVATION_RULE"));
|
||||
featureList.add(feature);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to get the list of the features from database.";
|
||||
log.error(msg);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||
}
|
||||
return featureList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeaturesForProfile(int profileId) throws FeatureManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "SELECT PF.FEATURE_ID FEATURE_ID, F.NAME NAME, F.CODE CODE, " +
|
||||
"F.EVALUVATION_RULE RULE, F.CONTENT AS CONTENT FROM DM_PROFILE_FEATURES AS PF " +
|
||||
"JOIN DM_FEATURES AS F ON F.ID = PF.FEATURE_ID WHERE PROFILE_ID=?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profileId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
Feature feature = new Feature();
|
||||
feature.setId(resultSet.getInt("FEATURE_ID"));
|
||||
feature.setCode(resultSet.getString("CODE"));
|
||||
feature.setName(resultSet.getString("NAME"));
|
||||
feature.setAttribute(resultSet.getObject("CONTENT"));
|
||||
feature.setRuleValue(resultSet.getString("RULE"));
|
||||
featureList.add(feature);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to get the list of the features from database.";
|
||||
log.error(msg);
|
||||
throw new FeatureManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||
}
|
||||
return featureList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFeature(int featureId) throws FeatureManagerDAOException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "";
|
||||
stmt = conn.prepareStatement(query);
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws FeatureManagerDAOException {
|
||||
try {
|
||||
return PolicyManagementDAOFactory.getDataSource().getConnection();
|
||||
} catch (SQLException e) {
|
||||
throw new FeatureManagerDAOException("Error occurred while obtaining a connection from the policy " +
|
||||
"management metadata repository datasource", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||
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.List;
|
||||
|
||||
public class ProfileDAOImpl implements ProfileDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ProfileDAOImpl.class);
|
||||
|
||||
|
||||
public Profile addProfile(Profile profile) throws ProfileManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
|
||||
// TODO : find a way to get the tenant Id.
|
||||
int tenantId = -1234;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_PROFILE (PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS);
|
||||
|
||||
stmt.setString(1, profile.getProfileName());
|
||||
stmt.setInt(2, tenantId);
|
||||
stmt.setLong(3, profile.getDeviceType().getId());
|
||||
stmt.setTimestamp(4, profile.getCreatedDate());
|
||||
stmt.setTimestamp(5, profile.getUpdatedDate());
|
||||
|
||||
int affectedRows = stmt.executeUpdate();
|
||||
|
||||
if (affectedRows == 0 && log.isDebugEnabled()) {
|
||||
String msg = "No rows are updated on the profile table.";
|
||||
log.debug(msg);
|
||||
}
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
|
||||
if (generatedKeys.next()) {
|
||||
profile.setProfileId(generatedKeys.getInt(1));
|
||||
}
|
||||
// Checking the profile id here, because profile id could have been passed from the calling method.
|
||||
if (profile.getProfileId() == 0) {
|
||||
throw new RuntimeException("Profile id is 0, this could be an issue.");
|
||||
}
|
||||
|
||||
persistFeatures(profile);
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the profile to database.";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
public Profile updateProfile(Profile profile) throws ProfileManagerDAOException {
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProfile(Profile profile) throws ProfileManagerDAOException {
|
||||
|
||||
// First delete the features related to the profile
|
||||
FeatureDAOImpl featureDAO = new FeatureDAOImpl();
|
||||
try {
|
||||
featureDAO.deleteFeaturesOfProfile(profile);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while deleting features.";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagerDAOException(msg, e);
|
||||
}
|
||||
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, profile.getProfileId());
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting the profile from the data base.";
|
||||
log.error(msg);
|
||||
throw new ProfileManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void persistFeatures(Profile profile) throws ProfileManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_ID, CONTENT) VALUES (?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(query);
|
||||
for (Feature feature : profile.getFeaturesList()) {
|
||||
stmt.setInt(1, profile.getProfileId());
|
||||
stmt.setInt(2, feature.getId());
|
||||
stmt.setObject(3, feature.getAttribute());
|
||||
stmt.addBatch();
|
||||
//Not adding the logic to check the size of the stmt and execute if the size records added is over 1000
|
||||
}
|
||||
stmt.executeBatch();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the feature list to the database.";
|
||||
log.error(msg, e);
|
||||
throw new ProfileManagerDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Profile> getAllProfiles() throws ProfileManagerDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "";
|
||||
stmt = conn.prepareStatement(query);
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Profile> getProfilesOfDeviceType(String deviceType) throws ProfileManagerDAOException {
|
||||
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "";
|
||||
stmt = conn.prepareStatement(query);
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Connection getConnection() throws ProfileManagerDAOException {
|
||||
try {
|
||||
return PolicyManagementDAOFactory.getDataSource().getConnection();
|
||||
} catch (SQLException e) {
|
||||
throw new ProfileManagerDAOException("Error occurred while obtaining a connection from the policy " +
|
||||
"management metadata repository datasource", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.FeatureDAOImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.ProfileDAOImpl;
|
||||
|
||||
public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class);
|
||||
|
||||
PolicyDAOImpl policyDAO;
|
||||
FeatureDAOImpl featureDAO;
|
||||
ProfileDAOImpl profileDAO;
|
||||
|
||||
public PolicyAdministratorPointImpl() {
|
||||
policyDAO = new PolicyDAOImpl();
|
||||
featureDAO = new FeatureDAOImpl();
|
||||
profileDAO = new ProfileDAOImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
||||
try {
|
||||
policy = policyDAO.addPolicy(policy);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the policy.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
||||
try {
|
||||
policy = policyDAO.updatePolicy(policy);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while updating the policy.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy)
|
||||
throws FeatureManagementException, PolicyManagementException {
|
||||
|
||||
try {
|
||||
policy = policyDAO.addPolicy(deviceId, deviceType, policy);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the policy.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicyToRole(String roleName, Policy policy)
|
||||
throws FeatureManagementException, PolicyManagementException {
|
||||
try {
|
||||
policy = policyDAO.addPolicyToRole(roleName, policy);
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the policy.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfDevice(String deviceId, String deviceType)
|
||||
throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfDeviceType(String deviceType)
|
||||
throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile addProfile(Profile profile) throws PolicyManagementException {
|
||||
try {
|
||||
profile = profileDAO.addProfile(profile);
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the policy.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteProfile(int profileId) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile updateProfile(Profile profile) throws PolicyManagementException {
|
||||
try {
|
||||
profile = profileDAO.updateProfile(profile);
|
||||
} catch (ProfileManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the profile.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature addFeature(Feature feature) throws FeatureManagementException {
|
||||
try {
|
||||
feature = featureDAO.addFeature(feature);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the feature.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature updateFeature(Feature feature) throws FeatureManagementException {
|
||||
try {
|
||||
feature = featureDAO.updateFeature(feature);
|
||||
} catch (FeatureManagerDAOException e) {
|
||||
String msg = "Error occurred while persisting the feature.";
|
||||
log.error(msg, e);
|
||||
throw new FeatureManagementException(msg, e);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFeature(int featureId) throws FeatureManagementException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
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.impl.DeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyInformationPointImpl.class);
|
||||
DeviceDAOImpl deviceDAO;
|
||||
|
||||
public PolicyInformationPointImpl() {
|
||||
deviceDAO = new DeviceDAOImpl(DeviceManagementDAOFactory.getDataSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
PIPDeviceData pipDeviceData = new PIPDeviceData();
|
||||
Device device;
|
||||
try {
|
||||
device = deviceDAO.getDevice(deviceIdentifier);
|
||||
pipDeviceData.setDevice(device);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred when retrieving the data related to device from the database.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
|
||||
return pipDeviceData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getRelatedFeatures(String deviceType) throws FeatureManagementException {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManager;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyManagementService implements PolicyManager {
|
||||
|
||||
|
||||
PolicyManager policyManager;
|
||||
|
||||
public PolicyManagementService() {
|
||||
policyManager = new PolicyManagerImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature addFeature(Feature feature) throws FeatureManagementException {
|
||||
return policyManager.addFeature(feature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature updateFeature(Feature feature) throws FeatureManagementException {
|
||||
return policyManager.updateFeature(feature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile addProfile(Profile profile) throws PolicyManagementException {
|
||||
return policyManager.addProfile(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Profile updateProfile(Profile profile) throws PolicyManagementException {
|
||||
return policyManager.updateProfile(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy addPolicy(Policy policy) throws PolicyManagementException {
|
||||
return policyManager.addPolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy updatePolicy(Policy policy) throws PolicyManagementException {
|
||||
return policyManager.updatePolicy(policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
return policyManager.getEffectivePolicy(deviceIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException {
|
||||
return policyManager.getEffectiveFeatures(deviceIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getPolicies(String deviceType) throws PolicyManagementException {
|
||||
return policyManager.getPolicies(deviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws FeatureManagementException {
|
||||
return policyManager.getFeatures();
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* 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.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
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.FeatureManagerDAOException;
|
||||
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.impl.FeatureDAOImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.util.FeatureCreator;
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyDAOTestCase {
|
||||
|
||||
|
||||
private DataSource dataSource;
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws PolicyManagerDAOException,
|
||||
PolicyManagementException {
|
||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.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;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFeatures() throws FeatureManagerDAOException {
|
||||
|
||||
FeatureDAOImpl policyDAO = new FeatureDAOImpl();
|
||||
List<Feature> featureList = FeatureCreator.getFeatureList();
|
||||
for (Feature feature : featureList) {
|
||||
policyDAO.addFeature(feature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TestUtils.class);
|
||||
|
||||
public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing result set", e);
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing prepared statement", e);
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
log.warn("Error occurred while closing database connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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,90 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FeatureCreator {
|
||||
|
||||
public static List<Feature> getFeatureList() {
|
||||
|
||||
Feature feature1 = new Feature();
|
||||
feature1.setName("Camera");
|
||||
feature1.setCode("C001");
|
||||
feature1.setDescription("Camera");
|
||||
feature1.setRuleValue("permit_override");
|
||||
|
||||
|
||||
Feature feature2 = new Feature();
|
||||
feature2.setName("LOCK");
|
||||
feature2.setCode("L001");
|
||||
feature2.setDescription("Lock the phone");
|
||||
feature2.setRuleValue("deny_override");
|
||||
|
||||
|
||||
Feature feature3 = new Feature();
|
||||
feature3.setName("WIFI");
|
||||
feature3.setCode("W001");
|
||||
feature3.setDescription("Wifi configuration for the device");
|
||||
feature3.setRuleValue("all_available");
|
||||
|
||||
Feature feature4 = new Feature();
|
||||
feature4.setName("RING");
|
||||
feature4.setCode("R001");
|
||||
feature4.setDescription("Ring the mobile");
|
||||
feature4.setRuleValue("first_applicable");
|
||||
|
||||
Feature feature5 = new Feature();
|
||||
feature5.setName("LDAP");
|
||||
feature5.setCode("L002");
|
||||
feature5.setDescription("LDAP Configurations");
|
||||
feature5.setRuleValue("all_available");
|
||||
|
||||
|
||||
Feature feature6 = new Feature();
|
||||
feature6.setName("VPN");
|
||||
feature6.setCode("V001");
|
||||
feature6.setDescription("VPN config for accessing the company network from out side");
|
||||
feature6.setRuleValue("all_available");
|
||||
|
||||
|
||||
Feature feature7 = new Feature();
|
||||
feature7.setName("PASSWORD");
|
||||
feature7.setCode("P001");
|
||||
feature7.setDescription("Setting the password for the mobile");
|
||||
feature7.setRuleValue("first_applicable");
|
||||
|
||||
Feature feature8 = new Feature();
|
||||
feature8.setName("WIPE");
|
||||
feature8.setCode("W002");
|
||||
feature8.setDescription("Wiping the company profile created to access the company secure data");
|
||||
feature8.setRuleValue("permit_override");
|
||||
|
||||
Feature feature9 = new Feature();
|
||||
feature9.setName("ENCRYPTION");
|
||||
feature9.setCode("E001");
|
||||
feature9.setDescription("Adding the encryption for the phone and SD card.");
|
||||
feature9.setRuleValue("permit_override");
|
||||
|
||||
Feature feature10 = new Feature();
|
||||
feature10.setName("APP");
|
||||
feature10.setCode("A001");
|
||||
feature10.setDescription("Installing an application to the phone");
|
||||
feature10.setRuleValue("permit_override");
|
||||
|
||||
Feature feature11 = new Feature();
|
||||
feature11.setName("EMAIL");
|
||||
feature11.setCode("E002");
|
||||
feature11.setDescription("Email configurations of the phone.");
|
||||
feature11.setRuleValue("all_applicable");
|
||||
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
featureList.add(feature1);
|
||||
featureList.add(feature2);
|
||||
featureList.add(feature3);
|
||||
featureList.add(feature4);
|
||||
featureList.add(feature5);
|
||||
featureList.add(feature6);
|
||||
featureList.add(feature7);
|
||||
featureList.add(feature8);
|
||||
featureList.add(feature9);
|
||||
featureList.add(feature10);
|
||||
featureList.add(feature11);
|
||||
|
||||
return featureList;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright 2009 WSO2, Inc. (http://wso2.com)
|
||||
#
|
||||
# Licensed 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.
|
||||
#
|
||||
|
||||
#
|
||||
# This is the log4j configuration file used by WSO2 Carbon
|
||||
#
|
||||
# IMPORTANT : Please do not remove or change the names of any
|
||||
# of the Appenders defined here. The layout pattern & log file
|
||||
# can be changed using the WSO2 Carbon Management Console, and those
|
||||
# settings will override the settings in this file.
|
||||
#
|
||||
|
||||
log4j.rootLogger=DEBUG, STD_OUT
|
||||
|
||||
# Redirect log messages to console
|
||||
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.STD_OUT.Target=System.out
|
||||
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
@ -0,0 +1,213 @@
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
|
||||
`ID` VARCHAR(20) 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)
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_PROFILE`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_PROFILE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`TENANT_ID` INT NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT NOT NULL ,
|
||||
`CREATED_TIME` DATETIME NOT NULL ,
|
||||
`UPDATED_TIME` DATETIME NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `DM_PROFILE_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NOT NULL ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`DEVICE_ID` VARCHAR(20) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
|
||||
FOREIGN KEY (`DEVICE_ID` )
|
||||
REFERENCES `DM_DEVICE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_DEVICE_TYPE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_DEVICE_TYPE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(256) NOT NULL ,
|
||||
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) );
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_PROFILE_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `DM_PROFILE_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
`FEATURE_ID` INT(11) NOT NULL ,
|
||||
`CONTENT` BLOB NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `DM_FEATURES` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_ROLE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`ROLE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
CONSTRAINT `FK_ROLE_POLICY_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_LOCATION`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_LOCATION (
|
||||
`LAT` VARCHAR(45) NOT NULL ,
|
||||
`LONG` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `DM_TIME`
|
||||
-- -----------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_TIME (
|
||||
`STARTING_TIME` DATETIME NOT NULL ,
|
||||
`ENDING_TIME` DATETIME NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_TIME`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION);
|
||||
;
|
||||
|
@ -0,0 +1,247 @@
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
|
||||
|
||||
DROP SCHEMA IF EXISTS `WSO2CDM` ;
|
||||
CREATE SCHEMA IF NOT EXISTS `WSO2CDM` DEFAULT CHARACTER SET latin1 ;
|
||||
USE `WSO2CDM` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`NAME` VARCHAR(300) NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE` (
|
||||
`ID` VARCHAR(20) 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`) ,
|
||||
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_PROFILE`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE` (
|
||||
`ID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`TENANT_ID` INT NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT NOT NULL ,
|
||||
`CREATED_TIME` DATETIME NOT NULL ,
|
||||
`UPDATED_TIME` DATETIME NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `DM_PROFILE_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `DM_PROFILE_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`TENANT_ID` INT(11) NOT NULL ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`DEVICE_ID` VARCHAR(20) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_POLICY_DEVICE_POLICY` (`POLICY_ID` ASC) ,
|
||||
INDEX `FK_DEVICE_DEVICE_POLICY` (`DEVICE_ID` ASC) ,
|
||||
CONSTRAINT `FK_POLICY_DEVICE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_DEVICE_POLICY`
|
||||
FOREIGN KEY (`DEVICE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DEVICE_TYPE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_TYPE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`DEVICE_TYPE_ID` INT(11) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY` (`POLICY_ID` ASC) ,
|
||||
INDEX `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE` (`DEVICE_TYPE_ID` ASC) ,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DEVICE_TYPE_POLICY_DEVICE_TYPE`
|
||||
FOREIGN KEY (`DEVICE_TYPE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_DEVICE_TYPE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_FEATURES` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`NAME` VARCHAR(256) NOT NULL ,
|
||||
`CODE` VARCHAR(45) NULL DEFAULT NULL ,
|
||||
`DESCRIPTION` TEXT NULL DEFAULT NULL ,
|
||||
`EVALUVATION_RULE` VARCHAR(60) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) )
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_PROFILE_FEATURES`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
`PROFILE_ID` INT(11) NOT NULL ,
|
||||
`FEATURE_ID` INT(11) NOT NULL ,
|
||||
`CONTENT` BLOB NULL DEFAULT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `fk_DM_POLICY_FEATURES_DM_FEATURES1` (`FEATURE_ID` ASC) ,
|
||||
INDEX `FK_DM_PROFILE_DM_POLICY_FEATURES` (`PROFILE_ID` ASC) ,
|
||||
CONSTRAINT `fk_DM_POLICY_FEATURES_DM_FEATURES1`
|
||||
FOREIGN KEY (`FEATURE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_FEATURES` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `FK_DM_PROFILE_DM_POLICY_FEATURES`
|
||||
FOREIGN KEY (`PROFILE_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_PROFILE` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_ROLE_POLICY`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_ROLE_POLICY` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_ROLE_POLICY` (
|
||||
`ID` INT(11) NOT NULL ,
|
||||
`ROLE_NAME` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
PRIMARY KEY (`ID`) ,
|
||||
INDEX `FK_ROLE_POLICY_POLICY` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_ROLE_POLICY_POLICY`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_LOCATION`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_LOCATION` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_LOCATION` (
|
||||
`LAT` VARCHAR(45) NOT NULL ,
|
||||
`LONG` VARCHAR(45) NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_LOCATION` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_LOCATION`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_TIME`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `WSO2CDM`.`DM_TIME` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_TIME` (
|
||||
`STARTING_TIME` DATETIME NOT NULL ,
|
||||
`ENDING_TIME` DATETIME NOT NULL ,
|
||||
`POLICY_ID` INT(11) NOT NULL ,
|
||||
INDEX `FK_DM_POLICY_DM_TIME` (`POLICY_ID` ASC) ,
|
||||
CONSTRAINT `FK_DM_POLICY_DM_TIME`
|
||||
FOREIGN KEY (`POLICY_ID` )
|
||||
REFERENCES `WSO2CDM`.`DM_POLICY` (`ID` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtTestDBConfigurations>
|
||||
<DBType typeName="MySql">
|
||||
<connectionurl>jdbc:mysql://10.100.0.47:3306/WSO2CDM</connectionurl>
|
||||
<driverclass>com.mysql.jdbc.Driver</driverclass>
|
||||
<userName>root</userName>
|
||||
<pwd>root</pwd>
|
||||
</DBType>
|
||||
<DBType typeName="H2">
|
||||
<connectionurl>jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1</connectionurl>
|
||||
<driverclass>org.h2.Driver</driverclass>
|
||||
<userName>wso2carbon</userName>
|
||||
<pwd>wso2carbon</pwd>
|
||||
</DBType>
|
||||
</DeviceMgtTestDBConfigurations>
|
@ -0,0 +1,31 @@
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="CDM-core-initializer">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
|
||||
<test name="DAO Unit Tests" preserve-order="true">
|
||||
<parameter name="dbType" value="H2"/>
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue