forked from community/device-mgt-core
parent
04396cd7b3
commit
d6090dd812
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2016, 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>
|
||||
<artifactId>device-mgt-extensions</artifactId>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<version>1.2.6-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions.device.type.deployer</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<name>WSO2 Carbon - Device Type Deployer</name>
|
||||
<description>WSO2 Carbon - Device Type Deployer Implementation</description>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis2.wso2</groupId>
|
||||
<artifactId>axis2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon</groupId>
|
||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||
<Bundle-Description>Device Type Deployer Bundle</Bundle-Description>
|
||||
<Export-Package>
|
||||
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.internal,
|
||||
org.wso2.carbon.device.mgt.extensions.device.type.deployer.*
|
||||
</Export-Package>
|
||||
<Import-Package>
|
||||
|
||||
</Import-Package>
|
||||
<Axis2Deployer>DeviceTypeDeployer</Axis2Deployer>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer;
|
||||
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.deployment.AbstractDeployer;
|
||||
import org.apache.axis2.deployment.DeploymentException;
|
||||
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.internal.DeviceTypeManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.DeviceTypeConfigIdentifier;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.DeviceTypeManagerService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.util.DeviceTypeConfigUtil;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
public class DeviceTypeDeployer extends AbstractDeployer {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceTypeDeployer.class);
|
||||
private ConfigurationContext configurationContext;
|
||||
protected Map<String, ServiceRegistration> deviceTypeServiceRegistrations = new ConcurrentHashMap();
|
||||
protected Map<String, DeviceTypeConfigIdentifier> deviceTypeConfigurationDataMap = new ConcurrentHashMap();
|
||||
|
||||
@Override
|
||||
public void init(ConfigurationContext configurationContext) {
|
||||
this.configurationContext = configurationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectory(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtension(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
|
||||
try {
|
||||
DeviceManagementConfiguration deviceManagementConfiguration = getDeviceTypeConfiguration(
|
||||
deploymentFileData.getFile().getAbsoluteFile());
|
||||
String deviceType = deviceManagementConfiguration.getDeviceType();
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
if (deviceType != null && !deviceType.isEmpty() && tenantDomain != null
|
||||
&& !tenantDomain.isEmpty()) {
|
||||
DeviceTypeConfigIdentifier deviceTypeConfigIdentifier = new DeviceTypeConfigIdentifier(deviceType,
|
||||
tenantDomain);
|
||||
ServiceRegistration serviceRegistration = registerDeviceType(deviceTypeConfigIdentifier,
|
||||
deviceManagementConfiguration);
|
||||
this.deviceTypeServiceRegistrations.put(deploymentFileData.getAbsolutePath(), serviceRegistration);
|
||||
this.deviceTypeConfigurationDataMap.put(deploymentFileData.getAbsolutePath(),
|
||||
deviceTypeConfigIdentifier);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Cannot deploy deviceType : " + deploymentFileData.getName(), e);
|
||||
throw new DeploymentException("Device type file " + deploymentFileData.getName() + " is not deployed ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy(String filePath) throws DeploymentException {
|
||||
DeviceTypeConfigIdentifier deviceTypeConfigIdentifier = this.deviceTypeConfigurationDataMap.get(filePath);
|
||||
unregisterDeviceType(filePath);
|
||||
this.deviceTypeConfigurationDataMap.remove(filePath);
|
||||
log.info("Device Type undeployed successfully : " + deviceTypeConfigIdentifier.getDeviceType() + " for tenant "
|
||||
+ deviceTypeConfigIdentifier.getTenantDomain());
|
||||
}
|
||||
|
||||
private DeviceManagementConfiguration getDeviceTypeConfiguration(File configurationFile)
|
||||
throws DeviceTypeConfigurationException {
|
||||
try {
|
||||
Document doc = DeviceTypeConfigUtil.convertToDocument(configurationFile);
|
||||
|
||||
/* Un-marshaling Webapp Authenticator configuration */
|
||||
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfiguration.class);
|
||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
||||
//unmarshaller.setSchema(getSchema());
|
||||
return (DeviceManagementConfiguration) unmarshaller.unmarshal(doc);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceTypeConfigurationException("Error occurred while un-marshalling the file " +
|
||||
configurationFile.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private ServiceRegistration registerDeviceType(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
||||
DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
DeviceTypeManagerService deviceTypeManagerService = new DeviceTypeManagerService(deviceTypeConfigIdentifier,
|
||||
deviceManagementConfiguration);
|
||||
BundleContext bundleContext = DeviceTypeManagementDataHolder.getInstance().getBundleContext();
|
||||
return bundleContext.registerService(DeviceManagementService.class.getName(), deviceTypeManagerService, null);
|
||||
}
|
||||
|
||||
private void unregisterDeviceType(String filePath) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("De-activating Virtual Firealarm Device Management Service Component");
|
||||
}
|
||||
try {
|
||||
if (this.deviceTypeServiceRegistrations.get(filePath) != null) {
|
||||
this.deviceTypeServiceRegistrations.get(filePath).unregister();
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Device Management Service has been successfully de-activated");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("Error occurred while de-activating Deactivating device management service.", e);
|
||||
}
|
||||
deviceTypeServiceRegistrations.remove(filePath);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer;
|
||||
|
||||
public class DeviceTypePluginConstants {
|
||||
public static final String DB_SCRIPTS_FOLDER = "cdm";
|
||||
public static final String CONFIG_REGISTRY_ROOT = "/_system/config";
|
||||
|
||||
public static final String MEDIA_TYPE_XML = "application/xml";
|
||||
public static final String CHARSET_UTF8 = "UTF8";
|
||||
public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
|
||||
public static final String LANGUAGE_CODE_ENGLISH_UK = "en_UK";
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding device type configuration and parsing with JAXB.
|
||||
*/
|
||||
@XmlRootElement(name = "DataSourceConfiguration")
|
||||
public class DataSourceConfig {
|
||||
|
||||
private JNDILookupDefinition jndiLookupDefinition;
|
||||
|
||||
@XmlElement(name = "JndiLookupDefinition", required = true)
|
||||
public JNDILookupDefinition getJndiLookupDefinition() {
|
||||
return jndiLookupDefinition;
|
||||
}
|
||||
|
||||
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
|
||||
this.jndiLookupDefinition = jndiLookupDefinition;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding management repository data.
|
||||
*/
|
||||
@XmlRootElement(name = "ManagementRepository")
|
||||
public class DeviceManagementConfigRepository {
|
||||
|
||||
private DataSourceConfig dataSourceConfig;
|
||||
private ProvisioningConfig provisioningConfig;
|
||||
|
||||
@XmlElement(name = "DataSourceConfiguration", required = true)
|
||||
public DataSourceConfig getDataSourceConfig() {
|
||||
return dataSourceConfig;
|
||||
}
|
||||
|
||||
public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
|
||||
this.dataSourceConfig = dataSourceConfig;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ProvisioningConfig", required = true)
|
||||
public ProvisioningConfig getProvisioningConfig() {
|
||||
return provisioningConfig;
|
||||
}
|
||||
|
||||
public void setProvisioningConfig(
|
||||
ProvisioningConfig provisioningConfig) {
|
||||
this.provisioningConfig = provisioningConfig;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "DeviceManagementConfiguration")
|
||||
public class DeviceManagementConfiguration {
|
||||
|
||||
private DeviceManagementConfigRepository deviceManagementConfigRepository;
|
||||
private PushNotificationConfig pushNotificationConfig;
|
||||
private String deviceType;
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceManagementConfiguration.class);
|
||||
|
||||
private DeviceManagementConfiguration() {
|
||||
}
|
||||
|
||||
@XmlElement(name = "DeviceType", required = false)
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ManagementRepository", required = true)
|
||||
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
|
||||
return deviceManagementConfigRepository;
|
||||
}
|
||||
|
||||
public void setDeviceManagementConfigRepository(DeviceManagementConfigRepository deviceManagementConfigRepository) {
|
||||
this.deviceManagementConfigRepository = deviceManagementConfigRepository;
|
||||
}
|
||||
|
||||
@XmlElement(name = "PushNotificationConfiguration", required = false)
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return pushNotificationConfig;
|
||||
}
|
||||
|
||||
public void setPushNotificationConfig(PushNotificationConfig pushNotificationConfig) {
|
||||
this.pushNotificationConfig = pushNotificationConfig;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding device type configuration and parsing with JAXB.
|
||||
*/
|
||||
@XmlRootElement(name = "FeaturesConfig")
|
||||
public class FeaturesConfig {
|
||||
|
||||
private JNDILookupDefinition jndiLookupDefinition;
|
||||
|
||||
@XmlElement(name = "JndiLookupDefinition", required = true)
|
||||
public JNDILookupDefinition getJndiLookupDefinition() {
|
||||
return jndiLookupDefinition;
|
||||
}
|
||||
|
||||
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
|
||||
this.jndiLookupDefinition = jndiLookupDefinition;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class for hold JndiLookupDefinition 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Class for holding device type configuration and parsing with JAXB.
|
||||
*/
|
||||
@XmlRootElement(name = "ProvisioningConfig")
|
||||
public class ProvisioningConfig {
|
||||
|
||||
private boolean sharedWithAllTenants;
|
||||
|
||||
@XmlElement(name = "SharedWithAllTenants", required = true)
|
||||
public boolean isSharedWithAllTenants() {
|
||||
return sharedWithAllTenants;
|
||||
}
|
||||
|
||||
public void setSharedWithAllTenants(boolean sharedWithAllTenants) {
|
||||
this.sharedWithAllTenants = sharedWithAllTenants;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.config;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import java.util.List;
|
||||
|
||||
@XmlRootElement(name = "PushNotificationConfiguration")
|
||||
public class PushNotificationConfig {
|
||||
|
||||
private String pushNotificationProvider;
|
||||
private List<Property> properties;
|
||||
|
||||
@XmlElementWrapper(name = "Properties", required = true)
|
||||
@XmlElement(name = "Property", required = true)
|
||||
public List<Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(List<Property> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@XmlElement(name = "PushNotificationProvider", required = true)
|
||||
public String getPushNotificationProvider() {
|
||||
return pushNotificationProvider;
|
||||
}
|
||||
|
||||
public void setPushNotificationProvider(String pushNotificationProvider) {
|
||||
this.pushNotificationProvider = pushNotificationProvider;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "Property")
|
||||
public static class Property {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
@XmlAttribute(name = "Name", required = true)
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.config.exception;
|
||||
|
||||
public class DeviceTypeConfigurationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -3151279431229070297L;
|
||||
|
||||
public DeviceTypeConfigurationException(int errorCode, String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DeviceTypeConfigurationException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DeviceTypeConfigurationException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public DeviceTypeConfigurationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DeviceTypeConfigurationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public DeviceTypeConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DeviceTypeConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception;
|
||||
|
||||
public class InvalidConfigurationStateException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -3151279411229070297L;
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(int errorCode, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception;
|
||||
|
||||
|
||||
public class DeviceTypeMgtPluginException extends Exception{
|
||||
|
||||
public DeviceTypeMgtPluginException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public DeviceTypeMgtPluginException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DeviceTypeMgtPluginException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public DeviceTypeMgtPluginException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DeviceTypeMgtPluginException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal;
|
||||
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
public class DeviceTypeManagementDataHolder {
|
||||
|
||||
private ConfigurationContextService configurationContextService;
|
||||
private BundleContext bundleContext;
|
||||
private RegistryService registryService;
|
||||
|
||||
private static DeviceTypeManagementDataHolder thisInstance = new DeviceTypeManagementDataHolder();
|
||||
|
||||
private DeviceTypeManagementDataHolder() {}
|
||||
|
||||
public static DeviceTypeManagementDataHolder getInstance() {
|
||||
return thisInstance;
|
||||
}
|
||||
|
||||
public ConfigurationContextService getConfigurationContextService() {
|
||||
return configurationContextService;
|
||||
}
|
||||
|
||||
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
this.configurationContextService = configurationContextService;
|
||||
}
|
||||
|
||||
public BundleContext getBundleContext() {
|
||||
return bundleContext;
|
||||
}
|
||||
|
||||
public void setBundleContext(BundleContext bundleContext) {
|
||||
this.bundleContext = bundleContext;
|
||||
}
|
||||
|
||||
public RegistryService getRegistryService() {
|
||||
return registryService;
|
||||
}
|
||||
|
||||
public void setRegistryService(RegistryService registryService) {
|
||||
this.registryService = registryService;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeManagementServiceComponent"
|
||||
* immediate="true"
|
||||
* @scr.reference name="config.context.service"
|
||||
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
||||
* cardinality="0..1"
|
||||
* policy="dynamic"
|
||||
* bind="setConfigurationContextService"
|
||||
* unbind="unsetConfigurationContextService"
|
||||
* @scr.reference name="registry.service"
|
||||
* interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="0..1"
|
||||
* policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
|
||||
*/
|
||||
public class DeviceTypeManagementServiceComponent {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypeManagementServiceComponent.class);
|
||||
|
||||
protected void activate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating DeviceType Deployer Service Component");
|
||||
}
|
||||
DeviceTypeManagementDataHolder.getInstance().setBundleContext(ctx.getBundleContext());
|
||||
}
|
||||
|
||||
protected void deactivate(ComponentContext ctx) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("De-activating DeviceType Deployer Service Component");
|
||||
}
|
||||
}
|
||||
|
||||
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting ConfigurationContextService");
|
||||
}
|
||||
|
||||
DeviceTypeManagementDataHolder.getInstance().setConfigurationContextService(configurationContextService);
|
||||
|
||||
}
|
||||
|
||||
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Un-setting ConfigurationContextService");
|
||||
}
|
||||
DeviceTypeManagementDataHolder.getInstance().setConfigurationContextService(null);
|
||||
}
|
||||
|
||||
protected void setRegistryService(RegistryService registryService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("RegistryService acquired");
|
||||
}
|
||||
DeviceTypeManagementDataHolder.getInstance().setRegistryService(registryService);
|
||||
}
|
||||
|
||||
protected void unsetRegistryService(RegistryService registryService) {
|
||||
DeviceTypeManagementDataHolder.getInstance().setRegistryService(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.template;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class holds key for the configuration of the device type and its provider tenant.
|
||||
*/
|
||||
public class DeviceTypeConfigIdentifier implements Serializable {
|
||||
|
||||
private String deviceType;
|
||||
private String tenantDomain;
|
||||
|
||||
public DeviceTypeConfigIdentifier(String deviceType, String tenantDomain) {
|
||||
this.deviceType = deviceType;
|
||||
this.tenantDomain = tenantDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.deviceType.hashCode();
|
||||
result = 31 * result + ("@" + this.tenantDomain).hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj instanceof DeviceTypeConfigIdentifier) && deviceType.equals(
|
||||
((DeviceTypeConfigIdentifier) obj).deviceType) && tenantDomain.equals(
|
||||
((DeviceTypeConfigIdentifier) obj).tenantDomain);
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public String getTenantDomain() {
|
||||
return tenantDomain;
|
||||
}
|
||||
}
|
@ -0,0 +1,320 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
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.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.DeviceTypePluginConstants;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao.DeviceTypePluginDAOManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.feature.AnnotationBasedFeatureManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils;
|
||||
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceTypeManager implements DeviceManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypeManager.class);
|
||||
private String deviceType;
|
||||
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
|
||||
private LicenseManager licenseManager;
|
||||
|
||||
private FeatureManager featureManager;
|
||||
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
||||
DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceManagementConfiguration);
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
boolean isSharedWithAllTenants =
|
||||
deviceManagementConfiguration.getDeviceManagementConfigRepository().getProvisioningConfig()
|
||||
.isSharedWithAllTenants();
|
||||
DeviceTypeIdentifier deviceTypeIdentifier;
|
||||
deviceType = deviceTypeConfigIdentifier.getDeviceType();
|
||||
if (isSharedWithAllTenants) {
|
||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType);
|
||||
} else {
|
||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId);
|
||||
}
|
||||
|
||||
featureManager = new AnnotationBasedFeatureManager(deviceTypeIdentifier);
|
||||
|
||||
this.licenseManager = new RegistryBasedLicenseManager();
|
||||
License defaultLicense;
|
||||
|
||||
try {
|
||||
if (licenseManager.getLicense(deviceType, DeviceTypePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) {
|
||||
defaultLicense = null;
|
||||
licenseManager.addLicense(deviceType, defaultLicense);
|
||||
}
|
||||
featureManager.addSupportedFeaturesToDB();
|
||||
} catch (LicenseManagementException e) {
|
||||
log.error("Error occurred while adding default license for Android devices", e);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Error occurred while adding supported device features for Android platform", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureManager getFeatureManager() {
|
||||
return featureManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveConfiguration(PlatformConfiguration tenantConfiguration)
|
||||
throws DeviceManagementException {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Persisting " + deviceType + " configurations in Registry");
|
||||
}
|
||||
StringWriter writer = new StringWriter();
|
||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||
Marshaller marshaller = context.createMarshaller();
|
||||
marshaller.marshal(tenantConfiguration, writer);
|
||||
|
||||
Resource resource = DeviceTypeUtils.getConfigurationRegistry().newResource();
|
||||
resource.setContent(writer.toString());
|
||||
resource.setMediaType(DeviceTypePluginConstants.MEDIA_TYPE_XML);
|
||||
DeviceTypeUtils.putRegistryResource(deviceType, resource);
|
||||
return true;
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while persisting the Registry resource of " + deviceType + " Configuration : "
|
||||
+ e.getMessage(), e);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing the " + deviceType + " configuration : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformConfiguration getConfiguration() throws DeviceManagementException {
|
||||
Resource resource;
|
||||
try {
|
||||
resource = DeviceTypeUtils.getRegistryResource(deviceType);
|
||||
if (resource != null) {
|
||||
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
|
||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
||||
return (PlatformConfiguration) unmarshaller.unmarshal(
|
||||
new StringReader(new String((byte[]) resource.getContent(), Charset.
|
||||
forName(DeviceTypePluginConstants.CHARSET_UTF8))));
|
||||
}
|
||||
return null;
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
|
||||
} catch (JAXBException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while parsing the " + deviceType + " configuration : " + e.getMessage(), e);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while retrieving the Registry resource of " + deviceType + " Configuration : "
|
||||
+ e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
boolean status = false;
|
||||
boolean isEnrolled = this.isEnrolled(
|
||||
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
|
||||
}
|
||||
if (isEnrolled) {
|
||||
this.modifyEnrollment(device);
|
||||
} else {
|
||||
deviceTypePluginDAOManager.beginTransaction();
|
||||
status = deviceTypePluginDAOManager.getDeviceDAO().addDevice(device);
|
||||
deviceTypePluginDAOManager.commitTransaction();
|
||||
}
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
try {
|
||||
deviceTypePluginDAOManager.rollbackTransaction();
|
||||
} catch (DeviceTypeMgtPluginException ex) {
|
||||
String msg = "Error occurred while roll back the device enrol transaction :" +
|
||||
device.toString();
|
||||
log.warn(msg, ex);
|
||||
}
|
||||
String msg = "Error while enrolling the " + deviceType + " device : " + device.getDeviceIdentifier();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
boolean status;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Modifying the Android device enrollment data");
|
||||
}
|
||||
deviceTypePluginDAOManager.beginTransaction();
|
||||
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device);
|
||||
deviceTypePluginDAOManager.commitTransaction();
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
try {
|
||||
deviceTypePluginDAOManager.rollbackTransaction();
|
||||
} catch (DeviceTypeMgtPluginException mobileDAOEx) {
|
||||
String msg = "Error occurred while roll back the update device transaction :" +
|
||||
device.toString();
|
||||
log.warn(msg, mobileDAOEx);
|
||||
}
|
||||
String msg = "Error while updating the enrollment of the " + deviceType + " device : " +
|
||||
device.getDeviceIdentifier();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
//Here we don't have anything specific to do. Hence returning.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
boolean isEnrolled = false;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Checking the enrollment of Android device : " + deviceId.getId());
|
||||
}
|
||||
Device device =
|
||||
deviceTypePluginDAOManager.getDeviceDAO().getDevice(deviceId.getId());
|
||||
if (device != null) {
|
||||
isEnrolled = true;
|
||||
}
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
String msg = "Error while checking the enrollment status of " + deviceType + " device : " +
|
||||
deviceId.getId();
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
return isEnrolled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setActive(DeviceIdentifier deviceId, boolean status)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
|
||||
Device device;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Getting the details of " + deviceType + " device : '" + deviceId.getId() + "'");
|
||||
}
|
||||
device = deviceTypePluginDAOManager.getDeviceDAO().getDevice(deviceId.getId());
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
|
||||
throws DeviceManagementException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setStatus(DeviceIdentifier deviceIdentifier, String currentUser,
|
||||
EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense(String languageCode) throws LicenseManagementException {
|
||||
return licenseManager.getLicense(deviceType, languageCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLicense(License license) throws LicenseManagementException {
|
||||
licenseManager.addLicense(deviceType, license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDeviceAuthorization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
|
||||
throws DeviceManagementException {
|
||||
boolean status;
|
||||
Device existingDevice = this.getDevice(deviceIdentifier);
|
||||
existingDevice.setProperties(device.getProperties());
|
||||
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(
|
||||
"updating the details of " + deviceType + " device : " + device.getDeviceIdentifier());
|
||||
}
|
||||
deviceTypePluginDAOManager.beginTransaction();
|
||||
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(existingDevice);
|
||||
deviceTypePluginDAOManager.commitTransaction();
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
try {
|
||||
deviceTypePluginDAOManager.rollbackTransaction();
|
||||
} catch (DeviceTypeMgtPluginException e1) {
|
||||
log.warn("Error occurred while roll back the update device info transaction : '" +
|
||||
device.toString() + "'", e1);
|
||||
}
|
||||
throw new DeviceManagementException(
|
||||
"Error occurred while updating the " + deviceType + " device: '" +
|
||||
device.getDeviceIdentifier() + "'", e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getAllDevices() throws DeviceManagementException {
|
||||
List<Device> devices = null;
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Fetching the details of all " + deviceType + " devices");
|
||||
}
|
||||
devices = deviceTypePluginDAOManager.getDeviceDAO().getAllDevices();
|
||||
} catch (DeviceTypeMgtPluginException e) {
|
||||
throw new DeviceManagementException("Error occurred while fetching all " + deviceType + " devices", e);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template;
|
||||
|
||||
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.DeviceManager;
|
||||
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
|
||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeviceTypeManagerService implements DeviceManagementService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypeManagerService.class);
|
||||
|
||||
private DeviceManager deviceManager;
|
||||
private PushNotificationConfig pushNotificationConfig;
|
||||
private ProvisioningConfig provisioningConfig;
|
||||
private String type;
|
||||
|
||||
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
|
||||
DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
this.setProvisioningConfig(deviceTypeConfigIdentifier.getTenantDomain(), deviceManagementConfiguration);
|
||||
this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceManagementConfiguration);
|
||||
this.setType(deviceManagementConfiguration);
|
||||
this.populatePushNotificationConfig(deviceManagementConfiguration);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws DeviceManagementException {
|
||||
}
|
||||
|
||||
private void populatePushNotificationConfig(DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfig sourceConfig =
|
||||
deviceManagementConfiguration.getPushNotificationConfig();
|
||||
if (sourceConfig != null) {
|
||||
if (true) {
|
||||
Map<String, String> staticProps = new HashMap<>();
|
||||
for (org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfig.Property
|
||||
property : sourceConfig.getProperties()) {
|
||||
staticProps.put(property.getName(), property.getValue());
|
||||
}
|
||||
pushNotificationConfig = new PushNotificationConfig(sourceConfig.getPushNotificationProvider(),
|
||||
staticProps);
|
||||
} else {
|
||||
try {
|
||||
PlatformConfiguration deviceTypeConfig = deviceManager.getConfiguration();
|
||||
if (deviceTypeConfig != null) {
|
||||
List<ConfigurationEntry> configuration = deviceTypeConfig.getConfiguration();
|
||||
if (configuration.size() > 0) {
|
||||
Map<String, String> properties = this.getConfigProperty(configuration);
|
||||
pushNotificationConfig = new PushNotificationConfig(
|
||||
sourceConfig.getPushNotificationProvider(), properties);
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Unable to get the " + type + " platform configuration from registry.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceManager getDeviceManager() {
|
||||
return deviceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationManager getApplicationManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProvisioningConfig getProvisioningConfig() {
|
||||
return provisioningConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PushNotificationConfig getPushNotificationConfig() {
|
||||
return pushNotificationConfig;
|
||||
}
|
||||
|
||||
private void setProvisioningConfig(String tenantDomain, DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
boolean sharedWithAllTenants = deviceManagementConfiguration
|
||||
.getDeviceManagementConfigRepository().getProvisioningConfig().isSharedWithAllTenants();
|
||||
provisioningConfig = new ProvisioningConfig(tenantDomain, sharedWithAllTenants);
|
||||
}
|
||||
|
||||
private void setType(DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
type = deviceManagementConfiguration.getDeviceType();
|
||||
}
|
||||
|
||||
private Map<String, String> getConfigProperty(List<ConfigurationEntry> configs) {
|
||||
Map<String, String> propertMap = new HashMap<>();
|
||||
for (ConfigurationEntry entry : configs) {
|
||||
propertMap.put(entry.getName(), entry.getValue().toString());
|
||||
}
|
||||
return propertMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implements CRUD for Devices.
|
||||
*/
|
||||
public class DeviceTypePluginDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypePluginDAO.class);
|
||||
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
|
||||
public DeviceTypePluginDAO(DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceManagementConfiguration);
|
||||
}
|
||||
|
||||
public Device getDevice(String deviceId) throws DeviceTypeMgtPluginException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
Device device = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
conn = deviceTypePluginDAOManager.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME" +
|
||||
" FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
if (resultSet.next()) {
|
||||
device = new Device();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Virtual Firealarm device " + deviceId + " data has been fetched from " +
|
||||
"Virtual Firealarm database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching Virtual Firealarm device : '" + deviceId + "'";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeMgtPluginException(msg, e);
|
||||
} finally {
|
||||
DeviceTypeUtils.cleanupResources(stmt, resultSet);
|
||||
deviceTypePluginDAOManager.closeConnection();
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
public boolean addDevice(Device device) throws DeviceTypeMgtPluginException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = deviceTypePluginDAOManager.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO VIRTUAL_FIREALARM_DEVICE(VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, device.getDeviceIdentifier());
|
||||
stmt.setString(2, device.getName());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Virtual Firealarm device " + device.getDeviceIdentifier() + " data has been" +
|
||||
" added to the Virtual Firealarm database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding the Virtual Firealarm device '" +
|
||||
device.getDeviceIdentifier() + "' to the Virtual Firealarm db.";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeMgtPluginException(msg, e);
|
||||
} finally {
|
||||
DeviceTypeUtils.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean updateDevice(Device device) throws DeviceTypeMgtPluginException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = DeviceTypePluginDAOManager.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE VIRTUAL_FIREALARM_DEVICE SET DEVICE_NAME = ? WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?";
|
||||
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, device.getName());
|
||||
stmt.setString(2, device.getDeviceIdentifier());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Virtualm Firealarm device " + device.getDeviceIdentifier() + " data has been" +
|
||||
" modified.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while modifying the Virtual Firealarm device '" +
|
||||
device.getDeviceIdentifier() + "' data.";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeMgtPluginException(msg, e);
|
||||
} finally {
|
||||
DeviceTypeUtils.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean deleteDevice(String iotDeviceId) throws DeviceTypeMgtPluginException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = deviceTypePluginDAOManager.getConnection();
|
||||
String deleteDBQuery = "DELETE FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, iotDeviceId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Virtual Firealarm device " + iotDeviceId + " data has deleted" +
|
||||
" from the Virtual Firealarm database.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting Virtual Firealarm device " + iotDeviceId;
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeMgtPluginException(msg, e);
|
||||
} finally {
|
||||
DeviceTypeUtils.cleanupResources(stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public List<Device> getAllDevices() throws DeviceTypeMgtPluginException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
Device device;
|
||||
List<Device> devices = new ArrayList<>();
|
||||
try {
|
||||
conn = deviceTypePluginDAOManager.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME FROM VIRTUAL_FIREALARM_DEVICE";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
device = new Device();
|
||||
device.setDeviceIdentifier(resultSet.getString(VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_ID));
|
||||
device.setName(resultSet.getString(VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_NAME));
|
||||
devices.add(device);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("All Virtual Firealarm device details have fetched from Firealarm database.");
|
||||
}
|
||||
return devices;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching all Virtual Firealarm device data'";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeMgtPluginException(msg, e);
|
||||
} finally {
|
||||
DeviceTypeUtils.cleanupResources(stmt, resultSet);
|
||||
deviceTypePluginDAOManager.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DeviceTypePluginDAOManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceTypePluginDAOManager.class);
|
||||
private DataSource dataSource;
|
||||
private ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||
private DeviceTypePluginDAO deviceTypePluginDAO;
|
||||
|
||||
public DeviceTypePluginDAOManager(DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
initDAO(deviceManagementConfiguration);
|
||||
deviceTypePluginDAO = new DeviceTypePluginDAO(deviceManagementConfiguration);
|
||||
}
|
||||
|
||||
public void initDAO(DeviceManagementConfiguration deviceManagementConfiguration) {
|
||||
String datasourceName = deviceManagementConfiguration.getDeviceManagementConfigRepository()
|
||||
.getDataSourceConfig().getJndiLookupDefinition().getJndiName();
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
dataSource = (DataSource) ctx.lookup(datasourceName);
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + datasourceName, e);
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceTypePluginDAO getDeviceDAO() {
|
||||
return deviceTypePluginDAO;
|
||||
}
|
||||
|
||||
public void beginTransaction() throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.setAutoCommit(false);
|
||||
currentConnection.set(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error occurred while retrieving datasource connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() throws DeviceTypeMgtPluginException {
|
||||
if (currentConnection.get() == null) {
|
||||
try {
|
||||
currentConnection.set(dataSource.getConnection());
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error occurred while retrieving data source connection", e);
|
||||
}
|
||||
}
|
||||
return currentConnection.get();
|
||||
}
|
||||
|
||||
public void commitTransaction() throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.commit();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence commit "
|
||||
+ "has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error occurred while committing the transaction", e);
|
||||
} finally {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
public void closeConnection() throws DeviceTypeMgtPluginException {
|
||||
|
||||
Connection con = currentConnection.get();
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
log.error("Error occurred while close the connection");
|
||||
}
|
||||
}
|
||||
currentConnection.remove();
|
||||
}
|
||||
|
||||
public void rollbackTransaction() throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
conn.rollback();
|
||||
} else {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Datasource connection associated with the current thread is null, hence rollback "
|
||||
+ "has not been attempted");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error occurred while rollback the transaction", e);
|
||||
} finally {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.template.feature;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.feature.mgt.GenericFeatureManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AnnotationBasedFeatureManager implements FeatureManager {
|
||||
private DeviceTypeIdentifier deviceType;
|
||||
|
||||
public AnnotationBasedFeatureManager(DeviceTypeIdentifier deviceTypeIdentifier) {
|
||||
this.deviceType = deviceTypeIdentifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature getFeature(String name) throws DeviceManagementException {
|
||||
return GenericFeatureManager.getInstance().getFeature(deviceType, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||
return GenericFeatureManager.getInstance().getFeatures(deviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFeature(String name) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.feature;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigurationBasedFeatureManager implements FeatureManager {
|
||||
|
||||
@Override
|
||||
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatures(List<Feature> features) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Feature getFeature(String name) throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFeature(String name) throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSupportedFeaturesToDB() throws DeviceManagementException {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.template.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
import org.wso2.carbon.utils.dbcreator.DatabaseCreator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Provides methods for initializing the database script.
|
||||
*/
|
||||
public class DeviceSchemaInitializer extends DatabaseCreator{
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceSchemaInitializer.class);
|
||||
private String setupSQLScriptBaseLocation;
|
||||
|
||||
public DeviceSchemaInitializer(DataSource dataSource, String deviceType) {
|
||||
super(dataSource);
|
||||
setupSQLScriptBaseLocation = CarbonUtils.getCarbonHome() + File.separator + "dbscripts"
|
||||
+ File.separator + "cdm" + File.separator + "plugins" + File.separator
|
||||
+ deviceType + File.separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
|
||||
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.internal.DeviceTypeManagementDataHolder;
|
||||
import org.wso2.carbon.registry.api.RegistryException;
|
||||
import org.wso2.carbon.registry.api.Resource;
|
||||
import org.wso2.carbon.registry.core.Registry;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Contains utility methods used by plugin.
|
||||
*/
|
||||
public class DeviceTypeUtils {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceTypeUtils.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
|
||||
cleanupResources(null, stmt, rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the device management schema.
|
||||
*/
|
||||
public static void setupDeviceManagementSchema(DeviceManagementConfiguration deviceManagementConfiguration)
|
||||
throws DeviceTypeMgtPluginException {
|
||||
String datasourceName = deviceManagementConfiguration.getDeviceManagementConfigRepository()
|
||||
.getDataSourceConfig().getJndiLookupDefinition().getJndiName();
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
DataSource dataSource = (DataSource) ctx.lookup(datasourceName);
|
||||
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource, deviceManagementConfiguration
|
||||
.getDeviceType());
|
||||
String checkSql = "select * from VIRTUAL_FIREALARM_DEVICE";
|
||||
if (!initializer.isDatabaseStructureCreated(checkSql)) {
|
||||
log.info("Initializing device management repository database schema");
|
||||
initializer.createRegistryDatabase();
|
||||
} else {
|
||||
log.info("Device management repository database already exists. Not creating a new database.");
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
log.error("Error while looking up the data source: " + datasourceName, e);
|
||||
} catch (Exception e) {
|
||||
throw new DeviceTypeMgtPluginException("Error occurred while initializing Device " +
|
||||
"Management database schema", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Registry getConfigurationRegistry() throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
return DeviceTypeManagementDataHolder.getInstance().getRegistryService()
|
||||
.getConfigSystemRegistry(tenantId);
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error in retrieving conf registry instance: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean putRegistryResource(String path, Resource resource) throws DeviceTypeMgtPluginException {
|
||||
boolean status;
|
||||
try {
|
||||
DeviceTypeUtils.getConfigurationRegistry().beginTransaction();
|
||||
DeviceTypeUtils.getConfigurationRegistry().put(path, resource);
|
||||
DeviceTypeUtils.getConfigurationRegistry().commitTransaction();
|
||||
status = true;
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error occurred while persisting registry resource : " +
|
||||
e.getMessage(), e);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
public static Resource getRegistryResource(String path) throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
if(DeviceTypeUtils.getConfigurationRegistry().resourceExists(path)){
|
||||
return DeviceTypeUtils.getConfigurationRegistry().get(path);
|
||||
}
|
||||
return null;
|
||||
} catch (RegistryException e) {
|
||||
throw new DeviceTypeMgtPluginException("Error in retrieving registry resource : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static License getDefaultLicense(String deviceType) {
|
||||
License license = new License();
|
||||
license.setName(deviceType);
|
||||
license.setLanguage("en_US");
|
||||
license.setVersion("1.0.0");
|
||||
license.setText("This End User License Agreement (\"Agreement\") is a legal agreement between you (\"You\") " +
|
||||
"and WSO2, Inc., regarding the enrollment of Your personal mobile device (\"Device\") in SoR's " +
|
||||
"mobile device management program, and the loading to and removal from Your Device and Your use " +
|
||||
"of certain applications and any associated software and user documentation, whether provided in " +
|
||||
"\"online\" or electronic format, used in connection with the operation of or provision of services " +
|
||||
"to WSO2, Inc., BY SELECTING \"I ACCEPT\" DURING INSTALLATION, YOU ARE ENROLLING YOUR DEVICE, AND " +
|
||||
"THEREBY AUTHORIZING SOR OR ITS AGENTS TO INSTALL, UPDATE AND REMOVE THE APPS FROM YOUR DEVICE AS " +
|
||||
"DESCRIBED IN THIS AGREEMENT. YOU ARE ALSO EXPLICITLY ACKNOWLEDGING AND AGREEING THAT (1) THIS IS " +
|
||||
"A BINDING CONTRACT AND (2) YOU HAVE READ AND AGREE TO THE TERMS OF THIS AGREEMENT.\n" +
|
||||
"\n" +
|
||||
"IF YOU DO NOT ACCEPT THESE TERMS, DO NOT ENROLL YOUR DEVICE AND DO NOT PROCEED ANY FURTHER.\n" +
|
||||
"\n" +
|
||||
"You agree that: (1) You understand and agree to be bound by the terms and conditions contained " +
|
||||
"in this Agreement, and (2) You are at least 21 years old and have the legal capacity to enter " +
|
||||
"into this Agreement as defined by the laws of Your jurisdiction. SoR shall have the right, " +
|
||||
"without prior notice, to terminate or suspend (i) this Agreement, (ii) the enrollment of Your " +
|
||||
"Device, or (iii) the functioning of the Apps in the event of a violation of this Agreement or " +
|
||||
"the cessation of Your relationship with SoR (including termination of Your employment if You are " +
|
||||
"an employee or expiration or termination of Your applicable franchise or supply agreement if You " +
|
||||
"are a franchisee of or supplier to the WSO2 WSO2, Inc., system). SoR expressly reserves all " +
|
||||
"rights not expressly granted herein.");
|
||||
return license;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 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.extensions.device.type.deployer.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
|
||||
public class DeviceTypeConfigUtil {
|
||||
|
||||
public static final String CARBON_HOME = "carbon.home";
|
||||
public static final String CARBON_HOME_ENTRY = "${carbon.home}";
|
||||
|
||||
public static Document convertToDocument(File file) throws DeviceTypeConfigurationException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
try {
|
||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
||||
return docBuilder.parse(file);
|
||||
} catch (Exception e) {
|
||||
throw new DeviceTypeConfigurationException("Error occurred while parsing file, while converting " +
|
||||
"to a org.w3c.dom.Document", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<!--
|
||||
~ Copyright (c) 2005 - 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.
|
||||
-->
|
||||
<component xmlns="http://products.wso2.org/carbon">
|
||||
<deployers>
|
||||
<deployer>
|
||||
<directory>devicetypes</directory>
|
||||
<extension>xml</extension>
|
||||
<class>org.wso2.carbon.device.mgt.extensions.device.type.deployer.DeviceTypeDeployer</class>
|
||||
</deployer>
|
||||
</deployers>
|
||||
</component>
|
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2016, 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.
|
||||
-->
|
||||
<DeviceManagementConfiguration>
|
||||
<DeviceType>sample</DeviceType>
|
||||
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/SampleDM_DB</Name>
|
||||
</JndiLookupDefinition>
|
||||
<DeviceDefinition>
|
||||
<TableName>SAMPLE_DEVICE</TableName>
|
||||
<!--Primary Key should be the device identifier-->
|
||||
<PrimaryKey>SAMPLE_DEVICE_ID</PrimaryKey>
|
||||
<Attributes>
|
||||
<!--types should be one of these boolean | byte | date | double | float | int | long | short-->
|
||||
<Attribute type="boolean">booleanColumn</Attribute>
|
||||
<Attribute type="byte">byteColumn</Attribute>
|
||||
<Attribute type="date">dateColumn</Attribute>
|
||||
<Attribute type="double">doubleColumn</Attribute>
|
||||
<Attribute type="float">floatColumn</Attribute>
|
||||
<Attribute type="int">intColumn</Attribute>
|
||||
<Attribute type="long">longColumn</Attribute>
|
||||
<Attribute type="short">shortColumn</Attribute>
|
||||
</Attributes>
|
||||
<License>
|
||||
<Language>en_US</Language>
|
||||
<Version>1.0.0</Version>
|
||||
<Text>This is license text</Text>
|
||||
</License>
|
||||
</DeviceDefinition>
|
||||
</DataSourceConfiguration>
|
||||
|
||||
<ProvisioningConfig>
|
||||
<SharedWithAllTenants>false</SharedWithAllTenants>
|
||||
</ProvisioningConfig>
|
||||
|
||||
<!--if generate is set to true then the feature information will be picked up from the annotation in the api-->
|
||||
<FeaturesConfig generate="false">
|
||||
<Feature>
|
||||
<Code>FEATURE_CODE_1</Code>
|
||||
<Name>feature name 1</Name>
|
||||
<Description>description</Description>
|
||||
</Feature>
|
||||
<Feature>
|
||||
<Code>FEATURE_CODE_2</Code>
|
||||
<Name>feature name 2</Name>
|
||||
<Description>description</Description>
|
||||
</Feature>
|
||||
</FeaturesConfig>
|
||||
</ManagementRepository>
|
||||
|
||||
|
||||
<PushNotificationConfiguration>
|
||||
<!--MQTT Config-->
|
||||
<PushNotificationProvider>MQTT</PushNotificationProvider>
|
||||
<FileBasedProperties>true</FileBasedProperties>
|
||||
<Properties>
|
||||
<Property Name="mqtt.adapter.name">sample.mqtt.adapter</Property>
|
||||
<Property Name="url">tcp://localhost:1883</Property>
|
||||
<Property Name="username">admin</Property>
|
||||
<Property Name="dcrUrl">https://localhost:9443/dynamic-client-web/register</Property>
|
||||
<Property Name="qos">0</Property>
|
||||
<Property Name="scopes"/>
|
||||
<Property Name="clearSession">true</Property>
|
||||
</Properties>
|
||||
</PushNotificationConfiguration>
|
||||
</DeviceManagementConfiguration>
|
Loading…
Reference in new issue