forked from community/device-mgt-plugins
revert-dabc3590
parent
715d242b22
commit
5e3ebc141c
@ -1,7 +1,7 @@
|
||||
product-cdm
|
||||
===========
|
||||
WSO2 CONNECTED DEVICE MANAGER
|
||||
WSO2 MOBILE DEVICE MANAGER
|
||||
|
||||
WSO2 Enterprise Mobility Manager (WSO2 EMM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program.
|
||||
WSO2 Mobile Device Manager (WSO2 MDM) is a comprehensive platform that helps solve mobile computing challenges enterprises face today when dealing with both corporate owned, personally enabled (COPE) devices and employee owned devices as part of a bring your own device (BYOD) program.
|
||||
|
||||
Whether it is device provisioning, device configuration management, policy enforcement, mobile application management, device data security, or compliance monitoring, WSO2 EMM offers a single enterprise-grade platform.
|
||||
|
@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Device Management Commons</name>
|
||||
<description>WSO2 Carbon - Device Management Commons</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>Device Management Common Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.device.mgt.common</Private-Package>
|
||||
<Import-Package>
|
||||
org.apache.commons.logging
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.device.mgt.common.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,178 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement
|
||||
public class Device {
|
||||
|
||||
private int id;
|
||||
private String type;
|
||||
private String description;
|
||||
private String name;
|
||||
private Long dateOfEnrolment;
|
||||
private Long dateOfLastUpdate;
|
||||
private String ownership;
|
||||
private boolean status;
|
||||
private int deviceTypeId;
|
||||
private String deviceIdentifier;
|
||||
private String owner;
|
||||
private List<Feature> features;
|
||||
private List<Device.Property> properties;
|
||||
|
||||
@XmlElement
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Long getDateOfEnrolment() {
|
||||
return dateOfEnrolment;
|
||||
}
|
||||
|
||||
public void setDateOfEnrolment(Long dateOfEnrolment) {
|
||||
this.dateOfEnrolment = dateOfEnrolment;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Long getDateOfLastUpdate() {
|
||||
return dateOfLastUpdate;
|
||||
}
|
||||
|
||||
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
|
||||
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getOwnership() {
|
||||
return ownership;
|
||||
}
|
||||
|
||||
public void setOwnership(String ownership) {
|
||||
this.ownership = ownership;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public boolean isStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getDeviceTypeId() {
|
||||
return deviceTypeId;
|
||||
}
|
||||
|
||||
public void setDeviceTypeId(int deviceTypeId) {
|
||||
this.deviceTypeId = deviceTypeId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getDeviceIdentifier() {
|
||||
return deviceIdentifier;
|
||||
}
|
||||
|
||||
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||
this.deviceIdentifier = deviceIdentifier;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Feature> getFeatures() {
|
||||
return features;
|
||||
}
|
||||
|
||||
public void setFeatures(List<Feature> features) {
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Device.Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<Device.Property> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
public class DeviceIdentifier {
|
||||
|
||||
private String type;
|
||||
|
||||
private String id;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
public final class DeviceManagementConstants {
|
||||
|
||||
public static final class DataSourceProperties {
|
||||
private DataSourceProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String DB_CHECK_QUERY = "SELECT * FROM DM_DEVICE";
|
||||
public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration";
|
||||
public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml";
|
||||
}
|
||||
|
||||
public static final class SecureValueProperties {
|
||||
private SecureValueProperties() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String SECRET_ALIAS_ATTRIBUTE_NAME_WITH_NAMESPACE = "secretAlias";
|
||||
public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration";
|
||||
}
|
||||
|
||||
public static final class MobileDeviceTypes {
|
||||
private MobileDeviceTypes() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public final static String MOBILE_DEVICE_TYPE_ANDROID = "android";
|
||||
public final static String MOBILE_DEVICE_TYPE_IOS = "ios";
|
||||
public final static String MOBILE_DEVICE_TYPE_WINDOWS = "windows";
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class DeviceManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070297L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public DeviceManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public DeviceManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public DeviceManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public DeviceManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DeviceManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Feature {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private List<MetadataEntry> metadataEntries;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<MetadataEntry> getMetadataEntries() {
|
||||
return metadataEntries;
|
||||
}
|
||||
|
||||
public void setMetadataEntries(List<MetadataEntry> metadataEntries) {
|
||||
this.metadataEntries = metadataEntries;
|
||||
}
|
||||
|
||||
public static class MetadataEntry {
|
||||
|
||||
private int id;
|
||||
private Object value;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +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 License {
|
||||
|
||||
private String licenseName;
|
||||
private String licenseText;
|
||||
private String licenseVersion;
|
||||
|
||||
public String getLicenseName() {
|
||||
return licenseName;
|
||||
}
|
||||
|
||||
public void setLicenseName(String licenseName) {
|
||||
this.licenseName = licenseName;
|
||||
}
|
||||
|
||||
public String getLicenseText() {
|
||||
return licenseText;
|
||||
}
|
||||
|
||||
public void setLicenseText(String licenseText) {
|
||||
this.licenseText = licenseText;
|
||||
}
|
||||
|
||||
public String getLicenseVersion() {
|
||||
return licenseVersion;
|
||||
}
|
||||
|
||||
public void setLicenseVersion(String licenseVersion) {
|
||||
this.licenseVersion = licenseVersion;
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.Properties;
|
||||
|
||||
@XmlRootElement
|
||||
public class Operation {
|
||||
|
||||
public enum Type {
|
||||
CONFIG, MESSAGE, INFO
|
||||
}
|
||||
|
||||
private String code;
|
||||
private Properties properties;
|
||||
private Type type;
|
||||
|
||||
@XmlElement
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
public class OperationExecutionException 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 OperationExecutionException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OperationExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public OperationExecutionException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OperationExecutionException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public OperationExecutionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
public class OperationManagementException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279311929070298L;
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public OperationManagementException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OperationManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public OperationManagementException(String msg) {
|
||||
super(msg);
|
||||
setErrorMessage(msg);
|
||||
}
|
||||
|
||||
public OperationManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public OperationManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This represents the Device Operation management functionality which should be implemented by
|
||||
* the device type plugins.
|
||||
*/
|
||||
public interface OperationManager {
|
||||
|
||||
/**
|
||||
* Method to add a operation to a device or a set of devices.
|
||||
*
|
||||
* @param operation Operation to be added
|
||||
* @param devices List of DeviceIdentifiers to execute the operation
|
||||
* @throws OperationManagementException If some unusual behaviour is observed while adding the
|
||||
* operation
|
||||
*/
|
||||
public boolean addOperation(Operation operation, List<DeviceIdentifier> devices)
|
||||
throws OperationManagementException;
|
||||
|
||||
/**
|
||||
* Method to retrieve the list of available operations to a device.
|
||||
*
|
||||
* @param deviceId DeviceIdentifier of the device
|
||||
* @throws OperationManagementException If some unusual behaviour is observed while fetching the
|
||||
* operation list.
|
||||
*/
|
||||
public List<Operation> getOperations(DeviceIdentifier deviceId)
|
||||
throws OperationManagementException;
|
||||
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.common.spi;
|
||||
|
||||
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 java.util.List;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public interface DeviceManagerService {
|
||||
|
||||
/**
|
||||
* Method to retrieve the provider type that implements DeviceManagerService interface.
|
||||
*
|
||||
* @return Returns provider type
|
||||
*/
|
||||
String getProviderType();
|
||||
|
||||
/**
|
||||
* Method to enrolling a particular device of type mobile, IoT, etc within CDM.
|
||||
*
|
||||
* @param device Metadata corresponding to the device being enrolled
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while enrolling a device
|
||||
*/
|
||||
boolean enrollDevice(Device device) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to modify the metadata corresponding to device enrollment.
|
||||
*
|
||||
* @param device Modified device enrollment related metadata
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while modify the enrollment of a
|
||||
* device
|
||||
*/
|
||||
boolean modifyEnrollment(Device device) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to disenroll a particular device from CDM.
|
||||
*
|
||||
* @param deviceId Fully qualified device identifier
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while disenrolling a device
|
||||
*/
|
||||
boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to retrieve the status of the registration process of a particular device.
|
||||
*
|
||||
* @param deviceId Fully qualified device identifier
|
||||
* @return Status of enrollment
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while checking the enrollment
|
||||
* status of the device
|
||||
*/
|
||||
boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to retrieve the status of a particular device.
|
||||
*
|
||||
* @param deviceId Fully qualified device identifier
|
||||
* @return Returns if the device is active
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while checking the status
|
||||
* of the device
|
||||
*/
|
||||
boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to set the status indicating whether a particular device registered within CDM is enabled at a given
|
||||
* moment.
|
||||
*
|
||||
* @param deviceId Fully qualified device identifier
|
||||
* @param status Indicates whether the device is active
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while updating the active status
|
||||
* of the device
|
||||
*/
|
||||
boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to retrieve metadata of all devices registered within CDM corresponding to a particular device type.
|
||||
*
|
||||
* @return List of metadata corresponding to all devices registered within CDM
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while obtaining the enrolled device list
|
||||
*/
|
||||
List<Device> getAllDevices() throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to retrieve metadata of a device corresponding to a particular type that carries a specific identifier.
|
||||
*
|
||||
* @param deviceId Fully qualified device identifier
|
||||
* @return Metadata corresponding to a particular device
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed obtaining the device object
|
||||
*/
|
||||
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to update device information.
|
||||
*
|
||||
* @param device Updated device information related data
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while updating the device info
|
||||
*/
|
||||
boolean updateDeviceInfo(Device device) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* Method to set the ownership type of a particular device. i.e. BYOD, COPE.
|
||||
*
|
||||
* @param deviceId Fully qualified device identifier
|
||||
* @param ownershipType Type of ownership
|
||||
* @throws DeviceManagementException If some unusual behaviour is observed while setting the ownership
|
||||
* of the device
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>device-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Device Management Core</name>
|
||||
<description>WSO2 Carbon - Device Management Core</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>Device Management Core Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.device.mgt.core.internal</Private-Package>
|
||||
<Import-Package>
|
||||
org.apache.axis2.*;version="${axis2.osgi.version.range}",
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging,
|
||||
javax.transaction.*,
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.core.internal,
|
||||
org.wso2.carbon.device.mgt.core.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.18</version>
|
||||
<configuration>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database.wso2</groupId>
|
||||
<artifactId>h2-database-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.user.api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,27 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
public final class DeviceManagementConstants {
|
||||
|
||||
public static final class Common {
|
||||
private Common() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
public static final String PROPERTY_SETUP = "setup";
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
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.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceManagementRepository {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
||||
private Map<String, DeviceManagerService> providers;
|
||||
|
||||
public DeviceManagementRepository() {
|
||||
providers = new HashMap<String, DeviceManagerService>();
|
||||
}
|
||||
|
||||
public void addDeviceManagementProvider(DeviceManagerService provider) {
|
||||
String deviceType = provider.getProviderType();
|
||||
try {
|
||||
DeviceManagerUtil.registerDeviceType(deviceType);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Exception occurred while registering the device type.", e);
|
||||
}
|
||||
providers.put(deviceType, provider);
|
||||
}
|
||||
|
||||
public void removeDeviceManagementProvider(DeviceManagerService provider) {
|
||||
String deviceType = provider.getProviderType();
|
||||
|
||||
try {
|
||||
DeviceManagerUtil.unregisterDeviceType(deviceType);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Exception occurred while registering the device type.", e);
|
||||
}
|
||||
providers.remove(deviceType);
|
||||
}
|
||||
|
||||
public DeviceManagerService getDeviceManagementProvider(String type) {
|
||||
return providers.get(type);
|
||||
}
|
||||
}
|
@ -1,56 +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,167 +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.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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagerImpl implements DeviceManager {
|
||||
|
||||
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.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) {
|
||||
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device);
|
||||
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil
|
||||
.createDeviceIdentifier(device, this.deviceTypeDAO
|
||||
.getDeviceType(device.getDeviceTypeId()));
|
||||
Device dmsDevice = dms.getDevice(deviceIdentifier);
|
||||
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());
|
||||
return dms.getDevice(deviceId);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +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.core.dto.DeviceType;
|
||||
|
||||
public class LicenseManager {
|
||||
|
||||
/* public void addLicense(DeviceType deviceType,String langCode, String
|
||||
);*/
|
||||
|
||||
}
|
@ -1,74 +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.config;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Class responsible for the cdm manager configuration initialization
|
||||
*/
|
||||
public class DeviceConfigurationManager {
|
||||
|
||||
private DeviceManagementConfig currentDeviceConfig;
|
||||
private static DeviceConfigurationManager deviceConfigManager;
|
||||
|
||||
private static final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
||||
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
|
||||
|
||||
public static DeviceConfigurationManager getInstance() {
|
||||
if (deviceConfigManager == null) {
|
||||
synchronized (DeviceConfigurationManager.class) {
|
||||
if (deviceConfigManager == null) {
|
||||
deviceConfigManager = new DeviceConfigurationManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return deviceConfigManager;
|
||||
}
|
||||
|
||||
public synchronized void initConfig() throws DeviceManagementException {
|
||||
|
||||
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
|
||||
try {
|
||||
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
||||
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
||||
|
||||
/* Un-marshaling Device Management configuration */
|
||||
JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class);
|
||||
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
||||
this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
|
||||
} catch (Exception e) {
|
||||
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceManagementConfig getDeviceManagementConfig() {
|
||||
return currentDeviceConfig;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +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.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Represents Device Mgt configuration.
|
||||
*/
|
||||
@XmlRootElement(name = "DeviceMgtConfiguration")
|
||||
public final class DeviceManagementConfig {
|
||||
|
||||
private DeviceManagementRepository deviceMgtRepository;
|
||||
|
||||
@XmlElement(name = "ManagementRepository", required = true)
|
||||
public DeviceManagementRepository getDeviceMgtRepository() {
|
||||
return deviceMgtRepository;
|
||||
}
|
||||
|
||||
public void setDeviceMgtRepository(DeviceManagementRepository deviceMgtRepository) {
|
||||
this.deviceMgtRepository = deviceMgtRepository;
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +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.config;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding management repository data
|
||||
*/
|
||||
@XmlRootElement(name = "ManagementRepository")
|
||||
public class DeviceManagementRepository {
|
||||
|
||||
private DataSourceConfig dataSourceConfig;
|
||||
|
||||
@XmlElement(name = "DataSourceConfiguration", required = false)
|
||||
public DataSourceConfig getDataSourceConfig() {
|
||||
return dataSourceConfig;
|
||||
}
|
||||
|
||||
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
|
||||
this.dataSourceConfig = dataSourceConfig;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +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.config.datasource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding data source configuration in malformed-cdm-config-no-mgt-repo.xml at parsing with JAXB
|
||||
*/
|
||||
@XmlRootElement(name = "DataSourceConfiguration")
|
||||
public class DataSourceConfig {
|
||||
|
||||
private JNDILookupDefinition jndiLookupDefintion;
|
||||
|
||||
@XmlElement(name = "JndiLookupDefinition", required = true)
|
||||
public JNDILookupDefinition getJndiLookupDefintion() {
|
||||
return jndiLookupDefintion;
|
||||
}
|
||||
|
||||
public void setJndiLookupDefintion(JNDILookupDefinition jndiLookupDefintion) {
|
||||
this.jndiLookupDefintion = jndiLookupDefintion;
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +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.
|
||||
* 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.config.datasource;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB
|
||||
*/
|
||||
@XmlRootElement(name = "JndiLookupDefinition")
|
||||
public class JNDILookupDefinition {
|
||||
|
||||
private String jndiName;
|
||||
private List<JNDIProperty> jndiProperties;
|
||||
|
||||
@XmlElement(name = "Name", required = false)
|
||||
public String getJndiName() {
|
||||
return jndiName;
|
||||
}
|
||||
|
||||
public void setJndiName(String jndiName) {
|
||||
this.jndiName = jndiName;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "Environment", required = false)
|
||||
@XmlElement(name = "Property", nillable = false)
|
||||
public List<JNDIProperty> getJndiProperties() {
|
||||
return jndiProperties;
|
||||
}
|
||||
|
||||
public void setJndiProperties(List<JNDIProperty> jndiProperties) {
|
||||
this.jndiProperties = jndiProperties;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "Property")
|
||||
public static class JNDIProperty {
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
@XmlAttribute(name = "Name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,49 +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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting device related information
|
||||
*/
|
||||
public interface DeviceDAO {
|
||||
|
||||
void addDevice(Device device) throws DeviceManagementDAOException;
|
||||
|
||||
void updateDevice(Device device) throws DeviceManagementDAOException;
|
||||
|
||||
void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException;
|
||||
|
||||
void deleteDevice(Long deviceId) throws DeviceManagementDAOException;
|
||||
|
||||
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
|
||||
|
||||
List<Device> getDevices() throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* @param type - The device type id.
|
||||
* @return a list of devices based on the type id.
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
List<Device> getDevices(Integer type) throws DeviceManagementDAOException;
|
||||
}
|
@ -1,78 +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.dao;
|
||||
|
||||
/**
|
||||
* Custom exception class for data access related exceptions
|
||||
*/
|
||||
public class DeviceManagementDAOException extends Exception {
|
||||
|
||||
private String message;
|
||||
private static final long serialVersionUID = 2021891706072918864L;
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message and nested exception.
|
||||
*
|
||||
* @param message error message
|
||||
* @param nestedException exception
|
||||
*/
|
||||
public DeviceManagementDAOException(String message, Exception nestedException) {
|
||||
super(message, nestedException);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message and cause.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public DeviceManagementDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified detail message
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public DeviceManagementDAOException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new exception with the specified and cause.
|
||||
*
|
||||
* @param cause the cause of this exception.
|
||||
*/
|
||||
public DeviceManagementDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.message = errorMessage;
|
||||
}
|
||||
|
||||
}
|
@ -1,88 +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.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.impl.DeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagementDAOFactory {
|
||||
|
||||
private static DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementDAOFactory.class);
|
||||
|
||||
public static DeviceDAO getDeviceDAO() {
|
||||
return new DeviceDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
public static DeviceTypeDAO getDeviceTypeDAO() {
|
||||
return new DeviceTypeDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
public static void init(DataSourceConfig config) {
|
||||
dataSource = resolveDataSource(config);
|
||||
}
|
||||
|
||||
public static void init(DataSource dtSource) {
|
||||
dataSource = dtSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getJndiLookupDefintion();
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,41 +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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting device type related information
|
||||
*/
|
||||
public interface DeviceTypeDAO {
|
||||
|
||||
void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
||||
|
||||
void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
||||
|
||||
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
|
||||
|
||||
DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException;
|
||||
|
||||
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
|
||||
|
||||
void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException;
|
||||
|
||||
}
|
@ -1,156 +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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceDAOImpl implements DeviceDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
|
||||
|
||||
|
||||
public DeviceDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(Device device) throws DeviceManagementDAOException {
|
||||
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);
|
||||
stmt.setString(1, device.getDescription());
|
||||
stmt.setString(2, device.getName());
|
||||
stmt.setLong(3, new Date().getTime());
|
||||
stmt.setLong(4, new Date().getTime());
|
||||
stmt.setString(5, device.getOwnerShip());
|
||||
stmt.setString(6, device.getStatus().toString());
|
||||
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) {
|
||||
String msg = "Error occurred while enrolling device '" + device.getName() + "'";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDevice(Device device) throws DeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDevice(Long deviceId) throws DeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDeviceByDeviceId(Long deviceId)
|
||||
throws DeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getDevices() throws DeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<Device> getDevices(Integer 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,160 +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.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
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 javax.sql.DataSource;
|
||||
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 DeviceTypeDAOImpl implements DeviceTypeDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(DeviceTypeDAOImpl.class);
|
||||
|
||||
public DeviceTypeDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
||||
Connection conn = this.getConnection();
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_TYPE (NAME) VALUES (?)");
|
||||
stmt.setString(1, deviceType.getName());
|
||||
stmt.execute();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while registering the device type '" + deviceType.getName() + "'";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
||||
Connection conn = this.getConnection();
|
||||
PreparedStatement stmt = null;
|
||||
List<DeviceType> deviceTypes = new ArrayList<DeviceType>();
|
||||
try {
|
||||
stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE");
|
||||
ResultSet results = stmt.executeQuery();
|
||||
|
||||
while (results.next()) {
|
||||
DeviceType deviceType = new DeviceType();
|
||||
deviceType.setId(results.getLong("DEVICE_TYPE_ID"));
|
||||
deviceType.setName(results.getString("DEVICE_TYPE"));
|
||||
deviceTypes.add(deviceType);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching the registered device types";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return deviceTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException {
|
||||
Connection conn = this.getConnection();
|
||||
PreparedStatement stmt = null;
|
||||
DeviceType deviceType = null;
|
||||
try {
|
||||
stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID=?");
|
||||
stmt.setInt(1, id);
|
||||
ResultSet results = stmt.executeQuery();
|
||||
|
||||
while (results.next()) {
|
||||
deviceType = new DeviceType();
|
||||
deviceType.setId(results.getLong("DEVICE_TYPE_ID"));
|
||||
deviceType.setName(results.getString("DEVICE_TYPE"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching the registered device type";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException {
|
||||
|
||||
Connection conn = this.getConnection();
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
Integer deviceTypeId = null;
|
||||
|
||||
try {
|
||||
String createDBQuery = "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?";
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, type);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
deviceTypeId = resultSet.getInt(1);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetch device type id for device type '" + type + "'";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
|
||||
return deviceTypeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
||||
|
||||
}
|
||||
|
||||
private Connection getConnection() throws DeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the device " +
|
||||
"management metadata repository datasource";
|
||||
log.error(msg, e);
|
||||
throw new DeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.dao.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
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.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.user.api.UserStoreException;
|
||||
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public final class DeviceManagementDAOUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementDAOUtil.class);
|
||||
|
||||
public static void cleanupResources(Connection conn, PreparedStatement 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id of the current tenant.
|
||||
*
|
||||
* @return tenant id
|
||||
* @throws DeviceManagementDAOException if an error is observed when getting tenant id
|
||||
*/
|
||||
public static int getTenantId() throws DeviceManagementDAOException {
|
||||
CarbonContext context = CarbonContext.getThreadLocalCarbonContext();
|
||||
int tenantId = context.getTenantId();
|
||||
if (tenantId != MultitenantConstants.INVALID_TENANT_ID) {
|
||||
return tenantId;
|
||||
}
|
||||
String tenantDomain = context.getTenantDomain();
|
||||
if (tenantDomain == null) {
|
||||
String msg = "Tenant domain is not properly set and thus, is null";
|
||||
throw new DeviceManagementDAOException(msg);
|
||||
}
|
||||
TenantManager tenantManager = DeviceManagementDataHolder.getInstance().getTenantManager();
|
||||
try {
|
||||
tenantId = tenantManager.getTenantId(tenantDomain);
|
||||
} catch (UserStoreException e) {
|
||||
String msg = "Error occurred while retrieving id from the domain of tenant " + tenantDomain;
|
||||
throw new DeviceManagementDAOException(msg);
|
||||
}
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
|
||||
try {
|
||||
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
||||
return (DataSource) InitialContext.doLookup(dataSourceName);
|
||||
}
|
||||
final InitialContext context = new InitialContext(jndiProperties);
|
||||
return (DataSource) context.lookup(dataSourceName);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param device - The DTO device object.
|
||||
* @return A Business Object.
|
||||
*/
|
||||
public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device){
|
||||
org.wso2.carbon.device.mgt.common.Device deviceBO =
|
||||
new org.wso2.carbon.device.mgt.common.Device();
|
||||
deviceBO.setDateOfEnrolment(device.getDateOfEnrollment());
|
||||
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
||||
deviceBO.setDescription(device.getDescription());
|
||||
deviceBO.setDeviceIdentifier(device.getDeviceIdentificationId());
|
||||
deviceBO.setDeviceTypeId(device.getDeviceTypeId());
|
||||
deviceBO.setName(device.getName());
|
||||
deviceBO.setId(device.getId());
|
||||
deviceBO.setOwner(device.getOwnerId());
|
||||
deviceBO.setOwnership(device.getOwnerShip());
|
||||
if (device.getStatus() == Status.ACTIVE) {
|
||||
deviceBO.setStatus(true);
|
||||
} else if (device.getStatus() == Status.INACTIVE) {
|
||||
deviceBO.setStatus(false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param devices - DTO Device Object list.
|
||||
* @return converted Business Object list.
|
||||
*/
|
||||
public static List<org.wso2.carbon.device.mgt.common.Device> convertDevices(
|
||||
List<Device> devices) {
|
||||
List<org.wso2.carbon.device.mgt.common.Device> deviceBOList =
|
||||
new ArrayList<org.wso2.carbon.device.mgt.common.Device>();
|
||||
for (Device device : devices) {
|
||||
deviceBOList.add(convertDevice(device));
|
||||
}
|
||||
return deviceBOList;
|
||||
}
|
||||
|
||||
public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device
|
||||
device) throws DeviceManagementDAOException {
|
||||
Device deviceBO = new Device();
|
||||
deviceBO.setDescription(device.getDescription());
|
||||
deviceBO.setName(device.getName());
|
||||
deviceBO.setDateOfEnrollment(device.getDateOfEnrolment());
|
||||
deviceBO.setDateOfLastUpdate(device.getDateOfLastUpdate());
|
||||
|
||||
if (!device.isStatus()){
|
||||
deviceBO.setStatus(Status.INACTIVE);
|
||||
}else{
|
||||
deviceBO.setStatus(Status.ACTIVE);
|
||||
}
|
||||
deviceBO.setOwnerId(device.getOwner());
|
||||
deviceBO.setOwnerShip(device.getOwnership());
|
||||
deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId());
|
||||
deviceBO.setDeviceIdentificationId(device.getDeviceIdentifier());
|
||||
return deviceBO;
|
||||
}
|
||||
|
||||
public static DeviceIdentifier createDeviceIdentifier(Device device, DeviceType deviceType) {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setType(deviceType.getName());
|
||||
deviceIdentifier.setId(device.getDeviceIdentificationId());
|
||||
return deviceIdentifier;
|
||||
}
|
||||
}
|
@ -1,125 +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.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Device implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -8101106997837486245L;
|
||||
private Integer id;
|
||||
private String description;
|
||||
private String name;
|
||||
private Long dateOfEnrollment;
|
||||
private Long dateOfLastUpdate;
|
||||
private String deviceIdentificationId;
|
||||
private Status status;
|
||||
private String ownerId;
|
||||
private String ownerShip;
|
||||
private int tenantId;
|
||||
private Integer deviceTypeId;
|
||||
|
||||
public Integer getDeviceTypeId() {
|
||||
return deviceTypeId;
|
||||
}
|
||||
|
||||
public void setDeviceTypeId(Integer deviceTypeId) {
|
||||
this.deviceTypeId = deviceTypeId;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getDateOfEnrollment() {
|
||||
return dateOfEnrollment;
|
||||
}
|
||||
|
||||
public void setDateOfEnrollment(Long dateOfEnrollment) {
|
||||
this.dateOfEnrollment = dateOfEnrollment;
|
||||
}
|
||||
|
||||
public Long getDateOfLastUpdate() {
|
||||
return dateOfLastUpdate;
|
||||
}
|
||||
|
||||
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
|
||||
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||
}
|
||||
|
||||
public String getDeviceIdentificationId() {
|
||||
return deviceIdentificationId;
|
||||
}
|
||||
|
||||
public void setDeviceIdentificationId(String deviceIdentificationId) {
|
||||
this.deviceIdentificationId = deviceIdentificationId;
|
||||
}
|
||||
|
||||
public void setOwnerShip(String ownerShip) {
|
||||
this.ownerShip = ownerShip;
|
||||
}
|
||||
|
||||
public String getOwnerShip() {
|
||||
return ownerShip;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setOwnerId(String ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
}
|
@ -1,45 +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.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceType implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7927802716452548282L;
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package org.wso2.carbon.device.mgt.core.dto;
|
||||
|
||||
|
||||
public enum OwnerShip {
|
||||
BYOD,COPE
|
||||
}
|
@ -1,23 +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.dto;
|
||||
|
||||
public enum Status {
|
||||
ACTIVE, INACTIVE
|
||||
}
|
@ -1,68 +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.internal;
|
||||
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManager;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||
|
||||
public class DeviceManagementDataHolder {
|
||||
|
||||
private RealmService realmService;
|
||||
private TenantManager tenantManager;
|
||||
private DeviceManager deviceManager;
|
||||
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
|
||||
|
||||
private DeviceManagementDataHolder() {
|
||||
}
|
||||
|
||||
public static DeviceManagementDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public RealmService getRealmService() {
|
||||
return realmService;
|
||||
}
|
||||
|
||||
public void setRealmService(RealmService realmService) {
|
||||
this.realmService = realmService;
|
||||
this.setTenantManager(realmService);
|
||||
}
|
||||
|
||||
private void setTenantManager(RealmService realmService) {
|
||||
if (realmService == null) {
|
||||
throw new IllegalStateException("Realm service is not initialized properly");
|
||||
}
|
||||
this.tenantManager = realmService.getTenantManager();
|
||||
}
|
||||
|
||||
public TenantManager getTenantManager() {
|
||||
return tenantManager;
|
||||
}
|
||||
|
||||
public DeviceManager getDeviceManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
|
||||
public void setDeviceManager(DeviceManager deviceManager) {
|
||||
this.deviceManager = deviceManager;
|
||||
}
|
||||
|
||||
}
|
@ -1,164 +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.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
|
||||
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.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.manager" immediate="true"
|
||||
* @scr.reference name="user.realmservice.default"
|
||||
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setRealmService"
|
||||
* unbind="unsetRealmService"
|
||||
* @scr.reference name="device.manager.service"
|
||||
* interface="org.wso2.carbon.device.mgt.common.spi.DeviceManagerService"
|
||||
* cardinality="0..n"
|
||||
* policy="dynamic"
|
||||
* bind="setDeviceManagerService"
|
||||
* unbind="unsetDeviceManagerService"
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class DeviceManagementServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
|
||||
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
|
||||
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Initializing device management core bundle");
|
||||
}
|
||||
/* Initializing Device Management Configuration */
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||
|
||||
DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig();
|
||||
DeviceManagementDAOFactory.init(dsConfig);
|
||||
|
||||
DeviceManager deviceManager = new DeviceManagerImpl(config, this.getPluginRepository());
|
||||
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
|
||||
|
||||
/* If -Dsetup option enabled then create device management database schema */
|
||||
String setupOption = System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
|
||||
if (setupOption != null) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("-Dsetup is enabled. Device management repository schema initialization is about " +
|
||||
"to begin");
|
||||
}
|
||||
this.setupDeviceManagementSchema(dsConfig);
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Registering OSGi service DeviceManagementService");
|
||||
}
|
||||
BundleContext bundleContext = componentContext.getBundleContext();
|
||||
bundleContext.registerService(DeviceManagementService.class.getName(),
|
||||
new DeviceManagementService(), null);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device management core bundle has been successfully initialized");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
String msg = "Error occurred while initializing device management core bundle";
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {
|
||||
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
|
||||
log.info("Initializing device management repository database schema");
|
||||
|
||||
try {
|
||||
initializer.createRegistryDatabase();
|
||||
} catch (Exception e) {
|
||||
throw new DeviceManagementException("Error occurred while initializing Device Management " +
|
||||
"database schema", e);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device management metadata repository schema has been successfully initialized");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Device Manager service.
|
||||
* @param deviceManagerService An instance of DeviceManagerService
|
||||
*/
|
||||
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Device Management Service Provider : '" +
|
||||
deviceManagerService.getProviderType() + "'");
|
||||
}
|
||||
this.getPluginRepository().addDeviceManagementProvider(deviceManagerService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets Device Management service.
|
||||
* @param deviceManagerService An Instance of DeviceManagerService
|
||||
*/
|
||||
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting Device Management Service Provider : '" +
|
||||
deviceManagerService.getProviderType() + "'");
|
||||
}
|
||||
this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Realm Service.
|
||||
* @param realmService An instance of RealmService
|
||||
*/
|
||||
protected void setRealmService(RealmService realmService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Realm Service");
|
||||
}
|
||||
DeviceManagementDataHolder.getInstance().setRealmService(realmService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets Realm Service.
|
||||
* @param realmService An instance of RealmService
|
||||
*/
|
||||
protected void unsetRealmService(RealmService realmService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting Realm Service");
|
||||
}
|
||||
DeviceManagementDataHolder.getInstance().setRealmService(null);
|
||||
}
|
||||
|
||||
private DeviceManagementRepository getPluginRepository() {
|
||||
return pluginRepository;
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.service;
|
||||
|
||||
import org.wso2.carbon.core.AbstractAdmin;
|
||||
|
||||
public class DeviceManagementAdminService extends AbstractAdmin {
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.service;
|
||||
|
||||
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.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagementService implements DeviceManager {
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +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.
|
||||
* 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.util;
|
||||
|
||||
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.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
|
||||
public final class DeviceManagementSchemaInitializer extends DatabaseCreator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementSchemaInitializer.class);
|
||||
private static final String setupSQLScriptBaseLocation =
|
||||
CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + File.separator;
|
||||
|
||||
public DeviceManagementSchemaInitializer(DataSourceConfig config) {
|
||||
super(DeviceManagerUtil.resolveDataSource(config));
|
||||
}
|
||||
|
||||
protected String getDbScriptLocation(String databaseType) {
|
||||
String scriptName = databaseType + ".sql";
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Loading database script from :" + scriptName);
|
||||
}
|
||||
return setupSQLScriptBaseLocation.replaceFirst("DBTYPE", databaseType) + scriptName;
|
||||
}
|
||||
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
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.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 javax.sql.DataSource;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public final class DeviceManagerUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
||||
|
||||
public static Document convertToDocument(File file) throws DeviceManagementException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new DeviceManagementException("Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve data source from the data source definition.
|
||||
*
|
||||
* @param config data source configuration
|
||||
* @return data source resolved from the data source definition
|
||||
*/
|
||||
public 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.getJndiLookupDefintion();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new device type to the database if it does not exists.
|
||||
*
|
||||
* @param deviceType device type
|
||||
* @return status of the operation
|
||||
*/
|
||||
public static boolean registerDeviceType(String deviceType) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
|
||||
if (deviceTypeId == null) {
|
||||
DeviceType dt = new DeviceType();
|
||||
dt.setName(deviceType);
|
||||
deviceTypeDAO.addDeviceType(dt);
|
||||
}
|
||||
status = true;
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while registering the device type " + deviceType;
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an existing device type from the device management metadata repository.
|
||||
*
|
||||
* @param deviceType device type
|
||||
* @return status of the operation
|
||||
*/
|
||||
public static boolean unregisterDeviceType(String deviceType) throws DeviceManagementException {
|
||||
try {
|
||||
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
Integer deviceTypeId = deviceTypeDAO.getDeviceTypeIdByDeviceTypeName(deviceType);
|
||||
if (deviceTypeId == null) {
|
||||
DeviceType dt = new DeviceType();
|
||||
dt.setName(deviceType);
|
||||
deviceTypeDAO.removeDeviceType(dt);
|
||||
}
|
||||
return true;
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while registering the device type " + deviceType;
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class DeviceManagementConfigTests {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementConfigTests.class);
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY =
|
||||
"./src/test/resources/config/malformed-cdm-config-no-mgt-repo.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG =
|
||||
"./src/test/resources/config/malformed-cdm-config-no-ds-config.xml";
|
||||
private static final String MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG =
|
||||
"./src/test/resources/config/malformed-cdm-config-no-jndi-config.xml";
|
||||
private static final String TEST_CONFIG_SCHEMA_LOCATION =
|
||||
"./src/test/resources/config/schema/DeviceManagementConfigSchema.xsd";
|
||||
|
||||
private Schema schema;
|
||||
|
||||
@BeforeClass
|
||||
private void initSchema() {
|
||||
File deviceManagementSchemaConfig = new File(DeviceManagementConfigTests.TEST_CONFIG_SCHEMA_LOCATION);
|
||||
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
try {
|
||||
schema = factory.newSchema(deviceManagementSchemaConfig);
|
||||
} catch (SAXException e) {
|
||||
Assert.fail("Invalid schema found", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testMandateManagementRepositoryElement() {
|
||||
File malformedConfig =
|
||||
new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateDataSourceConfigurationElement() {
|
||||
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandateJndiLookupDefinitionElement() {
|
||||
File malformedConfig = new File(DeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
|
||||
this.validateMalformedConfig(malformedConfig);
|
||||
}
|
||||
|
||||
private void validateMalformedConfig(File malformedConfig) {
|
||||
try {
|
||||
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
|
||||
Unmarshaller um = ctx.createUnmarshaller();
|
||||
um.setSchema(this.getSchema());
|
||||
um.unmarshal(malformedConfig);
|
||||
Assert.assertTrue(false);
|
||||
} catch (JAXBException e) {
|
||||
log.error("Error occurred while unmarsharlling device management config", e);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private Schema getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
|
||||
public class DeviceManagementRepositoryTests {
|
||||
|
||||
private DeviceManagementRepository repository;
|
||||
|
||||
@BeforeClass
|
||||
public void initRepository() {
|
||||
this.repository = new DeviceManagementRepository();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDeviceManagementService() {
|
||||
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
||||
this.getRepository().addDeviceManagementProvider(sourceProvider);
|
||||
|
||||
DeviceManagerService targetProvider =
|
||||
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
||||
|
||||
Assert.assertEquals(targetProvider.getProviderType(), sourceProvider.getProviderType());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddDeviceManagementService")
|
||||
public void testRemoveDeviceManagementService() {
|
||||
DeviceManagerService sourceProvider = new TestDeviceManagerService();
|
||||
this.getRepository().removeDeviceManagementProvider(sourceProvider);
|
||||
|
||||
DeviceManagerService targetProvider =
|
||||
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
|
||||
|
||||
Assert.assertNull(targetProvider);
|
||||
}
|
||||
|
||||
private DeviceManagementRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +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.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
public class DeviceManagementTestCase {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementTestCase.class);
|
||||
|
||||
@Test(groups = "device.mgt.test", description = "Testing the first test case with testng.")
|
||||
public void setUp() throws Exception {
|
||||
log.info("Testing started.");
|
||||
Assert.assertEquals("A", "A");
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
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.common.spi.DeviceManagerService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestDeviceManagerService implements DeviceManagerService {
|
||||
|
||||
public static final String DEVICE_TYPE_TEST = "Test";
|
||||
|
||||
@Override
|
||||
public String getProviderType() {
|
||||
return TestDeviceManagerService.DEVICE_TYPE_TEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationManager getOperationManager() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.wso2.carbon.device.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.common;
|
||||
|
||||
|
||||
public enum DBTypes {
|
||||
Oracle("Oracle"),H2("H2"),MySql("MySql");
|
||||
|
||||
String dbName ;
|
||||
DBTypes(String dbStrName) {
|
||||
dbName = dbStrName;
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DBType")
|
||||
public class TestDBConfiguration {
|
||||
|
||||
private String connectionUrl;
|
||||
private String driverClass;
|
||||
private String userName;
|
||||
private String pwd;
|
||||
|
||||
@Override public String toString() {
|
||||
return "TestDBConfiguration{" +
|
||||
"connectionUrl='" + connectionUrl + '\'' +
|
||||
", driverClass='" + driverClass + '\'' +
|
||||
", userName='" + userName + '\'' +
|
||||
", pwd='" + pwd + '\'' +
|
||||
", dbType='" + dbType + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
private String dbType;
|
||||
|
||||
@XmlElement(name = "connectionurl", nillable = false)
|
||||
public String getConnectionUrl() {
|
||||
return connectionUrl;
|
||||
}
|
||||
|
||||
public void setConnectionUrl(String connectionUrl) {
|
||||
this.connectionUrl = connectionUrl;
|
||||
}
|
||||
|
||||
@XmlElement(name = "driverclass", nillable = false)
|
||||
public String getDriverClass() {
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
public void setDriverClass(String driverClass) {
|
||||
this.driverClass = driverClass;
|
||||
}
|
||||
|
||||
@XmlElement(name = "userName", nillable = false)
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
@XmlElement(name = "pwd", nillable = false)
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
@XmlAttribute(name = "typeName")
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.common;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "DeviceMgtTestDBConfigurations")
|
||||
public class TestDBConfigurations {
|
||||
|
||||
private List<TestDBConfiguration> dbTypesList;
|
||||
|
||||
@XmlElement(name = "DBType")
|
||||
public List<TestDBConfiguration> getDbTypesList() {
|
||||
return dbTypesList;
|
||||
}
|
||||
|
||||
public void setDbTypesList(List<TestDBConfiguration> dbTypesList) {
|
||||
this.dbTypesList = dbTypesList;
|
||||
}
|
||||
|
||||
}
|
@ -1,177 +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.dao;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.TestUtils;
|
||||
import org.wso2.carbon.device.mgt.core.common.DBTypes;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDBConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.common.TestDBConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.dto.OwnerShip;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Status;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.Date;
|
||||
|
||||
public class DeviceManagementDAOTests {
|
||||
|
||||
@BeforeClass
|
||||
@Parameters("dbType")
|
||||
public void setUpDB(String dbTypeStr) throws Exception {
|
||||
DBTypes dbType = DBTypes.valueOf(dbTypeStr);
|
||||
TestDBConfiguration dbConfig = getTestDBConfiguration(dbType);
|
||||
|
||||
switch (dbType) {
|
||||
case H2:
|
||||
createH2DB(dbConfig);
|
||||
BasicDataSource testDataSource = new BasicDataSource();
|
||||
testDataSource.setDriverClassName(dbConfig.getDriverClass());
|
||||
testDataSource.setUrl(dbConfig.getConnectionUrl());
|
||||
testDataSource.setUsername(dbConfig.getUserName());
|
||||
testDataSource.setPassword(dbConfig.getPwd());
|
||||
DeviceManagementDAOFactory.init(testDataSource);
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
private TestDBConfiguration getTestDBConfiguration(DBTypes dbType) throws DeviceManagementDAOException,
|
||||
DeviceManagementException {
|
||||
File deviceMgtConfig = new File("src/test/resources/testdbconfig.xml");
|
||||
Document doc;
|
||||
TestDBConfigurations dbConfigs;
|
||||
|
||||
doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
|
||||
JAXBContext testDBContext = null;
|
||||
|
||||
try {
|
||||
testDBContext = JAXBContext.newInstance(TestDBConfigurations.class);
|
||||
Unmarshaller unmarshaller = testDBContext.createUnmarshaller();
|
||||
dbConfigs = (TestDBConfigurations) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementDAOException("Error parsing test db configurations", e);
|
||||
}
|
||||
|
||||
for (TestDBConfiguration config : dbConfigs.getDbTypesList()) {
|
||||
if (config.getDbType().equals(dbType.toString())) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void createH2DB(TestDBConfiguration testDBConf) throws Exception {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
Class.forName(testDBConf.getDriverClass());
|
||||
conn = DriverManager.getConnection(testDBConf.getConnectionUrl());
|
||||
stmt = conn.createStatement();
|
||||
stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/CreateH2TestDB.sql'");
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDeviceTypeTest() throws DeviceManagementDAOException, DeviceManagementException {
|
||||
DeviceTypeDAO deviceTypeMgtDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
|
||||
DeviceType deviceType = new DeviceType();
|
||||
deviceType.setName("IOS");
|
||||
|
||||
deviceTypeMgtDAO.addDeviceType(deviceType);
|
||||
Long deviceTypeId = null;
|
||||
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
try {
|
||||
conn = DeviceManagementDAOFactory.getDataSource().getConnection();
|
||||
stmt = conn.createStatement();
|
||||
ResultSet resultSet =
|
||||
stmt.executeQuery("SELECT ID,NAME from DM_DEVICE_TYPE DType where DType.NAME='IOS'");
|
||||
|
||||
while (resultSet.next()) {
|
||||
deviceTypeId = resultSet.getLong(1);
|
||||
}
|
||||
} catch (SQLException sqlEx) {
|
||||
throw new DeviceManagementDAOException("error in fetch device type by name IOS", sqlEx);
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
|
||||
Assert.assertNotNull(deviceTypeId, "Device Type Id is null");
|
||||
deviceType.setId(deviceTypeId);
|
||||
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"addDeviceTypeTest"})
|
||||
public void addDeviceTest() throws DeviceManagementDAOException, DeviceManagementException {
|
||||
DeviceDAO deviceMgtDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
|
||||
Device device = new Device();
|
||||
device.setDateOfEnrollment(new Date().getTime());
|
||||
device.setDateOfLastUpdate(new Date().getTime());
|
||||
device.setDescription("test description");
|
||||
device.setStatus(Status.ACTIVE);
|
||||
device.setDeviceIdentificationId("111");
|
||||
|
||||
DeviceType deviceType = new DeviceType();
|
||||
deviceType.setId(Long.parseLong("1"));
|
||||
|
||||
device.setDeviceTypeId(deviceType.getId().intValue());
|
||||
device.setOwnerShip(OwnerShip.BYOD.toString());
|
||||
device.setOwnerId("111");
|
||||
device.setTenantId(-1234);
|
||||
deviceMgtDAO.addDevice(device);
|
||||
|
||||
Long deviceId = null;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = DeviceManagementDAOFactory.getDataSource().getConnection();
|
||||
stmt = conn.prepareStatement("SELECT ID from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION='111'");
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
deviceId = rs.getLong(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("error in fetch device by device identification id", e);
|
||||
} finally {
|
||||
TestUtils.cleanupResources(conn, stmt, rs);
|
||||
}
|
||||
|
||||
Assert.assertNotNull(deviceId, "Device Id is null");
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<MalformedDataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</MalformedDataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<MalformedJndiLookupDefinition>
|
||||
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||
</MalformedJndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<MalformedManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/DEVICE_MGT_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</MalformedManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~ 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.
|
||||
-->
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xs:element name="DeviceMgtConfiguration">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="ManagementRepository" minOccurs="1" maxOccurs="1" type="DataSourceConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:complexType name="JndiLookupDefinitionType">
|
||||
<xs:sequence>
|
||||
<xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="DataSourceConfigurationType">
|
||||
<xs:sequence>
|
||||
<xs:element name="JndiLookupDefinition" minOccurs="1" maxOccurs="1"
|
||||
type="JndiLookupDefinitionType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:complexType name="ManagementRepositoryType">
|
||||
<xs:sequence>
|
||||
<xs:element name="DataSourceConfiguration" minOccurs="1" maxOccurs="1"
|
||||
type="DataSourceConfigurationType"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:schema>
|
@ -1,24 +0,0 @@
|
||||
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 INT 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
|
||||
);
|
@ -1,24 +0,0 @@
|
||||
<?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.
|
||||
~ 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="H2">
|
||||
<connectionurl>jdbc:h2:mem:cdm-test-db;DB_CLOSE_DELAY=-1</connectionurl>
|
||||
<driverclass>org.h2.Driver</driverclass>
|
||||
<userName></userName>
|
||||
<pwd></pwd>
|
||||
</DBType>
|
||||
</DeviceMgtTestDBConfigurations>
|
@ -1,29 +0,0 @@
|
||||
<!--
|
||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||
~ Version 2.0 (the "License"); you may not use this file except
|
||||
~ in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~ http://www.apache.org/licenses/LICENSE-2.
|
||||
~ 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="EMM-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.device.mgt.core.dao.DeviceManagementDAOTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementRepositoryTests"/>
|
||||
<class name="org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
@ -1,88 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>policy-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.evaluator</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Policy Decision Point</name>
|
||||
<description>WSO2 Carbon - Policy Decision Point</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>Policy Management Common Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.policy.evaluator</Private-Package>
|
||||
<Import-Package>
|
||||
org.apache.commons.logging
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.policy.evaluator.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FeatureFilter {
|
||||
|
||||
List<Feature> evaluate(List<Policy> policyList, List<FeatureRules> featureRulesList);
|
||||
|
||||
List<Feature> extractFeatures(List<Policy> policyList);
|
||||
|
||||
List<Feature> evaluateFeatures(List<Feature> featureList, List<FeatureRules> featureRulesList);
|
||||
|
||||
void getDenyOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getPermitOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getFirstApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getLastApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getAllApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getHighestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
|
||||
void getLowestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList);
|
||||
}
|
@ -1,250 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.evaluator.utils.Constants;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is responsible for evaluating the policy (Configurations sets) and returning
|
||||
* the effective features set.
|
||||
*/
|
||||
|
||||
public class FeatureFilterImpl implements FeatureFilter {
|
||||
|
||||
/**
|
||||
* This method returns the effective feature list when policy list and feature aggregation rules are supplied.
|
||||
* @param policyList
|
||||
* @param featureRulesList
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Feature> evaluate(List<Policy> policyList, List<FeatureRules> featureRulesList) {
|
||||
return evaluateFeatures(extractFeatures(policyList), featureRulesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method extract the features from the given policy list in the order they are provided in the list.
|
||||
* @param policyList
|
||||
* @return
|
||||
*/
|
||||
public List<Feature> extractFeatures(List<Policy> policyList) {
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
for (Policy policy : policyList) {
|
||||
featureList.addAll(policy.getFeaturesList());
|
||||
}
|
||||
return featureList;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is responsible for supplying tasks to other methods to evaluate given features.
|
||||
* @param featureList
|
||||
* @param featureRulesList
|
||||
* @return
|
||||
*/
|
||||
public List<Feature> evaluateFeatures(List<Feature> featureList, List<FeatureRules> featureRulesList) {
|
||||
List<Feature> effectiveFeatureList = new ArrayList<Feature>();
|
||||
for (FeatureRules rule : featureRulesList) {
|
||||
String ruleName = rule.getEvaluationCriteria();
|
||||
String featureName = rule.getName();
|
||||
if (ruleName.equalsIgnoreCase(Constants.DENY_OVERRIDES)) {
|
||||
getDenyOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.PERMIT_OVERRIDES)) {
|
||||
getPermitOverridesFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.FIRST_APPLICABLE)) {
|
||||
getFirstApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.LAST_APPLICABLE)) {
|
||||
getLastApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.ALL_APPLICABLE)) {
|
||||
getAllApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.HIGHEST_APPLICABLE)) {
|
||||
getHighestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
if (ruleName.equalsIgnoreCase(Constants.LOWEST_APPLICABLE)) {
|
||||
getLowestApplicableFeatures(featureName, featureList, effectiveFeatureList);
|
||||
}
|
||||
}
|
||||
return effectiveFeatureList;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks up denied features, if there is no denied features it will add to the list, the final permitted feature.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getDenyOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (feature.getRuleValue().equalsIgnoreCase("Deny")) {
|
||||
evaluatedFeature = feature;
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
return;
|
||||
} else {
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks up permitted features, if there is no permitted features it will add to the list, the final denied feature.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getPermitOverridesFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (feature.getRuleValue().equalsIgnoreCase("Permit")) {
|
||||
evaluatedFeature = feature;
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
return;
|
||||
} else {
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the first features of the give type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getFirstApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
effectiveFeatureList.add(feature);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the last features of the give type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getLastApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the all features of the give type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getAllApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
effectiveFeatureList.add(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the feature with the highest value of given type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getHighestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
int intValve = 0;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (Integer.parseInt(feature.getRuleValue()) > intValve) {
|
||||
intValve = Integer.parseInt(feature.getRuleValue());
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method picks the feature with the lowest value of given type.
|
||||
* But if given policies do not have features of given type, it will not add anything.
|
||||
*
|
||||
* @param featureName
|
||||
* @param featureList
|
||||
* @param effectiveFeatureList
|
||||
*/
|
||||
public void getLowestApplicableFeatures(String featureName, List<Feature> featureList, List<Feature> effectiveFeatureList) {
|
||||
Feature evaluatedFeature = null;
|
||||
int intValve = 0;
|
||||
for (Feature feature : featureList) {
|
||||
if (feature.getName().equalsIgnoreCase(featureName)) {
|
||||
if (Integer.parseInt(feature.getRuleValue()) < intValve) {
|
||||
intValve = Integer.parseInt(feature.getRuleValue());
|
||||
evaluatedFeature = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evaluatedFeature != null) {
|
||||
effectiveFeatureList.add(evaluatedFeature);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
public class FeatureRules {
|
||||
|
||||
private String name;
|
||||
private String evaluationCriteria;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEvaluationCriteria() {
|
||||
return evaluationCriteria;
|
||||
}
|
||||
|
||||
public void setEvaluationCriteria(String evaluationCriteria) {
|
||||
this.evaluationCriteria = evaluationCriteria;
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
public class PDPException extends Exception {
|
||||
|
||||
private String pdpErrorMessage;
|
||||
|
||||
public String getPdpErrorMessage() {
|
||||
return pdpErrorMessage;
|
||||
}
|
||||
|
||||
public void setPdpErrorMessage(String pdpErrorMessage) {
|
||||
this.pdpErrorMessage = pdpErrorMessage;
|
||||
}
|
||||
|
||||
public PDPException(String message) {
|
||||
setPdpErrorMessage(message);
|
||||
}
|
||||
|
||||
public PDPException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setPdpErrorMessage(message);
|
||||
}
|
||||
|
||||
public PDPException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setPdpErrorMessage(message);
|
||||
}
|
||||
|
||||
public PDPException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public PDPException(){
|
||||
super();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.evaluator.spi.PDPService;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PDPServiceImpl implements PDPService {
|
||||
@Override
|
||||
public List<Policy> getEffectivePolicyList(List<Policy> policies, List<String> roles, String deviceType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getEffectiveFeatureList(List<Policy> policies, List<FeatureRules> featureRulesList) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyFilter {
|
||||
|
||||
/**
|
||||
* This method will extract the policies related a given roles list from the policy list available.
|
||||
* @param policyList
|
||||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
public List<Policy> extractPoliciesRelatedToRoles(List<Policy> policyList, List<String> roles);
|
||||
|
||||
/**
|
||||
* This mehtod extract the policies related to a given device type from policy list.
|
||||
* @param policyList
|
||||
* @param deviceType
|
||||
* @return
|
||||
*/
|
||||
public List<Policy> extractPoliciesRelatedToDeviceType(List<Policy> policyList, String deviceType);
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.evaluator;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyFilterImpl implements PolicyFilter {
|
||||
|
||||
|
||||
/**
|
||||
* This method will extract the policies related a given roles list from the policy list available.
|
||||
*
|
||||
* @param policyList
|
||||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Policy> extractPoliciesRelatedToRoles(List<Policy> policyList, List<String> roles) {
|
||||
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
|
||||
for (Policy policy : policyList) {
|
||||
List<String> roleList = policy.getRoleList();
|
||||
|
||||
for (String role : roleList) {
|
||||
if (roles.contains(role)) {
|
||||
policies.add(policy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
||||
/**
|
||||
* This mehtod extract the policies related to a given device type from policy list.
|
||||
*
|
||||
* @param policyList
|
||||
* @param deviceType
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Policy> extractPoliciesRelatedToDeviceType(List<Policy> policyList, String deviceType) {
|
||||
List<Policy> policies = new ArrayList<Policy>();
|
||||
|
||||
for (Policy policy : policyList) {
|
||||
if (policy.getDeviceType().equalsIgnoreCase(deviceType)) {
|
||||
policies.add(policy);
|
||||
}
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
}
|
@ -1,34 +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.evaluator.spi;
|
||||
|
||||
|
||||
import org.wso2.carbon.policy.evaluator.FeatureRules;
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PDPService {
|
||||
|
||||
List<Policy> getEffectivePolicyList(List<Policy> policies, List<String> roles, String deviceType);
|
||||
|
||||
List<Feature> getEffectiveFeatureList(List<Policy> policies, List<FeatureRules> featureRulesList);
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.evaluator.utils;
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String DENY_OVERRIDES="deny_overrides";
|
||||
public static final String PERMIT_OVERRIDES="permit_overrides";
|
||||
public static final String FIRST_APPLICABLE="first_applicable";
|
||||
public static final String LAST_APPLICABLE="last_applicable";
|
||||
public static final String ALL_APPLICABLE="all_applicable";
|
||||
public static final String HIGHEST_APPLICABLE="highest_applicable";
|
||||
public static final String LOWEST_APPLICABLE="lowest_applicable";
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>policy-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Policy Management Common</name>
|
||||
<description>WSO2 Carbon - Policy Management Common</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>Policy Management Common Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.policy.mgt.common.internal</Private-Package>
|
||||
<Import-Package>
|
||||
org.apache.commons.logging
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
org.wso2.carbon.policy.mgt.common.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
public class Feature {
|
||||
|
||||
private int id;
|
||||
private String code;
|
||||
private String name;
|
||||
private Object attribute;
|
||||
private String ruleValue;
|
||||
|
||||
public String getRuleValue() {
|
||||
return ruleValue;
|
||||
}
|
||||
|
||||
public void setRuleValue(String ruleValue) {
|
||||
this.ruleValue = ruleValue;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Object getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
public void setAttribute(Object attribute) {
|
||||
this.attribute = attribute;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
public class FeatureManagementException extends Exception{
|
||||
|
||||
private String errorMessage;
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public FeatureManagementException(String message) {
|
||||
super(message);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public FeatureManagementException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public FeatureManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setErrorMessage(message);
|
||||
}
|
||||
|
||||
public FeatureManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FeatureManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FeatureManagerService {
|
||||
|
||||
void addFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
void editFeature(Feature feature) throws FeatureManagementException;
|
||||
|
||||
void removeFeature(int featureId) throws FeatureManagementException;
|
||||
|
||||
List<Feature> getFeatures() throws FeatureManagementException;
|
||||
|
||||
List<Feature> getFeaturesOfPolicy(int policyId) throws FeatureManagementException;
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Policy {
|
||||
private int id;
|
||||
private String policyName;
|
||||
private List<Feature> featuresList;
|
||||
private boolean generic;
|
||||
private List<String> roleList;
|
||||
private List<String> DeviceList;
|
||||
private String deviceType;
|
||||
|
||||
public List<String> getRoleList() {
|
||||
return roleList;
|
||||
}
|
||||
|
||||
public void setRoleList(List<String> roleList) {
|
||||
this.roleList = roleList;
|
||||
}
|
||||
|
||||
public List<String> getDeviceList() {
|
||||
return DeviceList;
|
||||
}
|
||||
|
||||
public void setDeviceList(List<String> deviceList) {
|
||||
DeviceList = deviceList;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public boolean isGeneric() {
|
||||
return generic;
|
||||
}
|
||||
|
||||
public void setGeneric(boolean generic) {
|
||||
this.generic = generic;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPolicyName() {
|
||||
return policyName;
|
||||
}
|
||||
|
||||
public void setPolicyName(String policyName) {
|
||||
this.policyName = policyName;
|
||||
}
|
||||
|
||||
public List<Feature> getFeaturesList() {
|
||||
return featuresList;
|
||||
}
|
||||
|
||||
public void setFeaturesList(List<Feature> featuresList) {
|
||||
this.featuresList = featuresList;
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
public class PolicyManagementException extends Exception {
|
||||
|
||||
private String policyErrorMessage;
|
||||
|
||||
public String getPolicyErrorMessage() {
|
||||
return policyErrorMessage;
|
||||
}
|
||||
|
||||
public void setPolicyErrorMessage(String policyErrorMessage) {
|
||||
this.policyErrorMessage = policyErrorMessage;
|
||||
}
|
||||
|
||||
public PolicyManagementException(String message) {
|
||||
super(message);
|
||||
setPolicyErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyManagementException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setPolicyErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyManagementException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setPolicyErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyManagementException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PolicyManagementException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
/**
|
||||
* This interface defines the policy management which should be implemented by the plugins
|
||||
*/
|
||||
|
||||
public interface PolicyManagerService {
|
||||
|
||||
/**
|
||||
* This method adds a policy to the platform
|
||||
*
|
||||
* @param policy
|
||||
* @return primary key (generated key)
|
||||
*/
|
||||
|
||||
int addPolicy(Policy policy);
|
||||
|
||||
/**
|
||||
* This method adds a policy per device which should be implemented by the related plugins.
|
||||
*
|
||||
* @param deviceId
|
||||
* @param deviceType
|
||||
* @param policy
|
||||
* @return primary key (generated key)
|
||||
*/
|
||||
|
||||
int 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.
|
||||
*
|
||||
* @param roleName
|
||||
* @param policy
|
||||
* @return primary key (generated key)
|
||||
*/
|
||||
int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException;
|
||||
|
||||
/**
|
||||
* This method returns the policy of whole platform
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
Policy getPolicy();
|
||||
|
||||
/**
|
||||
* This method gives the device specific policy.
|
||||
*
|
||||
* @param deviceId
|
||||
* @param deviceType
|
||||
* @return Policy
|
||||
*/
|
||||
|
||||
Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException;
|
||||
|
||||
/**
|
||||
* This method returns the device type specific policy.
|
||||
*
|
||||
* @param deviceType
|
||||
* @return Policy
|
||||
*/
|
||||
|
||||
Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException;
|
||||
|
||||
/**
|
||||
* This method returns the role specific policy.
|
||||
*
|
||||
* @param roleName
|
||||
* @return
|
||||
*/
|
||||
|
||||
Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException;
|
||||
|
||||
|
||||
boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException;
|
||||
|
||||
|
||||
boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException;
|
||||
|
||||
|
||||
void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
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.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagerService;
|
||||
|
||||
public class PolicyManagement implements PolicyManagerService {
|
||||
@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 {
|
||||
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wos2.carbon.policy.mgt.common.utils;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyCreator {
|
||||
|
||||
private static Policy policy = new Policy();
|
||||
|
||||
public static Policy createPolicy() {
|
||||
|
||||
Feature feature = new Feature();
|
||||
feature.setName("Camera");
|
||||
feature.setCode("502A");
|
||||
feature.setAttribute("disable");
|
||||
|
||||
List<Feature> featureList = new ArrayList<Feature>();
|
||||
featureList.add(feature);
|
||||
|
||||
policy.setFeaturesList(featureList);
|
||||
policy.setPolicyName("Camera_related_policy");
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>policy-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.mgt.core</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Policy Management Core</name>
|
||||
<description>WSO2 Carbon - Policy Management Core</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Description>Policy Management Core Bundle</Bundle-Description>
|
||||
<Private-Package>org.wso2.carbon.policy.mgt.core.internal</Private-Package>
|
||||
<Import-Package>
|
||||
org.apache.axis2.*;
|
||||
version="${axis2.osgi.version.range}",
|
||||
org.osgi.framework,
|
||||
org.osgi.service.component,
|
||||
org.apache.commons.logging,
|
||||
</Import-Package>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.policy.mgt.core.internal,
|
||||
org.wso2.carbon.policy.mgt.core.*
|
||||
</Export-Package>
|
||||
<DynamicImport-Package>*</DynamicImport-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.policy.mgt.common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.ndatasource.rdbms</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
<version>${carbon.kernel.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.config;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Class responsible for the rss manager configuration initialization
|
||||
*/
|
||||
public class PolicyConfigurationManager {
|
||||
|
||||
private PolicyManagementConfig currentPolicyConfig;
|
||||
private static PolicyConfigurationManager policyConfigurationManager;
|
||||
|
||||
private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
|
||||
PolicyManagementConstants.DEVICE_CONFIG_XML_NAME;
|
||||
|
||||
public static PolicyConfigurationManager getInstance() {
|
||||
if (policyConfigurationManager == null) {
|
||||
synchronized (PolicyConfigurationManager.class) {
|
||||
if (policyConfigurationManager == null) {
|
||||
policyConfigurationManager = new PolicyConfigurationManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return policyConfigurationManager;
|
||||
}
|
||||
|
||||
public synchronized void initConfig() throws PolicyManagementException {
|
||||
try {
|
||||
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
|
||||
Document doc = PolicyManagerUtil.convertToDocument(deviceMgtConfig);
|
||||
|
||||
/* Un-marshaling Device Management configuration */
|
||||
JAXBContext rssContext = JAXBContext.newInstance(PolicyManagementConfig.class);
|
||||
Unmarshaller unmarshaller = rssContext.createUnmarshaller();
|
||||
this.currentPolicyConfig = (PolicyManagementConfig) unmarshaller.unmarshal(doc);
|
||||
} catch (Exception e) {
|
||||
throw new PolicyManagementException("Error occurred while initializing RSS config", e);
|
||||
}
|
||||
}
|
||||
|
||||
public PolicyManagementConfig getPolicyManagementConfig() {
|
||||
return currentPolicyConfig;
|
||||
}
|
||||
|
||||
public DataSourceConfig getDataSourceConfig() {
|
||||
return currentPolicyConfig.getPolicyManagementRepository().getDataSourceConfig();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Represents Device Mgt configuration.
|
||||
*/
|
||||
@XmlRootElement(name = "DeviceMgtConfiguration")
|
||||
public final class PolicyManagementConfig {
|
||||
|
||||
public void setPolicyManagementRepository(PolicyManagementRepository policyManagementRepository) {
|
||||
this.policyManagementRepository = policyManagementRepository;
|
||||
}
|
||||
|
||||
private PolicyManagementRepository policyManagementRepository;
|
||||
|
||||
@XmlElement(name = "ManagementRepository", nillable = false)
|
||||
public PolicyManagementRepository getPolicyManagementRepository() {
|
||||
return policyManagementRepository;
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.config;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding management repository data
|
||||
*/
|
||||
@XmlRootElement(name = "ManagementRepository")
|
||||
public class PolicyManagementRepository {
|
||||
|
||||
private DataSourceConfig dataSourceConfig;
|
||||
|
||||
@XmlElement(name = "DataSourceConfiguration", nillable = false)
|
||||
public DataSourceConfig getDataSourceConfig() {
|
||||
return dataSourceConfig;
|
||||
}
|
||||
|
||||
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
|
||||
this.dataSourceConfig = dataSourceConfig;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.config.datasource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding data source configuration in rss-config.xml at parsing with JAXB
|
||||
*/
|
||||
@XmlRootElement(name = "DataSourceConfiguration")
|
||||
public class DataSourceConfig {
|
||||
|
||||
private JNDILookupDefinition jndiLookupDefinition;
|
||||
|
||||
@XmlElement(name = "JndiLookupDefinition", nillable = true)
|
||||
public JNDILookupDefinition getJndiLookupDefinition() {
|
||||
return jndiLookupDefinition;
|
||||
}
|
||||
|
||||
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
|
||||
this.jndiLookupDefinition = jndiLookupDefinition;
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.config.datasource;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB
|
||||
*/
|
||||
@XmlRootElement(name = "JndiLookupDefinition")
|
||||
public class JNDILookupDefinition {
|
||||
|
||||
private String jndiName;
|
||||
private List<JNDIProperty> jndiProperties;
|
||||
|
||||
@XmlElement(name = "Name", nillable = false)
|
||||
public String getJndiName() {
|
||||
return jndiName;
|
||||
}
|
||||
|
||||
public void setJndiName(String jndiName) {
|
||||
this.jndiName = jndiName;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "Environment", nillable = false)
|
||||
@XmlElement(name = "Property", nillable = false)
|
||||
public List<JNDIProperty> getJndiProperties() {
|
||||
return jndiProperties;
|
||||
}
|
||||
|
||||
public void setJndiProperties(List<JNDIProperty> jndiProperties) {
|
||||
this.jndiProperties = jndiProperties;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "Property")
|
||||
public static class JNDIProperty {
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
@XmlAttribute(name = "Name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
public interface PolicyDAO {
|
||||
|
||||
int addPolicy(Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
Policy getPolicy() throws PolicyManagerDAOException;
|
||||
|
||||
Policy getPolicy(String deviceType) throws PolicyManagerDAOException;
|
||||
|
||||
Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException;
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyManagementDAOFactory {
|
||||
|
||||
private static DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(PolicyManagementDAOFactory.class);
|
||||
|
||||
|
||||
public static PolicyDAO getDeviceTypeDAO() {
|
||||
return new PolicyDAOImpl(dataSource);
|
||||
}
|
||||
|
||||
public static void init(DataSourceConfig config) {
|
||||
dataSource = resolveDataSource(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 =
|
||||
PolicyManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||
} else {
|
||||
dataSource = PolicyManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||
}
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao;
|
||||
|
||||
public class PolicyManagerDAOException extends Exception{
|
||||
|
||||
private String policyDAOErrorMessage;
|
||||
|
||||
public String getPolicyDAOErrorMessage() {
|
||||
return policyDAOErrorMessage;
|
||||
}
|
||||
|
||||
public void setPolicyDAOErrorMessage(String policyDAOErrorMessage) {
|
||||
this.policyDAOErrorMessage = policyDAOErrorMessage;
|
||||
}
|
||||
|
||||
public PolicyManagerDAOException(String message) {
|
||||
super(message);
|
||||
setPolicyDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyManagerDAOException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setPolicyDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyManagerDAOException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setPolicyDAOErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyManagerDAOException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PolicyManagerDAOException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
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.Policy;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
private static DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(PolicyDAOImpl.class);
|
||||
|
||||
public PolicyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicy(Policy policy) throws PolicyManagerDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePolicy(int id, Policy policy) throws PolicyManagerDAOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy() throws PolicyManagerDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy(String deviceType) throws PolicyManagerDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws PolicyManagerDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
throw new PolicyManagerDAOException("Error occurred while obtaining a connection from the policy " +
|
||||
"management metadata repository datasource", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.dao.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class PolicyManagementDAOUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyManagementDAOUtil.class);
|
||||
|
||||
public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) {
|
||||
try {
|
||||
if (jndiProperties == null || jndiProperties.isEmpty()) {
|
||||
return (DataSource) InitialContext.doLookup(dataSourceName);
|
||||
}
|
||||
final InitialContext context = new InitialContext(jndiProperties);
|
||||
return (DataSource) context.doLookup(dataSourceName);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanupResources(Connection conn, PreparedStatement 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.internal;
|
||||
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||
|
||||
public class PolicyManagementDataHolder {
|
||||
|
||||
private RealmService realmService;
|
||||
private TenantManager tenantManager;
|
||||
private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder();
|
||||
|
||||
private PolicyManagementDataHolder() {}
|
||||
|
||||
public static PolicyManagementDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public RealmService getRealmService() {
|
||||
return realmService;
|
||||
}
|
||||
|
||||
public void setRealmService(RealmService realmService) {
|
||||
this.realmService = realmService;
|
||||
this.setTenantManager(realmService);
|
||||
}
|
||||
|
||||
private void setTenantManager(RealmService realmService) {
|
||||
if (realmService == null) {
|
||||
throw new IllegalStateException("Realm service is not initialized properly");
|
||||
}
|
||||
this.tenantManager = realmService.getTenantManager();
|
||||
}
|
||||
|
||||
public TenantManager getTenantManager() {
|
||||
return tenantManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
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.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.user.core.service.RealmService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.policy.manager" immediate="true"
|
||||
* @scr.reference name="user.realmservice.default"
|
||||
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setRealmService"
|
||||
* unbind="unsetRealmService"
|
||||
*/
|
||||
|
||||
public class PolicyManagementServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(PolicyManagementServiceComponent.class);
|
||||
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
|
||||
try {
|
||||
PolicyConfigurationManager.getInstance().initConfig();
|
||||
PolicyManagementConfig config = PolicyConfigurationManager.getInstance().getPolicyManagementConfig();
|
||||
DataSourceConfig dsConfig = config.getPolicyManagementRepository().getDataSourceConfig();
|
||||
PolicyManagementDAOFactory.init(dsConfig);
|
||||
|
||||
} catch (Throwable t) {
|
||||
String msg = "Error occurred while initializing the Policy management core.";
|
||||
log.error(msg, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets Realm Service
|
||||
*
|
||||
* @param realmService An instance of RealmService
|
||||
*/
|
||||
protected void setRealmService(RealmService realmService) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Realm Service");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().setRealmService(realmService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets Realm Service
|
||||
*
|
||||
* @param realmService An instance of RealmService
|
||||
*/
|
||||
protected void unsetRealmService(RealmService realmService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting Realm Service");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().setRealmService(null);
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.util;
|
||||
|
||||
public final class PolicyManagementConstants {
|
||||
public static final String DEVICE_CONFIG_XML_NAME = "cdm-config.xml";
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyManagerUtil {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyManagerUtil.class);
|
||||
|
||||
public static Document convertToDocument(File file) throws PolicyManagementException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new PolicyManagementException("Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve data source from the data source definition
|
||||
*
|
||||
* @param config data source configuration
|
||||
* @return data source resolved from the data source definition
|
||||
*/
|
||||
public 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 =
|
||||
PolicyManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
||||
} else {
|
||||
dataSource = PolicyManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
||||
}
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>wso2cdm-parent</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>policy-mgt</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - Policy Management Component</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<modules>
|
||||
<module>org.wso2.carbon.policy.mgt.core</module>
|
||||
<module>org.wso2.carbon.policy.mgt.common</module>
|
||||
<module>org.wso2.carbon.policy.evalutor</module>
|
||||
</modules>
|
||||
|
||||
<!-- <dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
<version>3.8.1.v20120830-144521</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
<version>3.6.100.v20120522-1841</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
<version>4.3.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>-->
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-scr-plugin</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-scr-scrdescriptor</id>
|
||||
<goals>
|
||||
<goal>scr</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -1,124 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<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/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>device-mgt-feature</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.server.feature</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<name>WSO2 Carbon - Device Management Server Feature</name>
|
||||
<url>http://wso2.org</url>
|
||||
<description>This feature contains the core bundles required for Back-end Devvice Management functionality
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>src/main/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<includes>
|
||||
<include>build.properties</include>
|
||||
<include>p2.inf</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.wso2.maven</groupId>
|
||||
<artifactId>carbon-p2-plugin</artifactId>
|
||||
<version>${carbon.p2.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>p2-feature-generation</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-feature-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<id>org.wso2.carbon.device.mgt.server</id>
|
||||
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||
<adviceFile>
|
||||
<properties>
|
||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||
</properties>
|
||||
</adviceFile>
|
||||
<bundles>
|
||||
<bundleDef>org.wso2.carbon:org.wso2.carbon.device.mgt.core:${project.version}
|
||||
</bundleDef>
|
||||
<bundleDef>org.wso2.carbon:org.wso2.carbon.device.mgt.common:${project.version}
|
||||
</bundleDef>
|
||||
</bundles>
|
||||
<importFeatures>
|
||||
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
|
||||
</importFeatureDef>
|
||||
</importFeatures>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1 +0,0 @@
|
||||
custom = true
|
@ -1,26 +0,0 @@
|
||||
<?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.
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/DM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue