forked from community/device-mgt-core
parent
ed366867d1
commit
abc9315f95
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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>
|
@ -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);
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in new issue