updated configs and Dao

revert-70aa11f8
ayyoob 8 years ago
parent d6090dd812
commit eeea1c372f

@ -31,7 +31,7 @@ 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.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;
@ -125,7 +125,7 @@ public class DeviceTypeDeployer extends AbstractDeployer {
private void unregisterDeviceType(String filePath) {
if (log.isDebugEnabled()) {
log.debug("De-activating Virtual Firealarm Device Management Service Component");
log.debug("De-activating Device Management Service.");
}
try {
if (this.deviceTypeServiceRegistrations.get(filePath) != null) {

@ -0,0 +1,59 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/**
* <p>Java class for Attribute complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Attribute">
* &lt;simpleContent>
* &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>string">
* &lt;attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/extension>
* &lt;/simpleContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class Attribute {
@XmlValue
protected String value;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
}

@ -0,0 +1,69 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for Attributes complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Attributes">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Attribute" type="{}Attribute" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Attributes", propOrder = {
"attribute"
})
public class Attributes {
@XmlElement(name = "Attribute")
protected List<Attribute> attribute;
/**
* Gets the value of the attribute property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the attribute property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getAttribute().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Attribute }
*
*
*/
public List<Attribute> getAttribute() {
if (attribute == null) {
attribute = new ArrayList<Attribute>();
}
return this.attribute;
}
}

@ -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.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,62 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for DataSourceConfiguration complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="DataSourceConfiguration">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="JndiLookupDefinition" type="{}JndiLookupDefinition"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DataSourceConfiguration", propOrder = {
"jndiLookupDefinition"
})
public class DataSourceConfiguration {
@XmlElement(name = "JndiLookupDefinition", required = true)
protected JndiLookupDefinition jndiLookupDefinition;
/**
* Gets the value of the jndiLookupDefinition property.
*
* @return
* possible object is
* {@link JndiLookupDefinition }
*
*/
public JndiLookupDefinition getJndiLookupDefinition() {
return jndiLookupDefinition;
}
/**
* Sets the value of the jndiLookupDefinition property.
*
* @param value
* allowed object is
* {@link JndiLookupDefinition }
*
*/
public void setJndiLookupDefinition(JndiLookupDefinition value) {
this.jndiLookupDefinition = value;
}
}

@ -0,0 +1,174 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for DeviceDefinition complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="DeviceDefinition">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="TableName" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="PrimaryKey" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Attributes" type="{}Attributes"/>
* &lt;element name="License" type="{}License"/>
* &lt;element name="Features" type="{}Features"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DeviceDefinition", propOrder = {
"tableName",
"primaryKey",
"attributes",
"license",
"features"
})
public class DeviceDefinition {
@XmlElement(name = "TableName", required = true)
protected String tableName;
@XmlElement(name = "PrimaryKey", required = true)
protected String primaryKey;
@XmlElement(name = "Attributes", required = true)
protected Attributes attributes;
@XmlElement(name = "License", required = true)
protected License license;
@XmlElement(name = "Features", required = true)
protected Features features;
/**
* Gets the value of the tableName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTableName() {
return tableName;
}
/**
* Sets the value of the tableName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTableName(String value) {
this.tableName = value;
}
/**
* Gets the value of the primaryKey property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPrimaryKey() {
return primaryKey;
}
/**
* Sets the value of the primaryKey property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPrimaryKey(String value) {
this.primaryKey = value;
}
/**
* Gets the value of the attributes property.
*
* @return
* possible object is
* {@link Attributes }
*
*/
public Attributes getAttributes() {
return attributes;
}
/**
* Sets the value of the attributes property.
*
* @param value
* allowed object is
* {@link Attributes }
*
*/
public void setAttributes(Attributes value) {
this.attributes = value;
}
/**
* Gets the value of the license property.
*
* @return
* possible object is
* {@link License }
*
*/
public License getLicense() {
return license;
}
/**
* Sets the value of the license property.
*
* @param value
* allowed object is
* {@link License }
*
*/
public void setLicense(License value) {
this.license = value;
}
/**
* Gets the value of the features property.
*
* @return
* possible object is
* {@link Features }
*
*/
public Features getFeatures() {
return features;
}
/**
* Sets the value of the features property.
*
* @param value
* allowed object is
* {@link Features }
*
*/
public void setFeatures(Features value) {
this.features = value;
}
}

@ -1,50 +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.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;
}
}

