mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added Pluggable Device Type
This commit is contained in:
parent
ed366867d1
commit
abc9315f95
@ -29,12 +29,12 @@ import org.osgi.framework.ServiceRegistration;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
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.DeviceTypeConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.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;
|
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.util.DeviceTypeConfigUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeConfigIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.DeviceTypeManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|||||||
@ -1,123 +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;
|
|
||||||
|
|
||||||
import org.apache.axis2.context.ConfigurationContext;
|
|
||||||
import org.apache.axis2.deployment.AbstractDeployer;
|
|
||||||
import org.apache.axis2.deployment.DeploymentException;
|
|
||||||
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the device deployer that will read and deploy the device type ui files from
|
|
||||||
* "deployment/server/devicetypes-ui"
|
|
||||||
* directory.
|
|
||||||
*/
|
|
||||||
public class DeviceTypeUIDeployer extends AbstractDeployer {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceTypeUIDeployer.class);
|
|
||||||
protected Map<String, String> deviceTypeDeployedUIMap = new ConcurrentHashMap<String, String>();
|
|
||||||
private static final String DEVICEMGT_JAGGERY_APP_PATH = CarbonUtils.getCarbonRepository() + File.separator
|
|
||||||
+ "jaggeryapps" + File.separator + "devicemgt" + File.separator + "app" + File.separator + "units"
|
|
||||||
+ File.separator;
|
|
||||||
|
|
||||||
private static final String UNIT_PREFIX = "cdmf.unit.device.type";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(ConfigurationContext configurationContext) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDirectory(String s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setExtension(String s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
|
|
||||||
if (!deploymentFileData.getFile().isDirectory()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
|
||||||
if (tenantDomain != null && !tenantDomain.isEmpty()) {
|
|
||||||
File jaggeryAppPath = new File(
|
|
||||||
DEVICEMGT_JAGGERY_APP_PATH + tenantDomain + "." + deploymentFileData.getName());
|
|
||||||
try {
|
|
||||||
if (!jaggeryAppPath.exists()) {
|
|
||||||
FileUtils.forceMkdir(jaggeryAppPath);
|
|
||||||
FileUtils.copyDirectory(deploymentFileData.getFile(), jaggeryAppPath);
|
|
||||||
File[] listOfFiles = jaggeryAppPath.listFiles();
|
|
||||||
|
|
||||||
for (int i = 0; i < listOfFiles.length; i++) {
|
|
||||||
if (listOfFiles[i].isFile()) {
|
|
||||||
String content = FileUtils.readFileToString(listOfFiles[i]);
|
|
||||||
FileUtils.writeStringToFile(listOfFiles[i], content.replaceAll(UNIT_PREFIX
|
|
||||||
, tenantDomain + "." + UNIT_PREFIX));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.debug("units already exists " + deploymentFileData.getName());
|
|
||||||
}
|
|
||||||
this.deviceTypeDeployedUIMap.put(deploymentFileData.getAbsolutePath(),
|
|
||||||
jaggeryAppPath.getAbsolutePath());
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (jaggeryAppPath.exists()) {
|
|
||||||
try {
|
|
||||||
FileUtils.deleteDirectory(jaggeryAppPath);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
log.error("Failed to delete directory " + jaggeryAppPath.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.error("Cannot deploy deviceType ui : " + deploymentFileData.getName(), e);
|
|
||||||
throw new DeploymentException(
|
|
||||||
"Device type ui file " + deploymentFileData.getName() + " is not deployed ", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
log.error("Cannot deploy deviceType ui: " + deploymentFileData.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void undeploy(String filePath) throws DeploymentException {
|
|
||||||
try {
|
|
||||||
String jaggeryUnitPath = this.deviceTypeDeployedUIMap.remove(filePath);
|
|
||||||
FileUtils.deleteDirectory(new File(jaggeryUnitPath));
|
|
||||||
log.info("Device Type units un deployed successfully.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DeploymentException("Failed to remove the units: " + filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,198 +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.JAXBElement;
|
|
||||||
import javax.xml.bind.annotation.XmlElementDecl;
|
|
||||||
import javax.xml.bind.annotation.XmlRegistry;
|
|
||||||
import javax.xml.namespace.QName;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This object contains factory methods for each
|
|
||||||
* Java content interface and Java element interface
|
|
||||||
* generated in the org.wso2.carbon package.
|
|
||||||
* <p>An ObjectFactory allows you to programatically
|
|
||||||
* construct new instances of the Java representation
|
|
||||||
* for XML content. The Java representation of XML
|
|
||||||
* content can consist of schema derived interfaces
|
|
||||||
* and classes representing the binding of schema
|
|
||||||
* type definitions, element declarations and model
|
|
||||||
* groups. Factory methods for each of these are
|
|
||||||
* provided in this class.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@XmlRegistry
|
|
||||||
public class ObjectFactory {
|
|
||||||
|
|
||||||
private final static QName _DeviceTypeConfiguration_QNAME = new QName("", "DeviceTypeConfiguration");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.wso2.carbon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public ObjectFactory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link DeviceTypeConfiguration }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public DeviceTypeConfiguration createDeviceTypeConfiguration() {
|
|
||||||
return new DeviceTypeConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link Operation }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Operation createOperation() {
|
|
||||||
return new Operation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link Attributes }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Attributes createAttributes() {
|
|
||||||
return new Attributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link ProvisioningConfig }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public ProvisioningConfig createProvisioningConfig() {
|
|
||||||
return new ProvisioningConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link TableConfig }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public TableConfig createTableConfig() {
|
|
||||||
return new TableConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link Table }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Table createTable() {
|
|
||||||
return new Table();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link Property }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Property createProperty() {
|
|
||||||
return new Property();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link JndiConfig }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public JndiConfig createJndiConfig() {
|
|
||||||
return new JndiConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link FormParameters }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public FormParameters createFormParameters() {
|
|
||||||
return new FormParameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link Features }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Features createFeatures() {
|
|
||||||
return new Features();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link Feature }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Feature createFeature() {
|
|
||||||
return new Feature();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link PushNotificationProvider }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public PushNotificationProvider createPushNotificationProvider() {
|
|
||||||
return new PushNotificationProvider();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link DataSource }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public DataSource createDataSource() {
|
|
||||||
return new DataSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link ConfigProperties }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public ConfigProperties createConfigProperties() {
|
|
||||||
return new ConfigProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link License }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public License createLicense() {
|
|
||||||
return new License();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link DeviceDetails }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public DeviceDetails createDeviceDetails() {
|
|
||||||
return new DeviceDetails();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link QueryParameters }
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public QueryParameters createQueryParameters() {
|
|
||||||
return new QueryParameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of {@link JAXBElement }{@code <}{@link DeviceTypeConfiguration }{@code >}}
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@XmlElementDecl(namespace = "", name = "DeviceTypeConfiguration")
|
|
||||||
public JAXBElement<DeviceTypeConfiguration> createDeviceTypeConfiguration(DeviceTypeConfiguration value) {
|
|
||||||
return new JAXBElement<DeviceTypeConfiguration>(_DeviceTypeConfiguration_QNAME, DeviceTypeConfiguration.class, null, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -28,7 +28,7 @@ import org.wso2.carbon.registry.core.service.RegistryService;
|
|||||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeManagementServiceComponent"
|
* @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeExtensionServiceComponent"
|
||||||
* immediate="true"
|
* immediate="true"
|
||||||
* @scr.reference name="config.context.service"
|
* @scr.reference name="config.context.service"
|
||||||
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
|
package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException;
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
|||||||
@ -22,9 +22,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util;
|
|||||||
* This holds the constants used for this bundle.
|
* This holds the constants used for this bundle.
|
||||||
*/
|
*/
|
||||||
public class DeviceTypePluginConstants {
|
public class DeviceTypePluginConstants {
|
||||||
public static final String MEDIA_TYPE_XML = "application/xml";
|
|
||||||
public static final String CHARSET_UTF8 = "UTF8";
|
|
||||||
public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
|
|
||||||
|
|
||||||
public static final String CDMF_UI_TYPE = "devicetype/ui";
|
public static final String CDMF_UI_TYPE = "devicetype/ui";
|
||||||
public static final String CDMF_UI_TYPE_DIR = "devicetypes-ui";
|
public static final String CDMF_UI_TYPE_DIR = "devicetypes-ui";
|
||||||
|
|||||||
@ -1,145 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
~
|
|
||||||
~ WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
~ Version 2.0 (the "License"); you may not use this file except
|
|
||||||
~ in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing,
|
|
||||||
~ software distributed under the License is distributed on an
|
|
||||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
~ KIND, either express or implied. See the License for the
|
|
||||||
~ specific language governing permissions and limitations
|
|
||||||
~ under the License.
|
|
||||||
-->
|
|
||||||
<DeviceTypeConfiguration name="samples">
|
|
||||||
|
|
||||||
<!--IF SAVE ON PREDEFINED TABLE-->
|
|
||||||
<!--<DeviceDetails table-id="SAMPLE_DEVICE_1"/>-->
|
|
||||||
<!--ELSE SAVE ON EXISTING TABLE-->
|
|
||||||
<DeviceDetails>
|
|
||||||
<Properties>
|
|
||||||
<Property>attr1</Property>
|
|
||||||
<Property>attr2</Property>
|
|
||||||
</Properties>
|
|
||||||
</DeviceDetails>
|
|
||||||
<!--END-->
|
|
||||||
|
|
||||||
<Features>
|
|
||||||
<Feature code="abc">
|
|
||||||
<Name>abc</Name>
|
|
||||||
<Description>this is a feature</Description>
|
|
||||||
<Operation context="/bulb/{state}" method="PUT" type="application/json">
|
|
||||||
<QueryParameters>
|
|
||||||
<Parameter>deviceId</Parameter>
|
|
||||||
</QueryParameters>
|
|
||||||
<FormParameters>
|
|
||||||
<Parameter>test</Parameter>
|
|
||||||
</FormParameters>
|
|
||||||
</Operation>
|
|
||||||
</Feature>
|
|
||||||
</Features>
|
|
||||||
|
|
||||||
<Claimable enabled="true"/>
|
|
||||||
|
|
||||||
<!--<Sensors table-id="SAMPLE_DEVICE_2">-->
|
|
||||||
<!--<Sensor code="CPU_Temperature">-->
|
|
||||||
<!--<Name>temperature sensor fitted</Name>-->
|
|
||||||
<!--<StreamDefinition>org.wso2.temperature.stream</StreamDefinition>-->
|
|
||||||
<!--<Description>this is a sensor</Description>-->
|
|
||||||
<!--<SensorStaticProperties>-->
|
|
||||||
<!--<Property name="unit">celcius</Property>-->
|
|
||||||
<!--<Property name="model_number">atmeggga11234</Property>-->
|
|
||||||
<!--</SensorStaticProperties>-->
|
|
||||||
<!--</Sensor>-->
|
|
||||||
<!--<Sensor code="DHT11_Temperature">-->
|
|
||||||
<!--<Name>temperature sensor fitted</Name>-->
|
|
||||||
<!--<StreamDefinition>org.wso2.temperature.stream</StreamDefinition>-->
|
|
||||||
<!--<Description>this is a sensor</Description>-->
|
|
||||||
<!--<SensorStaticProperties>-->
|
|
||||||
<!--<Property name="unit">celcius</Property>-->
|
|
||||||
<!--</SensorStaticProperties>-->
|
|
||||||
<!--<SensorDynamicProperties>-->
|
|
||||||
<!--<Property name="model_number"/>-->
|
|
||||||
<!--</SensorDynamicProperties>-->
|
|
||||||
<!--</Sensor>-->
|
|
||||||
<!--</Sensors>-->
|
|
||||||
|
|
||||||
<ProvisioningConfig>
|
|
||||||
<SharedWithAllTenants>false</SharedWithAllTenants>
|
|
||||||
</ProvisioningConfig>
|
|
||||||
|
|
||||||
<DeviceAuthorizationConfig>
|
|
||||||
<authorizationRequired>true</authorizationRequired>
|
|
||||||
</DeviceAuthorizationConfig>
|
|
||||||
|
|
||||||
<PushNotificationProvider type="MQTT">
|
|
||||||
<FileBasedProperties>true</FileBasedProperties>
|
|
||||||
<!--if file based properties is set to false then the configuration will be picked from platform configuration-->
|
|
||||||
<ConfigProperties>
|
|
||||||
<Property Name="mqttAdapterName">sample.mqtt.adapter</Property>
|
|
||||||
<Property Name="url">tcp://localhost:1883</Property>
|
|
||||||
<Property Name="username">admin</Property>
|
|
||||||
<Property Name="password">admin</Property>
|
|
||||||
<Property Name="qos">0</Property>
|
|
||||||
<Property Name="scopes"/>
|
|
||||||
<Property Name="clearSession">true</Property>
|
|
||||||
</ConfigProperties>
|
|
||||||
</PushNotificationProvider>
|
|
||||||
|
|
||||||
<PolicyMonitoring enabled="true"/>
|
|
||||||
|
|
||||||
<License>
|
|
||||||
<Language>en_US</Language>
|
|
||||||
<Version>1.0.0</Version>
|
|
||||||
<Text>This is license text</Text>
|
|
||||||
</License>
|
|
||||||
|
|
||||||
<TaskConfiguration>
|
|
||||||
<Enable>true</Enable>
|
|
||||||
<Frequency>600000</Frequency>
|
|
||||||
<Operations>
|
|
||||||
<Operation>
|
|
||||||
<Name>DEVICE_INFO</Name>
|
|
||||||
<RecurrentTimes>1</RecurrentTimes>
|
|
||||||
</Operation>
|
|
||||||
<Operation>
|
|
||||||
<Name>APPLICATION_LIST</Name>
|
|
||||||
<RecurrentTimes>5</RecurrentTimes>
|
|
||||||
</Operation>
|
|
||||||
<Operation>
|
|
||||||
<Name>DEVICE_LOCATION</Name>
|
|
||||||
<RecurrentTimes>1</RecurrentTimes>
|
|
||||||
</Operation>
|
|
||||||
</Operations>
|
|
||||||
</TaskConfiguration>
|
|
||||||
|
|
||||||
<DataSource>
|
|
||||||
<jndiConfig>
|
|
||||||
<name>jdbc/SampleDM_DB</name>
|
|
||||||
</jndiConfig>
|
|
||||||
<tableConfig>
|
|
||||||
<Table name="SAMPLE_DEVICE_1">
|
|
||||||
<PrimaryKey>SAMPLE_DEVICE_ID</PrimaryKey>
|
|
||||||
<Attributes>
|
|
||||||
<Attribute>column1</Attribute>
|
|
||||||
<Attribute>column2</Attribute>
|
|
||||||
</Attributes>
|
|
||||||
</Table>
|
|
||||||
</tableConfig>
|
|
||||||
</DataSource>
|
|
||||||
|
|
||||||
<InitialOperationConfig>
|
|
||||||
<Operations>
|
|
||||||
<Operation>DEVICE_INFO</Operation>
|
|
||||||
<Operation>APPLICATION_LIST</Operation>
|
|
||||||
<Operation>DEVICE_LOCATION</Operation>
|
|
||||||
</Operations>
|
|
||||||
</InitialOperationConfig>
|
|
||||||
|
|
||||||
</DeviceTypeConfiguration>
|
|
||||||
@ -167,6 +167,11 @@
|
|||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import io.swagger.annotations.ApiResponses;
|
|||||||
import io.swagger.annotations.ResponseHeader;
|
import io.swagger.annotations.ResponseHeader;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
@ -206,4 +207,57 @@ public interface DeviceTypeManagementService {
|
|||||||
@HeaderParam("If-Modified-Since")
|
@HeaderParam("If-Modified-Since")
|
||||||
String ifModifiedSince);
|
String ifModifiedSince);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/all/{type}")
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "GET",
|
||||||
|
value = "Getting Details of a Device Type",
|
||||||
|
notes = "Get the details of a device by searching via the device type and the tenant domain.",
|
||||||
|
response = DeviceType.class,
|
||||||
|
tags = "Device Type Management Administrative Service",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "perm:device-types:types")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the device type.",
|
||||||
|
response = DeviceType.class,
|
||||||
|
responseContainer = "List",
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body")
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 304,
|
||||||
|
message = "Not Modified. Empty body because the client already has the latest version of the " +
|
||||||
|
"requested resource.\n"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 401,
|
||||||
|
message = "Unauthorized.\n The unauthorized access to the requested resource.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found.\n The specified device does not exist",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 406,
|
||||||
|
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response getDeviceTypeByName(
|
||||||
|
@ApiParam(
|
||||||
|
name = "type",
|
||||||
|
value = "The device type name, such as ios, android, windows or fire-alarm.",
|
||||||
|
required = true)
|
||||||
|
@PathParam("type")
|
||||||
|
@Size(min = 2, max = 45)
|
||||||
|
String type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,175 @@
|
|||||||
|
/*
|
||||||
|
* 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.jaxrs.service.api.admin;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import io.swagger.annotations.ApiResponse;
|
||||||
|
import io.swagger.annotations.ApiResponses;
|
||||||
|
import io.swagger.annotations.Extension;
|
||||||
|
import io.swagger.annotations.ExtensionProperty;
|
||||||
|
import io.swagger.annotations.Info;
|
||||||
|
import io.swagger.annotations.ResponseHeader;
|
||||||
|
import io.swagger.annotations.SwaggerDefinition;
|
||||||
|
import io.swagger.annotations.Tag;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
|
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@SwaggerDefinition(
|
||||||
|
info = @Info(
|
||||||
|
version = "1.0.0",
|
||||||
|
title = "",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = "name", value = "DeviceTypeManagementAdminService"),
|
||||||
|
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/admin/device-types"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
),
|
||||||
|
tags = {
|
||||||
|
@Tag(name = "device_management", description = "")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@Path("/admin/device-types")
|
||||||
|
@Api(value = "Device Type Management Administrative Service", description = "This an API intended to be used by " +
|
||||||
|
"'internal' components to log in as an admin user and do a selected number of operations. " +
|
||||||
|
"Further, this is strictly restricted to admin users only ")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Scopes(
|
||||||
|
scopes = {
|
||||||
|
@Scope(
|
||||||
|
name = "Getting Details of a Device",
|
||||||
|
description = "Getting Details of a Device",
|
||||||
|
key = "perm:admin:device-type",
|
||||||
|
permissions = {"/device-mgt/admin/device-type"}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public interface DeviceTypeManagementAdminService {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "POST",
|
||||||
|
value = "Add a Device Type",
|
||||||
|
notes = "Add the details of a device type.",
|
||||||
|
tags = "Device Type Management Administrative Service",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(code = 200, message = "OK. \n Successfully added the device type.",
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body")
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 304,
|
||||||
|
message = "Not Modified. Empty body because the client already has the latest version of the " +
|
||||||
|
"requested resource.\n"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 401,
|
||||||
|
message = "Unauthorized.\n The unauthorized access to the requested resource.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found.\n The specified device does not exist",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 406,
|
||||||
|
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response addDeviceType(@ApiParam(
|
||||||
|
name = "type",
|
||||||
|
value = "The device type such as ios, android, windows or fire-alarm.",
|
||||||
|
required = true)DeviceType deviceType);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "PUT",
|
||||||
|
value = "Update Device Type",
|
||||||
|
notes = "Update the details of a device type.",
|
||||||
|
response = DeviceType.class,
|
||||||
|
tags = "Device Type Management Administrative Service",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "perm:admin:device-type")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(code = 200, message = "OK. \n Successfully updated the device type.",
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The content type of the body")
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 304,
|
||||||
|
message = "Not Modified. Empty body because the client already has the latest version of the " +
|
||||||
|
"requested resource.\n"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 401,
|
||||||
|
message = "Unauthorized.\n The unauthorized access to the requested resource.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found.\n The specified device does not exist",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 406,
|
||||||
|
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n Server error occurred while fetching the device list.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response updateDeviceType(@ApiParam(
|
||||||
|
name = "type",
|
||||||
|
value = "The device type such as ios, android, windows or fire-alarm.",
|
||||||
|
required = true) DeviceType deviceType);
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.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 org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
||||||
@ -35,6 +36,7 @@ import javax.ws.rs.GET;
|
|||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -86,4 +88,26 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
|
|||||||
return Response.status(Response.Status.OK).entity(features).build();
|
return Response.status(Response.Status.OK).entity(features).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GET
|
||||||
|
@Path("/all/{type}")
|
||||||
|
public Response getDeviceTypeByName(@PathParam("type") String type) {
|
||||||
|
if (type != null && type.length() > 0) {
|
||||||
|
try {
|
||||||
|
DeviceType deviceType = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(type);
|
||||||
|
if (deviceType == null) {
|
||||||
|
String msg = "Device type does not exist, " + type;
|
||||||
|
return Response.status(Response.Status.NO_CONTENT).entity(msg).build();
|
||||||
|
}
|
||||||
|
return Response.status(Response.Status.OK).entity(deviceType).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred at server side while fetching device type.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(msg).build();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* 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.jaxrs.service.impl.admin;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.HTTPDeviceTypeManagerService;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementAdminService;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@Path("/admin/device-types")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public class DeviceTypeManagementAdminServiceImpl implements DeviceTypeManagementAdminService {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceTypeManagementAdminServiceImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@POST
|
||||||
|
public Response addDeviceType(DeviceType deviceType) {
|
||||||
|
if (deviceType != null) {
|
||||||
|
try {
|
||||||
|
if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) != null) {
|
||||||
|
String msg = "Device type already available, " + deviceType.getName();
|
||||||
|
return Response.status(Response.Status.CONFLICT).entity(msg).build();
|
||||||
|
}
|
||||||
|
HTTPDeviceTypeManagerService httpDeviceTypeManagerService = new HTTPDeviceTypeManagerService
|
||||||
|
(deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
|
||||||
|
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred at server side while fetching device list.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(msg).build();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PUT
|
||||||
|
public Response updateDeviceType(DeviceType deviceType) {
|
||||||
|
if (deviceType != null) {
|
||||||
|
try {
|
||||||
|
if (DeviceMgtAPIUtils.getDeviceManagementService().getDeviceType(deviceType.getName()) == null) {
|
||||||
|
String msg = "Device type does not exist, " + deviceType.getName();
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
|
}
|
||||||
|
HTTPDeviceTypeManagerService httpDeviceTypeManagerService = new HTTPDeviceTypeManagerService
|
||||||
|
(deviceType.getName(), deviceType.getDeviceTypeMetaDefinition());
|
||||||
|
DeviceMgtAPIUtils.getDeviceManagementService().registerDeviceType(httpDeviceTypeManagerService);
|
||||||
|
return Response.status(Response.Status.OK).build();
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred at server side while fetching device list.";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(msg).build();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,6 +29,7 @@
|
|||||||
<ref bean="deviceManagementAdminService"/>
|
<ref bean="deviceManagementAdminService"/>
|
||||||
<ref bean="deviceAccessAuthorizationAdminService"/>
|
<ref bean="deviceAccessAuthorizationAdminService"/>
|
||||||
<ref bean="deviceTypeManagementService"/>
|
<ref bean="deviceTypeManagementService"/>
|
||||||
|
<ref bean="configurationManagementService"/>
|
||||||
<ref bean="activityProviderService"/>
|
<ref bean="activityProviderService"/>
|
||||||
<ref bean="notificationManagementService"/>
|
<ref bean="notificationManagementService"/>
|
||||||
<ref bean="policyManagementService"/>
|
<ref bean="policyManagementService"/>
|
||||||
@ -38,10 +39,9 @@
|
|||||||
<ref bean="groupManagementService"/>
|
<ref bean="groupManagementService"/>
|
||||||
<ref bean="groupManagementAdminService"/>
|
<ref bean="groupManagementAdminService"/>
|
||||||
<ref bean="applicationManagementAdminService"/>
|
<ref bean="applicationManagementAdminService"/>
|
||||||
<ref bean="deviceTypeManagementAdminService"/>
|
|
||||||
<ref bean="deviceTypeManagementAdminService"/>
|
<ref bean="deviceTypeManagementAdminService"/>
|
||||||
<ref bean="deviceAnalyticsArtifactUploaderAdminService"/>
|
<ref bean="deviceAnalyticsArtifactUploaderAdminService"/>
|
||||||
<ref bean="deviceEventManagementService"/>\
|
<ref bean="deviceEventManagementService"/>
|
||||||
<ref bean="swaggerResource"/>
|
<ref bean="swaggerResource"/>
|
||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
<jaxrs:providers>
|
<jaxrs:providers>
|
||||||
@ -70,7 +70,8 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="deviceManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceManagementServiceImpl"/>
|
<bean id="deviceManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceManagementServiceImpl"/>
|
||||||
<bean id="deviceTypeManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ConfigurationServiceImpl"/>
|
<bean id="deviceTypeManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementServiceImpl"/>
|
||||||
|
<bean id="configurationManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ConfigurationServiceImpl"/>
|
||||||
<bean id="activityProviderService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ActivityProviderServiceImpl"/>
|
<bean id="activityProviderService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.ActivityProviderServiceImpl"/>
|
||||||
<bean id="notificationManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.NotificationManagementServiceImpl"/>
|
<bean id="notificationManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.NotificationManagementServiceImpl"/>
|
||||||
<bean id="policyManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.PolicyManagementServiceImpl"/>
|
<bean id="policyManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.PolicyManagementServiceImpl"/>
|
||||||
@ -81,7 +82,7 @@
|
|||||||
<bean id="applicationManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.ApplicationManagementAdminServiceImpl"/>
|
<bean id="applicationManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.ApplicationManagementAdminServiceImpl"/>
|
||||||
<bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/>
|
<bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/>
|
||||||
<bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/>
|
<bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/>
|
||||||
<bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementServiceImpl"/>
|
<bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceTypeManagementAdminServiceImpl"/>
|
||||||
<bean id="deviceAccessAuthorizationAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceAccessAuthorizationAdminServiceImpl"/>
|
<bean id="deviceAccessAuthorizationAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceAccessAuthorizationAdminServiceImpl"/>
|
||||||
<bean id="deviceAnalyticsArtifactUploaderAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceAnalyticsArtifactUploaderAdminServiceImpl"/>
|
<bean id="deviceAnalyticsArtifactUploaderAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceAnalyticsArtifactUploaderAdminServiceImpl"/>
|
||||||
<bean id="deviceEventManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceEventManagementServiceImpl"/>
|
<bean id="deviceEventManagementService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceEventManagementServiceImpl"/>
|
||||||
|
|||||||
@ -22,18 +22,18 @@ import java.io.Serializable;
|
|||||||
/**
|
/**
|
||||||
* This class holds the information of the device type and its provider tenant.
|
* This class holds the information of the device type and its provider tenant.
|
||||||
*/
|
*/
|
||||||
public class DeviceTypeIdentifier implements Serializable {
|
public class DeviceTypeServiceIdentifier implements Serializable {
|
||||||
|
|
||||||
private String deviceType;
|
private String deviceType;
|
||||||
private int tenantId;
|
private int tenantId;
|
||||||
private static final int DEFAULT_SHARE_WITH_ALL_TENANTS_ID = -1;
|
private static final int DEFAULT_SHARE_WITH_ALL_TENANTS_ID = -1;
|
||||||
|
|
||||||
public DeviceTypeIdentifier(String deviceType, int tenantId) {
|
public DeviceTypeServiceIdentifier(String deviceType, int tenantId) {
|
||||||
this.deviceType = deviceType.toLowerCase();
|
this.deviceType = deviceType.toLowerCase();
|
||||||
this.tenantId = tenantId;
|
this.tenantId = tenantId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceTypeIdentifier(String deviceType) {
|
public DeviceTypeServiceIdentifier(String deviceType) {
|
||||||
this.deviceType = deviceType.toLowerCase();
|
this.deviceType = deviceType.toLowerCase();
|
||||||
this.tenantId = DEFAULT_SHARE_WITH_ALL_TENANTS_ID;
|
this.tenantId = DEFAULT_SHARE_WITH_ALL_TENANTS_ID;
|
||||||
}
|
}
|
||||||
@ -59,8 +59,8 @@ public class DeviceTypeIdentifier implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return (obj instanceof DeviceTypeIdentifier) && deviceType.equals(
|
return (obj instanceof DeviceTypeServiceIdentifier) && deviceType.equals(
|
||||||
((DeviceTypeIdentifier) obj).deviceType) && tenantId == ((DeviceTypeIdentifier) obj).tenantId;
|
((DeviceTypeServiceIdentifier) obj).deviceType) && tenantId == ((DeviceTypeServiceIdentifier) obj).tenantId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSharedWithAllTenant() {
|
public boolean isSharedWithAllTenant() {
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.type.mgt;
|
||||||
|
|
||||||
|
public interface DeviceTypeDefinitionProvider {
|
||||||
|
|
||||||
|
DeviceTypeMetaDefinition getDeviceTypeMeta();
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.common.type.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceTypeMetaDefinition {
|
||||||
|
|
||||||
|
private List<String> properties;
|
||||||
|
private List<Feature> features;
|
||||||
|
private boolean claimable;
|
||||||
|
private PushNotificationConfig pushNotificationConfig;
|
||||||
|
private boolean policyMonitoringEnabled;
|
||||||
|
private OperationMonitoringTaskConfig taskConfig;
|
||||||
|
private InitialOperationConfig initialOperationConfig;
|
||||||
|
private License license;
|
||||||
|
|
||||||
|
public List<String> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(List<String> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Feature> getFeatures() {
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFeatures(List<Feature> features) {
|
||||||
|
this.features = features;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClaimable() {
|
||||||
|
return claimable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClaimable(boolean isClaimable) {
|
||||||
|
this.claimable = isClaimable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationConfig getPushNotificationConfig() {
|
||||||
|
return pushNotificationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPushNotificationConfig(
|
||||||
|
PushNotificationConfig pushNotificationConfig) {
|
||||||
|
this.pushNotificationConfig = pushNotificationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPolicyMonitoringEnabled() {
|
||||||
|
return policyMonitoringEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolicyMonitoringEnabled(boolean policyMonitoringEnabled) {
|
||||||
|
this.policyMonitoringEnabled = policyMonitoringEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationMonitoringTaskConfig getTaskConfig() {
|
||||||
|
return taskConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskConfig(OperationMonitoringTaskConfig taskConfig) {
|
||||||
|
this.taskConfig = taskConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InitialOperationConfig getInitialOperationConfig() {
|
||||||
|
return initialOperationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitialOperationConfig(InitialOperationConfig initialOperationConfig) {
|
||||||
|
this.initialOperationConfig = initialOperationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public License getLicense() {
|
||||||
|
return license;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLicense(License license) {
|
||||||
|
this.license = license;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -133,6 +133,10 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
|||||||
@ -17,11 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core;
|
package org.wso2.carbon.device.mgt.core;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
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.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceTypeServiceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
@ -29,6 +30,9 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|||||||
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.push.notification.PushNotificationProvider;
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
|
||||||
@ -38,6 +42,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerRepository;
|
|||||||
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
||||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
||||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.HTTPDeviceTypeManagerService;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -45,19 +50,22 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
||||||
|
|
||||||
private Map<DeviceTypeIdentifier, DeviceManagementService> providers;
|
private Map<DeviceTypeServiceIdentifier, DeviceManagementService> providers;
|
||||||
|
private Map<DeviceTypeServiceIdentifier, Long> dynamicProviderTimestamp;
|
||||||
private boolean isInited;
|
private boolean isInited;
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class);
|
private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class);
|
||||||
private OperationManagerRepository operationManagerRepository;
|
private OperationManagerRepository operationManagerRepository;
|
||||||
|
private static final long DEFAULT_UPDATE_TIMESTAMP = 900000L;
|
||||||
|
|
||||||
public DeviceManagementPluginRepository() {
|
public DeviceManagementPluginRepository() {
|
||||||
this.operationManagerRepository = new OperationManagerRepository();
|
this.operationManagerRepository = new OperationManagerRepository();
|
||||||
providers = Collections.synchronizedMap(new HashMap<DeviceTypeIdentifier, DeviceManagementService>());
|
providers = Collections.synchronizedMap(new HashMap<DeviceTypeServiceIdentifier, DeviceManagementService>());
|
||||||
|
dynamicProviderTimestamp = Collections.synchronizedMap(new HashMap<DeviceTypeServiceIdentifier, Long>());
|
||||||
DeviceManagementServiceComponent.registerStartupListener(this);
|
DeviceManagementServiceComponent.registerStartupListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
|
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
|
||||||
String deviceType = provider.getType().toLowerCase();
|
String deviceType = provider.getType();
|
||||||
|
|
||||||
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
||||||
String tenantDomain = provisioningConfig.getProviderTenantDomain();
|
String tenantDomain = provisioningConfig.getProviderTenantDomain();
|
||||||
@ -71,7 +79,18 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|||||||
if (isInited) {
|
if (isInited) {
|
||||||
/* Initializing Device Management Service Provider */
|
/* Initializing Device Management Service Provider */
|
||||||
provider.init();
|
provider.init();
|
||||||
DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants);
|
DeviceTypeMetaDefinition deviceTypeDefinition = null;
|
||||||
|
if (provider instanceof DeviceTypeDefinitionProvider) {
|
||||||
|
deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta();
|
||||||
|
|
||||||
|
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(
|
||||||
|
provider.getType().toLowerCase(), tenantId);
|
||||||
|
DeviceManagementService existingProvider = providers.get(deviceTypeIdentifier);
|
||||||
|
if (existingProvider != null) {
|
||||||
|
removeDeviceManagementProvider(provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants, deviceTypeDefinition);
|
||||||
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
|
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
|
||||||
provider.getDeviceManager()
|
provider.getDeviceManager()
|
||||||
.requireDeviceAuthorization());
|
.requireDeviceAuthorization());
|
||||||
@ -83,33 +102,39 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|||||||
deviceType + "'", e);
|
deviceType + "'", e);
|
||||||
}
|
}
|
||||||
if (isSharedWithAllTenants) {
|
if (isSharedWithAllTenants) {
|
||||||
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType);
|
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType);
|
||||||
providers.put(deviceTypeIdentifier, provider);
|
providers.put(deviceTypeIdentifier, provider);
|
||||||
} else {
|
} else {
|
||||||
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId);
|
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId);
|
||||||
providers.put(deviceTypeIdentifier, provider);
|
providers.put(deviceTypeIdentifier, provider);
|
||||||
|
if (provider instanceof DeviceTypeDefinitionProvider) {
|
||||||
|
dynamicProviderTimestamp.put(deviceTypeIdentifier, System.currentTimeMillis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDeviceManagementProvider(DeviceManagementService provider)
|
public void removeDeviceManagementProvider(DeviceManagementService provider)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
String deviceTypeName = provider.getType().toLowerCase();
|
String deviceTypeName = provider.getType();
|
||||||
DeviceTypeIdentifier deviceTypeIdentifier;
|
DeviceTypeServiceIdentifier deviceTypeIdentifier;
|
||||||
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
||||||
if (provisioningConfig.isSharedWithAllTenants()) {
|
if (provisioningConfig.isSharedWithAllTenants()) {
|
||||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName);
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName);
|
||||||
providers.remove(deviceTypeIdentifier);
|
providers.remove(deviceTypeIdentifier);
|
||||||
} else {
|
} else {
|
||||||
int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
|
int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
|
||||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName, providerTenantId);
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName, providerTenantId);
|
||||||
providers.remove(deviceTypeIdentifier);
|
providers.remove(deviceTypeIdentifier);
|
||||||
|
if (provider instanceof DeviceTypeDefinitionProvider) {
|
||||||
|
dynamicProviderTimestamp.remove(deviceTypeIdentifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unregisterPushNotificationStrategy(deviceTypeIdentifier);
|
unregisterPushNotificationStrategy(deviceTypeIdentifier);
|
||||||
unregisterMonitoringTask(provider);
|
unregisterMonitoringTask(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unregisterPushNotificationStrategy(DeviceTypeIdentifier deviceTypeIdentifier) {
|
private void unregisterPushNotificationStrategy(DeviceTypeServiceIdentifier deviceTypeIdentifier) {
|
||||||
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
||||||
deviceTypeIdentifier);
|
deviceTypeIdentifier);
|
||||||
if (operationManager != null) {
|
if (operationManager != null) {
|
||||||
@ -123,18 +148,60 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|||||||
|
|
||||||
public DeviceManagementService getDeviceManagementService(String type, int tenantId) {
|
public DeviceManagementService getDeviceManagementService(String type, int tenantId) {
|
||||||
//Priority need to be given to the tenant before public.
|
//Priority need to be given to the tenant before public.
|
||||||
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase(), tenantId);
|
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type.toLowerCase(), tenantId);
|
||||||
DeviceManagementService provider = providers.get(deviceTypeIdentifier);
|
DeviceManagementService provider = providers.get(deviceTypeIdentifier);
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase());
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type.toLowerCase());
|
||||||
provider = providers.get(deviceTypeIdentifier);
|
provider = providers.get(deviceTypeIdentifier);
|
||||||
|
if (provider == null) {
|
||||||
|
try {
|
||||||
|
DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId);
|
||||||
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
|
||||||
|
if (deviceTypeMetaDefinition != null) {
|
||||||
|
HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService
|
||||||
|
(type, deviceTypeMetaDefinition);
|
||||||
|
addDeviceManagementProvider(deviceTypeManagerService);
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Failing to retrieve the device type service for " + type, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// retrieves per tenant device type management service
|
||||||
|
if (provider instanceof DeviceTypeDefinitionProvider) {
|
||||||
|
//handle updates.
|
||||||
|
long updatedTimestamp = dynamicProviderTimestamp.get(deviceTypeIdentifier);
|
||||||
|
if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) {
|
||||||
|
try {
|
||||||
|
DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId);
|
||||||
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
|
||||||
|
if (deviceTypeMetaDefinition != null) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String dbStoredDefinition = gson.toJson(deviceTypeMetaDefinition);
|
||||||
|
deviceTypeMetaDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta();
|
||||||
|
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
|
||||||
|
if (!cachedDefinition.equals(dbStoredDefinition)) {
|
||||||
|
HTTPDeviceTypeManagerService deviceTypeManagerService = new HTTPDeviceTypeManagerService
|
||||||
|
(type, deviceTypeMetaDefinition);
|
||||||
|
addDeviceManagementProvider(deviceTypeManagerService);
|
||||||
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId);
|
||||||
|
provider = providers.get(deviceTypeIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Failing to retrieve the device type service for " + type, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<DeviceTypeIdentifier, DeviceManagementService> getAllDeviceManagementServices(int tenantId) {
|
public Map<DeviceTypeServiceIdentifier, DeviceManagementService> getAllDeviceManagementServices(int tenantId) {
|
||||||
Map<DeviceTypeIdentifier, DeviceManagementService> tenantProviders = new HashMap<>();
|
Map<DeviceTypeServiceIdentifier, DeviceManagementService> tenantProviders = new HashMap<>();
|
||||||
for (DeviceTypeIdentifier identifier : providers.keySet()) {
|
for (DeviceTypeServiceIdentifier identifier : providers.keySet()) {
|
||||||
if (identifier.getTenantId() == tenantId || identifier.isSharedWithAllTenant()) {
|
if (identifier.getTenantId() == tenantId || identifier.isSharedWithAllTenant()) {
|
||||||
tenantProviders.put(identifier, providers.get(identifier));
|
tenantProviders.put(identifier, providers.get(identifier));
|
||||||
}
|
}
|
||||||
@ -150,12 +217,12 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|||||||
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
||||||
try {
|
try {
|
||||||
boolean isSharedWithAllTenants = deviceManagementService.getProvisioningConfig().isSharedWithAllTenants();
|
boolean isSharedWithAllTenants = deviceManagementService.getProvisioningConfig().isSharedWithAllTenants();
|
||||||
DeviceTypeIdentifier deviceTypeIdentifier;
|
DeviceTypeServiceIdentifier deviceTypeIdentifier;
|
||||||
if (isSharedWithAllTenants) {
|
if (isSharedWithAllTenants) {
|
||||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType());
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType());
|
||||||
} else {
|
} else {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId);
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pushNoteConfig != null) {
|
if (pushNoteConfig != null) {
|
||||||
@ -222,10 +289,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|||||||
|
|
||||||
public OperationManager getOperationManager(String deviceType, int tenantId) {
|
public OperationManager getOperationManager(String deviceType, int tenantId) {
|
||||||
//Priority need to be given to the tenant before public.
|
//Priority need to be given to the tenant before public.
|
||||||
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase(), tenantId);
|
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType.toLowerCase(), tenantId);
|
||||||
OperationManager operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier);
|
OperationManager operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier);
|
||||||
if (operationManager == null) {
|
if (operationManager == null) {
|
||||||
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase());
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType.toLowerCase());
|
||||||
operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier);
|
operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier);
|
||||||
}
|
}
|
||||||
return operationManager;
|
return operationManager;
|
||||||
@ -241,8 +308,19 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|||||||
deviceTypeName = provider.getType().toLowerCase();
|
deviceTypeName = provider.getType().toLowerCase();
|
||||||
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
||||||
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
|
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
|
||||||
DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId,
|
DeviceTypeMetaDefinition deviceTypeDefinition = null;
|
||||||
provisioningConfig.isSharedWithAllTenants());
|
if (provider instanceof DeviceTypeDefinitionProvider) {
|
||||||
|
deviceTypeDefinition = ((DeviceTypeDefinitionProvider) provider).getDeviceTypeMeta();
|
||||||
|
|
||||||
|
DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(
|
||||||
|
provider.getType().toLowerCase(), tenantId);
|
||||||
|
DeviceManagementService existingProvider = providers.get(deviceTypeIdentifier);
|
||||||
|
if (existingProvider == null) {
|
||||||
|
removeDeviceManagementProvider(provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId
|
||||||
|
, provisioningConfig.isSharedWithAllTenants(), deviceTypeDefinition);
|
||||||
registerPushNotificationStrategy(provider);
|
registerPushNotificationStrategy(provider);
|
||||||
registerMonitoringTask(provider);
|
registerMonitoringTask(provider);
|
||||||
//TODO:
|
//TODO:
|
||||||
|
|||||||
@ -55,7 +55,7 @@ public interface DeviceTypeDAO {
|
|||||||
* @return return only the device types that are associated with the provider tenant.
|
* @return return only the device types that are associated with the provider tenant.
|
||||||
* @throws DeviceManagementDAOException
|
* @throws DeviceManagementDAOException
|
||||||
*/
|
*/
|
||||||
List<String> getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException;
|
List<DeviceType> getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return sharedWithAllDeviceTypes This returns public shared device types.
|
* @return sharedWithAllDeviceTypes This returns public shared device types.
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.dao.impl;
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||||
@ -27,7 +29,9 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
||||||
@ -40,10 +44,18 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
stmt = conn.prepareStatement(
|
stmt = conn.prepareStatement(
|
||||||
"INSERT INTO DM_DEVICE_TYPE (NAME,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS) VALUES (?,?,?)");
|
"INSERT INTO DM_DEVICE_TYPE (NAME,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS,DEVICE_TYPE_META" +
|
||||||
|
",LAST_UPDATED_TIMESTAMP) VALUES (?,?,?,?,?)");
|
||||||
stmt.setString(1, deviceType.getName());
|
stmt.setString(1, deviceType.getName());
|
||||||
stmt.setInt(2, providerTenantId);
|
stmt.setInt(2, providerTenantId);
|
||||||
stmt.setBoolean(3, isSharedWithAllTenants);
|
stmt.setBoolean(3, isSharedWithAllTenants);
|
||||||
|
String deviceMeta = null;
|
||||||
|
if (deviceType.getDeviceTypeMetaDefinition() != null) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
deviceMeta = gson.toJson(deviceType.getDeviceTypeMetaDefinition());
|
||||||
|
}
|
||||||
|
stmt.setString(4, deviceMeta);
|
||||||
|
stmt.setTimestamp(5, new Timestamp(new Date().getTime()));
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new DeviceManagementDAOException(
|
throw new DeviceManagementDAOException(
|
||||||
@ -54,8 +66,29 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDeviceType(DeviceType deviceType, int tenantId)
|
public void updateDeviceType(DeviceType deviceType, int tenantId) throws DeviceManagementDAOException {
|
||||||
throws DeviceManagementDAOException {
|
Connection conn;
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
conn = this.getConnection();
|
||||||
|
stmt = conn.prepareStatement("UPDATE DM_DEVICE_TYPE SET DEVICE_TYPE_META = ?, LAST_UPDATED_TIMESTAMP = ? " +
|
||||||
|
"WHERE NAME = ? AND PROVIDER_TENANT_ID = ?");
|
||||||
|
String deviceMeta = null;
|
||||||
|
if (deviceType.getDeviceTypeMetaDefinition() != null) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
deviceMeta = gson.toJson(deviceType.getDeviceTypeMetaDefinition());
|
||||||
|
}
|
||||||
|
stmt.setString(1, deviceMeta);
|
||||||
|
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
|
||||||
|
stmt.setString(3, deviceType.getName());
|
||||||
|
stmt.setInt(4, tenantId);
|
||||||
|
stmt.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementDAOException("Error occurred while updating device type'" +
|
||||||
|
deviceType.getName() + "'", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,8 +100,8 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql =
|
String sql =
|
||||||
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =" +
|
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE, DEVICE_TYPE_META,LAST_UPDATED_TIMESTAMP " +
|
||||||
"? OR SHARED_WITH_ALL_TENANTS = ?";
|
"FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =? OR SHARED_WITH_ALL_TENANTS = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
stmt.setBoolean(2, true);
|
stmt.setBoolean(2, true);
|
||||||
@ -78,6 +111,12 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
DeviceType deviceType = new DeviceType();
|
DeviceType deviceType = new DeviceType();
|
||||||
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
||||||
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
||||||
|
String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
|
||||||
|
if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
|
||||||
|
, DeviceTypeMetaDefinition.class));
|
||||||
|
}
|
||||||
deviceTypes.add(deviceType);
|
deviceTypes.add(deviceType);
|
||||||
}
|
}
|
||||||
return deviceTypes;
|
return deviceTypes;
|
||||||
@ -89,21 +128,30 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException {
|
public List<DeviceType> getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException {
|
||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> deviceTypes = new ArrayList<>();
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql =
|
String sql =
|
||||||
"SELECT NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =?";
|
"SELECT NAME AS DEVICE_TYPE, DEVICE_TYPE_META FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
deviceTypes.add(rs.getString("DEVICE_TYPE"));
|
DeviceType deviceType = new DeviceType();
|
||||||
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
||||||
|
String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
|
||||||
|
if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
|
||||||
|
, DeviceTypeMetaDefinition.class));
|
||||||
|
}
|
||||||
|
deviceTypes.add(deviceType);
|
||||||
|
|
||||||
}
|
}
|
||||||
return deviceTypes;
|
return deviceTypes;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -146,7 +194,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, DEVICE_TYPE_META, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, id);
|
stmt.setInt(1, id);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
@ -155,6 +203,13 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
deviceType = new DeviceType();
|
deviceType = new DeviceType();
|
||||||
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
||||||
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
||||||
|
String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
|
||||||
|
if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
|
||||||
|
, DeviceTypeMetaDefinition.class));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return deviceType;
|
return deviceType;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -174,7 +229,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
DeviceType deviceType = null;
|
DeviceType deviceType = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
String sql = "SELECT ID AS DEVICE_TYPE_ID FROM DM_DEVICE_TYPE WHERE (PROVIDER_TENANT_ID =? OR " +
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, DEVICE_TYPE_META FROM DM_DEVICE_TYPE WHERE (PROVIDER_TENANT_ID =? OR " +
|
||||||
"SHARED_WITH_ALL_TENANTS = ?) AND NAME =?";
|
"SHARED_WITH_ALL_TENANTS = ?) AND NAME =?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setInt(1, tenantId);
|
stmt.setInt(1, tenantId);
|
||||||
@ -185,6 +240,12 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|||||||
deviceType = new DeviceType();
|
deviceType = new DeviceType();
|
||||||
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
||||||
deviceType.setName(type);
|
deviceType.setName(type);
|
||||||
|
String devicetypeMeta = rs.getString("DEVICE_TYPE_META");
|
||||||
|
if (devicetypeMeta != null && devicetypeMeta.length() > 0) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(gson.fromJson(devicetypeMeta
|
||||||
|
, DeviceTypeMetaDefinition.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return deviceType;
|
return deviceType;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
@ -18,8 +18,10 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.mgt.core.dto;
|
package org.wso2.carbon.device.mgt.core.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@ -33,6 +35,10 @@ public class DeviceType implements Serializable {
|
|||||||
@ApiModelProperty(name = "name", value = "Device type name", required = true)
|
@ApiModelProperty(name = "name", value = "Device type name", required = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@JsonProperty("metaDefinition")
|
||||||
|
@ApiModelProperty(name = "metaDefinition", value = "Device type definition", required = true)
|
||||||
|
private DeviceTypeMetaDefinition deviceTypeMetaDefinition;
|
||||||
|
|
||||||
public DeviceType() {
|
public DeviceType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,4 +62,13 @@ public class DeviceType implements Serializable {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeviceTypeMetaDefinition getDeviceTypeMetaDefinition() {
|
||||||
|
return deviceTypeMetaDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceTypeMetaDefinition(
|
||||||
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
|
||||||
|
this.deviceTypeMetaDefinition = deviceTypeMetaDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.operation.mgt;
|
package org.wso2.carbon.device.mgt.core.operation.mgt;
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceTypeServiceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -26,21 +26,21 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
public class OperationManagerRepository {
|
public class OperationManagerRepository {
|
||||||
|
|
||||||
private Map<DeviceTypeIdentifier, OperationManager> operationManagers;
|
private Map<DeviceTypeServiceIdentifier, OperationManager> operationManagers;
|
||||||
|
|
||||||
public OperationManagerRepository() {
|
public OperationManagerRepository() {
|
||||||
operationManagers = new ConcurrentHashMap<>();
|
operationManagers = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOperationManager(DeviceTypeIdentifier type, OperationManager operationManager) {
|
public void addOperationManager(DeviceTypeServiceIdentifier type, OperationManager operationManager) {
|
||||||
operationManagers.put(type, operationManager);
|
operationManagers.put(type, operationManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationManager getOperationManager(DeviceTypeIdentifier type) {
|
public OperationManager getOperationManager(DeviceTypeServiceIdentifier type) {
|
||||||
return operationManagers.get(type);
|
return operationManagers.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeOperationManager(DeviceTypeIdentifier type) {
|
public void removeOperationManager(DeviceTypeServiceIdentifier type) {
|
||||||
operationManagers.remove(type);
|
operationManagers.remove(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -328,4 +330,17 @@ public interface DeviceManagementProviderService {
|
|||||||
*/
|
*/
|
||||||
boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus)
|
boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus)
|
||||||
throws DeviceManagementException;
|
throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will handle add and update of device type services.
|
||||||
|
* @param deviceManagementService
|
||||||
|
*/
|
||||||
|
void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This retrieves the device type info for the given type
|
||||||
|
* @param deviceType name of the type.
|
||||||
|
* @throws DeviceManagementException
|
||||||
|
*/
|
||||||
|
DeviceType getDeviceType(String deviceType) throws DeviceManagementException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
|
import org.wso2.carbon.device.mgt.common.DeviceTypeServiceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||||
@ -1007,7 +1007,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAvailableDeviceTypes() throws DeviceManagementException {
|
public List<String> getAvailableDeviceTypes() throws DeviceManagementException {
|
||||||
List<String> deviceTypesProvidedByTenant;
|
List<DeviceType> deviceTypesProvidedByTenant;
|
||||||
List<String> publicSharedDeviceTypesInDB;
|
List<String> publicSharedDeviceTypesInDB;
|
||||||
List<String> deviceTypesResponse = new ArrayList<>();
|
List<String> deviceTypesResponse = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
@ -1015,17 +1015,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
int tenantId = this.getTenantId();
|
int tenantId = this.getTenantId();
|
||||||
deviceTypesProvidedByTenant = deviceTypeDAO.getDeviceTypesByProvider(tenantId);
|
deviceTypesProvidedByTenant = deviceTypeDAO.getDeviceTypesByProvider(tenantId);
|
||||||
publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes();
|
publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes();
|
||||||
Map<DeviceTypeIdentifier, DeviceManagementService> registeredTypes =
|
Map<DeviceTypeServiceIdentifier, DeviceManagementService> registeredTypes =
|
||||||
pluginRepository.getAllDeviceManagementServices(tenantId);
|
pluginRepository.getAllDeviceManagementServices(tenantId);
|
||||||
Set<String> deviceTypeSetForTenant = new HashSet<>();
|
Set<String> deviceTypeSetForTenant = new HashSet<>();
|
||||||
|
|
||||||
if (registeredTypes != null) {
|
if (registeredTypes != null) {
|
||||||
if (deviceTypesProvidedByTenant != null) {
|
if (deviceTypesProvidedByTenant != null) {
|
||||||
for (String deviceType : deviceTypesProvidedByTenant) {
|
for (DeviceType deviceType : deviceTypesProvidedByTenant) {
|
||||||
DeviceTypeIdentifier providerKey = new DeviceTypeIdentifier(deviceType, tenantId);
|
DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType.getName(), tenantId);
|
||||||
if (registeredTypes.get(providerKey) != null) {
|
if (registeredTypes.get(providerKey) != null || deviceType.getDeviceTypeMetaDefinition() != null) {
|
||||||
deviceTypesResponse.add(deviceType);
|
deviceTypesResponse.add(deviceType.getName());
|
||||||
deviceTypeSetForTenant.add(deviceType);
|
deviceTypeSetForTenant.add(deviceType.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1033,7 +1033,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
// priority to that
|
// priority to that
|
||||||
if (publicSharedDeviceTypesInDB != null) {
|
if (publicSharedDeviceTypesInDB != null) {
|
||||||
for (String deviceType : publicSharedDeviceTypesInDB) {
|
for (String deviceType : publicSharedDeviceTypesInDB) {
|
||||||
DeviceTypeIdentifier providerKey = new DeviceTypeIdentifier(deviceType);
|
DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType);
|
||||||
if (registeredTypes.get(providerKey) != null && !deviceTypeSetForTenant.contains(deviceType)) {
|
if (registeredTypes.get(providerKey) != null && !deviceTypeSetForTenant.contains(deviceType)) {
|
||||||
deviceTypesResponse.add(deviceType);
|
deviceTypesResponse.add(deviceType);
|
||||||
}
|
}
|
||||||
@ -2164,4 +2164,27 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
return defaultGroup;
|
return defaultGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerDeviceType(DeviceManagementService deviceManagementService) throws DeviceManagementException {
|
||||||
|
if (deviceManagementService != null) {
|
||||||
|
pluginRepository.addDeviceManagementProvider(deviceManagementService);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceType getDeviceType(String deviceType) throws DeviceManagementException {
|
||||||
|
HashMap<Integer, Device> deviceHashMap;
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
return deviceTypeDAO.getDeviceType(deviceType, tenantId);
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while obtaining the device type " + deviceType, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.*;
|
|||||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||||
@ -48,6 +49,7 @@ import javax.xml.XMLConstants;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
@ -108,7 +110,8 @@ public final class DeviceManagerUtil {
|
|||||||
* @param isSharedWithAllTenants is this device type shared with all tenants.
|
* @param isSharedWithAllTenants is this device type shared with all tenants.
|
||||||
* @return status of the operation
|
* @return status of the operation
|
||||||
*/
|
*/
|
||||||
public static boolean registerDeviceType(String typeName, int tenantId, boolean isSharedWithAllTenants)
|
public static boolean registerDeviceType(String typeName, int tenantId, boolean isSharedWithAllTenants
|
||||||
|
, DeviceTypeMetaDefinition deviceTypeDefinition)
|
||||||
throws DeviceManagementException {
|
throws DeviceManagementException {
|
||||||
boolean status;
|
boolean status;
|
||||||
try {
|
try {
|
||||||
@ -118,7 +121,13 @@ public final class DeviceManagerUtil {
|
|||||||
if (deviceType == null) {
|
if (deviceType == null) {
|
||||||
deviceType = new DeviceType();
|
deviceType = new DeviceType();
|
||||||
deviceType.setName(typeName);
|
deviceType.setName(typeName);
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(deviceTypeDefinition);
|
||||||
deviceTypeDAO.addDeviceType(deviceType, tenantId, isSharedWithAllTenants);
|
deviceTypeDAO.addDeviceType(deviceType, tenantId, isSharedWithAllTenants);
|
||||||
|
} else {
|
||||||
|
if (deviceTypeDefinition != null) {
|
||||||
|
deviceType.setDeviceTypeMetaDefinition(deviceTypeDefinition);
|
||||||
|
deviceTypeDAO.updateDeviceType(deviceType, tenantId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
status = true;
|
status = true;
|
||||||
@ -136,6 +145,32 @@ public final class DeviceManagerUtil {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new device type to the database if it does not exists.
|
||||||
|
*
|
||||||
|
* @param typeName device type
|
||||||
|
* @param tenantId provider tenant Id
|
||||||
|
* @return device type.
|
||||||
|
*/
|
||||||
|
public static DeviceType getDeviceType(String typeName, int tenantId)
|
||||||
|
throws DeviceManagementException {
|
||||||
|
try {
|
||||||
|
DeviceManagementDAOFactory.openConnection();
|
||||||
|
DeviceTypeDAO deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||||
|
return deviceTypeDAO.getDeviceType(typeName, tenantId);
|
||||||
|
|
||||||
|
} catch (DeviceManagementDAOException e) {
|
||||||
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
|
throw new DeviceManagementException("Error occurred while retrieving the device type '"
|
||||||
|
+ typeName + "'", e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new DeviceManagementException("SQL occurred while retrieving the device type '"
|
||||||
|
+ typeName + "'", e);
|
||||||
|
} finally {
|
||||||
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Un-registers an existing device type from the device management metadata repository.
|
* Un-registers an existing device type from the device management metadata repository.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID INT AUTO_INCREMENT NOT NULL,
|
ID INT AUTO_INCREMENT NOT NULL,
|
||||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR(2000) NULL DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
|
|||||||
@ -50,10 +50,6 @@
|
|||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
|
<groupId>org.apache.ws.commons.axiom.wso2</groupId>
|
||||||
<artifactId>axiom</artifactId>
|
<artifactId>axiom</artifactId>
|
||||||
@ -62,10 +58,18 @@
|
|||||||
<groupId>org.wso2.carbon</groupId>
|
<groupId>org.wso2.carbon</groupId>
|
||||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.felix</groupId>
|
<groupId>org.apache.felix</groupId>
|
||||||
<artifactId>maven-bundle-plugin</artifactId>
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
@ -77,14 +81,14 @@
|
|||||||
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
<Bundle-Description>Device Management Extensions Bundle</Bundle-Description>
|
<Bundle-Description>Device Management Extensions Bundle</Bundle-Description>
|
||||||
<Export-Package>
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.device.mgt.extensions.internal,
|
||||||
org.wso2.carbon.device.mgt.extensions.*
|
org.wso2.carbon.device.mgt.extensions.*
|
||||||
</Export-Package>
|
</Export-Package>
|
||||||
<Import-Package>
|
<Import-Package>
|
||||||
org.wso2.carbon.governance.api.*,
|
org.wso2.carbon.governance.api.*,
|
||||||
javax.xml.namespace;resolution:=optional,
|
javax.xml.namespace;resolution:=optional,
|
||||||
org.wso2.carbon.device.mgt.core.*,
|
|
||||||
org.wso2.carbon.context,
|
org.wso2.carbon.context,
|
||||||
org.wso2.carbon.device.mgt.common,
|
org.wso2.carbon.device.mgt.common.*,
|
||||||
org.wso2.carbon.device.mgt.common.license.mgt,
|
org.wso2.carbon.device.mgt.common.license.mgt,
|
||||||
org.wso2.carbon.registry.api,
|
org.wso2.carbon.registry.api,
|
||||||
org.wso2.carbon.registry.core,
|
org.wso2.carbon.registry.core,
|
||||||
@ -93,7 +97,19 @@
|
|||||||
org.wso2.carbon.base,
|
org.wso2.carbon.base,
|
||||||
javax.xml.bind,
|
javax.xml.bind,
|
||||||
org.apache.commons.logging,
|
org.apache.commons.logging,
|
||||||
org.wso2.carbon.utils
|
org.wso2.carbon.utils,
|
||||||
|
javax.naming,
|
||||||
|
javax.sql,
|
||||||
|
javax.xml,
|
||||||
|
javax.xml.bind.annotation,
|
||||||
|
javax.xml.parsers;resolution:=optional,
|
||||||
|
org.apache.commons.lang,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.w3c.dom,
|
||||||
|
org.wso2.carbon.ndatasource.core,
|
||||||
|
org.wso2.carbon.registry.core.service,
|
||||||
|
org.wso2.carbon.utils.dbcreator,
|
||||||
|
org.wso2.carbon.utils.multitenancy
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* 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.template;
|
||||||
|
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||||
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
|
||||||
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Claimable;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigProperties;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Features;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.License;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyMonitoring;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ProvisioningConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the template for device type manager service. This will create and instance of device management service
|
||||||
|
* through the json payload.
|
||||||
|
*/
|
||||||
|
public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService implements DeviceTypeDefinitionProvider {
|
||||||
|
|
||||||
|
private DeviceTypeMetaDefinition deviceTypeMetaDefinition;
|
||||||
|
|
||||||
|
public HTTPDeviceTypeManagerService(String deviceTypeName, DeviceTypeMetaDefinition deviceTypeMetaDefinition) {
|
||||||
|
super(getDeviceTypeConfigIdentifier(deviceTypeName), getDeviceTypeConfiguration(
|
||||||
|
deviceTypeName, deviceTypeMetaDefinition));
|
||||||
|
this.deviceTypeMetaDefinition = deviceTypeMetaDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeviceTypeConfiguration getDeviceTypeConfiguration(String deviceTypeName, DeviceTypeMetaDefinition
|
||||||
|
deviceTypeMetaDefinition) {
|
||||||
|
DeviceTypeConfiguration deviceTypeConfiguration = new DeviceTypeConfiguration();
|
||||||
|
|
||||||
|
if (deviceTypeMetaDefinition != null) {
|
||||||
|
Claimable claimable = new Claimable();
|
||||||
|
claimable.setEnabled(deviceTypeMetaDefinition.isClaimable());
|
||||||
|
deviceTypeConfiguration.setClaimable(claimable);
|
||||||
|
|
||||||
|
if (deviceTypeMetaDefinition.getProperties() != null &&
|
||||||
|
deviceTypeMetaDefinition.getProperties().size() > 0) {
|
||||||
|
DeviceDetails deviceDetails = new DeviceDetails();
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.addProperties(deviceTypeMetaDefinition.getProperties());
|
||||||
|
deviceDetails.setProperties(properties);
|
||||||
|
deviceTypeConfiguration.setDeviceDetails(deviceDetails);
|
||||||
|
}
|
||||||
|
if (deviceTypeMetaDefinition.getFeatures() != null && deviceTypeMetaDefinition.getFeatures().size() > 0) {
|
||||||
|
Features features = new Features();
|
||||||
|
List<org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature> featureList
|
||||||
|
= new ArrayList<>();
|
||||||
|
for (Feature feature : deviceTypeMetaDefinition.getFeatures()) {
|
||||||
|
org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature configFeature = new org
|
||||||
|
.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature();
|
||||||
|
configFeature.setCode(feature.getCode());
|
||||||
|
configFeature.setDescription(feature.getDescription());
|
||||||
|
configFeature.setName(feature.getName());
|
||||||
|
if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) {
|
||||||
|
List<String> metaValues = new ArrayList<>();
|
||||||
|
for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) {
|
||||||
|
metadataEntry.getValue();
|
||||||
|
}
|
||||||
|
configFeature.setMetaData(metaValues);
|
||||||
|
}
|
||||||
|
featureList.add(configFeature);
|
||||||
|
}
|
||||||
|
features.addFeatures(featureList);
|
||||||
|
deviceTypeConfiguration.setFeatures(features);
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceTypeConfiguration.setName(deviceTypeName);
|
||||||
|
if (deviceTypeMetaDefinition.getLicense() != null) {
|
||||||
|
License license = new License();
|
||||||
|
license.setLanguage(deviceTypeMetaDefinition.getLicense().getLanguage());
|
||||||
|
license.setText(deviceTypeMetaDefinition.getLicense().getText());
|
||||||
|
license.setVersion(deviceTypeMetaDefinition.getLicense().getVersion());
|
||||||
|
deviceTypeConfiguration.setLicense(license);
|
||||||
|
}
|
||||||
|
PolicyMonitoring policyMonitoring = new PolicyMonitoring();
|
||||||
|
policyMonitoring.setEnabled(deviceTypeMetaDefinition.isPolicyMonitoringEnabled());
|
||||||
|
deviceTypeConfiguration.setPolicyMonitoring(policyMonitoring);
|
||||||
|
|
||||||
|
ProvisioningConfig provisioningConfig = new ProvisioningConfig();
|
||||||
|
provisioningConfig.setSharedWithAllTenants(false);
|
||||||
|
deviceTypeConfiguration.setProvisioningConfig(provisioningConfig);
|
||||||
|
|
||||||
|
PushNotificationConfig pushNotificationConfig = deviceTypeMetaDefinition.getPushNotificationConfig();
|
||||||
|
if (pushNotificationConfig != null) {
|
||||||
|
PushNotificationProvider pushNotificationProvider = new PushNotificationProvider();
|
||||||
|
pushNotificationProvider.setType(pushNotificationConfig.getType());
|
||||||
|
pushNotificationProvider.setScheduled(pushNotificationConfig.isScheduled());
|
||||||
|
if (pushNotificationConfig.getProperties() != null &&
|
||||||
|
pushNotificationConfig.getProperties().size() > 0) {
|
||||||
|
ConfigProperties configProperties = new ConfigProperties();
|
||||||
|
List<Property> properties = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, String> entry : pushNotificationConfig.getProperties().entrySet()) {
|
||||||
|
Property property = new Property();
|
||||||
|
property.setName(entry.getKey());
|
||||||
|
property.setValue(entry.getValue());
|
||||||
|
properties.add(property);
|
||||||
|
}
|
||||||
|
configProperties.addProperties(properties);
|
||||||
|
pushNotificationProvider.setConfigProperties(configProperties);
|
||||||
|
}
|
||||||
|
pushNotificationProvider.setFileBasedProperties(true);
|
||||||
|
deviceTypeConfiguration.setPushNotificationProvider(pushNotificationProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceTypeMetaDefinition.getTaskConfig();
|
||||||
|
if (operationMonitoringTaskConfig != null) {
|
||||||
|
TaskConfiguration taskConfiguration = new TaskConfiguration();
|
||||||
|
taskConfiguration.setEnabled(operationMonitoringTaskConfig.isEnabled());
|
||||||
|
taskConfiguration.setFrequency(operationMonitoringTaskConfig.getFrequency());
|
||||||
|
if (operationMonitoringTaskConfig.getMonitoringOperation() != null) {
|
||||||
|
List<TaskConfiguration.Operation> operations = new ArrayList<>();
|
||||||
|
for (MonitoringOperation monitoringOperation : operationMonitoringTaskConfig
|
||||||
|
.getMonitoringOperation()) {
|
||||||
|
TaskConfiguration.Operation operation = new TaskConfiguration.Operation();
|
||||||
|
operation.setOperationName(monitoringOperation.getTaskName());
|
||||||
|
operation.setRecurrency(monitoringOperation.getRecurrentTimes());
|
||||||
|
operations.add(operation);
|
||||||
|
}
|
||||||
|
taskConfiguration.setOperations(operations);
|
||||||
|
}
|
||||||
|
deviceTypeConfiguration.setTaskConfiguration(taskConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceTypeMetaDefinition.getInitialOperationConfig() != null) {
|
||||||
|
InitialOperationConfig initialOperationConfig = deviceTypeMetaDefinition.getInitialOperationConfig();
|
||||||
|
deviceTypeConfiguration.setOperations(initialOperationConfig.getOperations());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceTypeConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeviceTypeConfigIdentifier getDeviceTypeConfigIdentifier(String deviceType) {
|
||||||
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
|
return new DeviceTypeConfigIdentifier(deviceType, tenantDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceTypeMetaDefinition getDeviceTypeMeta() {
|
||||||
|
return deviceTypeMetaDefinition;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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.template.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds the constants used for this bundle.
|
||||||
|
*/
|
||||||
|
public class DeviceTypePluginConstants {
|
||||||
|
public static final String MEDIA_TYPE_XML = "application/xml";
|
||||||
|
public static final String CHARSET_UTF8 = "UTF8";
|
||||||
|
public static final String LANGUAGE_CODE_ENGLISH_US = "en_US";
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.extensions.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds the necessary services required for the bundle.
|
||||||
|
*/
|
||||||
|
public class DeviceTypeExtensionDataHolder {
|
||||||
|
|
||||||
|
private RegistryService registryService;
|
||||||
|
|
||||||
|
private static DeviceTypeExtensionDataHolder thisInstance = new DeviceTypeExtensionDataHolder();
|
||||||
|
|
||||||
|
private DeviceTypeExtensionDataHolder() {}
|
||||||
|
|
||||||
|
public static DeviceTypeExtensionDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistryService getRegistryService() {
|
||||||
|
return registryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRegistryService(RegistryService registryService) {
|
||||||
|
this.registryService = registryService;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.ndatasource.core.DataSourceService;
|
||||||
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.device.mgt.extensions.DeviceTypeExtensionServiceComponent"
|
||||||
|
* immediate="true"
|
||||||
|
* @scr.reference name="registry.service"
|
||||||
|
* interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="0..1"
|
||||||
|
* policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
|
||||||
|
* @scr.reference name="org.wso2.carbon.ndatasource"
|
||||||
|
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setDataSourceService"
|
||||||
|
* unbind="unsetDataSourceService"
|
||||||
|
*/
|
||||||
|
public class DeviceTypeExtensionServiceComponent {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(DeviceTypeExtensionServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext ctx) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Activating DeviceType Deployer Service Component");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext ctx) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("De-activating DeviceType Deployer Service Component");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setRegistryService(RegistryService registryService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("RegistryService acquired");
|
||||||
|
}
|
||||||
|
DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetRegistryService(RegistryService registryService) {
|
||||||
|
DeviceTypeExtensionDataHolder.getInstance().setRegistryService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDataSourceService(DataSourceService dataSourceService) {
|
||||||
|
/* This is to avoid device management component getting initialized before the underlying datasources
|
||||||
|
are registered */
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Data source service set to android mobile service component");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetDataSourceService(DataSourceService dataSourceService) {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"appContext": "/devicemgt/",
|
"appContext": "/devicemgt/",
|
||||||
"isCloud": false,
|
"isCloud": false,
|
||||||
"httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%",
|
"httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%",
|
||||||
"httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port",
|
"httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port%",
|
||||||
"wssURL": "https://%iot.analytics.host%:%iot.analytics.https.port%",
|
"wssURL": "https://%iot.analytics.host%:%iot.analytics.https.port%",
|
||||||
"portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%",
|
"portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%",
|
||||||
"dashboardServerURL": "%https.ip%",
|
"dashboardServerURL": "%https.ip%",
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID INT AUTO_INCREMENT NOT NULL,
|
ID INT AUTO_INCREMENT NOT NULL,
|
||||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR(2000) NULL DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
@ -39,6 +41,15 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
|||||||
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
||||||
|
DEVICE_TYPE_NAME VARCHAR(300) NOT NULL,
|
||||||
|
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||||
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
|
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||||
|
TENANT_ID VARCHAR(100) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
DEVICE_ID INTEGER DEFAULT NULL,
|
DEVICE_ID INTEGER DEFAULT NULL,
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID INT AUTO_INCREMENT NOT NULL,
|
ID INT AUTO_INCREMENT NOT NULL,
|
||||||
NAME VARCHAR(300) NULL DEFAULT NULL,
|
NAME VARCHAR(300) NULL DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR(2000) NULL DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
@ -44,6 +46,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
|||||||
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||||
|
TENANT_ID VARCHAR(100) DEFAULT NULL,
|
||||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
|
|||||||
CREATE TABLE DM_DEVICE_TYPE (
|
CREATE TABLE DM_DEVICE_TYPE (
|
||||||
ID INTEGER IDENTITY(1,1) NOT NULL,
|
ID INTEGER IDENTITY(1,1) NOT NULL,
|
||||||
NAME VARCHAR(300) DEFAULT NULL,
|
NAME VARCHAR(300) DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP DATETIME2 NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER NULL,
|
PROVIDER_TENANT_ID INTEGER NULL,
|
||||||
SHARED_WITH_ALL_TENANTS BIT NOT NULL DEFAULT 0,
|
SHARED_WITH_ALL_TENANTS BIT NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (ID),
|
PRIMARY KEY (ID),
|
||||||
@ -58,6 +60,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
|||||||
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||||
|
TENANT_ID VARCHAR(100) DEFAULT NULL,
|
||||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||||
NAME VARCHAR(300) DEFAULT NULL,
|
NAME VARCHAR(300) DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
PRIMARY KEY (ID)
|
PRIMARY KEY (ID)
|
||||||
@ -51,6 +53,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
|||||||
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||||
|
TENANT_ID VARCHAR(100) DEFAULT NULL,
|
||||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
CREATE TABLE DM_DEVICE_TYPE (
|
CREATE TABLE DM_DEVICE_TYPE (
|
||||||
ID NUMBER(10) NOT NULL,
|
ID NUMBER(10) NOT NULL,
|
||||||
NAME VARCHAR2(300) DEFAULT NULL,
|
NAME VARCHAR2(300) DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR2(2000) DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL,
|
SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL,
|
||||||
CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID),
|
CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID),
|
||||||
@ -102,6 +104,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
|||||||
DEVICE_IDENTIFICATION VARCHAR2(300) NOT NULL,
|
DEVICE_IDENTIFICATION VARCHAR2(300) NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR2(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR2(100) DEFAULT 0,
|
||||||
PROPERTY_VALUE VARCHAR2(100) DEFAULT NULL,
|
PROPERTY_VALUE VARCHAR2(100) DEFAULT NULL,
|
||||||
|
TENANT_ID VARCHAR2(100) DEFAULT NULL,
|
||||||
CONSTRAINT PK_DM_DEVICE_PROPERTY PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
CONSTRAINT PK_DM_DEVICE_PROPERTY PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
)
|
)
|
||||||
/
|
/
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
|
||||||
ID BIGSERIAL PRIMARY KEY,
|
ID BIGSERIAL PRIMARY KEY,
|
||||||
NAME VARCHAR(300) DEFAULT NULL,
|
NAME VARCHAR(300) DEFAULT NULL,
|
||||||
|
DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL,
|
||||||
|
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
|
||||||
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
|
||||||
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
UNIQUE(NAME, PROVIDER_TENANT_ID)
|
UNIQUE(NAME, PROVIDER_TENANT_ID)
|
||||||
@ -43,6 +45,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
|
|||||||
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
|
||||||
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
|
||||||
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
|
||||||
|
TENANT_ID VARCHAR(100) DEFAULT NULL,
|
||||||
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user