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.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.DeviceManagementConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException; 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.DeviceTypeConfigIdentifier;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.DeviceTypeManagerService; 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 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) { private void unregisterDeviceType(String filePath) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("De-activating Virtual Firealarm Device Management Service Component"); log.debug("De-activating Device Management Service.");
} }
try { try {
if (this.deviceTypeServiceRegistrations.get(filePath) != null) { 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; package org.wso2.carbon.device.mgt.extensions.device.type.deployer.config;
import org.apache.commons.logging.LogFactory;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; 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") @XmlRootElement(name = "DeviceManagementConfiguration")
public class DeviceManagementConfiguration { public class DeviceManagementConfiguration {
private DeviceManagementConfigRepository deviceManagementConfigRepository; @XmlElement(name = "DeviceType", required = true)
private PushNotificationConfig pushNotificationConfig; protected String deviceType;
private String deviceType; @XmlElement(name = "ManagementRepository", required = true)
protected ManagementRepository managementRepository;
private static final Log log = LogFactory.getLog(DeviceManagementConfiguration.class); @XmlElement(name = "PushNotificationConfiguration", required = true)
protected PushNotificationConfiguration pushNotificationConfiguration;
private DeviceManagementConfiguration() {
}
@XmlElement(name = "DeviceType", required = false) /**
* Gets the value of the device property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getDeviceType() { public String getDeviceType() {
return deviceType; 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() { * Gets the value of the managementRepository property.
return deviceManagementConfigRepository; *
* @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() { * Gets the value of the pushNotificationConfiguration property.
return pushNotificationConfig; *
* @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; 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.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 { 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() { * Sets the value of the sharedWithAllTenants property.
return sharedWithAllTenants; *
} * @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, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -15,26 +15,29 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * 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;
/** public class DeviceTypeDeployerFileException extends RuntimeException {
* Class for holding device type configuration and parsing with JAXB.
*/ public DeviceTypeDeployerFileException(String msg, Exception nestedEx) {
@XmlRootElement(name = "FeaturesConfig") super(msg, nestedEx);
public class FeaturesConfig { }
private JNDILookupDefinition jndiLookupDefinition; public DeviceTypeDeployerFileException(String message, Throwable cause) {
super(message, cause);
}
public DeviceTypeDeployerFileException(String msg) {
super(msg);
}
@XmlElement(name = "JndiLookupDefinition", required = true) public DeviceTypeDeployerFileException() {
public JNDILookupDefinition getJndiLookupDefinition() { super();
return jndiLookupDefinition;
} }
public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) { public DeviceTypeDeployerFileException(Throwable cause) {
this.jndiLookupDefinition = jndiLookupDefinition; 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.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; 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.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.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.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.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.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.device.type.deployer.template.util.DeviceTypeUtils;
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
@ -39,14 +45,14 @@ public class DeviceTypeManager implements DeviceManager {
private String deviceType; private String deviceType;
private DeviceTypePluginDAOManager deviceTypePluginDAOManager; private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
private LicenseManager licenseManager; private LicenseManager licenseManager;
private boolean propertiesExist;
private FeatureManager featureManager; private FeatureManager featureManager;
public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceManagementConfiguration deviceManagementConfiguration) { DeviceManagementConfiguration deviceManagementConfiguration) {
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceManagementConfiguration);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
boolean isSharedWithAllTenants = boolean isSharedWithAllTenants = deviceManagementConfiguration.getManagementRepository().getProvisioningConfig()
deviceManagementConfiguration.getDeviceManagementConfigRepository().getProvisioningConfig()
.isSharedWithAllTenants(); .isSharedWithAllTenants();
DeviceTypeIdentifier deviceTypeIdentifier; DeviceTypeIdentifier deviceTypeIdentifier;
deviceType = deviceTypeConfigIdentifier.getDeviceType(); deviceType = deviceTypeConfigIdentifier.getDeviceType();
@ -56,21 +62,54 @@ public class DeviceTypeManager implements DeviceManager {
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId); 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(); if (deviceDefinition.getLicense() != null) {
License defaultLicense; 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 { //Check whether device dao definition exist.
if (licenseManager.getLicense(deviceType, DeviceTypePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) {
defaultLicense = null; String tableName = deviceManagementConfiguration.getManagementRepository().getDeviceDefinition()
licenseManager.addLicense(deviceType, defaultLicense); .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 @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status = false; if (propertiesExist) {
boolean isEnrolled = this.isEnrolled( boolean status = false;
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); boolean isEnrolled = this.isEnrolled(
try { new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
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 { try {
deviceTypePluginDAOManager.rollbackTransaction(); if (log.isDebugEnabled()) {
} catch (DeviceTypeMgtPluginException ex) { log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier());
String msg = "Error occurred while roll back the device enrol transaction :" + }
device.toString(); if (isEnrolled) {
log.warn(msg, ex); 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(); return status;
throw new DeviceManagementException(msg, e);
} }
return status; return true;
} }
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status; if (propertiesExist) {
try { boolean status;
if (log.isDebugEnabled()) {
log.debug("Modifying the Android device enrollment data");
}
deviceTypePluginDAOManager.beginTransaction();
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device);
deviceTypePluginDAOManager.commitTransaction();
} catch (DeviceTypeMgtPluginException e) {
try { try {
deviceTypePluginDAOManager.rollbackTransaction(); if (log.isDebugEnabled()) {
} catch (DeviceTypeMgtPluginException mobileDAOEx) { log.debug("Modifying the Android device enrollment data");
String msg = "Error occurred while roll back the update device transaction :" + }
device.toString(); deviceTypePluginDAOManager.beginTransaction();
log.warn(msg, mobileDAOEx); 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 : " + return status;
device.getDeviceIdentifier();
throw new DeviceManagementException(msg, e);
} }
return status; return true;
} }
@Override @Override
@ -198,22 +243,25 @@ public class DeviceTypeManager implements DeviceManager {
@Override @Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean isEnrolled = false; if (propertiesExist) {
try { boolean isEnrolled = false;
if (log.isDebugEnabled()) { try {
log.debug("Checking the enrollment of Android device : " + deviceId.getId()); if (log.isDebugEnabled()) {
} log.debug("Checking the enrollment of Android device : " + deviceId.getId());
Device device = }
deviceTypePluginDAOManager.getDeviceDAO().getDevice(deviceId.getId()); Device device =
if (device != null) { deviceTypePluginDAOManager.getDeviceDAO().getDevice(deviceId.getId());
isEnrolled = true; 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) { return isEnrolled;
String msg = "Error while checking the enrollment status of " + deviceType + " device : " +
deviceId.getId();
throw new DeviceManagementException(msg, e);
} }
return isEnrolled; return true;
} }
@Override @Override
@ -229,17 +277,20 @@ public class DeviceTypeManager implements DeviceManager {
@Override @Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
Device device; if (propertiesExist) {
try { Device device;
if (log.isDebugEnabled()) { try {
log.debug("Getting the details of " + deviceType + " device : '" + deviceId.getId() + "'"); 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()); return device;
} catch (DeviceTypeMgtPluginException e) {
throw new DeviceManagementException(
"Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e);
} }
return device; return null;
} }
@Override @Override
@ -277,44 +328,50 @@ public class DeviceTypeManager implements DeviceManager {
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device)
throws DeviceManagementException { throws DeviceManagementException {
boolean status; if (propertiesExist) {
Device existingDevice = this.getDevice(deviceIdentifier); boolean status;
existingDevice.setProperties(device.getProperties()); 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 { try {
deviceTypePluginDAOManager.rollbackTransaction(); if (log.isDebugEnabled()) {
} catch (DeviceTypeMgtPluginException e1) { log.debug(
log.warn("Error occurred while roll back the update device info transaction : '" + "updating the details of " + deviceType + " device : " + device.getDeviceIdentifier());
device.toString() + "'", e1); }
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( return status;
"Error occurred while updating the " + deviceType + " device: '" +
device.getDeviceIdentifier() + "'", e);
} }
return status; return true;
} }
@Override @Override
public List<Device> getAllDevices() throws DeviceManagementException { public List<Device> getAllDevices() throws DeviceManagementException {
List<Device> devices = null; if (propertiesExist) {
try { List<Device> devices = null;
if (log.isDebugEnabled()) { try {
log.debug("Fetching the details of all " + deviceType + " devices"); 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(); return devices;
} catch (DeviceTypeMgtPluginException e) {
throw new DeviceManagementException("Error occurred while fetching all " + deviceType + " devices", e);
} }
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.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; 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.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.HashMap;
import java.util.List; import java.util.List;
@ -29,9 +31,8 @@ public class DeviceTypeManagerService implements DeviceManagementService {
DeviceManagementConfiguration deviceManagementConfiguration) { DeviceManagementConfiguration deviceManagementConfiguration) {
this.setProvisioningConfig(deviceTypeConfigIdentifier.getTenantDomain(), deviceManagementConfiguration); this.setProvisioningConfig(deviceTypeConfigIdentifier.getTenantDomain(), deviceManagementConfiguration);
this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceManagementConfiguration); this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceManagementConfiguration);
this.setType(deviceManagementConfiguration); this.setType(deviceManagementConfiguration.getDeviceType());
this.populatePushNotificationConfig(deviceManagementConfiguration); this.populatePushNotificationConfig(deviceManagementConfiguration.getPushNotificationConfiguration());
} }
@Override @Override
@ -43,14 +44,11 @@ public class DeviceTypeManagerService implements DeviceManagementService {
public void init() throws DeviceManagementException { public void init() throws DeviceManagementException {
} }
private void populatePushNotificationConfig(DeviceManagementConfiguration deviceManagementConfiguration) { private void populatePushNotificationConfig(PushNotificationConfiguration sourceConfig) {
org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfig sourceConfig =
deviceManagementConfiguration.getPushNotificationConfig();
if (sourceConfig != null) { if (sourceConfig != null) {
if (true) { if (sourceConfig.isFileBasedProperties()) {
Map<String, String> staticProps = new HashMap<>(); Map<String, String> staticProps = new HashMap<>();
for (org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.PushNotificationConfig.Property for (Property property : sourceConfig.getProperties().getProperty()) {
property : sourceConfig.getProperties()) {
staticProps.put(property.getName(), property.getValue()); staticProps.put(property.getName(), property.getValue());
} }
pushNotificationConfig = new PushNotificationConfig(sourceConfig.getPushNotificationProvider(), pushNotificationConfig = new PushNotificationConfig(sourceConfig.getPushNotificationProvider(),
@ -95,12 +93,12 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private void setProvisioningConfig(String tenantDomain, DeviceManagementConfiguration deviceManagementConfiguration) { private void setProvisioningConfig(String tenantDomain, DeviceManagementConfiguration deviceManagementConfiguration) {
boolean sharedWithAllTenants = deviceManagementConfiguration boolean sharedWithAllTenants = deviceManagementConfiguration
.getDeviceManagementConfigRepository().getProvisioningConfig().isSharedWithAllTenants(); .getManagementRepository().getProvisioningConfig().isSharedWithAllTenants();
provisioningConfig = new ProvisioningConfig(tenantDomain, sharedWithAllTenants); provisioningConfig = new ProvisioningConfig(tenantDomain, sharedWithAllTenants);
} }
private void setType(DeviceManagementConfiguration deviceManagementConfiguration) { private void setType(String type) {
type = deviceManagementConfiguration.getDeviceType(); this.type = type;
} }
private Map<String, String> getConfigProperty(List<ConfigurationEntry> configs) { 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; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; 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.exception.DeviceTypeMgtPluginException;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util.DeviceTypeUtils;
@ -37,163 +37,220 @@ import java.util.List;
*/ */
public class DeviceTypePluginDAO { public class DeviceTypePluginDAO {
private static final Log log = LogFactory.getLog(DeviceTypePluginDAO.class); private static final Log log = LogFactory.getLog(DeviceTypePluginDAO.class);
private DeviceTypePluginDAOManager deviceTypePluginDAOManager; private DeviceTypePluginDAOManager deviceTypePluginDAOManager;
public DeviceTypePluginDAO(DeviceManagementConfiguration deviceManagementConfiguration) { private DeviceDAODefinition deviceDAODefinition;
deviceTypePluginDAOManager = new DeviceTypePluginDAOManager(deviceManagementConfiguration);
} public DeviceTypePluginDAO(DeviceDAODefinition deviceDAODefinition,
DeviceTypePluginDAOManager deviceTypePluginDAOManager) {
public Device getDevice(String deviceId) throws DeviceTypeMgtPluginException { this.deviceTypePluginDAOManager = deviceTypePluginDAOManager;
Connection conn = null; this.deviceDAODefinition = deviceDAODefinition;
PreparedStatement stmt = null; }
Device device = null;
ResultSet resultSet = null; public Device getDevice(String deviceId) throws DeviceTypeMgtPluginException {
try { Connection conn = null;
conn = deviceTypePluginDAOManager.getConnection(); PreparedStatement stmt = null;
String selectDBQuery = Device device = null;
"SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME" + ResultSet resultSet = null;
" FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?"; try {
stmt = conn.prepareStatement(selectDBQuery); conn = deviceTypePluginDAOManager.getConnection();
stmt.setString(1, deviceId); String selectDBQuery = "SELECT " + getDeviceTableColumnNames() + " FROM " +
resultSet = stmt.executeQuery(); deviceDAODefinition.getDeviceTableName() + " WHERE " + deviceDAODefinition.getPrimarkey() + " = ?";
stmt = conn.prepareStatement(selectDBQuery);
if (resultSet.next()) { stmt.setString(1, deviceId);
device = new Device(); resultSet = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Virtual Firealarm device " + deviceId + " data has been fetched from " + if (resultSet.next()) {
"Virtual Firealarm database."); device = new Device();
} if (log.isDebugEnabled()) {
} log.debug(deviceId + " data has been fetched from " + deviceDAODefinition.getDeviceTableName() +
} catch (SQLException e) { " database.");
String msg = "Error occurred while fetching Virtual Firealarm device : '" + deviceId + "'"; }
log.error(msg, e); List<Device.Property> properties = new ArrayList<>();
throw new DeviceTypeMgtPluginException(msg, e); for (String columnName : deviceDAODefinition.getColumnNames()) {
} finally { Device.Property property = new Device.Property();
DeviceTypeUtils.cleanupResources(stmt, resultSet); property.setName(columnName);
deviceTypePluginDAOManager.closeConnection(); property.setValue(resultSet.getString(columnName));
} properties.add(property);
}
return device; device.setProperties(properties);
} }
public boolean addDevice(Device device) throws DeviceTypeMgtPluginException { } catch (SQLException e) {
boolean status = false; String msg = "Error occurred while fetching device : '" + deviceId + "' from " + deviceDAODefinition
Connection conn = null; .getDeviceTableName();
PreparedStatement stmt = null; log.error(msg, e);
try { throw new DeviceTypeMgtPluginException(msg, e);
conn = deviceTypePluginDAOManager.getConnection(); } finally {
String createDBQuery = DeviceTypeUtils.cleanupResources(stmt, resultSet);
"INSERT INTO VIRTUAL_FIREALARM_DEVICE(VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)"; deviceTypePluginDAOManager.closeConnection();
}
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, device.getDeviceIdentifier()); return device;
stmt.setString(2, device.getName()); }
int rows = stmt.executeUpdate();
if (rows > 0) { public boolean addDevice(Device device) throws DeviceTypeMgtPluginException {
status = true; boolean status = false;
if (log.isDebugEnabled()) { Connection conn = null;
log.debug("Virtual Firealarm device " + device.getDeviceIdentifier() + " data has been" + PreparedStatement stmt = null;
" added to the Virtual Firealarm database."); try {
} conn = deviceTypePluginDAOManager.getConnection();
} String createDBQuery = "INSERT INTO " + deviceDAODefinition.getDeviceTableName() + "("
} catch (SQLException e) { + deviceDAODefinition.getPrimarkey() + " , " + getDeviceTableColumnNames() + ") VALUES ("
String msg = "Error occurred while adding the Virtual Firealarm device '" + + getPreparedInputString(deviceDAODefinition.getColumnNames().size() + 1) + ")";
device.getDeviceIdentifier() + "' to the Virtual Firealarm db."; stmt = conn.prepareStatement(createDBQuery);
log.error(msg, e); stmt.setString(1, device.getDeviceIdentifier());
throw new DeviceTypeMgtPluginException(msg, e); int columnIndex = 2;
} finally { for (String columnName : deviceDAODefinition.getColumnNames()) {
DeviceTypeUtils.cleanupResources(stmt, null); stmt.setString(columnIndex, getPropertString(device.getProperties(), columnName));
} columnIndex++;
return status; }
} int rows = stmt.executeUpdate();
if (rows > 0) {
public boolean updateDevice(Device device) throws DeviceTypeMgtPluginException { status = true;
boolean status = false; if (log.isDebugEnabled()) {
Connection conn = null; log.debug("device " + device.getDeviceIdentifier() + " data has been" +
PreparedStatement stmt = null; " added to the " + deviceDAODefinition.getDeviceTableName() + " database.");
try { }
conn = DeviceTypePluginDAOManager.getConnection(); }
String updateDBQuery = } catch (SQLException e) {
"UPDATE VIRTUAL_FIREALARM_DEVICE SET DEVICE_NAME = ? WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?"; String msg = "Error occurred while adding the device '" +
device.getDeviceIdentifier() + "' to the " + deviceDAODefinition.getDeviceTableName() + " db.";
stmt = conn.prepareStatement(updateDBQuery); log.error(msg, e);
stmt.setString(1, device.getName()); throw new DeviceTypeMgtPluginException(msg, e);
stmt.setString(2, device.getDeviceIdentifier()); } finally {
int rows = stmt.executeUpdate(); DeviceTypeUtils.cleanupResources(stmt, null);
if (rows > 0) { }
status = true; return status;
if (log.isDebugEnabled()) { }
log.debug("Virtualm Firealarm device " + device.getDeviceIdentifier() + " data has been" +
" modified."); public boolean updateDevice(Device device) throws DeviceTypeMgtPluginException {
} boolean status = false;
} Connection conn = null;
} catch (SQLException e) { PreparedStatement stmt = null;
String msg = "Error occurred while modifying the Virtual Firealarm device '" + try {
device.getDeviceIdentifier() + "' data."; conn = deviceTypePluginDAOManager.getConnection();
log.error(msg, e); String updateDBQuery = "UPDATE " + deviceDAODefinition.getDeviceTableName() + " SET "
throw new DeviceTypeMgtPluginException(msg, e); + getDeviceTableColumnNamesForUpdateQuery()+ " WHERE " + deviceDAODefinition.getPrimarkey()
} finally { + " = ?";
DeviceTypeUtils.cleanupResources(stmt, null);
} stmt = conn.prepareStatement(updateDBQuery);
return status; int columnIndex = 1;
} for (String columnName : deviceDAODefinition.getColumnNames()) {
stmt.setString(columnIndex, getPropertString(device.getProperties(), columnName));
public boolean deleteDevice(String iotDeviceId) throws DeviceTypeMgtPluginException { columnIndex++;
boolean status = false; }
Connection conn = null; stmt.setString(columnIndex, device.getDeviceIdentifier());
PreparedStatement stmt = null; int rows = stmt.executeUpdate();
try { if (rows > 0) {
conn = deviceTypePluginDAOManager.getConnection(); status = true;
String deleteDBQuery = "DELETE FROM VIRTUAL_FIREALARM_DEVICE WHERE VIRTUAL_FIREALARM_DEVICE_ID = ?"; if (log.isDebugEnabled()) {
stmt = conn.prepareStatement(deleteDBQuery); log.debug("device " + device.getDeviceIdentifier() + " data has been modified.");
stmt.setString(1, iotDeviceId); }
int rows = stmt.executeUpdate(); }
if (rows > 0) { } catch (SQLException e) {
status = true; String msg = "Error occurred while modifying the device '" +
if (log.isDebugEnabled()) { device.getDeviceIdentifier() + "' data. " + deviceDAODefinition.getDeviceTableName();
log.debug("Virtual Firealarm device " + iotDeviceId + " data has deleted" + log.error(msg, e);
" from the Virtual Firealarm database."); throw new DeviceTypeMgtPluginException(msg, e);
} } finally {
} DeviceTypeUtils.cleanupResources(stmt, null);
} catch (SQLException e) { }
String msg = "Error occurred while deleting Virtual Firealarm device " + iotDeviceId; return status;
log.error(msg, e); }
throw new DeviceTypeMgtPluginException(msg, e);
} finally { public boolean deleteDevice(String deviceId) throws DeviceTypeMgtPluginException {
DeviceTypeUtils.cleanupResources(stmt, null); boolean status = false;
} Connection conn = null;
return status; PreparedStatement stmt = null;
} try {
conn = deviceTypePluginDAOManager.getConnection();
public List<Device> getAllDevices() throws DeviceTypeMgtPluginException { String deleteDBQuery = "DELETE FROM " + deviceDAODefinition.getDeviceTableName()
Connection conn; + " WHERE " + deviceDAODefinition.getPrimarkey() + " = ?";
PreparedStatement stmt = null; stmt = conn.prepareStatement(deleteDBQuery);
ResultSet resultSet = null; stmt.setString(1, deviceId);
Device device; int rows = stmt.executeUpdate();
List<Device> devices = new ArrayList<>(); if (rows > 0) {
try { status = true;
conn = deviceTypePluginDAOManager.getConnection(); if (log.isDebugEnabled()) {
String selectDBQuery = log.debug("device " + deviceId + " data has deleted from the " +
"SELECT VIRTUAL_FIREALARM_DEVICE_ID, DEVICE_NAME FROM VIRTUAL_FIREALARM_DEVICE"; deviceDAODefinition.getDeviceTableName() + " table.");
stmt = conn.prepareStatement(selectDBQuery); }
resultSet = stmt.executeQuery(); }
while (resultSet.next()) { } catch (SQLException e) {
device = new Device(); String msg =
device.setDeviceIdentifier(resultSet.getString(VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_ID)); "Error occurred while deleting " + deviceDAODefinition.getDeviceTableName() + " device " + deviceId;
device.setName(resultSet.getString(VirtualFireAlarmConstants.DEVICE_PLUGIN_DEVICE_NAME)); log.error(msg, e);
devices.add(device); throw new DeviceTypeMgtPluginException(msg, e);
} } finally {
if (log.isDebugEnabled()) { DeviceTypeUtils.cleanupResources(stmt, null);
log.debug("All Virtual Firealarm device details have fetched from Firealarm database."); }
} return status;
return devices; }
} catch (SQLException e) {
String msg = "Error occurred while fetching all Virtual Firealarm device data'"; public List<Device> getAllDevices() throws DeviceTypeMgtPluginException {
log.error(msg, e); Connection conn;
throw new DeviceTypeMgtPluginException(msg, e); PreparedStatement stmt = null;
} finally { ResultSet resultSet = null;
DeviceTypeUtils.cleanupResources(stmt, resultSet); Device device;
deviceTypePluginDAOManager.closeConnection(); 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.Log;
import org.apache.commons.logging.LogFactory; 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.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 org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException;
import javax.naming.Context; import javax.naming.Context;
@ -37,19 +38,17 @@ public class DeviceTypePluginDAOManager {
private ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>(); private ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
private DeviceTypePluginDAO deviceTypePluginDAO; private DeviceTypePluginDAO deviceTypePluginDAO;
public DeviceTypePluginDAOManager(DeviceManagementConfiguration deviceManagementConfiguration) { public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) {
initDAO(deviceManagementConfiguration); initDAO(datasourceName);
deviceTypePluginDAO = new DeviceTypePluginDAO(deviceManagementConfiguration); deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, this);
} }
public void initDAO(DeviceManagementConfiguration deviceManagementConfiguration) { public void initDAO(String datasourceName) {
String datasourceName = deviceManagementConfiguration.getDeviceManagementConfigRepository()
.getDataSourceConfig().getJndiLookupDefinition().getJndiName();
try { try {
Context ctx = new InitialContext(); Context ctx = new InitialContext();
dataSource = (DataSource) ctx.lookup(datasourceName); dataSource = (DataSource) ctx.lookup(datasourceName);
} catch (NamingException e) { } 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.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.FeatureManager;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ConfigurationBasedFeatureManager implements FeatureManager { 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 @Override
public boolean addFeature(Feature feature) throws DeviceManagementException { public boolean addFeature(Feature feature) throws DeviceManagementException {
return false; return false;
@ -20,12 +31,18 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
@Override @Override
public Feature getFeature(String name) throws DeviceManagementException { 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 @Override
public List<Feature> getFeatures() throws DeviceManagementException { public List<Feature> getFeatures() throws DeviceManagementException {
return null; return features;
} }
@Override @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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.config.DeviceManagementConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException; 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.RegistryException;
import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.core.Registry; import org.wso2.carbon.registry.core.Registry;
@ -78,8 +77,8 @@ public class DeviceTypeUtils {
*/ */
public static void setupDeviceManagementSchema(DeviceManagementConfiguration deviceManagementConfiguration) public static void setupDeviceManagementSchema(DeviceManagementConfiguration deviceManagementConfiguration)
throws DeviceTypeMgtPluginException { throws DeviceTypeMgtPluginException {
String datasourceName = deviceManagementConfiguration.getDeviceManagementConfigRepository() String datasourceName = deviceManagementConfiguration.getManagementRepository().getDataSourceConfiguration()
.getDataSourceConfig().getJndiLookupDefinition().getJndiName(); .getJndiLookupDefinition().getName();
try { try {
Context ctx = new InitialContext(); Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(datasourceName); 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 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 { public static Document convertToDocument(File file) throws DeviceTypeConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);

@ -25,46 +25,39 @@
<JndiLookupDefinition> <JndiLookupDefinition>
<Name>jdbc/SampleDM_DB</Name> <Name>jdbc/SampleDM_DB</Name>
</JndiLookupDefinition> </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> </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> <ProvisioningConfig>
<SharedWithAllTenants>false</SharedWithAllTenants> <SharedWithAllTenants>false</SharedWithAllTenants>
</ProvisioningConfig> </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> </ManagementRepository>
@ -72,6 +65,7 @@
<!--MQTT Config--> <!--MQTT Config-->
<PushNotificationProvider>MQTT</PushNotificationProvider> <PushNotificationProvider>MQTT</PushNotificationProvider>
<FileBasedProperties>true</FileBasedProperties> <FileBasedProperties>true</FileBasedProperties>
<!--if file based properties is set to false then the configuration will be picked from platform configuration-->
<Properties> <Properties>
<Property Name="mqtt.adapter.name">sample.mqtt.adapter</Property> <Property Name="mqtt.adapter.name">sample.mqtt.adapter</Property>
<Property Name="url">tcp://localhost:1883</Property> <Property Name="url">tcp://localhost:1883</Property>

Loading…
Cancel
Save