@ -1,65 +1,120 @@
/*
* 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;
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for DeviceManagementConfiguration complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="DeviceManagementConfiguration">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Device" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="ManagementRepository" type="{}ManagementRepository"/>
* &lt;element name="PushNotificationConfiguration" type="{}PushNotificationConfiguration"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
//@XmlAccessorType(XmlAccessType.FIELD)
//@XmlType(name = "DeviceManagementConfiguration", propOrder = {
// "deviceType",
// "managementRepository",
// "pushNotificationConfiguration"
//})
@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 = true)
protected String deviceType;
@XmlElement(name = "ManagementRepository", required = true)
protected ManagementRepository managementRepository;
@XmlElement(name = "PushNotificationConfiguration", required = true)
protected PushNotificationConfiguration pushNotificationConfiguration;
@XmlElement(name = "DeviceType", required = false)
/**
* Gets the value of the device property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
/**
* Sets the value of the device property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setDeviceType(String value) {
this.deviceType = value;
}
@XmlElement(name = "ManagementRepository", required = true)
public DeviceManagementConfigRepository getDeviceManagementConfigRepository() {
return deviceManagementConfigRepository;
/**
* Gets the value of the managementRepository property.
*
* @return
* possible object is
* {@link ManagementRepository }
*
*/
public ManagementRepository getManagementRepository() {
return managementRepository;
}
public void setDeviceManagementConfigRepository(DeviceManagementConfigRepository deviceManagementConfigRepository) {
this.deviceManagementConfigRepository = deviceManagementConfigRepository;
/**
* Sets the value of the managementRepository property.
*
* @param value
* allowed object is
* {@link ManagementRepository }
*
*/
public void setManagementRepository(ManagementRepository value) {
this.managementRepository = value;
}
@XmlElement(name = "PushNotificationConfiguration", required = false)
public PushNotificationConfig getPushNotificationConfig() {
return pushNotificationConfig;
/**
* Gets the value of the pushNotificationConfiguration property.
*
* @return
* possible object is
* {@link PushNotificationConfiguration }
*
*/
public PushNotificationConfiguration getPushNotificationConfiguration() {
return pushNotificationConfiguration;
}
public void setPushNotificationConfig(PushNotificationConfig pushNotificationConfig) {
this.pushNotificationConfig = pushNotificationConfig;
/**
* Sets the value of the pushNotificationConfiguration property.
*
* @param value
* allowed object is
* {@link PushNotificationConfiguration }
*
*/
public void setPushNotificationConfiguration(PushNotificationConfiguration value) {
this.pushNotificationConfiguration = value;
}
}

@ -0,0 +1,118 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for Feature complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Feature">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Code" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Description" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Feature", propOrder = {
"code",
"name",
"description"
})
public class Feature {
@XmlElement(name = "Code", required = true)
protected String code;
@XmlElement(name = "Name", required = true)
protected String name;
@XmlElement(name = "Description", required = true)
protected String description;
/**
* Gets the value of the code property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getCode() {
return code;
}
/**
* Sets the value of the code property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setCode(String value) {
this.code = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
/**
* Gets the value of the description property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDescription() {
return description;
}
/**
* Sets the value of the description property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setDescription(String value) {
this.description = value;
}
}

@ -0,0 +1,97 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for Features complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Features">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Feature" type="{}Feature" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;attribute name="generate" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Features", propOrder = {
"feature"
})
public class Features {
@XmlElement(name = "Feature")
protected List<Feature> feature;
@XmlAttribute(name = "generate")
protected boolean generate;
/**
* Gets the value of the feature property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the feature property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getFeature().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Feature }
*
*
*/
public List<Feature> getFeature() {
if (feature == null) {
feature = new ArrayList<Feature>();
}
return this.feature;
}
/**
* Gets the value of the generate property.
*
* @return
* possible object is
* {@link String }
*
*/
public boolean isGenerate() {
return generate;
}
/**
* Sets the value of the generate property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setGenerate(boolean value) {
this.generate = value;
}
}

@ -1,83 +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.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,62 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for JndiLookupDefinition complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="JndiLookupDefinition">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Name" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "JndiLookupDefinition", propOrder = {
"name"
})
public class JndiLookupDefinition {
@XmlElement(name = "Name", required = true)
protected String name;
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
}

@ -0,0 +1,118 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for License complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="License">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Language" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Version" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Text" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "License", propOrder = {
"language",
"version",
"text"
})
public class License {
@XmlElement(name = "Language", required = true)
protected String language;
@XmlElement(name = "Version", required = true)
protected String version;
@XmlElement(name = "Text", required = true)
protected String text;
/**
* Gets the value of the language property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getLanguage() {
return language;
}
/**
* Sets the value of the language property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setLanguage(String value) {
this.language = value;
}
/**
* Gets the value of the version property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getVersion() {
return version;
}
/**
* Sets the value of the version property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setVersion(String value) {
this.version = value;
}
/**
* Gets the value of the text property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getText() {
return text;
}
/**
* Sets the value of the text property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setText(String value) {
this.text = value;
}
}

@ -0,0 +1,118 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for ManagementRepository complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="ManagementRepository">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="DataSourceConfiguration" type="{}DataSourceConfiguration"/>
* &lt;element name="DeviceDefinition" type="{}DeviceDefinition"/>
* &lt;element name="ProvisioningConfig" type="{}ProvisioningConfig"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ManagementRepository", propOrder = {
"dataSourceConfiguration",
"deviceDefinition",
"provisioningConfig"
})
public class ManagementRepository {
@XmlElement(name = "DataSourceConfiguration", required = true)
protected DataSourceConfiguration dataSourceConfiguration;
@XmlElement(name = "DeviceDefinition", required = true)
protected DeviceDefinition deviceDefinition;
@XmlElement(name = "ProvisioningConfig", required = true)
protected ProvisioningConfig provisioningConfig;
/**
* Gets the value of the dataSourceConfiguration property.
*
* @return
* possible object is
* {@link DataSourceConfiguration }
*
*/
public DataSourceConfiguration getDataSourceConfiguration() {
return dataSourceConfiguration;
}
/**
* Sets the value of the dataSourceConfiguration property.
*
* @param value
* allowed object is
* {@link DataSourceConfiguration }
*
*/
public void setDataSourceConfiguration(DataSourceConfiguration value) {
this.dataSourceConfiguration = value;
}
/**
* Gets the value of the deviceDefinition property.
*
* @return
* possible object is
* {@link DeviceDefinition }
*
*/
public DeviceDefinition getDeviceDefinition() {
return deviceDefinition;
}
/**
* Sets the value of the deviceDefinition property.
*
* @param value
* allowed object is
* {@link DeviceDefinition }
*
*/
public void setDeviceDefinition(DeviceDefinition value) {
this.deviceDefinition = value;
}
/**
* Gets the value of the provisioningConfig property.
*
* @return
* possible object is
* {@link ProvisioningConfig }
*
*/
public ProvisioningConfig getProvisioningConfig() {
return provisioningConfig;
}
/**
* Sets the value of the provisioningConfig property.
*
* @param value
* allowed object is
* {@link ProvisioningConfig }
*
*/
public void setProvisioningConfig(ProvisioningConfig value) {
this.provisioningConfig = value;
}
}

@ -0,0 +1,69 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for Properties complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Properties">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Property" type="{}Property" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Properties", propOrder = {
"property"
})
public class Properties {
@XmlElement(name = "Property")
protected List<Property> property;
/**
* Gets the value of the property property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the property property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getProperty().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Property }
*
*
*/
public List<Property> getProperty() {
if (property == null) {
property = new ArrayList<Property>();
}
return this.property;
}
}

