mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
merge with master
This commit is contained in:
commit
232ef4bd90
@ -19,9 +19,8 @@ package org.wso2.carbon.device.mgt.common;
|
|||||||
|
|
||||||
public class DeviceIdentifier {
|
public class DeviceIdentifier {
|
||||||
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
private String type;
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
|
|||||||
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.config.license;
|
package org.wso2.carbon.device.mgt.common.license.mgt;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
package org.wso2.carbon.device.mgt.common.license.mgt;
|
||||||
|
|
||||||
public class LicenseManagementException extends Exception {
|
public class LicenseManagementException extends Exception {
|
||||||
|
|
||||||
@ -16,14 +16,12 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
package org.wso2.carbon.device.mgt.common.license.mgt;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.License;
|
|
||||||
|
|
||||||
public interface LicenseManager {
|
public interface LicenseManager {
|
||||||
|
|
||||||
License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException;
|
License getLicense(String deviceType, String languageCode) throws LicenseManagementException;
|
||||||
|
|
||||||
void addLicense(License license) throws LicenseManagementException;
|
boolean addLicense(String deviceType, License license) throws LicenseManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
package org.wso2.carbon.device.mgt.common.license.mgt;
|
||||||
|
|
||||||
public class LicenseNotFoundException extends RuntimeException {
|
public class LicenseNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common.operation.mgt;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@ -15,7 +15,7 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common.operation.mgt;
|
||||||
|
|
||||||
public class OperationExecutionException extends Exception {
|
public class OperationExecutionException extends Exception {
|
||||||
|
|
||||||
@ -15,7 +15,7 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common.operation.mgt;
|
||||||
|
|
||||||
public class OperationManagementException extends Exception {
|
public class OperationManagementException extends Exception {
|
||||||
|
|
||||||
@ -15,7 +15,9 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.common;
|
package org.wso2.carbon.device.mgt.common.operation.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -60,8 +62,8 @@ public interface OperationManager {
|
|||||||
* TODO: Move this into a separate FeatureManager
|
* TODO: Move this into a separate FeatureManager
|
||||||
* @param deviceType - Device type
|
* @param deviceType - Device type
|
||||||
* @return a list of Feature objects.
|
* @return a list of Feature objects.
|
||||||
* @throws FeatureManagementException
|
* @throws org.wso2.carbon.device.mgt.common.FeatureManagementException
|
||||||
*/
|
*/
|
||||||
public List<Feature> getFeaturesForDeviceType(String deviceType) throws FeatureManagementException;
|
public List<Feature> getFeatures(String deviceType) throws FeatureManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -18,10 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.common.spi;
|
package org.wso2.carbon.device.mgt.common.spi;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.*;
|
||||||
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 java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -29,15 +26,22 @@ import java.util.List;
|
|||||||
* This represents the service provider interface that has to be implemented by any of new
|
* This represents the service provider interface that has to be implemented by any of new
|
||||||
* device type plugin implementation intended to be managed through CDM.
|
* device type plugin implementation intended to be managed through CDM.
|
||||||
*/
|
*/
|
||||||
public interface DeviceManagerService {
|
public interface DeviceManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to retrieve the provider type that implements DeviceManagerService interface.
|
* Method to retrieve the provider type that implements DeviceManager interface.
|
||||||
*
|
*
|
||||||
* @return Returns provider type
|
* @return Returns provider type
|
||||||
*/
|
*/
|
||||||
String getProviderType();
|
String getProviderType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to return feature manager implementation associated with a particular platform-specific plugin.
|
||||||
|
*
|
||||||
|
* @return Returns an instance of feature manager
|
||||||
|
*/
|
||||||
|
FeatureManager getFeatureManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to enrolling a particular device of type mobile, IoT, etc within CDM.
|
* Method to enrolling a particular device of type mobile, IoT, etc within CDM.
|
||||||
*
|
*
|
||||||
@ -129,12 +133,5 @@ public interface DeviceManagerService {
|
|||||||
*/
|
*/
|
||||||
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to retrieve the Operation manager implementation associated with a given plugin.
|
|
||||||
*
|
|
||||||
* @return An appropriate instance of the underlying operation management implementation
|
|
||||||
* @throws DeviceManagementException
|
|
||||||
*/
|
|
||||||
OperationManager getOperationManager() throws DeviceManagementException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,7 +72,9 @@
|
|||||||
org.wso2.carbon.registry.core.service,
|
org.wso2.carbon.registry.core.service,
|
||||||
org.wso2.carbon.registry.core.session,
|
org.wso2.carbon.registry.core.session,
|
||||||
org.w3c.dom,
|
org.w3c.dom,
|
||||||
org.wso2.carbon.email.verification.util
|
org.wso2.carbon.governance.api.exception,
|
||||||
|
org.wso2.carbon.governance.api.generic,
|
||||||
|
org.wso2.carbon.governance.api.generic.dataobjects
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
!org.wso2.carbon.device.mgt.core.internal,
|
!org.wso2.carbon.device.mgt.core.internal,
|
||||||
@ -153,6 +155,10 @@
|
|||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.base</artifactId>
|
<artifactId>org.wso2.carbon.base</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.governance</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.governance.api</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -20,7 +20,8 @@ package org.wso2.carbon.device.mgt.core;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -28,35 +29,36 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DeviceManagementRepository {
|
public class DeviceManagementRepository {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
private Map<String, DeviceManager> providers;
|
||||||
private Map<String, DeviceManagerService> providers;
|
|
||||||
|
|
||||||
public DeviceManagementRepository() {
|
public DeviceManagementRepository() {
|
||||||
providers = new HashMap<String, DeviceManagerService>();
|
providers = new HashMap<String, DeviceManager>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeviceManagementProvider(DeviceManagerService provider) {
|
public void addDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException {
|
||||||
String deviceType = provider.getProviderType();
|
String deviceType = provider.getProviderType();
|
||||||
try {
|
try {
|
||||||
DeviceManagerUtil.registerDeviceType(deviceType);
|
DeviceManagerUtil.registerDeviceType(deviceType);
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error("Exception occurred while registering the device type.", e);
|
throw new DeviceManagementException("Error occurred while adding device management provider '" +
|
||||||
|
deviceType + "'");
|
||||||
}
|
}
|
||||||
providers.put(deviceType, provider);
|
providers.put(deviceType, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDeviceManagementProvider(DeviceManagerService provider) {
|
public void removeDeviceManagementProvider(DeviceManager provider) throws DeviceManagementException {
|
||||||
String deviceType = provider.getProviderType();
|
String deviceType = provider.getProviderType();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DeviceManagerUtil.unregisterDeviceType(deviceType);
|
DeviceManagerUtil.unregisterDeviceType(deviceType);
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error("Exception occurred while registering the device type.", e);
|
throw new DeviceManagementException("Error occurred while removing device management provider '" +
|
||||||
|
deviceType + "'", e);
|
||||||
}
|
}
|
||||||
providers.remove(deviceType);
|
providers.remove(deviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceManagerService getDeviceManagementProvider(String type) {
|
public DeviceManager getDeviceManagementProvider(String type) {
|
||||||
return providers.get(type);
|
return providers.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.config.license;
|
package org.wso2.carbon.device.mgt.core.config.license;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|||||||
@ -22,7 +22,7 @@ package org.wso2.carbon.device.mgt.core.config.license;
|
|||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.dao;
|
package org.wso2.carbon.device.mgt.core.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||||
|
|
||||||
@ -32,27 +33,31 @@ public interface DeviceDAO {
|
|||||||
|
|
||||||
void updateDevice(Device device) throws DeviceManagementDAOException;
|
void updateDevice(Device device) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException;
|
void updateDeviceStatus(int deviceId, Status status) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void deleteDevice(Long deviceId) throws DeviceManagementDAOException;
|
void deleteDevice(int deviceId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
Device getDevice(int deviceId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementDAOException;
|
||||||
* @param type - Device type.
|
|
||||||
* @param identifier - Device identifier.
|
|
||||||
* @return the Device object which matches given data
|
|
||||||
* @throws DeviceManagementDAOException
|
|
||||||
*/
|
|
||||||
Device getDeviceByDeviceIdentifier(Integer type, String identifier)
|
|
||||||
throws DeviceManagementDAOException;
|
|
||||||
|
|
||||||
List<Device> getDevices() throws DeviceManagementDAOException;
|
List<Device> getDevices() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
List<Integer> getDeviceIds(List<DeviceIdentifier> devices) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type - The device type id.
|
* @param type - The device type id.
|
||||||
* @return a list of devices based on the type id.
|
* @return a list of devices based on the type id.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<Device> getDevices(Integer type) throws DeviceManagementDAOException;
|
List<Device> getDevices(int type) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of devices belongs to a user.
|
||||||
|
* @param username Requested user.
|
||||||
|
* @return List of devices of the user.
|
||||||
|
* @throws DeviceManagementDAOException
|
||||||
|
*/
|
||||||
|
List<Device> getDeviceListOfUser(String username) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,4 +90,5 @@ public class DeviceManagementDAOFactory {
|
|||||||
public static DataSource getDataSource() {
|
public static DataSource getDataSource() {
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,10 @@ public interface DeviceTypeDAO {
|
|||||||
|
|
||||||
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
|
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
|
||||||
|
|
||||||
DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException;
|
DeviceType getDeviceType(int id) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
DeviceType getDeviceType(String name) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
void removeDeviceType(String type) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,12 @@ package org.wso2.carbon.device.mgt.core.dao.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -37,164 +39,192 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DeviceDAOImpl implements DeviceDAO {
|
public class DeviceDAOImpl implements DeviceDAO {
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
|
|
||||||
|
|
||||||
public DeviceDAOImpl(DataSource dataSource) {
|
private DataSource dataSource;
|
||||||
this.dataSource = dataSource;
|
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public DeviceDAOImpl(DataSource dataSource) {
|
||||||
public void addDevice(Device device) throws DeviceManagementDAOException {
|
this.dataSource = dataSource;
|
||||||
Connection conn = null;
|
}
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String createDBQuery =
|
|
||||||
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " +
|
|
||||||
"OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " +
|
|
||||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
|
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
@Override
|
||||||
stmt.setString(1, device.getDescription());
|
public void addDevice(Device device) throws DeviceManagementDAOException {
|
||||||
stmt.setString(2, device.getName());
|
Connection conn = null;
|
||||||
stmt.setLong(3, new Date().getTime());
|
PreparedStatement stmt = null;
|
||||||
stmt.setLong(4, new Date().getTime());
|
try {
|
||||||
stmt.setString(5, device.getOwnerShip());
|
conn = this.getConnection();
|
||||||
stmt.setString(6, device.getStatus().toString());
|
String sql =
|
||||||
stmt.setInt(7, device.getDeviceTypeId());
|
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DATE_OF_ENROLLMENT, DATE_OF_LAST_UPDATE, " +
|
||||||
stmt.setString(8, device.getDeviceIdentificationId());
|
"OWNERSHIP, STATUS, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, OWNER, TENANT_ID) " +
|
||||||
stmt.setString(9, device.getOwnerId());
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
stmt.setInt(10, device.getTenantId());
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.executeUpdate();
|
stmt.setString(1, device.getDescription());
|
||||||
} catch (SQLException e) {
|
stmt.setString(2, device.getName());
|
||||||
String msg = "Error occurred while enrolling device '" + device.getName() + "'";
|
stmt.setLong(3, new Date().getTime());
|
||||||
log.error(msg, e);
|
stmt.setLong(4, new Date().getTime());
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
stmt.setString(5, device.getOwnerShip());
|
||||||
} finally {
|
stmt.setString(6, device.getStatus().toString());
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
stmt.setInt(7, device.getDeviceTypeId());
|
||||||
}
|
stmt.setString(8, device.getDeviceIdentificationId());
|
||||||
}
|
stmt.setString(9, device.getOwnerId());
|
||||||
|
stmt.setInt(10, device.getTenantId());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while enrolling device " +
|
||||||
|
"'" + device.getName() + "'", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(Device device) throws DeviceManagementDAOException {
|
public void updateDevice(Device device) throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDeviceStatus(Long deviceId, Status status)
|
public void updateDeviceStatus(int deviceId, Status status) throws DeviceManagementDAOException {
|
||||||
throws DeviceManagementDAOException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDevice(Long deviceId) throws DeviceManagementDAOException {
|
public void deleteDevice(int deviceId) throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException {
|
public Device getDevice(int deviceId) throws DeviceManagementDAOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device getDeviceByDeviceIdentifier(Integer type, String identifier)
|
public Device getDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementDAOException {
|
||||||
throws DeviceManagementDAOException {
|
Connection conn = null;
|
||||||
Connection conn = null;
|
PreparedStatement stmt = null;
|
||||||
PreparedStatement stmt = null;
|
ResultSet rs = null;
|
||||||
ResultSet resultSet = null;
|
Device device = null;
|
||||||
Device device = null;
|
try {
|
||||||
try {
|
conn = this.getConnection();
|
||||||
conn = this.getConnection();
|
String sql =
|
||||||
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
|
"SELECT d.ID, d.DESCRIPTION, d.NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " +
|
||||||
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
|
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DEVICE_TYPE dt WHERE " +
|
||||||
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
|
"dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?";
|
||||||
"WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND " +
|
stmt = conn.prepareStatement(sql);
|
||||||
"DM_DEVICE.DEVICE_IDENTIFICATION=?";
|
stmt.setString(1, deviceIdentifier.getType());
|
||||||
stmt = conn.prepareStatement(selectDBQueryForType);
|
stmt.setString(2, deviceIdentifier.getId());
|
||||||
stmt.setInt(1, type);
|
|
||||||
stmt.setString(2, identifier);
|
|
||||||
resultSet = stmt.executeQuery();
|
|
||||||
while (resultSet.next()) {
|
|
||||||
device = new Device();
|
|
||||||
device.setId(resultSet.getInt(1));
|
|
||||||
device.setDescription(resultSet.getString(2));
|
|
||||||
device.setName(resultSet.getString(3));
|
|
||||||
device.setDateOfEnrollment(resultSet.getLong(4));
|
|
||||||
device.setDateOfLastUpdate(resultSet.getLong(5));
|
|
||||||
//TODO:- Ownership is not a enum in DeviceDAO
|
|
||||||
device.setOwnerShip(resultSet.getString(6));
|
|
||||||
device.setStatus(Status.valueOf(resultSet.getString(7)));
|
|
||||||
device.setDeviceTypeId(resultSet.getInt(8));
|
|
||||||
device.setDeviceIdentificationId(resultSet.getString(9));
|
|
||||||
device.setOwnerId(resultSet.getString(10));
|
|
||||||
device.setTenantId(resultSet.getInt(11));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while listing devices for type '" + type + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
|
||||||
}
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
rs = stmt.executeQuery();
|
||||||
public List<Device> getDevices() throws DeviceManagementDAOException {
|
if (rs.next()) {
|
||||||
return null;
|
device = new Device();
|
||||||
}
|
device.setId(rs.getInt("ID"));
|
||||||
|
device.setDescription(rs.getString("DESCRIPTION"));
|
||||||
|
device.setName(rs.getString("NAME"));
|
||||||
|
device.setDateOfEnrollment(rs.getLong("DATE_OF_ENROLLMENT"));
|
||||||
|
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
|
||||||
|
//TODO:- Ownership is not a enum in DeviceDAO
|
||||||
|
device.setOwnerShip(rs.getString("OWNERSHIP"));
|
||||||
|
device.setStatus(Status.valueOf(rs.getString("STATUS")));
|
||||||
|
device.setDeviceTypeId(rs.getInt("DEVICE_TYPE_ID"));
|
||||||
|
device.setDeviceIdentificationId(rs.getString("DEVICE_IDENTIFICATION"));
|
||||||
|
device.setOwnerId(rs.getString("OWNER"));
|
||||||
|
device.setTenantId(rs.getInt("TENANT_ID"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type " +
|
||||||
|
"'" + deviceIdentifier.getType() + "'", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> getDevices(Integer type) throws DeviceManagementDAOException {
|
public List<Device> getDevices() throws DeviceManagementDAOException {
|
||||||
Connection conn = null;
|
return null;
|
||||||
PreparedStatement stmt = null;
|
}
|
||||||
ResultSet resultSet = null;
|
|
||||||
List<Device> devicesList = null;
|
|
||||||
try {
|
|
||||||
conn = this.getConnection();
|
|
||||||
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
|
|
||||||
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
|
|
||||||
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
|
|
||||||
"WHERE DM_DEVICE.DEVICE_TYPE_ID=?";
|
|
||||||
stmt = conn.prepareStatement(selectDBQueryForType);
|
|
||||||
stmt.setInt(1, type);
|
|
||||||
resultSet = stmt.executeQuery();
|
|
||||||
devicesList = new ArrayList<Device>();
|
|
||||||
while (resultSet.next()) {
|
|
||||||
Device device = new Device();
|
|
||||||
device.setId(resultSet.getInt(1));
|
|
||||||
device.setDescription(resultSet.getString(2));
|
|
||||||
device.setName(resultSet.getString(3));
|
|
||||||
device.setDateOfEnrollment(resultSet.getLong(4));
|
|
||||||
device.setDateOfLastUpdate(resultSet.getLong(5));
|
|
||||||
//TODO:- Ownership is not a enum in DeviceDAO
|
|
||||||
device.setOwnerShip(resultSet.getString(6));
|
|
||||||
device.setStatus(Status.valueOf(resultSet.getString(7)));
|
|
||||||
device.setDeviceTypeId(resultSet.getInt(8));
|
|
||||||
device.setDeviceIdentificationId(resultSet.getString(9));
|
|
||||||
device.setOwnerId(resultSet.getString(10));
|
|
||||||
device.setTenantId(resultSet.getInt(11));
|
|
||||||
devicesList.add(device);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
String msg = "Error occurred while listing devices for type '" + type + "'";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
|
||||||
}
|
|
||||||
return devicesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Connection getConnection() throws DeviceManagementDAOException {
|
@Override
|
||||||
try {
|
public List<Integer> getDeviceIds(List<DeviceIdentifier> devices) throws DeviceManagementDAOException {
|
||||||
return dataSource.getConnection();
|
List<Integer> deviceIds = new ArrayList<Integer>();
|
||||||
} catch (SQLException e) {
|
try {
|
||||||
throw new DeviceManagementDAOException(
|
Connection conn = this.getConnection();
|
||||||
"Error occurred while obtaining a connection from the device " +
|
String sql = "SELECT DISTINCT ID FROM DEVICE WHERE NAME IN (?) AND ID IN (?)";
|
||||||
"management metadata repository datasource", e);
|
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||||
}
|
//stmt.setArray(1, new java.sql.Date[0]);
|
||||||
}
|
stmt.setString(2, "");
|
||||||
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
deviceIds.add(rs.getInt("ID"));
|
||||||
|
}
|
||||||
|
return deviceIds;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while retrieving device ids", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDeviceNameString(List<DeviceIdentifier> devices) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (DeviceIdentifier device : devices) {
|
||||||
|
sb.append(device.getId());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevices(int type) throws DeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
List<Device> devicesList = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
|
||||||
|
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
|
||||||
|
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
|
||||||
|
"WHERE DM_DEVICE.DEVICE_TYPE_ID = ?";
|
||||||
|
stmt = conn.prepareStatement(selectDBQueryForType);
|
||||||
|
stmt.setInt(1, type);
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
devicesList = new ArrayList<Device>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
Device device = new Device();
|
||||||
|
device.setId(resultSet.getInt(1));
|
||||||
|
device.setDescription(resultSet.getString(2));
|
||||||
|
device.setName(resultSet.getString(3));
|
||||||
|
device.setDateOfEnrollment(resultSet.getLong(4));
|
||||||
|
device.setDateOfLastUpdate(resultSet.getLong(5));
|
||||||
|
//TODO:- Ownership is not a enum in DeviceDAO
|
||||||
|
device.setOwnerShip(resultSet.getString(6));
|
||||||
|
device.setStatus(Status.valueOf(resultSet.getString(7)));
|
||||||
|
device.setDeviceTypeId(resultSet.getInt(8));
|
||||||
|
device.setDeviceIdentificationId(resultSet.getString(9));
|
||||||
|
device.setOwnerId(resultSet.getString(10));
|
||||||
|
device.setTenantId(resultSet.getInt(11));
|
||||||
|
devicesList.add(device);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while listing devices for type '" + type + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||||
|
}
|
||||||
|
return devicesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Device> getDeviceListOfUser(String username) throws DeviceManagementDAOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws DeviceManagementDAOException {
|
||||||
|
try {
|
||||||
|
return dataSource.getConnection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException(
|
||||||
|
"Error occurred while obtaining a connection from the device " +
|
||||||
|
"management metadata repository datasource", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,9 +50,8 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
stmt.setString(1, deviceType.getName());
|
stmt.setString(1, deviceType.getName());
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while registering the device type '" + deviceType.getName() + "'";
|
throw new DeviceManagementDAOException("Error occurred while registering the device type " +
|
||||||
log.error(msg, e);
|
"'" + deviceType.getName() + "'", e);
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||||
}
|
}
|
||||||
@ -65,85 +64,88 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
List<DeviceType> deviceTypes = new ArrayList<DeviceType>();
|
ResultSet rs = null;
|
||||||
|
List<DeviceType> deviceTypes = null;
|
||||||
try {
|
try {
|
||||||
stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE");
|
conn = this.getConnection();
|
||||||
ResultSet results = stmt.executeQuery();
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (results.next()) {
|
while (rs.next()) {
|
||||||
|
deviceTypes = new ArrayList<DeviceType>();
|
||||||
DeviceType deviceType = new DeviceType();
|
DeviceType deviceType = new DeviceType();
|
||||||
deviceType.setId(results.getLong("DEVICE_TYPE_ID"));
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
||||||
deviceType.setName(results.getString("DEVICE_TYPE"));
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
||||||
deviceTypes.add(deviceType);
|
deviceTypes.add(deviceType);
|
||||||
}
|
}
|
||||||
|
return deviceTypes;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching the registered device types";
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e);
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
||||||
}
|
}
|
||||||
return deviceTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException {
|
public DeviceType getDeviceType(int id) throws DeviceManagementDAOException {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
DeviceType deviceType = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID=?");
|
conn = this.getConnection();
|
||||||
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
ResultSet results = stmt.executeQuery();
|
|
||||||
|
|
||||||
while (results.next()) {
|
rs = stmt.executeQuery();
|
||||||
|
DeviceType deviceType = null;
|
||||||
|
while (rs.next()) {
|
||||||
deviceType = new DeviceType();
|
deviceType = new DeviceType();
|
||||||
deviceType.setId(results.getLong("DEVICE_TYPE_ID"));
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
||||||
deviceType.setName(results.getString("DEVICE_TYPE"));
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
||||||
}
|
}
|
||||||
|
return deviceType;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetching the registered device type";
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device type", e);
|
||||||
log.error(msg, e);
|
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
||||||
}
|
}
|
||||||
return deviceType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException {
|
public DeviceType getDeviceType(String type) throws DeviceManagementDAOException {
|
||||||
|
Connection conn = null;
|
||||||
Connection conn = this.getConnection();
|
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet rs = null;
|
||||||
Integer deviceTypeId = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String createDBQuery = "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?";
|
conn = this.getConnection();
|
||||||
stmt = conn.prepareStatement(createDBQuery);
|
String sql = "SELECT ID From DM_DEVICE_TYPE WHERE NAME = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, type);
|
stmt.setString(1, type);
|
||||||
resultSet = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
int id = -1;
|
||||||
deviceTypeId = resultSet.getInt(1);
|
if (rs.next()) {
|
||||||
|
id = rs.getInt("ID");
|
||||||
}
|
}
|
||||||
|
DeviceType deviceType = new DeviceType();
|
||||||
|
deviceType.setId(id);
|
||||||
|
deviceType.setName(type);
|
||||||
|
|
||||||
|
return deviceType;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Error occurred while fetch device type id for device type '" + type + "'";
|
throw new DeviceManagementDAOException("Error occurred while fetch device type id for device type " +
|
||||||
log.error(msg, e);
|
"'" + type + "'", e);
|
||||||
throw new DeviceManagementDAOException(msg, e);
|
|
||||||
} finally {
|
} finally {
|
||||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
DeviceManagementDAOUtil.cleanupResources(conn, stmt, rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deviceTypeId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
public void removeDeviceType(String type) throws DeviceManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,4 +159,5 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
throw new DeviceManagementDAOException(msg, e);
|
throw new DeviceManagementDAOException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import java.io.Serializable;
|
|||||||
public class Device implements Serializable {
|
public class Device implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -8101106997837486245L;
|
private static final long serialVersionUID = -8101106997837486245L;
|
||||||
private Integer id;
|
private int id;
|
||||||
private String description;
|
private String description;
|
||||||
private String name;
|
private String name;
|
||||||
private Long dateOfEnrollment;
|
private Long dateOfEnrollment;
|
||||||
@ -33,13 +33,22 @@ public class Device implements Serializable {
|
|||||||
private String ownerId;
|
private String ownerId;
|
||||||
private String ownerShip;
|
private String ownerShip;
|
||||||
private int tenantId;
|
private int tenantId;
|
||||||
private Integer deviceTypeId;
|
private int deviceTypeId;
|
||||||
|
private DeviceType deviceType;
|
||||||
|
|
||||||
public Integer getDeviceTypeId() {
|
public DeviceType getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceType(DeviceType deviceType) {
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeviceTypeId() {
|
||||||
return deviceTypeId;
|
return deviceTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeviceTypeId(Integer deviceTypeId) {
|
public void setDeviceTypeId(int deviceTypeId) {
|
||||||
this.deviceTypeId = deviceTypeId;
|
this.deviceTypeId = deviceTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,14 +23,14 @@ import java.io.Serializable;
|
|||||||
public class DeviceType implements Serializable {
|
public class DeviceType implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7927802716452548282L;
|
private static final long serialVersionUID = 7927802716452548282L;
|
||||||
private Long id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public Long getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.internal;
|
package org.wso2.carbon.device.mgt.core.internal;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManager;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
|
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager;
|
|
||||||
import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
|
import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
import org.wso2.carbon.user.core.tenant.TenantManager;
|
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||||
@ -31,7 +31,7 @@ public class DeviceManagementDataHolder {
|
|||||||
|
|
||||||
private RealmService realmService;
|
private RealmService realmService;
|
||||||
private TenantManager tenantManager;
|
private TenantManager tenantManager;
|
||||||
private DeviceManager deviceManager;
|
private DeviceManagementService deviceManagerProvider;
|
||||||
private LicenseManager licenseManager;
|
private LicenseManager licenseManager;
|
||||||
private RegistryService registryService;
|
private RegistryService registryService;
|
||||||
private LicenseConfig licenseConfig;
|
private LicenseConfig licenseConfig;
|
||||||
@ -74,12 +74,12 @@ public class DeviceManagementDataHolder {
|
|||||||
return tenantManager;
|
return tenantManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceManager getDeviceManager() {
|
public DeviceManagementService getDeviceManagementProvider() {
|
||||||
return deviceManager;
|
return deviceManagerProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeviceManager(DeviceManager deviceManager) {
|
public void setDeviceManagementProvider(DeviceManagementService deviceManagerProvider) {
|
||||||
this.deviceManager = deviceManager;
|
this.deviceManagerProvider = deviceManagerProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegistryService getRegistryService() {
|
public RegistryService getRegistryService() {
|
||||||
|
|||||||
@ -22,23 +22,22 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManager;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
|
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementException;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagementService;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManager;
|
|
||||||
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
import org.wso2.carbon.device.mgt.core.license.mgt.LicenseManagerImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementServiceImpl;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
|
||||||
import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
|
import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
@ -53,11 +52,11 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|||||||
* bind="setRealmService"
|
* bind="setRealmService"
|
||||||
* unbind="unsetRealmService"
|
* unbind="unsetRealmService"
|
||||||
* @scr.reference name="device.manager.service"
|
* @scr.reference name="device.manager.service"
|
||||||
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagerService"
|
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceManager"
|
||||||
* cardinality="0..n"
|
* cardinality="0..n"
|
||||||
* policy="dynamic"
|
* policy="dynamic"
|
||||||
* bind="setDeviceManagerService"
|
* bind="setDeviceManager"
|
||||||
* unbind="unsetDeviceManagerService"
|
* unbind="unsetDeviceManager"
|
||||||
* @scr.reference name="registry.service"
|
* @scr.reference name="registry.service"
|
||||||
* interface="org.wso2.carbon.registry.core.service.RegistryService"
|
* interface="org.wso2.carbon.registry.core.service.RegistryService"
|
||||||
* cardinality="1..1"
|
* cardinality="1..1"
|
||||||
@ -75,6 +74,7 @@ public class DeviceManagementServiceComponent {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Initializing device management core bundle");
|
log.debug("Initializing device management core bundle");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initializing Device Management Configuration */
|
/* Initializing Device Management Configuration */
|
||||||
DeviceConfigurationManager.getInstance().initConfig();
|
DeviceConfigurationManager.getInstance().initConfig();
|
||||||
DeviceManagementConfig config =
|
DeviceManagementConfig config =
|
||||||
@ -83,8 +83,9 @@ public class DeviceManagementServiceComponent {
|
|||||||
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
||||||
DeviceManagementDAOFactory.init(dsConfig);
|
DeviceManagementDAOFactory.init(dsConfig);
|
||||||
|
|
||||||
DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository());
|
DeviceManagementService deviceManagementProvider =
|
||||||
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
|
new DeviceManagementServiceProviderImpl(this.getPluginRepository());
|
||||||
|
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
|
||||||
|
|
||||||
LicenseConfigurationManager.getInstance().initConfig();
|
LicenseConfigurationManager.getInstance().initConfig();
|
||||||
LicenseConfig licenseConfig =
|
LicenseConfig licenseConfig =
|
||||||
@ -99,25 +100,17 @@ public class DeviceManagementServiceComponent {
|
|||||||
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
||||||
if (setupOption != null) {
|
if (setupOption != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(
|
log.debug("-Dsetup is enabled. Device management repository schema initialization is about to " +
|
||||||
"-Dsetup is enabled. Device management repository schema initialization " +
|
"begin");
|
||||||
"is about to begin");
|
|
||||||
}
|
}
|
||||||
this.setupDeviceManagementSchema(dsConfig);
|
this.setupDeviceManagementSchema(dsConfig);
|
||||||
// this.setupDefaultLicenses(licenseConfig);
|
this.setupDefaultLicenses(licenseConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */
|
||||||
log.debug("Registering OSGi service DeviceManagementService");
|
this.registerServices(componentContext);
|
||||||
}
|
|
||||||
/* Registering Device Management service */
|
if (log.isDebugEnabled()) {
|
||||||
BundleContext bundleContext = componentContext.getBundleContext();
|
|
||||||
bundleContext.registerService(DeviceManagementService.class.getName(),
|
|
||||||
new DeviceManagementService(), null);
|
|
||||||
/* Registering License Management service */
|
|
||||||
bundleContext.registerService(LicenseManagementService.class.getName(),
|
|
||||||
new LicenseManagementService(), null);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Device management core bundle has been successfully initialized");
|
log.debug("Device management core bundle has been successfully initialized");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -126,6 +119,16 @@ public class DeviceManagementServiceComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerServices(ComponentContext componentContext) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Registering OSGi service DeviceManagementServiceImpl");
|
||||||
|
}
|
||||||
|
/* Registering Device Management Service */
|
||||||
|
BundleContext bundleContext = componentContext.getBundleContext();
|
||||||
|
bundleContext.registerService(DeviceManagementService.class.getName(),
|
||||||
|
new DeviceManagementServiceImpl(), null);
|
||||||
|
}
|
||||||
|
|
||||||
private void setupDeviceManagementSchema(DataSourceConfig config)
|
private void setupDeviceManagementSchema(DataSourceConfig config)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
DeviceManagementSchemaInitializer initializer =
|
DeviceManagementSchemaInitializer initializer =
|
||||||
@ -140,50 +143,54 @@ public class DeviceManagementServiceComponent {
|
|||||||
"database schema", e);
|
"database schema", e);
|
||||||
}
|
}
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(
|
log.debug("Device management metadata repository schema has been successfully initialized");
|
||||||
"Device management metadata repository schema has been successfully initialized");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDefaultLicenses(LicenseConfig licenseConfig)
|
private void setupDefaultLicenses(LicenseConfig licenseConfig)
|
||||||
throws LicenseManagementException {
|
throws LicenseManagementException {
|
||||||
LicenseManager licenseManager =
|
LicenseManager licenseManager = DeviceManagementDataHolder.getInstance().getLicenseManager();
|
||||||
DeviceManagementDataHolder.getInstance().getLicenseManager();
|
|
||||||
for (License license : licenseConfig.getLicenses()) {
|
for (License license : licenseConfig.getLicenses()) {
|
||||||
License extLicense =
|
License extLicense = licenseManager.getLicense(license.getName(), license.getLanguage());
|
||||||
licenseManager.getLicense(license.getName(), license.getLanguage());
|
if (extLicense == null) {
|
||||||
if (extLicense != null) {
|
licenseManager.addLicense(license.getName(), license);;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
licenseManager.addLicense(license);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Device Manager service.
|
* Sets Device Manager service.
|
||||||
*
|
*
|
||||||
* @param deviceManagerService An instance of DeviceManagerService
|
* @param deviceManager An instance of DeviceManager
|
||||||
*/
|
*/
|
||||||
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
|
protected void setDeviceManager(DeviceManager deviceManager) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Setting Device Management Service Provider : '" +
|
log.debug("Setting Device Management Service Provider: '" + deviceManager.getProviderType() + "'");
|
||||||
deviceManagerService.getProviderType() + "'");
|
|
||||||
}
|
}
|
||||||
this.getPluginRepository().addDeviceManagementProvider(deviceManagerService);
|
try {
|
||||||
}
|
this.getPluginRepository().addDeviceManagementProvider(deviceManager);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error occurred while adding device management provider '" +
|
||||||
|
deviceManager.getProviderType() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets Device Management service.
|
* Unsets Device Management service.
|
||||||
*
|
*
|
||||||
* @param deviceManagerService An Instance of DeviceManagerService
|
* @param deviceManager An Instance of DeviceManager
|
||||||
*/
|
*/
|
||||||
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
|
protected void unsetDeviceManager(DeviceManager deviceManager) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Unsetting Device Management Service Provider : '" +
|
log.debug("Unsetting Device Management Service Provider : '" + deviceManager.getProviderType() + "'");
|
||||||
deviceManagerService.getProviderType() + "'");
|
|
||||||
}
|
}
|
||||||
this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService);
|
try {
|
||||||
}
|
this.getPluginRepository().removeDeviceManagementProvider(deviceManager);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error occurred while removing device management provider '" +
|
||||||
|
deviceManager.getProviderType() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Realm Service.
|
* Sets Realm Service.
|
||||||
|
|||||||
@ -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() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,7 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
package org.wso2.carbon.device.mgt.core.license.mgt;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.License;
|
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.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
|
||||||
public class LicenseManagementService implements LicenseManager {
|
public class LicenseManagementService implements LicenseManager {
|
||||||
@ -29,8 +31,8 @@ public class LicenseManagementService implements LicenseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLicense(License license) throws LicenseManagementException {
|
public boolean addLicense(String deviceType, License license) throws LicenseManagementException {
|
||||||
DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(license);
|
return DeviceManagementDataHolder.getInstance().getLicenseManager().addLicense(deviceType, license);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
* KIND, either express or implied. See the License for the
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.license.mgt;
|
package org.wso2.carbon.device.mgt.core.license.mgt;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
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.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class LicenseManagerImpl implements LicenseManager {
|
public class LicenseManagerImpl implements LicenseManager {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagerImpl.class);
|
private static Log log = LogFactory.getLog(DeviceManagementServiceProviderImpl.class);
|
||||||
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
|
private static final DateFormat format = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public License getLicense(final String deviceType, final String languageCode)
|
public License getLicense(final String deviceType, final String languageCode) throws LicenseManagementException {
|
||||||
throws LicenseManagementException {
|
GenericArtifactManager artifactManager =
|
||||||
License deviceLicense = new License();
|
GenericArtifactManagerFactory.getTenantAwareGovernanceArtifactManager();
|
||||||
LicenseConfig licenseConfig = DeviceManagementDataHolder.getInstance().getLicenseConfig();
|
try {
|
||||||
for (License license : licenseConfig.getLicenses()) {
|
GenericArtifact[] artifacts = artifactManager.findGenericArtifacts(new GenericArtifactFilter() {
|
||||||
if ((deviceType.equals(license.getName())) &&
|
@Override
|
||||||
(languageCode.equals(license.getLanguage()))) {
|
public boolean matches(GenericArtifact artifact) throws GovernanceException {
|
||||||
deviceLicense = license;
|
String attributeNameVal = artifact.getAttribute(
|
||||||
break;
|
DeviceManagementConstants.LicenseProperties.NAME);
|
||||||
}
|
String attributeLangVal = artifact.getAttribute(
|
||||||
}
|
DeviceManagementConstants.LicenseProperties.LANGUAGE);
|
||||||
return deviceLicense;
|
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 + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private License populateLicense(GenericArtifact artifact) throws GovernanceException, ParseException {
|
||||||
public void addLicense(License license) throws LicenseManagementException {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,9 +4,9 @@
|
|||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* you may obtain a copy of the License at
|
* 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,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
@ -18,79 +18,21 @@
|
|||||||
package org.wso2.carbon.device.mgt.core.service;
|
package org.wso2.carbon.device.mgt.core.service;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
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.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.OperationManager;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManager;
|
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceManagementService implements DeviceManager {
|
/**
|
||||||
|
* Proxy class for all Device Management related operations that take the corresponding plugin type in
|
||||||
|
* and resolve the appropriate plugin implementation
|
||||||
|
*/
|
||||||
|
public interface DeviceManagementService extends DeviceManager, LicenseManager, OperationManager {
|
||||||
|
|
||||||
@Override
|
List<Device> getAllDevices(String type) throws DeviceManagementException;
|
||||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
List<Device> getDeviceListOfUser(String username) throws DeviceManagementException;
|
||||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
|
||||||
.disenrollDevice(deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().isEnrolled(deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
|
||||||
throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
|
||||||
.setActive(deviceId, status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Device> getAllDevices(String type) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public org.wso2.carbon.device.mgt.common.Device getDevice(DeviceIdentifier deviceId)
|
|
||||||
throws DeviceManagementException {
|
|
||||||
|
|
||||||
Device device =
|
|
||||||
DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
|
||||||
throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager()
|
|
||||||
.setOwnership(deviceId, ownershipType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OperationManager getOperationManager(String type) throws DeviceManagementException {
|
|
||||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().
|
|
||||||
getOperationManager(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -51,11 +51,10 @@ public final class DeviceManagerUtil {
|
|||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||||
return docBuilder.parse(file);
|
return docBuilder.parse(file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DeviceManagementException(
|
throw new DeviceManagementException("Error occurred while parsing file, while converting " +
|
||||||
"Error occurred while parsing file, while converting " +
|
"to a org.w3c.dom.Document", e);
|
||||||
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve data source from the data source definition.
|
* Resolve data source from the data source definition.
|
||||||
@ -66,16 +65,13 @@ public final class DeviceManagerUtil {
|
|||||||
public static DataSource resolveDataSource(DataSourceConfig config) {
|
public static DataSource resolveDataSource(DataSourceConfig config) {
|
||||||
DataSource dataSource = null;
|
DataSource dataSource = null;
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException("Device Management Repository data source configuration is null and thus, " +
|
||||||
"Device Management Repository data source configuration " +
|
"is not initialized");
|
||||||
"is null and thus, is not initialized");
|
|
||||||
}
|
}
|
||||||
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
||||||
if (jndiConfig != null) {
|
if (jndiConfig != null) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(
|
log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition");
|
||||||
"Initializing Device Management Repository data source using the JNDI " +
|
|
||||||
"Lookup Definition");
|
|
||||||
}
|
}
|
||||||
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
||||||
jndiConfig.getJndiProperties();
|
jndiConfig.getJndiProperties();
|
||||||
@ -84,11 +80,9 @@ public final class DeviceManagerUtil {
|
|||||||
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
||||||
jndiProperties.put(prop.getName(), prop.getValue());
|
jndiProperties.put(prop.getName(), prop.getValue());
|
||||||
}
|
}
|
||||||
dataSource = DeviceManagementDAOUtil
|
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||||
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
||||||
} else {
|
} else {
|
||||||
dataSource =
|
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||||
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dataSource;
|
return dataSource;
|
||||||
@ -104,7 +98,7 @@ public final class DeviceManagerUtil {
|
|||||||
boolean status;
|
boolean status;
|
||||||
try {
|
try {
|
||||||
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
|
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType);
|
||||||
if (deviceTypeId == null) {
|
if (deviceTypeId == null) {
|
||||||
DeviceType dt = new DeviceType();
|
DeviceType dt = new DeviceType();
|
||||||
dt.setName(deviceType);
|
dt.setName(deviceType);
|
||||||
@ -112,14 +106,14 @@ public final class DeviceManagerUtil {
|
|||||||
}
|
}
|
||||||
status = true;
|
status = true;
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String msg = "Error occurred while registering the device type " + deviceType;
|
throw new DeviceManagementException("Error occurred while registering the device type '" +
|
||||||
throw new DeviceManagementException(msg, e);
|
deviceType + "'", e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters an existing device type from the device management metadata repository.
|
* Un-registers an existing device type from the device management metadata repository.
|
||||||
*
|
*
|
||||||
* @param deviceType device type
|
* @param deviceType device type
|
||||||
* @return status of the operation
|
* @return status of the operation
|
||||||
@ -127,27 +121,19 @@ public final class DeviceManagerUtil {
|
|||||||
public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException {
|
public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException {
|
||||||
try {
|
try {
|
||||||
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
|
DeviceType deviceTypeId = deviceTypeDAO.getDeviceType(deviceType);
|
||||||
if (deviceTypeId == null) {
|
if (deviceTypeId == null) {
|
||||||
DeviceType dt = new DeviceType();
|
DeviceType dt = new DeviceType();
|
||||||
dt.setName(deviceType);
|
dt.setName(deviceType);
|
||||||
deviceTypeDAO.removeDeviceType(dt);
|
deviceTypeDAO.removeDeviceType(deviceType);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String msg = "Error occurred while registering the device type " + deviceType;
|
throw new DeviceManagementException("Error occurred while registering the device type '" +
|
||||||
throw new DeviceManagementException(msg, e);
|
deviceType + "'", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> convertPropertiesToMap(List<Device.Property> properties) {
|
|
||||||
Map<String, String> propertiesMap = new HashMap<String, String>();
|
|
||||||
for (Device.Property prop : properties) {
|
|
||||||
propertiesMap.put(prop.getName(), prop.getValue());
|
|
||||||
}
|
|
||||||
return propertiesMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendEmail(){
|
public static void sendEmail(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -20,7 +20,8 @@ package org.wso2.carbon.device.mgt.core;
|
|||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||||
|
|
||||||
public class DeviceManagementRepositoryTests {
|
public class DeviceManagementRepositoryTests {
|
||||||
|
|
||||||
@ -33,23 +34,27 @@ public class DeviceManagementRepositoryTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddDeviceManagementService() {
|
public void testAddDeviceManagementService() {
|
||||||
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
DeviceManager sourceProvider = new TestDeviceManager();
|
||||||
this.getRepository().addDeviceManagementProvider(sourceProvider);
|
try {
|
||||||
|
this.getRepository().addDeviceManagementProvider(sourceProvider);
|
||||||
DeviceManagerService targetProvider =
|
} catch (DeviceManagementException e) {
|
||||||
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
Assert.fail("Unexpected error occurred while invoking addDeviceManagementProvider functionality", e);
|
||||||
|
}
|
||||||
|
DeviceManager targetProvider =
|
||||||
|
this.getRepository().getDeviceManagementProvider(TestDeviceManager.DEVICE_TYPE_TEST);
|
||||||
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType());
|
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = "testAddDeviceManagementService")
|
@Test(dependsOnMethods = "testAddDeviceManagementService")
|
||||||
public void testRemoveDeviceManagementService() {
|
public void testRemoveDeviceManagementService() {
|
||||||
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
DeviceManager sourceProvider = new TestDeviceManager();
|
||||||
this.getRepository().removeDeviceManagementProvider(sourceProvider);
|
try {
|
||||||
|
this.getRepository().removeDeviceManagementProvider(sourceProvider);
|
||||||
DeviceManagerService targetProvider =
|
} catch (DeviceManagementException e) {
|
||||||
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
Assert.fail("Unexpected error occurred while invoking removeDeviceManagementProvider functionality", e);
|
||||||
|
}
|
||||||
|
DeviceManager targetProvider =
|
||||||
|
this.getRepository().getDeviceManagementProvider(TestDeviceManager.DEVICE_TYPE_TEST);
|
||||||
Assert.assertNull(targetProvider);
|
Assert.assertNull(targetProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -20,18 +20,23 @@ package org.wso2.carbon.device.mgt.core;
|
|||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.OperationManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TestDeviceManagerService implements DeviceManagerService {
|
public class TestDeviceManager implements DeviceManager {
|
||||||
|
|
||||||
public static final String DEVICE_TYPE_TEST = "Test";
|
public static final String DEVICE_TYPE_TEST = "Test";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProviderType() {
|
public String getProviderType() {
|
||||||
return TestDeviceManagerService.DEVICE_TYPE_TEST;
|
return TestDeviceManager.DEVICE_TYPE_TEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureManager getFeatureManager() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,9 +89,4 @@ public class TestDeviceManagerService implements DeviceManagerService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public OperationManager getOperationManager() throws DeviceManagementException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -114,17 +114,17 @@ public class DeviceManagementDAOTests {
|
|||||||
deviceType.setName("IOS");
|
deviceType.setName("IOS");
|
||||||
deviceTypeMgtDAO.addDeviceType(deviceType);
|
deviceTypeMgtDAO.addDeviceType(deviceType);
|
||||||
|
|
||||||
Long id = null;
|
int id = -1;
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
String sql = "SELECT ID, NAME from DM_DEVICE_TYPE DType where DType.NAME='IOS'";
|
String sql = "SELECT dt.ID, dt.NAME FROM DM_DEVICE_TYPE dt where dt.NAME = 'IOS'";
|
||||||
try {
|
try {
|
||||||
conn = this.getDataSource().getConnection();
|
conn = this.getDataSource().getConnection();
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
id = rs.getLong("ID");
|
id = rs.getInt("ID");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException("error in fetch device type by name IOS", e);
|
throw new DeviceManagementDAOException("error in fetch device type by name IOS", e);
|
||||||
@ -147,9 +147,9 @@ public class DeviceManagementDAOTests {
|
|||||||
device.setDeviceIdentificationId("111");
|
device.setDeviceIdentificationId("111");
|
||||||
|
|
||||||
DeviceType deviceType = new DeviceType();
|
DeviceType deviceType = new DeviceType();
|
||||||
deviceType.setId(Long.parseLong("1"));
|
deviceType.setId(Integer.parseInt("1"));
|
||||||
|
|
||||||
device.setDeviceTypeId(deviceType.getId().intValue());
|
device.setDeviceTypeId(deviceType.getId());
|
||||||
device.setOwnerShip(OwnerShip.BYOD.toString());
|
device.setOwnerShip(OwnerShip.BYOD.toString());
|
||||||
device.setOwnerId("111");
|
device.setOwnerId("111");
|
||||||
device.setTenantId(-1234);
|
device.setTenantId(-1234);
|
||||||
|
|||||||
@ -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
|
||||||
|
)
|
||||||
|
|
||||||
@ -28,6 +28,7 @@
|
|||||||
<class name="org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOTests"/>
|
<class name="org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOTests"/>
|
||||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
|
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
|
||||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
|
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
|
||||||
|
<!--<class name="org.wso2.carbon.device.mgt.core.DeviceOperationManagementTests"/>-->
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
@ -51,7 +51,7 @@ public class FeatureFilterImpl implements FeatureFilter {
|
|||||||
public List<Feature> extractFeatures(List<Policy> policyList) {
|
public List<Feature> extractFeatures(List<Policy> policyList) {
|
||||||
List<Feature> featureList = new ArrayList<Feature>();
|
List<Feature> featureList = new ArrayList<Feature>();
|
||||||
for (Policy policy : policyList) {
|
for (Policy policy : policyList) {
|
||||||
featureList.addAll(policy.getFeaturesList());
|
featureList.addAll(policy.getProfile().getFeaturesList());
|
||||||
}
|
}
|
||||||
return featureList;
|
return featureList;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class PolicyFilterImpl implements PolicyFilter {
|
|||||||
List<Policy> policies = new ArrayList<Policy>();
|
List<Policy> policies = new ArrayList<Policy>();
|
||||||
|
|
||||||
for (Policy policy : policyList) {
|
for (Policy policy : policyList) {
|
||||||
if (policy.getDeviceType().equalsIgnoreCase(deviceType)) {
|
if (policy.getProfile().getDeviceType().getName().equalsIgnoreCase(deviceType)) {
|
||||||
policies.add(policy);
|
policies.add(policy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,17 +18,18 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.information.point;
|
package org.wso2.carbon.policy.information.point;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||||
import org.wso2.carbon.policy.mgt.common.PIPDeviceData;
|
import org.wso2.carbon.policy.mgt.common.PIPDeviceData;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationService;
|
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PolicyInformationServiceImpl implements PolicyInformationService{
|
public class PolicyInformationServiceImpl implements PolicyInformationPoint {
|
||||||
@Override
|
@Override
|
||||||
public void getDeviceData(PIPDeviceData pipDeviceData) {
|
public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import org.osgi.framework.BundleActivator;
|
|||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.framework.ServiceRegistration;
|
import org.osgi.framework.ServiceRegistration;
|
||||||
import org.wso2.carbon.policy.information.point.PolicyInformationServiceImpl;
|
import org.wso2.carbon.policy.information.point.PolicyInformationServiceImpl;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationService;
|
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||||
|
|
||||||
public class PolicyInformationPointBundleActivator implements BundleActivator {
|
public class PolicyInformationPointBundleActivator implements BundleActivator {
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public class PolicyInformationPointBundleActivator implements BundleActivator {
|
|||||||
log.debug("Activating Policy information Point bundle.");
|
log.debug("Activating Policy information Point bundle.");
|
||||||
}
|
}
|
||||||
|
|
||||||
pipServiceRegRef = bundleContext.registerService(PolicyInformationService.class.getName(),
|
pipServiceRegRef = bundleContext.registerService(PolicyInformationPoint.class.getName(),
|
||||||
new PolicyInformationServiceImpl(), null);
|
new PolicyInformationServiceImpl(), null);
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
|||||||
@ -54,7 +54,9 @@
|
|||||||
<Bundle-Description>Policy Management Common Bundle</Bundle-Description>
|
<Bundle-Description>Policy Management Common Bundle</Bundle-Description>
|
||||||
<Private-Package>org.wso2.carbon.policy.mgt.common.internal</Private-Package>
|
<Private-Package>org.wso2.carbon.policy.mgt.common.internal</Private-Package>
|
||||||
<Import-Package>
|
<Import-Package>
|
||||||
org.apache.commons.logging
|
org.apache.commons.logging,
|
||||||
|
org.wso2.carbon.device.mgt.common.*,
|
||||||
|
org.wso2.carbon.device.mgt.core.dto.*
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
org.wso2.carbon.policy.mgt.common.*
|
org.wso2.carbon.policy.mgt.common.*
|
||||||
@ -82,6 +84,10 @@
|
|||||||
<groupId>org.testng</groupId>
|
<groupId>org.testng</groupId>
|
||||||
<artifactId>testng</artifactId>
|
<artifactId>testng</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -23,9 +23,18 @@ public class Feature {
|
|||||||
private int id;
|
private int id;
|
||||||
private String code;
|
private String code;
|
||||||
private String name;
|
private String name;
|
||||||
|
private String description;
|
||||||
private Object attribute;
|
private Object attribute;
|
||||||
private String ruleValue;
|
private String ruleValue;
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRuleValue() {
|
public String getRuleValue() {
|
||||||
return ruleValue;
|
return ruleValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,5 +30,5 @@ public interface FeatureManagerService {
|
|||||||
|
|
||||||
List<Feature> getFeatures() throws FeatureManagementException;
|
List<Feature> getFeatures() throws FeatureManagementException;
|
||||||
|
|
||||||
List<Feature> getFeaturesOfPolicy(int policyId) throws FeatureManagementException;
|
List<Feature> getFeaturesOfPolicy(int profileId) throws FeatureManagementException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,14 +18,18 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.common;
|
package org.wso2.carbon.policy.mgt.common;
|
||||||
|
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PIPDeviceData {
|
public class PIPDeviceData {
|
||||||
|
|
||||||
String deviceId;
|
Device device;
|
||||||
String deviceType;
|
DeviceType deviceType;
|
||||||
String ownershipType;
|
String ownershipType;
|
||||||
List<String> userIds;
|
List<String> userIds;
|
||||||
List<String> roles;
|
List<String> roles;
|
||||||
@ -36,4 +40,75 @@ public class PIPDeviceData {
|
|||||||
/*This will be used to record attributes to which would come from other PDPs*/
|
/*This will be used to record attributes to which would come from other PDPs*/
|
||||||
Map<String, Object> attributes;
|
Map<String, Object> attributes;
|
||||||
|
|
||||||
|
public Device getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevice(Device device) {
|
||||||
|
this.device = device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceType getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceType(DeviceType deviceType) {
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnershipType() {
|
||||||
|
return ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnershipType(String ownershipType) {
|
||||||
|
this.ownershipType = ownershipType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getUserIds() {
|
||||||
|
return userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserIds(List<String> userIds) {
|
||||||
|
this.userIds = userIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRoles() {
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(List<String> roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAltitude() {
|
||||||
|
return altitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAltitude(String altitude) {
|
||||||
|
this.altitude = altitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLongitude(String longitude) {
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestamp(Timestamp timestamp) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getAttributes() {
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributes(Map<String, Object> attributes) {
|
||||||
|
this.attributes = attributes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,13 +28,12 @@ import java.util.Map;
|
|||||||
public class Policy {
|
public class Policy {
|
||||||
private int id; // Identifier of the policy.
|
private int id; // Identifier of the policy.
|
||||||
private int priorityId; // Priority of the policies. This will be used only for simple evaluation.
|
private int priorityId; // Priority of the policies. This will be used only for simple evaluation.
|
||||||
|
private Profile profile; // Profile id
|
||||||
private String policyName; // Name of the policy.
|
private String policyName; // Name of the policy.
|
||||||
private List<Feature> featuresList; // Features included in the policies.
|
|
||||||
private boolean generic; // If true, this should be applied to all related device.
|
private boolean generic; // If true, this should be applied to all related device.
|
||||||
private List<String> roleList; // Roles which this policy should be applied.
|
private List<String> roleList; // Roles which this policy should be applied.
|
||||||
private String ownershipType; // Ownership type (COPE, BYOD, CPE)
|
private String ownershipType; // Ownership type (COPE, BYOD, CPE)
|
||||||
private List<String> DeviceList; // Individual devices this policy should be applied
|
private List<String> DeviceList; // Individual devices this policy should be applied
|
||||||
private String deviceType; // Device type to apply the policy.
|
|
||||||
|
|
||||||
/*Dynamic policy attributes*/
|
/*Dynamic policy attributes*/
|
||||||
|
|
||||||
@ -71,6 +70,14 @@ public class Policy {
|
|||||||
this.priorityId = priorityId;
|
this.priorityId = priorityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Profile getProfile() {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProfile(Profile profile) {
|
||||||
|
this.profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPolicyName() {
|
public String getPolicyName() {
|
||||||
return policyName;
|
return policyName;
|
||||||
}
|
}
|
||||||
@ -79,14 +86,6 @@ public class Policy {
|
|||||||
this.policyName = policyName;
|
this.policyName = policyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Feature> getFeaturesList() {
|
|
||||||
return featuresList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFeaturesList(List<Feature> featuresList) {
|
|
||||||
this.featuresList = featuresList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGeneric() {
|
public boolean isGeneric() {
|
||||||
return generic;
|
return generic;
|
||||||
}
|
}
|
||||||
@ -119,14 +118,6 @@ public class Policy {
|
|||||||
DeviceList = deviceList;
|
DeviceList = deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeviceType() {
|
|
||||||
return deviceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceType(String deviceType) {
|
|
||||||
this.deviceType = deviceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStartTime() {
|
public int getStartTime() {
|
||||||
return startTime;
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ package org.wso2.carbon.policy.mgt.common;
|
|||||||
* This interface defines the policy management which should be implemented by the plugins
|
* This interface defines the policy management which should be implemented by the plugins
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface PolicyAdministratorService {
|
public interface PolicyAdministratorPoint {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds a policy to the platform
|
* This method adds a policy to the platform
|
||||||
@ -31,7 +31,10 @@ public interface PolicyAdministratorService {
|
|||||||
* @return primary key (generated key)
|
* @return primary key (generated key)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int addPolicy(Policy policy);
|
Policy addPolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
|
|
||||||
|
Policy updatePolicy(Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds a policy per device which should be implemented by the related plugins.
|
* This method adds a policy per device which should be implemented by the related plugins.
|
||||||
@ -42,17 +45,7 @@ public interface PolicyAdministratorService {
|
|||||||
* @return primary key (generated key)
|
* @return primary key (generated key)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException;
|
Policy addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException;
|
||||||
|
|
||||||
/**
|
|
||||||
* This method adds a policy to device type by the related device type plugins.
|
|
||||||
*
|
|
||||||
* @param deviceType
|
|
||||||
* @param policy
|
|
||||||
* @return primary key (generated key)
|
|
||||||
*/
|
|
||||||
|
|
||||||
int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method adds the policy to specific role.
|
* This method adds the policy to specific role.
|
||||||
@ -61,7 +54,7 @@ public interface PolicyAdministratorService {
|
|||||||
* @param policy
|
* @param policy
|
||||||
* @return primary key (generated key)
|
* @return primary key (generated key)
|
||||||
*/
|
*/
|
||||||
int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException;
|
Policy addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the policy of whole platform
|
* This method returns the policy of whole platform
|
||||||
@ -102,6 +95,7 @@ public interface PolicyAdministratorService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks weather a policy is available for a device.
|
* This method checks weather a policy is available for a device.
|
||||||
|
*
|
||||||
* @param deviceId
|
* @param deviceId
|
||||||
* @param deviceType
|
* @param deviceType
|
||||||
* @return
|
* @return
|
||||||
@ -112,20 +106,38 @@ public interface PolicyAdministratorService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks weather a policy is used by a particular device.
|
* This method checks weather a policy is used by a particular device.
|
||||||
|
*
|
||||||
* @param deviceId
|
* @param deviceId
|
||||||
* @param deviceType
|
* @param deviceType
|
||||||
* @return
|
* @return
|
||||||
* @throws PolicyManagementException
|
* @throws PolicyManagementException
|
||||||
*/
|
*/
|
||||||
boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException;
|
boolean isPolicyApplied(String deviceId, String deviceType) throws PolicyManagementException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param deviceId
|
* @param deviceId
|
||||||
* @param deviceType
|
* @param deviceType
|
||||||
* @param policy
|
* @param policy
|
||||||
* @throws PolicyManagementException
|
* @throws PolicyManagementException
|
||||||
*/
|
*/
|
||||||
void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException;
|
void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will add the profile to database,
|
||||||
|
* @param profile
|
||||||
|
* @throws PolicyManagementException
|
||||||
|
*/
|
||||||
|
Profile addProfile(Profile profile) throws PolicyManagementException;
|
||||||
|
|
||||||
|
boolean deleteProfile(int profileId) throws PolicyManagementException;
|
||||||
|
|
||||||
|
Profile updateProfile(Profile profile) throws PolicyManagementException;
|
||||||
|
|
||||||
|
Feature addFeature(Feature feature) throws FeatureManagementException;
|
||||||
|
|
||||||
|
Feature updateFeature(Feature feature) throws FeatureManagementException;
|
||||||
|
|
||||||
|
void deleteFeature(int featureId) throws FeatureManagementException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -19,26 +19,28 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.common;
|
package org.wso2.carbon.policy.mgt.common;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the interface which will be used to create plug-able policy decision points.
|
* This is the interface which will be used to create plug-able policy decision points.
|
||||||
*/
|
*/
|
||||||
public interface PolicyEvaluationService {
|
public interface PolicyEvaluationPoint {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the effective policy from the list.
|
* This method returns the effective policy from the list.
|
||||||
* @param pipDeviceData device information.
|
* @param deviceIdentifier device information.
|
||||||
* @return returns the effective policy.
|
* @return returns the effective policy.
|
||||||
*/
|
*/
|
||||||
Policy getEffectivePolicy(PIPDeviceData pipDeviceData);
|
Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will return the effective feature set from the list.
|
* This class will return the effective feature set from the list.
|
||||||
* @param pipDeviceData device information.
|
* @param deviceIdentifier device information.
|
||||||
* @return returns the effective feature set.
|
* @return returns the effective feature set.
|
||||||
*/
|
*/
|
||||||
List<Feature> getEffectiveFeatures(PIPDeviceData pipDeviceData);
|
List<Feature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier);
|
||||||
}
|
}
|
||||||
@ -19,26 +19,30 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.common;
|
package org.wso2.carbon.policy.mgt.common;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will be used retrieve data database. This interface has to be implemented by PIP. PIP will be plug-able.
|
* This will be used retrieve data database. This interface has to be implemented by PIP. PIP will be plug-able.
|
||||||
*/
|
*/
|
||||||
public interface PolicyInformationService {
|
public interface PolicyInformationPoint {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will return the data related Device, Some of the device data will provided in the initial pipDeviceData object such as
|
* This method will return the data related Device, Some of the device data will provided in the initial pipDeviceData object such as
|
||||||
* device id, device time and location, Other data such as roles, owned users and ownership type will be filled by this method.
|
* device id, device time and location, Other data such as roles, owned users and ownership type will be filled by this method.
|
||||||
* @param pipDeviceData device data.
|
* @param deviceIdentifier device data.
|
||||||
|
* @return PIPDeviceData
|
||||||
*/
|
*/
|
||||||
void getDeviceData(PIPDeviceData pipDeviceData);
|
PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will retrieve the policies related given device Data.
|
* This method will retrieve the policies related given device Data.
|
||||||
* @param pipDeviceData
|
* @param pipDeviceData
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData);
|
List<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is will retrieve the features related to device type. This feature list will be used for dynamically
|
* This is will retrieve the features related to device type. This feature list will be used for dynamically
|
||||||
@ -46,5 +50,5 @@ public interface PolicyInformationService {
|
|||||||
* @param deviceType
|
* @param deviceType
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Feature> getRelatedFeatures(String deviceType);
|
List<Feature> getRelatedFeatures(String deviceType) 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.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -20,6 +20,7 @@ package org.wos2.carbon.policy.mgt.common.utils;
|
|||||||
|
|
||||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -38,7 +39,14 @@ public class PolicyCreator {
|
|||||||
List<Feature> featureList = new ArrayList<Feature>();
|
List<Feature> featureList = new ArrayList<Feature>();
|
||||||
featureList.add(feature);
|
featureList.add(feature);
|
||||||
|
|
||||||
policy.setFeaturesList(featureList);
|
Profile profile = new Profile();
|
||||||
|
profile.setProfileId(1);
|
||||||
|
profile.setProfileName("Test-01");
|
||||||
|
profile.setTenantId(-1234);
|
||||||
|
|
||||||
|
policy.setProfile(profile);
|
||||||
|
profile.setFeaturesList(featureList);
|
||||||
|
|
||||||
policy.setPolicyName("Camera_related_policy");
|
policy.setPolicyName("Camera_related_policy");
|
||||||
|
|
||||||
return policy;
|
return policy;
|
||||||
|
|||||||
@ -18,7 +18,8 @@
|
|||||||
~ under the License.
|
~ under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>policy-mgt</artifactId>
|
<artifactId>policy-mgt</artifactId>
|
||||||
@ -66,7 +67,9 @@
|
|||||||
org.w3c.dom,
|
org.w3c.dom,
|
||||||
org.wso2.carbon.policy.mgt.common.*,
|
org.wso2.carbon.policy.mgt.common.*,
|
||||||
org.wso2.carbon.user.core.*,
|
org.wso2.carbon.user.core.*,
|
||||||
org.wso2.carbon.utils
|
org.wso2.carbon.utils.*,
|
||||||
|
org.wso2.carbon.device.mgt.core.*,
|
||||||
|
org.wso2.carbon.device.mgt.common.*
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
!org.wso2.carbon.policy.mgt.core.internal,
|
!org.wso2.carbon.policy.mgt.core.internal,
|
||||||
@ -75,6 +78,21 @@
|
|||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.18</version>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<log4j.configuration>file:src/test/resources/log4j.properties</log4j.configuration>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
<suiteXmlFiles>
|
||||||
|
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||||
|
</suiteXmlFiles>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@ -113,6 +131,30 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--Test Case -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.wso2</groupId>
|
||||||
|
<artifactId>jdbc-pool</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.34</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database.wso2</groupId>
|
||||||
|
<artifactId>h2-database-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,21 +18,61 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.policy.mgt.core.dao;
|
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.Policy;
|
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface PolicyDAO {
|
public interface PolicyDAO {
|
||||||
|
|
||||||
int addPolicy(Policy policy) throws PolicyManagerDAOException;
|
Policy addPolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException;
|
Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException;
|
Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException;
|
Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
Policy updatePolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getPolicy() throws PolicyManagerDAOException;
|
Policy getPolicy() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getPolicy(String deviceType) throws PolicyManagerDAOException;
|
Policy getPolicy(String deviceType) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException;
|
Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void deletePolicy(Policy policy) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Profile addProfile(Profile profile) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
Profile updateProfile(Profile profile) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void deleteProfile(Profile profile) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
List<Profile> getAllProfiles() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
List<Profile> getProfilesOfDeviceType(String deviceType) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<Feature> getAllFeatures() throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
List<Feature> getFeaturesForProfile(int ProfileId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void deleteFeature(int featureId) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
void deleteFeaturesOfProfile(Profile profile) throws PolicyManagerDAOException;
|
||||||
|
|
||||||
|
Feature addFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException;
|
||||||
|
|
||||||
|
Feature updateFeature(Feature feature) throws PolicyManagerDAOException, FeatureManagementException;*/
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,14 +35,22 @@ public class PolicyManagementDAOFactory {
|
|||||||
private static final Log log = LogFactory.getLog(PolicyManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(PolicyManagementDAOFactory.class);
|
||||||
|
|
||||||
|
|
||||||
public static PolicyDAO getDeviceTypeDAO() {
|
|
||||||
return new PolicyDAOImpl(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init(DataSourceConfig config) {
|
public static void init(DataSourceConfig config) {
|
||||||
dataSource = resolveDataSource(config);
|
dataSource = resolveDataSource(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void init(DataSource dtSource) {
|
||||||
|
dataSource = dtSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataSource getDataSource() {
|
||||||
|
if (dataSource != null) {
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Data source is not yet configured.");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve data source from the data source definition
|
* Resolve data source from the data source definition
|
||||||
*
|
*
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,64 +20,282 @@ package org.wso2.carbon.policy.mgt.core.dao.impl;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.Policy;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PolicyDAOImpl implements PolicyDAO {
|
public class PolicyDAOImpl implements PolicyDAO {
|
||||||
|
|
||||||
private static DataSource dataSource;
|
|
||||||
private static final Log log = LogFactory.getLog(PolicyDAOImpl.class);
|
private static final Log log = LogFactory.getLog(PolicyDAOImpl.class);
|
||||||
|
|
||||||
public PolicyDAOImpl(DataSource dataSource) {
|
|
||||||
this.dataSource = dataSource;
|
@Override
|
||||||
|
public Policy addPolicy(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
persistPolicy(policy);
|
||||||
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addPolicy(Policy policy) throws PolicyManagerDAOException {
|
public Policy addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException {
|
||||||
return 0;
|
|
||||||
|
// First persist the policy to the data base.
|
||||||
|
persistPolicy(policy);
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "INSERT INTO DM_DEVICE_TYPE_POLICY (DEVICE_TYPE_ID, POLICY_ID) VALUES (?, ?)";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, getDeviceTypeId(deviceType));
|
||||||
|
stmt.setInt(2, policy.getId());
|
||||||
|
|
||||||
|
stmt.executeQuery();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while adding the device type policy to database.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
return policy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException {
|
public Policy addPolicyToRole(String roleName, Policy policy) throws PolicyManagerDAOException {
|
||||||
return 0;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException {
|
public Policy addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException {
|
||||||
return 0;
|
|
||||||
|
// First persist the policy to the data base.
|
||||||
|
persistPolicy(policy);
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet generatedKeys = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException {
|
public Policy updatePolicy(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet generatedKeys = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getPolicy() throws PolicyManagerDAOException {
|
public Policy getPolicy() throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet generatedKeys = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getPolicy(String deviceType) throws PolicyManagerDAOException {
|
public Policy getPolicy(String deviceType) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet generatedKeys = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException {
|
public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet generatedKeys = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deletePolicy(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet generatedKeys = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "DELETE FROM DM_POLICY WHERE ID = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setInt(1, policy.getId());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Policy (" + policy.getPolicyName() + ") delete from database.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = "Unable to delete the policy (" + policy.getPolicyName() + ") from database.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws PolicyManagerDAOException {
|
private Connection getConnection() throws PolicyManagerDAOException {
|
||||||
try {
|
try {
|
||||||
return dataSource.getConnection();
|
return PolicyManagementDAOFactory.getDataSource().getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new PolicyManagerDAOException("Error occurred while obtaining a connection from the policy " +
|
throw new PolicyManagerDAOException("Error occurred while obtaining a connection from the policy " +
|
||||||
"management metadata repository datasource", e);
|
"management metadata repository datasource", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void persistPolicy(Policy policy) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
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_POLICY (NAME, PROFILE_ID, TENANT_ID) VALUES (?, ?, ?)";
|
||||||
|
stmt = conn.prepareStatement(query, stmt.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
|
stmt.setString(1, policy.getPolicyName());
|
||||||
|
stmt.setInt(2, policy.getProfile().getProfileId());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
|
||||||
|
int affectedRows = stmt.executeUpdate();
|
||||||
|
|
||||||
|
if (affectedRows == 0 && log.isDebugEnabled()) {
|
||||||
|
String msg = "No rows are updated on the policy table.";
|
||||||
|
log.debug(msg);
|
||||||
|
}
|
||||||
|
generatedKeys = stmt.getGeneratedKeys();
|
||||||
|
|
||||||
|
if (generatedKeys.next()) {
|
||||||
|
policy.setId(generatedKeys.getInt(1));
|
||||||
|
}
|
||||||
|
// checking policy id here, because it object could have passed with id from the calling method.
|
||||||
|
if (policy.getId() == 0) {
|
||||||
|
throw new RuntimeException("No rows were inserted, policy id cannot be null.");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while adding policy to the database.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, generatedKeys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns the device type id when supplied with device type name.
|
||||||
|
*
|
||||||
|
* @param deviceType
|
||||||
|
* @return
|
||||||
|
* @throws PolicyManagerDAOException
|
||||||
|
*/
|
||||||
|
private int getDeviceTypeId(String deviceType) throws PolicyManagerDAOException {
|
||||||
|
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
int deviceTypeId = -1;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
String query = "SELECT ID FROM DM_DEVICE_TYPE WHERE NAME = ?";
|
||||||
|
stmt = conn.prepareStatement(query);
|
||||||
|
stmt.setString(1, deviceType);
|
||||||
|
|
||||||
|
resultSet = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
deviceTypeId = resultSet.getInt("ID");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while selecting the device type id.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyManagerDAOException(msg, e);
|
||||||
|
} finally {
|
||||||
|
PolicyManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
|
||||||
|
}
|
||||||
|
return deviceTypeId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,11 +21,13 @@ package org.wso2.carbon.policy.mgt.core.internal;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationService;
|
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
|
import org.wso2.carbon.policy.mgt.core.config.PolicyConfigurationManager;
|
||||||
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig;
|
import org.wso2.carbon.policy.mgt.core.config.PolicyManagementConfig;
|
||||||
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
||||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.service.PolicyManagementService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,7 +39,7 @@ import org.wso2.carbon.user.core.service.RealmService;
|
|||||||
* bind="setRealmService"
|
* bind="setRealmService"
|
||||||
* unbind="unsetRealmService"
|
* unbind="unsetRealmService"
|
||||||
* @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default"
|
* @scr.reference name="org.wso2.carbon.devicemgt.policy.information.point.default"
|
||||||
* interface="org.wso2.carbon.policy.mgt.common.PolicyInformationService"
|
* interface="org.wso2.carbon.policy.mgt.common.PolicyInformationPoint"
|
||||||
* cardinality="1..1"
|
* cardinality="1..1"
|
||||||
* policy="dynamic"
|
* policy="dynamic"
|
||||||
* bind="setPIPService"
|
* bind="setPIPService"
|
||||||
@ -56,6 +58,9 @@ public class PolicyManagementServiceComponent {
|
|||||||
DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig();
|
DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig();
|
||||||
PolicyManagementDAOFactory.init(dsConfig);
|
PolicyManagementDAOFactory.init(dsConfig);
|
||||||
|
|
||||||
|
componentContext.getBundleContext().registerService(
|
||||||
|
PolicyManager.class.getName(), new PolicyManagementService(), null);
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
String msg = "Error occurred while initializing the Policy management core.";
|
String msg = "Error occurred while initializing the Policy management core.";
|
||||||
log.error(msg, t);
|
log.error(msg, t);
|
||||||
@ -89,13 +94,13 @@ public class PolicyManagementServiceComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setPIPService(PolicyInformationService policyInformationService) {
|
protected void setPIPService(PolicyInformationPoint policyInformationService) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Setting Policy Information Service");
|
log.debug("Setting Policy Information Service");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unsetPIPService(PolicyInformationService policyInformationService) {
|
protected void unsetPIPService(PolicyInformationPoint policyInformationService) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Unsetting Policy Information Service");
|
log.debug("Unsetting Policy Information Service");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
||||||
@ -59,5 +59,9 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user