diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypePluginDeployer.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypePluginDeployer.java index 5dfa895f39..eb02504d97 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypePluginDeployer.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypePluginDeployer.java @@ -29,12 +29,12 @@ import org.osgi.framework.ServiceRegistration; import org.w3c.dom.Document; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; -import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.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.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.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.JAXBException; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypeUIDeployer.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypeUIDeployer.java deleted file mode 100644 index 5ee352751e..0000000000 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/DeviceTypeUIDeployer.java +++ /dev/null @@ -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 deviceTypeDeployedUIMap = new ConcurrentHashMap(); - 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); - } - } - -} diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java deleted file mode 100644 index be089a9ccc..0000000000 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/config/ObjectFactory.java +++ /dev/null @@ -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. - *

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 createDeviceTypeConfiguration(DeviceTypeConfiguration value) { - return new JAXBElement(_DeviceTypeConfiguration_QNAME, DeviceTypeConfiguration.class, null, value); - } - -} diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java index 9c7d771c11..88761df2e1 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/internal/DeviceTypeManagementServiceComponent.java @@ -28,7 +28,7 @@ import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.utils.ConfigurationContextService; /** - * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeManagementServiceComponent" + * @scr.component name="org.wso2.carbon.device.mgt.iot.internal.DeviceTypeExtensionServiceComponent" * immediate="true" * @scr.reference name="config.context.service" * interface="org.wso2.carbon.utils.ConfigurationContextService" diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java index 495a72b48d..4611deb8f3 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypeConfigUtil.java @@ -19,7 +19,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.util; import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.extensions.device.type.deployer.config.exception.DeviceTypeConfigurationException; +import org.wso2.carbon.device.mgt.extensions.device.type.template.config.exception.DeviceTypeConfigurationException; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java index 290fe93b7b..8b8ad98cf2 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/util/DeviceTypePluginConstants.java @@ -22,9 +22,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.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"; public static final String CDMF_UI_TYPE = "devicetype/ui"; public static final String CDMF_UI_TYPE_DIR = "devicetypes-ui"; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml deleted file mode 100644 index e79f988710..0000000000 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - - - - - attr1 - attr2 - - - - - - - abc - this is a feature - - - deviceId - - - test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - false - - - - true - - - - true - - - sample.mqtt.adapter - tcp://localhost:1883 - admin - admin - 0 - - true - - - - - - - en_US - 1.0.0 - This is license text - - - - true - 600000 - - - DEVICE_INFO - 1 - - - APPLICATION_LIST - 5 - - - DEVICE_LOCATION - 1 - - - - - - - jdbc/SampleDM_DB - - - - SAMPLE_DEVICE_ID - - column1 - column2 - -
-
-
- - - - DEVICE_INFO - APPLICATION_LIST - DEVICE_LOCATION - - - -
\ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index 80e39df11f..ec7025d04f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -167,6 +167,11 @@ org.wso2.carbon.device.mgt.common provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + provided + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index b71c918fca..24bfe0b920 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -31,6 +31,7 @@ import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ResponseHeader; import org.wso2.carbon.apimgt.annotations.api.Scope; 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.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; @@ -206,4 +207,57 @@ public interface DeviceTypeManagementService { @HeaderParam("If-Modified-Since") 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); + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java new file mode 100644 index 0000000000..b01c18ab8d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceTypeManagementAdminService.java @@ -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); + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java index 3bd43681e9..2d1a0d5f6d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceTypeManagementServiceImpl.java @@ -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.Feature; 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.jaxrs.beans.DeviceTypeList; 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.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.util.List; @@ -86,4 +88,26 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ 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(); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java new file mode 100644 index 0000000000..aaeee3a0af --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceTypeManagementAdminServiceImpl.java @@ -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(); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index c883b57dd2..6fa36bfb92 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -29,6 +29,7 @@ + @@ -39,9 +40,8 @@ - - \ + @@ -70,7 +70,8 @@ - + + @@ -81,7 +82,7 @@ - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeServiceIdentifier.java similarity index 81% rename from components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java rename to components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeServiceIdentifier.java index 1849a97c0d..2b55b13a22 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceTypeServiceIdentifier.java @@ -22,18 +22,18 @@ import java.io.Serializable; /** * 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 int tenantId; 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.tenantId = tenantId; } - public DeviceTypeIdentifier(String deviceType) { + public DeviceTypeServiceIdentifier(String deviceType) { this.deviceType = deviceType.toLowerCase(); this.tenantId = DEFAULT_SHARE_WITH_ALL_TENANTS_ID; } @@ -59,8 +59,8 @@ public class DeviceTypeIdentifier implements Serializable { @Override public boolean equals(Object obj) { - return (obj instanceof DeviceTypeIdentifier) && deviceType.equals( - ((DeviceTypeIdentifier) obj).deviceType) && tenantId == ((DeviceTypeIdentifier) obj).tenantId; + return (obj instanceof DeviceTypeServiceIdentifier) && deviceType.equals( + ((DeviceTypeServiceIdentifier) obj).deviceType) && tenantId == ((DeviceTypeServiceIdentifier) obj).tenantId; } public boolean isSharedWithAllTenant() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeDefinitionProvider.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeDefinitionProvider.java new file mode 100644 index 0000000000..76320b6612 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeDefinitionProvider.java @@ -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(); + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java new file mode 100644 index 0000000000..8f6cd14a6d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/type/mgt/DeviceTypeMetaDefinition.java @@ -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 properties; + private List features; + private boolean claimable; + private PushNotificationConfig pushNotificationConfig; + private boolean policyMonitoringEnabled; + private OperationMonitoringTaskConfig taskConfig; + private InitialOperationConfig initialOperationConfig; + private License license; + + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + public List getFeatures() { + return features; + } + + public void setFeatures(List 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; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 365576d8a3..b0b30b119d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -133,6 +133,10 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + org.wso2.carbon org.wso2.carbon.logging diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index ca32fa037b..b547221d72 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -17,11 +17,12 @@ */ package org.wso2.carbon.device.mgt.core; +import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.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.ProvisioningConfig; 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.PushNotificationProvider; 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.DeviceManagementServiceComponent; 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.DeviceTaskManagerService; 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.HashMap; @@ -45,19 +50,22 @@ import java.util.Map; public class DeviceManagementPluginRepository implements DeviceManagerStartupListener { - private Map providers; + private Map providers; + private Map dynamicProviderTimestamp; private boolean isInited; private static final Log log = LogFactory.getLog(DeviceManagementPluginRepository.class); private OperationManagerRepository operationManagerRepository; + private static final long DEFAULT_UPDATE_TIMESTAMP = 900000L; public DeviceManagementPluginRepository() { this.operationManagerRepository = new OperationManagerRepository(); - providers = Collections.synchronizedMap(new HashMap()); + providers = Collections.synchronizedMap(new HashMap()); + dynamicProviderTimestamp = Collections.synchronizedMap(new HashMap()); DeviceManagementServiceComponent.registerStartupListener(this); } public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceType = provider.getType().toLowerCase(); + String deviceType = provider.getType(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); String tenantDomain = provisioningConfig.getProviderTenantDomain(); @@ -71,7 +79,18 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis if (isInited) { /* Initializing Device Management Service Provider */ 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, provider.getDeviceManager() .requireDeviceAuthorization()); @@ -83,33 +102,39 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis deviceType + "'", e); } if (isSharedWithAllTenants) { - DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType); + DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType); providers.put(deviceTypeIdentifier, provider); } else { - DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType, tenantId); + DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId); providers.put(deviceTypeIdentifier, provider); + if (provider instanceof DeviceTypeDefinitionProvider) { + dynamicProviderTimestamp.put(deviceTypeIdentifier, System.currentTimeMillis()); + } } } } public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { - String deviceTypeName = provider.getType().toLowerCase(); - DeviceTypeIdentifier deviceTypeIdentifier; + String deviceTypeName = provider.getType(); + DeviceTypeServiceIdentifier deviceTypeIdentifier; ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); if (provisioningConfig.isSharedWithAllTenants()) { - deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName); providers.remove(deviceTypeIdentifier); } else { int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); - deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName, providerTenantId); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceTypeName, providerTenantId); providers.remove(deviceTypeIdentifier); + if (provider instanceof DeviceTypeDefinitionProvider) { + dynamicProviderTimestamp.remove(deviceTypeIdentifier); + } } unregisterPushNotificationStrategy(deviceTypeIdentifier); unregisterMonitoringTask(provider); } - private void unregisterPushNotificationStrategy(DeviceTypeIdentifier deviceTypeIdentifier) { + private void unregisterPushNotificationStrategy(DeviceTypeServiceIdentifier deviceTypeIdentifier) { OperationManager operationManager = operationManagerRepository.getOperationManager( deviceTypeIdentifier); if (operationManager != null) { @@ -123,18 +148,60 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public DeviceManagementService getDeviceManagementService(String type, int tenantId) { //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); if (provider == null) { - deviceTypeIdentifier = new DeviceTypeIdentifier(type.toLowerCase()); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type.toLowerCase()); 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; } - public Map getAllDeviceManagementServices(int tenantId) { - Map tenantProviders = new HashMap<>(); - for (DeviceTypeIdentifier identifier : providers.keySet()) { + public Map getAllDeviceManagementServices(int tenantId) { + Map tenantProviders = new HashMap<>(); + for (DeviceTypeServiceIdentifier identifier : providers.keySet()) { if (identifier.getTenantId() == tenantId || identifier.isSharedWithAllTenant()) { tenantProviders.put(identifier, providers.get(identifier)); } @@ -150,12 +217,12 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true); try { boolean isSharedWithAllTenants = deviceManagementService.getProvisioningConfig().isSharedWithAllTenants(); - DeviceTypeIdentifier deviceTypeIdentifier; + DeviceTypeServiceIdentifier deviceTypeIdentifier; if (isSharedWithAllTenants) { - deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType()); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType()); } else { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId); } if (pushNoteConfig != null) { @@ -222,10 +289,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public OperationManager getOperationManager(String deviceType, int tenantId) { //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); if (operationManager == null) { - deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType.toLowerCase()); + deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType.toLowerCase()); operationManager = operationManagerRepository.getOperationManager(deviceTypeIdentifier); } return operationManager; @@ -241,8 +308,19 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis deviceTypeName = provider.getType().toLowerCase(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); - DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId, - provisioningConfig.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(deviceTypeName, tenantId + , provisioningConfig.isSharedWithAllTenants(), deviceTypeDefinition); registerPushNotificationStrategy(provider); registerMonitoringTask(provider); //TODO: diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java index 0e34fc1ab0..337a5af133 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java @@ -55,7 +55,7 @@ public interface DeviceTypeDAO { * @return return only the device types that are associated with the provider tenant. * @throws DeviceManagementDAOException */ - List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException; + List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException; /** * @return sharedWithAllDeviceTypes This returns public shared device types. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index c7e4952328..a4ecacfd3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -17,6 +17,8 @@ */ 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.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; @@ -27,7 +29,9 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Date; import java.util.List; public class DeviceTypeDAOImpl implements DeviceTypeDAO { @@ -40,10 +44,18 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { try { conn = this.getConnection(); 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.setInt(2, providerTenantId); 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(); } catch (SQLException e) { throw new DeviceManagementDAOException( @@ -54,8 +66,29 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { } @Override - public void updateDeviceType(DeviceType deviceType, int tenantId) - throws DeviceManagementDAOException { + public void updateDeviceType(DeviceType deviceType, int tenantId) 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 @@ -67,8 +100,8 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { try { conn = this.getConnection(); String sql = - "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =" + - "? OR SHARED_WITH_ALL_TENANTS = ?"; + "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE, DEVICE_TYPE_META,LAST_UPDATED_TIMESTAMP " + + "FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =? OR SHARED_WITH_ALL_TENANTS = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); stmt.setBoolean(2, true); @@ -78,6 +111,12 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { DeviceType deviceType = new DeviceType(); deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); 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; @@ -89,21 +128,30 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { } @Override - public List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException { + public List getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - List deviceTypes = new ArrayList<>(); + List deviceTypes = new ArrayList<>(); try { conn = this.getConnection(); 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.setInt(1, tenantId); rs = stmt.executeQuery(); 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; } catch (SQLException e) { @@ -146,7 +194,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { ResultSet rs = null; try { 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.setInt(1, id); rs = stmt.executeQuery(); @@ -155,6 +203,13 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { deviceType = new DeviceType(); deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); 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; } catch (SQLException e) { @@ -174,7 +229,7 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { DeviceType deviceType = null; try { 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 =?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); @@ -185,6 +240,12 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { deviceType = new DeviceType(); deviceType.setId(rs.getInt("DEVICE_TYPE_ID")); 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; } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java index eb363fff1c..fbfc8b4404 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java @@ -18,8 +18,10 @@ package org.wso2.carbon.device.mgt.core.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition; import java.io.Serializable; @@ -33,6 +35,10 @@ public class DeviceType implements Serializable { @ApiModelProperty(name = "name", value = "Device type name", required = true) private String name; + @JsonProperty("metaDefinition") + @ApiModelProperty(name = "metaDefinition", value = "Device type definition", required = true) + private DeviceTypeMetaDefinition deviceTypeMetaDefinition; + public DeviceType() { } @@ -56,4 +62,13 @@ public class DeviceType implements Serializable { this.name = name; } + public DeviceTypeMetaDefinition getDeviceTypeMetaDefinition() { + return deviceTypeMetaDefinition; + } + + public void setDeviceTypeMetaDefinition( + DeviceTypeMetaDefinition deviceTypeMetaDefinition) { + this.deviceTypeMetaDefinition = deviceTypeMetaDefinition; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java index c9c863593c..d59a3748f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerRepository.java @@ -18,7 +18,7 @@ */ 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 java.util.Map; @@ -26,21 +26,21 @@ import java.util.concurrent.ConcurrentHashMap; public class OperationManagerRepository { - private Map operationManagers; + private Map operationManagers; public OperationManagerRepository() { operationManagers = new ConcurrentHashMap<>(); } - public void addOperationManager(DeviceTypeIdentifier type, OperationManager operationManager) { + public void addOperationManager(DeviceTypeServiceIdentifier type, OperationManager operationManager) { operationManagers.put(type, operationManager); } - public OperationManager getOperationManager(DeviceTypeIdentifier type) { + public OperationManager getOperationManager(DeviceTypeServiceIdentifier type) { return operationManagers.get(type); } - public void removeOperationManager(DeviceTypeIdentifier type) { + public void removeOperationManager(DeviceTypeServiceIdentifier type) { operationManagers.remove(type); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 9117468541..4398349a89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -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.policy.mgt.PolicyMonitoringManager; 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.HashMap; @@ -328,4 +330,17 @@ public interface DeviceManagementProviderService { */ boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) 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; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 13a5547687..376acb4916 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -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.DeviceManager; 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.FeatureManager; import org.wso2.carbon.device.mgt.common.InitialOperationConfig; @@ -1007,7 +1007,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getAvailableDeviceTypes() throws DeviceManagementException { - List deviceTypesProvidedByTenant; + List deviceTypesProvidedByTenant; List publicSharedDeviceTypesInDB; List deviceTypesResponse = new ArrayList<>(); try { @@ -1015,17 +1015,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int tenantId = this.getTenantId(); deviceTypesProvidedByTenant = deviceTypeDAO.getDeviceTypesByProvider(tenantId); publicSharedDeviceTypesInDB = deviceTypeDAO.getSharedDeviceTypes(); - Map registeredTypes = + Map registeredTypes = pluginRepository.getAllDeviceManagementServices(tenantId); Set deviceTypeSetForTenant = new HashSet<>(); if (registeredTypes != null) { if (deviceTypesProvidedByTenant != null) { - for (String deviceType : deviceTypesProvidedByTenant) { - DeviceTypeIdentifier providerKey = new DeviceTypeIdentifier(deviceType, tenantId); - if (registeredTypes.get(providerKey) != null) { - deviceTypesResponse.add(deviceType); - deviceTypeSetForTenant.add(deviceType); + for (DeviceType deviceType : deviceTypesProvidedByTenant) { + DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType.getName(), tenantId); + if (registeredTypes.get(providerKey) != null || deviceType.getDeviceTypeMetaDefinition() != null) { + deviceTypesResponse.add(deviceType.getName()); + deviceTypeSetForTenant.add(deviceType.getName()); } } } @@ -1033,7 +1033,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv // priority to that if (publicSharedDeviceTypesInDB != null) { for (String deviceType : publicSharedDeviceTypesInDB) { - DeviceTypeIdentifier providerKey = new DeviceTypeIdentifier(deviceType); + DeviceTypeServiceIdentifier providerKey = new DeviceTypeServiceIdentifier(deviceType); if (registeredTypes.get(providerKey) != null && !deviceTypeSetForTenant.contains(deviceType)) { deviceTypesResponse.add(deviceType); } @@ -2164,4 +2164,27 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv 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 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(); + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index c5558fe92a..08715c479f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -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.notification.mgt.NotificationManagementException; 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.DeviceManagementConfig; 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.DocumentBuilderFactory; import java.io.File; +import java.sql.SQLException; import java.util.*; @@ -108,7 +110,8 @@ public final class DeviceManagerUtil { * @param isSharedWithAllTenants is this device type shared with all tenants. * @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 { boolean status; try { @@ -118,7 +121,13 @@ public final class DeviceManagerUtil { if (deviceType == null) { deviceType = new DeviceType(); deviceType.setName(typeName); + deviceType.setDeviceTypeMetaDefinition(deviceTypeDefinition); deviceTypeDAO.addDeviceType(deviceType, tenantId, isSharedWithAllTenants); + } else { + if (deviceTypeDefinition != null) { + deviceType.setDeviceTypeMetaDefinition(deviceTypeDefinition); + deviceTypeDAO.updateDeviceType(deviceType, tenantId); + } } DeviceManagementDAOFactory.commitTransaction(); status = true; @@ -136,6 +145,32 @@ public final class DeviceManagerUtil { 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. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index eb06e9adcb..04e4548545 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -1,6 +1,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT 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, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 792ab01c8b..4fc6554209 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -50,10 +50,6 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - org.apache.ws.commons.axiom.wso2 axiom @@ -62,10 +58,18 @@ org.wso2.carbon org.wso2.carbon.utils + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + org.apache.felix + maven-scr-plugin + org.apache.felix maven-bundle-plugin @@ -77,14 +81,14 @@ ${carbon.device.mgt.version} Device Management Extensions Bundle + !org.wso2.carbon.device.mgt.extensions.internal, org.wso2.carbon.device.mgt.extensions.* org.wso2.carbon.governance.api.*, javax.xml.namespace;resolution:=optional, - org.wso2.carbon.device.mgt.core.*, 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.registry.api, org.wso2.carbon.registry.core, @@ -93,7 +97,19 @@ org.wso2.carbon.base, javax.xml.bind, 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 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java new file mode 100644 index 0000000000..6d00a881b1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/HTTPDeviceTypeManagerService.java @@ -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 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 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 properties = new ArrayList<>(); + for (Map.Entry 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 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; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypePluginConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypePluginConstants.java new file mode 100644 index 0000000000..4ac7c2292c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/util/DeviceTypePluginConstants.java @@ -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"; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionDataHolder.java new file mode 100644 index 0000000000..69ac6b5d97 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionDataHolder.java @@ -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; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java new file mode 100644 index 0000000000..3bc00675dc --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/internal/DeviceTypeExtensionServiceComponent.java @@ -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 + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index b0becff9d7..b123053b3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -2,7 +2,7 @@ "appContext": "/devicemgt/", "isCloud": false, "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%", "portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", "dashboardServerURL": "%https.ip%", diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index efc3005e2e..1811fbdaa9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -1,6 +1,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT 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, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, 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 ); +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 ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER DEFAULT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index f0aed697e2..b809b7c796 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -1,6 +1,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT 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, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID) @@ -44,6 +46,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( 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) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index a2ba39876b..b2171e5086 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -2,6 +2,8 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D CREATE TABLE DM_DEVICE_TYPE ( ID INTEGER IDENTITY(1,1) NOT NULL, NAME VARCHAR(300) DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL, + LAST_UPDATED_TIMESTAMP DATETIME2 NOT NULL, PROVIDER_TENANT_ID INTEGER NULL, SHARED_WITH_ALL_TENANTS BIT NOT NULL DEFAULT 0, PRIMARY KEY (ID), @@ -58,6 +60,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( 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) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 475bf9a214..673b85daea 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -1,6 +1,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INTEGER AUTO_INCREMENT NOT 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, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID) @@ -51,6 +53,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( 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) )ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 6b8bfba1c4..02dcacea77 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1,6 +1,8 @@ CREATE TABLE DM_DEVICE_TYPE ( ID NUMBER(10) NOT 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, SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL, 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, PROPERTY_NAME VARCHAR2(100) DEFAULT 0, 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) ) / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 13be9ff65f..fd10c778ee 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -1,6 +1,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID BIGSERIAL PRIMARY KEY, NAME VARCHAR(300) DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(2000) DEFAULT NULL, + LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, UNIQUE(NAME, PROVIDER_TENANT_ID) @@ -43,6 +45,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( 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) );