@ -0,0 +1,87 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
/**
* <p>Java class for Property complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="Property">
* &lt;simpleContent>
* &lt;extension base="&lt;http://www.w3.org/2001/XMLSchema>string">
* &lt;attribute name="Name" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/extension>
* &lt;/simpleContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Property", propOrder = {
"value"
})
public class Property {
@XmlValue
protected String value;
@XmlAttribute(name = "Name")
protected String name;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}
/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}
}

@ -1,39 +1,62 @@
/*
* 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.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* Class for holding device type configuration and parsing with JAXB.
* <p>Java class for ProvisioningConfig complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="ProvisioningConfig">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="SharedWithAllTenants" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlRootElement(name = "ProvisioningConfig")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ProvisioningConfig", propOrder = {
"sharedWithAllTenants"
})
public class ProvisioningConfig {
private boolean sharedWithAllTenants;
@XmlElement(name = "SharedWithAllTenants", required = true)
protected boolean sharedWithAllTenants;
/**
* Gets the value of the sharedWithAllTenants property.
*
* @return
* possible object is
* {@link boolean }
*
*/
public boolean isSharedWithAllTenants() {
return sharedWithAllTenants;
}
@XmlElement(name = "SharedWithAllTenants", required = true)
public boolean isSharedWithAllTenants() {
return sharedWithAllTenants;
}
/**
* Sets the value of the sharedWithAllTenants property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setSharedWithAllTenants(boolean value) {
this.sharedWithAllTenants = value;
}
public void setSharedWithAllTenants(boolean sharedWithAllTenants) {
this.sharedWithAllTenants = sharedWithAllTenants;
}
}
}

@ -1,79 +0,0 @@
/*
* 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,118 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for PushNotificationConfiguration complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="PushNotificationConfiguration">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="PushNotificationProvider" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="FileBasedProperties" type="{http://www.w3.org/2001/XMLSchema}string"/>
* &lt;element name="Properties" type="{}Properties"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PushNotificationConfiguration", propOrder = {
"pushNotificationProvider",
"fileBasedProperties",
"properties"
})
public class PushNotificationConfiguration {
@XmlElement(name = "PushNotificationProvider", required = true)
protected String pushNotificationProvider;
@XmlElement(name = "FileBasedProperties", required = true)
protected boolean fileBasedProperties;
@XmlElement(name = "Properties", required = true)
protected Properties properties;
/**
* Gets the value of the pushNotificationProvider property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPushNotificationProvider() {
return pushNotificationProvider;
}
/**
* Sets the value of the pushNotificationProvider property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPushNotificationProvider(String value) {
this.pushNotificationProvider = value;
}
/**
* Gets the value of the fileBasedProperties property.
*
* @return
* possible object is
* {@link String }
*
*/
public boolean isFileBasedProperties() {
return fileBasedProperties;
}
/**
* Sets the value of the fileBasedProperties property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setFileBasedProperties(boolean value) {
this.fileBasedProperties = value;
}
/**
* Gets the value of the properties property.
*
* @return
* possible object is
* {@link Properties }
*
*/
public Properties getProperties() {
return properties;
}
/**
* Sets the value of the properties property.
*
* @param value
* allowed object is
* {@link Properties }
*
*/
public void setProperties(Properties value) {
this.properties = value;
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
@ -15,26 +15,29 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception;
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 {
public class DeviceTypeDeployerFileException extends RuntimeException {
public DeviceTypeDeployerFileException(String msg, Exception nestedEx) {
super(msg, nestedEx);
}
private JNDILookupDefinition jndiLookupDefinition;
public DeviceTypeDeployerFileException(String message, Throwable cause) {
super(message, cause);
}
public DeviceTypeDeployerFileException(String msg) {
super(msg);
}
@XmlElement(name = "JndiLookupDefinition", required = true)
public JNDILookupDefinition getJndiLookupDefinition() {
return jndiLookupDefinition;
public DeviceTypeDeployerFileException() {
super();
}
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
this.jndiLookupDefinition = jndiLookupDefinition;
public DeviceTypeDeployerFileException(Throwable cause) {
super(cause);
}
}
}

@ -15,10 +15,16 @@ 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.DeviceDefinition;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceManagementConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Features;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeDeployerFileException;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao.DeviceDAODefinition;
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.feature.ConfigurationBasedFeatureManager;
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;
@ -39,14 +45,14 @@ public class DeviceTypeManager implements DeviceManager {
private String deviceType;
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
private LicenseManager licenseManager;
private boolean propertiesExist;
private FeatureManager featureManager;
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceManagementConfiguration deviceManagementConfiguration) {
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceManagementConfiguration);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean isSharedWithAllTenants =
deviceManagementConfiguration.getDeviceManagementConfigRepository().getProvisioningConfig()
boolean isSharedWithAllTenants = deviceManagementConfiguration.getManagementRepository().getProvisioningConfig()
.isSharedWithAllTenants();
DeviceTypeIdentifier deviceTypeIdentifier;
deviceType = deviceTypeConfigIdentifier.getDeviceType();
@ -56,21 +62,54 @@ public class DeviceTypeManager implements DeviceManager {
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId);
}
featureManager = new AnnotationBasedFeatureManager(deviceTypeIdentifier);
DeviceDefinition deviceDefinition = deviceManagementConfiguration.getManagementRepository().getDeviceDefinition();
if (deviceDefinition != null) {
//generate features.
Features featuresList = deviceManagementConfiguration.getManagementRepository().getDeviceDefinition().getFeatures();
if (featuresList != null) {
if (featuresList.isGenerate()) {
featureManager = new AnnotationBasedFeatureManager(deviceTypeIdentifier);
} else {
List<Feature> features = deviceDefinition.getFeatures().getFeature();
if (features != null) {
featureManager = new ConfigurationBasedFeatureManager(features);
}
}
}
//add license to registry.
this.licenseManager = new RegistryBasedLicenseManager();
try {
if (licenseManager.getLicense(deviceType, DeviceTypePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) {
this.licenseManager = new RegistryBasedLicenseManager();
License defaultLicense;
if (deviceDefinition.getLicense() != null) {
License defaultLicense = new License();
defaultLicense.setLanguage(deviceDefinition.getLicense().getLanguage());
defaultLicense.setVersion(deviceDefinition.getLicense().getVersion());
defaultLicense.setText(deviceDefinition.getLicense().getText());
licenseManager.addLicense(deviceType, defaultLicense);
}
}
} catch (LicenseManagementException e) {
String msg = "Error occurred while adding default license for " + deviceType + " devices";
throw new DeviceTypeDeployerFileException(msg, e);
}
try {
if (licenseManager.getLicense(deviceType, DeviceTypePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) {
defaultLicense = null;
licenseManager.addLicense(deviceType, defaultLicense);
//Check whether device dao definition exist.
String tableName = deviceManagementConfiguration.getManagementRepository().getDeviceDefinition()
.getTableName();
if (tableName != null && !tableName.isEmpty()) {
propertiesExist = true;
DeviceDAODefinition deviceDAODefinition = new DeviceDAODefinition(deviceDefinition);
String datasourceName = deviceManagementConfiguration.getManagementRepository()
.getDataSourceConfiguration().getJndiLookupDefinition().getName();
if (datasourceName != null && !datasourceName.isEmpty()) {
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(datasourceName, deviceDAODefinition);
} else {
throw new DeviceTypeDeployerFileException("Invalid datasource name.");
}
}
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);
}
}
@ -137,57 +176,63 @@ public class DeviceTypeManager implements DeviceManager {
@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) {
if (propertiesExist) {
boolean status = false;
boolean isEnrolled = this.isEnrolled(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
try {
deviceTypePluginDAOManager.rollbackTransaction();
} catch (DeviceTypeMgtPluginException ex) {
String msg = "Error occurred while roll back the device enrol transaction :" +
device.toString();
log.warn(msg, ex);
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);
}
String msg = "Error while enrolling the " + deviceType + " device : " + device.getDeviceIdentifier();
throw new DeviceManagementException(msg, e);
return status;
}
return status;
return true;
}
@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) {
if (propertiesExist) {
boolean status;
try {
deviceTypePluginDAOManager.rollbackTransaction();
} catch (DeviceTypeMgtPluginException mobileDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
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);
}
String msg = "Error while updating the enrollment of the " + deviceType + " device : " +
device.getDeviceIdentifier();
throw new DeviceManagementException(msg, e);
return status;
}
return status;
return true;
}
@Override
@ -198,22 +243,25 @@ public class DeviceTypeManager implements DeviceManager {
@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;
if (propertiesExist) {
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);
}
} catch (DeviceTypeMgtPluginException e) {
String msg = "Error while checking the enrollment status of " + deviceType + " device : " +
deviceId.getId();
throw new DeviceManagementException(msg, e);
return isEnrolled;
}
return isEnrolled;
return true;
}
@Override
@ -229,17 +277,20 @@ public class DeviceTypeManager implements DeviceManager {
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device;
try {
if (log.isDebugEnabled()) {
log.debug("Getting the details of " + deviceType + " device : '" + deviceId.getId() + "'");
if (propertiesExist) {
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);
}
device = deviceTypePluginDAOManager.getDeviceDAO().getDevice(deviceId.getId());
} catch (DeviceTypeMgtPluginException e) {
throw new DeviceManagementException(
"Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e);
return device;
}
return device;
return null;
}
@Override
@ -277,44 +328,50 @@ public class DeviceTypeManager implements DeviceManager {
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
throws DeviceManagementException {
boolean status;
Device existingDevice = this.getDevice(deviceIdentifier);
existingDevice.setProperties(device.getProperties());
if (propertiesExist) {
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);
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);
}
throw new DeviceManagementException(
"Error occurred while updating the " + deviceType + " device: '" +
device.getDeviceIdentifier() + "'", e);
return status;
}
return status;
return true;
}
@Override
public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null;
try {
if (log.isDebugEnabled()) {
log.debug("Fetching the details of all " + deviceType + " devices");
if (propertiesExist) {
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);
}
devices = deviceTypePluginDAOManager.getDeviceDAO().getAllDevices();
} catch (DeviceTypeMgtPluginException e) {
throw new DeviceManagementException("Error occurred while fetching all " + deviceType + " devices", e);
return devices;
}
return devices;
return null;
}
}

@ -11,6 +11,8 @@ 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 org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Property;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfiguration;
import java.util.HashMap;
import java.util.List;
@ -29,9 +31,8 @@ public class DeviceTypeManagerService implements DeviceManagementService {
DeviceManagementConfiguration deviceManagementConfiguration) {
this.setProvisioningConfig(deviceTypeConfigIdentifier.getTenantDomain(), deviceManagementConfiguration);
this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceManagementConfiguration);
this.setType(deviceManagementConfiguration);
this.populatePushNotificationConfig(deviceManagementConfiguration);
this.setType(deviceManagementConfiguration.getDeviceType());
this.populatePushNotificationConfig(deviceManagementConfiguration.getPushNotificationConfiguration());
}
@Override
@ -43,14 +44,11 @@ public class DeviceTypeManagerService implements DeviceManagementService {
public void init() throws DeviceManagementException {
}
private void populatePushNotificationConfig(DeviceManagementConfiguration deviceManagementConfiguration) {
org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfig sourceConfig =
deviceManagementConfiguration.getPushNotificationConfig();
private void populatePushNotificationConfig(PushNotificationConfiguration sourceConfig) {
if (sourceConfig != null) {
if (true) {
if (sourceConfig.isFileBasedProperties()) {
Map<String, String> staticProps = new HashMap<>();
for (org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfig.Property
property : sourceConfig.getProperties()) {
for (Property property : sourceConfig.getProperties().getProperty()) {
staticProps.put(property.getName(), property.getValue());
}
pushNotificationConfig = new PushNotificationConfig(sourceConfig.getPushNotificationProvider(),
@ -95,12 +93,12 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private void setProvisioningConfig(String tenantDomain, DeviceManagementConfiguration deviceManagementConfiguration) {
boolean sharedWithAllTenants = deviceManagementConfiguration
.getDeviceManagementConfigRepository().getProvisioningConfig().isSharedWithAllTenants();
.getManagementRepository().getProvisioningConfig().isSharedWithAllTenants();
provisioningConfig = new ProvisioningConfig(tenantDomain, sharedWithAllTenants);
}
private void setType(DeviceManagementConfiguration deviceManagementConfiguration) {
type = deviceManagementConfiguration.getDeviceType();
private void setType(String type) {
this.type = type;
}
private Map<String, String> getConfigProperty(List<ConfigurationEntry> configs) {

@ -0,0 +1,54 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Attribute;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.DeviceDefinition;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeDeployerFileException;
import java.util.ArrayList;
import java.util.List;
public class DeviceDAODefinition {
private String deviceTableName;
private String primarkey;
public List<String> getColumnNames() {
return columnNames;
}
private List<String> columnNames = new ArrayList<>();
public DeviceDAODefinition(DeviceDefinition deviceDefinition) {
deviceTableName = deviceDefinition.getTableName();
primarkey = deviceDefinition.getPrimaryKey();
List<Attribute> attributes = deviceDefinition.getAttributes().getAttribute();
if (deviceTableName == null || deviceTableName.isEmpty()) {
throw new DeviceTypeDeployerFileException("Missing deviceTableName");
}
if (primarkey == null || primarkey.isEmpty()) {
throw new DeviceTypeDeployerFileException("Missing primaryKey ");
}
if (attributes == null || attributes.size() == 0) {
throw new DeviceTypeDeployerFileException("Missing Attributes ");
}
for (Attribute attribute : attributes) {
if (attribute.getValue() == null ||attribute.getValue().isEmpty()) {
throw new DeviceTypeDeployerFileException("Unsupported attribute format for device definition");
}
columnNames.add(attribute.getValue());
}
}
public String getDeviceTableName() {
return deviceTableName;
}
public String getPrimarkey() {
return primarkey;
}
}

@ -18,10 +18,10 @@
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao;
import org.apache.commons.lang.StringUtils;
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;
@ -37,163 +37,220 @@ import java.util.List;
*/
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();
}
}
private static final Log log = LogFactory.getLog(DeviceTypePluginDAO.class);
private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
private DeviceDAODefinition deviceDAODefinition;
public DeviceTypePluginDAO(DeviceDAODefinition deviceDAODefinition,
DeviceTypePluginDAOManager deviceTypePluginDAOManager) {
this.deviceTypePluginDAOManager = deviceTypePluginDAOManager;
this.deviceDAODefinition = deviceDAODefinition;
}
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 " + getDeviceTableColumnNames() + " FROM " +
deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition.getPrimarkey() + " = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
resultSet = stmt.executeQuery();
if (resultSet.next()) {
device = new Device();
if (log.isDebugEnabled()) {
log.debug(deviceId + " data has been fetched from " + deviceDAODefinition.getDeviceTableName() +
" database.");
}
List<Device.Property> properties = new ArrayList<>();
for (String columnName : deviceDAODefinition.getColumnNames()) {
Device.Property property = new Device.Property();
property.setName(columnName);
property.setValue(resultSet.getString(columnName));
properties.add(property);
}
device.setProperties(properties);
}
} catch (SQLException e) {
String msg = "Error occurred while fetching device : '" + deviceId + "' from " + deviceDAODefinition
.getDeviceTableName();
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 " + deviceDAODefinition.getDeviceTableName() + "("
+ deviceDAODefinition.getPrimarkey() + " , " + getDeviceTableColumnNames() + ") VALUES ("
+ getPreparedInputString(deviceDAODefinition.getColumnNames().size() + 1) + ")";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, device.getDeviceIdentifier());
int columnIndex = 2;
for (String columnName : deviceDAODefinition.getColumnNames()) {
stmt.setString(columnIndex, getPropertString(device.getProperties(), columnName));
columnIndex++;
}
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("device " + device.getDeviceIdentifier() + " data has been" +
" added to the " + deviceDAODefinition.getDeviceTableName() + " database.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while adding the device '" +
device.getDeviceIdentifier() + "' to the " + deviceDAODefinition.getDeviceTableName() + " 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 " + deviceDAODefinition.getDeviceTableName() + " SET "
+ getDeviceTableColumnNamesForUpdateQuery()+ " WHERE " + deviceDAODefinition.getPrimarkey()
+ " = ?";
stmt = conn.prepareStatement(updateDBQuery);
int columnIndex = 1;
for (String columnName : deviceDAODefinition.getColumnNames()) {
stmt.setString(columnIndex, getPropertString(device.getProperties(), columnName));
columnIndex++;
}
stmt.setString(columnIndex, device.getDeviceIdentifier());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("device " + device.getDeviceIdentifier() + " data has been modified.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while modifying the device '" +
device.getDeviceIdentifier() + "' data. " + deviceDAODefinition.getDeviceTableName();
log.error(msg, e);
throw new DeviceTypeMgtPluginException(msg, e);
} finally {
DeviceTypeUtils.cleanupResources(stmt, null);
}
return status;
}
public boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = deviceTypePluginDAOManager.getConnection();
String deleteDBQuery = "DELETE FROM " + deviceDAODefinition.getDeviceTableName()
+ " WHERE " + deviceDAODefinition.getPrimarkey() + " = ?";
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1, deviceId);
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("device " + deviceId + " data has deleted from the " +
deviceDAODefinition.getDeviceTableName() + " table.");
}
}
} catch (SQLException e) {
String msg =
"Error occurred while deleting " + deviceDAODefinition.getDeviceTableName() + " device " + deviceId;
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 " + getDeviceTableColumnNames() + " FROM "
+ deviceDAODefinition.getDeviceTableName();
stmt = conn.prepareStatement(selectDBQuery);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
device = new Device();
device.setDeviceIdentifier(resultSet.getString(deviceDAODefinition.getPrimarkey()));
List<Device.Property> properties = new ArrayList<>();
for (String columnName : deviceDAODefinition.getColumnNames()) {
Device.Property property = new Device.Property();
property.setName(columnName);
property.setValue(resultSet.getString(columnName));
properties.add(property);
}
device.setProperties(properties);
devices.add(device);
}
if (log.isDebugEnabled()) {
log.debug(
"All device details have fetched from " + deviceDAODefinition.getDeviceTableName() + " table.");
}
return devices;
} catch (SQLException e) {
String msg =
"Error occurred while fetching all " + deviceDAODefinition.getDeviceTableName() + " device data'";
log.error(msg, e);
throw new DeviceTypeMgtPluginException(msg, e);
} finally {
DeviceTypeUtils.cleanupResources(stmt, resultSet);
deviceTypePluginDAOManager.closeConnection();
}
}
private String getDeviceTableColumnNames() {
return StringUtils.join(deviceDAODefinition.getColumnNames(), ", ");
}
private String getDeviceTableColumnNamesForUpdateQuery() {
return StringUtils.join(deviceDAODefinition.getColumnNames(), "= ?,");
}
private String getPreparedInputString(int length) {
String preparedInput = "?";
for (int i = 1; i < length; i++) {
preparedInput += ", ?";
}
return preparedInput;
}
private String getPropertString(List<Device.Property> properties, String propertyName) {
for (Device.Property property : properties) {
if (property.getName().equals(propertyName)) {
return property.getValue();
}
}
return null;
}
}

@ -21,6 +21,7 @@ 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.DeviceTypeDeployerFileException;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
import javax.naming.Context;
@ -37,19 +38,17 @@ public class DeviceTypePluginDAOManager {
private ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
private DeviceTypePluginDAO deviceTypePluginDAO;
public DeviceTypePluginDAOManager(DeviceManagementConfiguration deviceManagementConfiguration) {
initDAO(deviceManagementConfiguration);
deviceTypePluginDAO = new DeviceTypePluginDAO(deviceManagementConfiguration);
public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
initDAO(datasourceName);
deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, this);
}
public void initDAO(DeviceManagementConfiguration deviceManagementConfiguration) {
String datasourceName = deviceManagementConfiguration.getDeviceManagementConfigRepository()
.getDataSourceConfig().getJndiLookupDefinition().getJndiName();
public void initDAO(String datasourceName) {
try {
Context ctx = new InitialContext();
dataSource = (DataSource) ctx.lookup(datasourceName);
} catch (NamingException e) {
log.error("Error while looking up the data source: " + datasourceName, e);
throw new DeviceTypeDeployerFileException("Error while looking up the data source: " + datasourceName, e);
}
}

@ -4,10 +4,21 @@ 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.ArrayList;
import java.util.List;
public class ConfigurationBasedFeatureManager implements FeatureManager {
private List<Feature> features = new ArrayList<>();
public ConfigurationBasedFeatureManager(List<org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature> features) {
for (org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.Feature feature : features) {
Feature deviceFeature = new Feature();
deviceFeature.setCode(feature.getCode());
deviceFeature.setName(feature.getName());
deviceFeature.setDescription(feature.getDescription());
this.features.add(deviceFeature);
}
}
@Override
public boolean addFeature(Feature feature) throws DeviceManagementException {
return false;
@ -20,12 +31,18 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
@Override
public Feature getFeature(String name) throws DeviceManagementException {
return null;
Feature extractedFeature = null;
for (Feature feature : features) {
if (feature.getName().equalsIgnoreCase(name)) {
extractedFeature = feature;
}
}
return extractedFeature;
}
@Override
public List<Feature> getFeatures() throws DeviceManagementException {
return null;
return features;
}
@Override

@ -21,10 +21,9 @@ 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.device.mgt.extensions.device.type.deployer.internal.DeviceTypeManagementDataHolder;
import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.core.Registry;
@ -78,8 +77,8 @@ public class DeviceTypeUtils {
*/
public static void setupDeviceManagementSchema(DeviceManagementConfiguration deviceManagementConfiguration)
throws DeviceTypeMgtPluginException {
String datasourceName = deviceManagementConfiguration.getDeviceManagementConfigRepository()
.getDataSourceConfig().getJndiLookupDefinition().getJndiName();
String datasourceName = deviceManagementConfiguration.getManagementRepository().getDataSourceConfiguration()
.getJndiLookupDefinition().getName();
try {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(datasourceName);
@ -135,33 +134,4 @@ public class DeviceTypeUtils {
}
}
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;
}
}

@ -27,9 +27,6 @@ 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);

@ -25,46 +25,39 @@
<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>
<DeviceDefinition>
<TableName>SAMPLE_DEVICE</TableName>
<!--Primary Key should be the device identifier-->
<PrimaryKey>SAMPLE_DEVICE_ID</PrimaryKey>
<Attributes>
<Attribute>column1</Attribute>
<Attribute>column2</Attribute>
</Attributes>
<License>
<Language>en_US</Language>
<Version>1.0.0</Version>
<Text>This is license text</Text>
</License>
<!--if generate is set to true then the feature information will be picked up from the annotation in the api-->
<Features 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>
</Features>
</DeviceDefinition>
<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>
@ -72,6 +65,7 @@
<!--MQTT Config-->
<PushNotificationProvider>MQTT</PushNotificationProvider>
<FileBasedProperties>true</FileBasedProperties>
<!--if file based properties is set to false then the configuration will be picked from platform configuration-->
<Properties>
<Property Name="mqtt.adapter.name">sample.mqtt.adapter</Property>
<Property Name="url">tcp://localhost:1883</Property>

Loading…
Cancel
Save