diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index b7b32ca34db..2cebd98c611 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -109,7 +109,8 @@ import java.util.stream.Stream; /** * Default Concrete implementation of Application Management related implementations. */ -public class ApplicationManagerImpl implements ApplicationManager { +public class +ApplicationManagerImpl implements ApplicationManager { private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); private VisibilityDAO visibilityDAO; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java index e6f33f85deb..620ac7ce7e9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceManagementService.java @@ -39,6 +39,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -80,4 +81,5 @@ public interface DeviceManagementService { DeviceEnrollmentInvitationDetails getDeviceEnrollmentInvitationDetails(); + License getLicenseConfig(); } 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 03579f65b3f..efc4c930e3d 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 @@ -964,4 +964,6 @@ public interface DeviceManagementProviderService { int getActivitiesCount(ActivityPaginationRequest activityPaginationRequest) throws OperationManagementException; + License getLicenseConfig (String deviceTypeName) 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 769aad8583a..0bbbb8a607b 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 @@ -4349,4 +4349,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.closeConnection(); } } + + @Override + public License getLicenseConfig (String deviceTypeName) throws DeviceManagementException { + DeviceManagementService deviceManagementService = + pluginRepository.getDeviceManagementService(deviceTypeName, + this.getTenantId()); + if (deviceManagementService == null) { + String msg = "Device management service loading is failed for the device type: " + deviceTypeName; + log.error(msg); + throw new DeviceManagementException(msg); + } + return deviceManagementService.getLicenseConfig(); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java index c3789d47fa7..46e50f8bf1a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestDeviceManagementService.java @@ -38,6 +38,7 @@ import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -148,4 +149,6 @@ public class TestDeviceManagementService implements DeviceManagementService { public DeviceEnrollmentInvitationDetails getDeviceEnrollmentInvitationDetails() { return null; } + + @Override public License getLicenseConfig() { return null; } } 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 d9feeb366d9..5f522a4109b 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,6 +50,10 @@ 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 @@ -180,6 +184,8 @@ org.wso2.carbon.registry.core.service, org.wso2.carbon.utils.dbcreator, org.wso2.carbon.utils.multitenancy, + org.wso2.carbon.device.mgt.core.service, + com.google.gson, org.osgi.framework org.wso2.carbon.device.mgt.extensions.pull.notification, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java index 3805fd09d35..2022447e646 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManager.java @@ -64,7 +64,7 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.Devi import org.wso2.carbon.device.mgt.extensions.device.type.template.feature.ConfigurationBasedFeatureManager; import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypePluginConstants; import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils; -import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; +import org.wso2.carbon.device.mgt.extensions.license.mgt.meta.data.MetaRepositoryBasedLicenseManager; import org.wso2.carbon.device.mgt.extensions.spi.DeviceTypePluginExtensionService; import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.Resource; @@ -121,20 +121,17 @@ public class DeviceTypeManager implements DeviceManager { requiredDeviceTypeAuthorization = true; } //add license to registry. - this.licenseManager = new RegistryBasedLicenseManager(); + this.licenseManager = new MetaRepositoryBasedLicenseManager(); try { - if (licenseManager.getLicense(deviceType, DeviceTypePluginConstants.LANGUAGE_CODE_ENGLISH_US) == null) { - - if (deviceTypeConfiguration.getLicense() != null) { - License defaultLicense = new License(); - defaultLicense.setLanguage(deviceTypeConfiguration.getLicense().getLanguage()); - defaultLicense.setVersion(deviceTypeConfiguration.getLicense().getVersion()); - defaultLicense.setText(deviceTypeConfiguration.getLicense().getText()); - licenseManager.addLicense(deviceType, defaultLicense); - } + if (deviceTypeConfiguration.getLicense() != null) { + License defaultLicense = new License(); + defaultLicense.setLanguage(deviceTypeConfiguration.getLicense().getLanguage()); + defaultLicense.setVersion(deviceTypeConfiguration.getLicense().getVersion()); + defaultLicense.setText(deviceTypeConfiguration.getLicense().getText()); + licenseManager.addLicense(deviceType, defaultLicense); } } catch (LicenseManagementException e) { - String msg = "Error occurred while adding default license for " + deviceType + " devices."; + String msg = "Error occurred while adding default license of device type: " + deviceType; throw new DeviceTypeDeployerPayloadException(msg, e); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java index 5896039d993..587752458dd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerService.java @@ -49,6 +49,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -90,6 +91,7 @@ public class DeviceTypeManagerService implements DeviceManagementService { private PolicyMonitoringManager policyMonitoringManager; private final InitialOperationConfig initialOperationConfig; private StartupOperationConfig startupOperationConfig; + private License licenseConfig; private PullNotificationSubscriber pullNotificationSubscriber; private final DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private DeviceTypePlatformDetails deviceTypePlatformDetails; @@ -120,6 +122,8 @@ public class DeviceTypeManagerService implements DeviceManagementService { this.setGeneralConfig(deviceTypeConfiguration); this.deviceEnrollmentInvitationDetails = new DeviceEnrollmentInvitationDetails(); this.setDeviceEnrollmentInvitationDetails(deviceTypeConfiguration); + this.licenseConfig = new License(); + this.setLicenseConfig(deviceTypeConfiguration); } @Override @@ -268,6 +272,11 @@ public class DeviceTypeManagerService implements DeviceManagementService { return deviceEnrollmentInvitationDetails; } + @Override + public License getLicenseConfig() { + return licenseConfig; + } + private void setProvisioningConfig(String tenantDomain, DeviceTypeConfiguration deviceTypeConfiguration) { if (deviceTypeConfiguration.getProvisioningConfig() != null) { boolean sharedWithAllTenants = deviceTypeConfiguration.getProvisioningConfig().isSharedWithAllTenants(); @@ -372,4 +381,15 @@ public class DeviceTypeManagerService implements DeviceManagementService { deviceEnrollmentInvitationDetailsFromConfig.getEnrollmentDetails()); } } + + public void setLicenseConfig(DeviceTypeConfiguration deviceTypeConfiguration) { + org.wso2.carbon.device.mgt.extensions.device.type.template.config.License license = deviceTypeConfiguration + .getLicense(); + if (license != null) { + licenseConfig.setName(deviceTypeConfiguration.getName()); + licenseConfig.setLanguage(license.getLanguage()); + licenseConfig.setVersion(license.getVersion()); + licenseConfig.setText(license.getText()); + } + } } 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 index 140ff44cbea..93c83cf3e0c 100644 --- 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 @@ -24,4 +24,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template.util; public class DeviceTypePluginConstants { public static final String MEDIA_TYPE_XML = "application/xml"; public static final String LANGUAGE_CODE_ENGLISH_US = "en_US"; + public static final String UNDERSCORE = "_"; + public static final String LICENCE_META_KEY_SUFFIX = "_Licence_"; } 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 index 69ac6b5d976..663d34bfbfc 100644 --- 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 @@ -18,6 +18,9 @@ */ package org.wso2.carbon.device.mgt.extensions.internal; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.registry.core.service.RegistryService; /** @@ -26,6 +29,8 @@ import org.wso2.carbon.registry.core.service.RegistryService; public class DeviceTypeExtensionDataHolder { private RegistryService registryService; + private MetadataManagementService metadataManagementService; + private DeviceManagementProviderService deviceManagementProviderService; private static DeviceTypeExtensionDataHolder thisInstance = new DeviceTypeExtensionDataHolder(); @@ -42,4 +47,30 @@ public class DeviceTypeExtensionDataHolder { public void setRegistryService(RegistryService registryService) { this.registryService = registryService; } + + public MetadataManagementService getMetadataManagementService() { + if (metadataManagementService == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + metadataManagementService = (MetadataManagementService) + ctx.getOSGiService(MetadataManagementService.class, null); + } + return metadataManagementService; + } + + public void setMetadataManagementService(MetadataManagementService metadataManagementService) { + this.metadataManagementService = metadataManagementService; + } + + public DeviceManagementProviderService getDeviceManagementProviderService() { + if (deviceManagementProviderService == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + deviceManagementProviderService = (DeviceManagementProviderService) + ctx.getOSGiService(DeviceManagementProviderService.class, null); + } + return deviceManagementProviderService; + } + + public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) { + this.deviceManagementProviderService = deviceManagementProviderService; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/meta/data/MetaRepositoryBasedLicenseManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/meta/data/MetaRepositoryBasedLicenseManager.java new file mode 100644 index 00000000000..391e3e1fe32 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/license/mgt/meta/data/MetaRepositoryBasedLicenseManager.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.license.mgt.meta.data; + +import com.google.gson.Gson; +import org.apache.commons.lang.StringUtils; +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.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.MetadataKeyAlreadyExistsException; +import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; +import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata; +import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypePluginConstants; +import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder; + +public class MetaRepositoryBasedLicenseManager implements LicenseManager { + + private static final Log log = LogFactory.getLog(MetaRepositoryBasedLicenseManager.class); + + @Override + public License getLicense(String deviceType, String languageCode) throws LicenseManagementException { + MetadataManagementService metadataManagementService = DeviceTypeExtensionDataHolder.getInstance() + .getMetadataManagementService(); + String licenceKey = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + + DeviceTypePluginConstants.UNDERSCORE + deviceType + DeviceTypePluginConstants.LICENCE_META_KEY_SUFFIX + + languageCode; + + try { + Metadata metadata = metadataManagementService.retrieveMetadata(licenceKey); + if (metadata == null) { + DeviceManagementProviderService deviceManagementProviderService = DeviceTypeExtensionDataHolder + .getInstance().getDeviceManagementProviderService(); + + License license = deviceManagementProviderService.getLicenseConfig(deviceType); + + if (license != null && !StringUtils.isBlank(license.getLanguage()) && !StringUtils + .isBlank(license.getName()) && !StringUtils.isBlank(license.getText()) && !StringUtils + .isBlank(license.getVersion())) { + addLicense(deviceType, license); + return license; + } else { + license = new License(); + license.setName(deviceType); + license.setVersion("1.0.0"); + license.setLanguage("en_US"); + license.setText("This is license text"); + addLicense(deviceType, license); + return license; + } + } + Gson g = new Gson(); + return g.fromJson(metadata.getMetaValue(), License.class); + } catch (MetadataManagementException e) { + String msg = "Error occurred while accessing meta data service to store licence data"; + log.error(msg, e); + throw new LicenseManagementException(msg, e); + } catch (DeviceManagementException e) { + String msg = "Error occurred while getting device details."; + log.error(msg, e); + throw new LicenseManagementException(msg, e); + } + } + + @Override + public void addLicense(String deviceType, License license) throws LicenseManagementException { + + String languageCode = license.getLanguage(); + if (StringUtils.isBlank(languageCode)) { + languageCode = DeviceTypePluginConstants.LANGUAGE_CODE_ENGLISH_US; + } + + String licenceKey = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + + DeviceTypePluginConstants.UNDERSCORE + deviceType + DeviceTypePluginConstants.LICENCE_META_KEY_SUFFIX + + languageCode; + + Metadata metadata = new Metadata(); + metadata.setMetaKey(licenceKey); + metadata.setMetaValue(new Gson().toJson(license)); + + MetadataManagementService metadataManagementService = DeviceTypeExtensionDataHolder.getInstance() + .getMetadataManagementService(); + try { + if (metadataManagementService.retrieveMetadata(licenceKey) != null) { + metadataManagementService.updateMetadata(metadata); + } else { + metadataManagementService.createMetadata(metadata); + } + } catch (MetadataManagementException e) { + String msg = "Error occurred while saving the licence value in meta data repository"; + log.error(msg, e); + throw new LicenseManagementException(msg, e); + } catch (MetadataKeyAlreadyExistsException e) { + String msg = + "Error occurred while saving the licence key and licence key exist. Licence Key: " + licenceKey; + log.error(msg, e); + throw new LicenseManagementException(msg, e); + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/common/DataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/common/DataSourceConfig.java new file mode 100644 index 00000000000..86582007c62 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/common/DataSourceConfig.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.common; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "DataSourceConfig") +public class DataSourceConfig { + + private String url; + private String driverClassName; + private String user; + private String password; + + @Override public String toString() { + return "DataSourceConfig[" + + " Url ='" + url + '\'' + + ", DriverClassName ='" + driverClassName + '\'' + + ", UserName ='" + user + '\'' + + ", Password ='" + password + '\'' + + "]"; + } + + @XmlElement(name = "Url", nillable = false) + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @XmlElement(name = "DriverClassName", nillable = false) + public String getDriverClassName() { + return driverClassName; + } + + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + @XmlElement(name = "User", nillable = false) + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + @XmlElement(name = "Password", nillable = false) + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java index 3ec819a10be..e4859a8b974 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/BaseExtensionsTest.java @@ -19,28 +19,50 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template; +import org.apache.tomcat.jdbc.pool.PoolProperties; +import org.mockito.Mockito; import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.w3c.dom.Document; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.context.internal.OSGiDataHolder; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl; +import org.wso2.carbon.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.device.mgt.extensions.common.DataSourceConfig; import org.wso2.carbon.device.mgt.extensions.internal.DeviceTypeExtensionDataHolder; +import org.wso2.carbon.device.mgt.extensions.license.mgt.meta.data.MetaRepositoryBasedLicenseManager; +import org.wso2.carbon.device.mgt.extensions.mock.TypeXDeviceManagementService; import org.wso2.carbon.device.mgt.extensions.utils.Utils; import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration; import org.wso2.carbon.governance.api.util.GovernanceUtils; import org.wso2.carbon.registry.core.Registry; -import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.session.UserRegistry; import org.wso2.carbon.utils.FileUtil; +import javax.sql.DataSource; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; import java.io.File; -import java.io.IOException; import java.net.URL; +import java.sql.Connection; +import java.sql.Statement; import java.util.ArrayList; import java.util.List; +import static org.mockito.Matchers.anyString; import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration; /** @@ -48,8 +70,20 @@ import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceA */ public class BaseExtensionsTest { + protected static final String DATASOURCE_EXT = ".xml"; + private DataSource dataSource; + private static String datasourceLocation; + @BeforeSuite - public void init() throws RegistryException, IOException { + @Parameters({"datasource"}) + public void init( + @Optional("src/test/resources/carbon-home/repository/conf/datasource/data-source-config") String datasource) + throws Exception { + + datasourceLocation = datasource; + this.initDataSource(); + this.initSQLScript(); + ClassLoader classLoader = getClass().getClassLoader(); URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "license.rxt"); String rxt = null; @@ -78,7 +112,59 @@ public class BaseExtensionsTest { GovernanceUtils.loadGovernanceArtifacts(systemRegistry, configurations); Registry governanceSystemRegistry = registryService.getConfigSystemRegistry(); DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService); + + DeviceManagementProviderService deviceManagementProviderService = new DeviceManagementProviderServiceImpl(); + deviceManagementProviderService.registerDeviceType(new TypeXDeviceManagementService("defectiveDeviceType")); + deviceManagementProviderService.registerDeviceType(new TypeXDeviceManagementService("arduino")); + deviceManagementProviderService.registerDeviceType(new TypeXDeviceManagementService("androidsense")); + deviceManagementProviderService.registerDeviceType(new TypeXDeviceManagementService("sample")); + deviceManagementProviderService.registerDeviceType(new TypeXDeviceManagementService("wrong")); + + DeviceTypeExtensionDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); + DeviceTypeExtensionDataHolder.getInstance().setMetadataManagementService(new MetadataManagementServiceImpl()); + PrivilegedCarbonContext.getThreadLocalCarbonContext() .setRegistry(RegistryType.SYSTEM_CONFIGURATION, governanceSystemRegistry); } + + protected void initDataSource() throws Exception { + this.dataSource = this.getDataSource(this. + readDataSourceConfig(datasourceLocation + DATASOURCE_EXT)); + DeviceManagementDAOFactory.init(dataSource); + MetadataManagementDAOFactory.init(dataSource); + } + + protected DataSourceConfig readDataSourceConfig(String configLocation) throws DeviceManagementException { + try { + File file = new File(configLocation); + Document doc = DeviceManagerUtil.convertToDocument(file); + JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class); + Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); + return (DataSourceConfig) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new DeviceManagementException("Error occurred while reading data source configuration", e); + } + } + + protected DataSource getDataSource(DataSourceConfig config) { + PoolProperties properties = new PoolProperties(); + properties.setUrl(config.getUrl()); + properties.setDriverClassName(config.getDriverClassName()); + properties.setUsername(config.getUser()); + properties.setPassword(config.getPassword()); + return new org.apache.tomcat.jdbc.pool.DataSource(properties); + } + + protected DataSource getDataSource() { + return dataSource; + } + + private void initSQLScript() throws Exception { + try (Connection conn = this.getDataSource().getConnection()) { + try (Statement stmt = conn.createStatement()) { + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql-files/h2.sql'"); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql-files/android_h2.sql'"); + } + } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java index 4307316c36e..5ce556836fb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/device/type/template/DeviceTypeManagerNegativeTest.java @@ -26,6 +26,7 @@ import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; @@ -72,7 +73,7 @@ public class DeviceTypeManagerNegativeTest { @BeforeClass public void setup() throws SAXException, JAXBException, ParserConfigurationException, DeviceTypeConfigurationException, - IOException, NoSuchFieldException, IllegalAccessException { + IOException, NoSuchFieldException, IllegalAccessException, LicenseManagementException { ClassLoader classLoader = getClass().getClassLoader(); URL resourceUrl = classLoader.getResource(Utils.DEVICE_TYPE_FOLDER + "defective-devicetype.xml"); File configurationFile = null; @@ -291,7 +292,7 @@ public class DeviceTypeManagerNegativeTest { */ private void createDefectiveDeviceTypeManager() throws NoSuchFieldException, SAXException, JAXBException, ParserConfigurationException, - DeviceTypeConfigurationException, IOException, IllegalAccessException { + DeviceTypeConfigurationException, IOException, IllegalAccessException, LicenseManagementException { Field datasourceField = DeviceTypeDAOHandler.class.getDeclaredField("dataSource"); datasourceField.setAccessible(true); Field currentConnection = DeviceTypeDAOHandler.class.getDeclaredField("currentConnection"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/mock/TypeXDeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/mock/TypeXDeviceManagementService.java new file mode 100644 index 00000000000..f6f641f165c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/mock/TypeXDeviceManagementService.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mock; + +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; +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.ProvisioningConfig; +import org.wso2.carbon.device.mgt.common.StartupOperationConfig; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.carbon.device.mgt.common.general.GeneralConfig; +import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; +import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; +import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypePlatformDetails; + +import java.util.ArrayList; + +public class TypeXDeviceManagementService implements DeviceManagementService { + + private String deviceType; + + public TypeXDeviceManagementService(String deviceType) { + this.deviceType = deviceType; + } + + @Override + public void init() throws DeviceManagementException { + + } + + @Override + public String getType() { + return deviceType; + } + + @Override + public OperationMonitoringTaskConfig getOperationMonitoringConfig() { + OperationMonitoringTaskConfig operationMonitoringTaskConfig = new OperationMonitoringTaskConfig(); + operationMonitoringTaskConfig.setMonitoringOperation(new ArrayList()); + return operationMonitoringTaskConfig; + } + + @Override + public DeviceManager getDeviceManager() { + return new TypeXDeviceManager(); + } + + @Override + public ApplicationManager getApplicationManager() { + return null; + } + + @Override + public ProvisioningConfig getProvisioningConfig() { + return new ProvisioningConfig("carbon.super", true); + } + + @Override + public PushNotificationConfig getPushNotificationConfig() { + return null; + } + + @Override + public PolicyMonitoringManager getPolicyMonitoringManager() { + return null; + } + + @Override + public InitialOperationConfig getInitialOperationConfig() { + return null; + } + + @Override + public StartupOperationConfig getStartupOperationConfig() { + return null; + } + + @Override + public PullNotificationSubscriber getPullNotificationSubscriber() { + return null; + } + + @Override + public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() { + return null; + } + + @Override + public GeneralConfig getGeneralConfig() { + return null; + } + + @Override + public DeviceTypePlatformDetails getDeviceTypePlatformDetails() { + return null; + } + + @Override + public DeviceEnrollmentInvitationDetails getDeviceEnrollmentInvitationDetails() { + return null; + } + + @Override + public License getLicenseConfig() { return null; } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/mock/TypeXDeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/mock/TypeXDeviceManager.java new file mode 100644 index 00000000000..509c40a0d70 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/java/org/wso2/carbon/device/mgt/extensions/mock/TypeXDeviceManager.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mock; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; + +import java.util.List; + +public class TypeXDeviceManager implements DeviceManager { + + @Override + public FeatureManager getFeatureManager() { + return null; + } + + @Override + public boolean saveConfiguration(PlatformConfiguration configuration) + throws DeviceManagementException { + return false; + } + + @Override public PlatformConfiguration getConfiguration() throws DeviceManagementException { + return null; + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + return true; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + return false; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public void deleteDevices(List deviceIdentifiers) throws DeviceManagementException { + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return false; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + return false; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + return null; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + return null; + } + + @Override public boolean updateDeviceProperties(DeviceIdentifier deviceId, List list) + throws DeviceManagementException { + return false; + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) + throws DeviceManagementException { + return false; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, EnrolmentInfo.Status status) + throws DeviceManagementException { + return false; + } + + @Override + public License getLicense(String languageCode) throws LicenseManagementException { + return null; + } + + @Override + public void addLicense(License license) throws LicenseManagementException { + + } + + @Override + public boolean requireDeviceAuthorization() { + return false; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/datasource/data-source-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/datasource/data-source-config.xml new file mode 100644 index 00000000000..1f670566e5c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/datasource/data-source-config.xml @@ -0,0 +1,33 @@ + + + + + jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true + org.h2.Driver + wso2carbon + wso2carbon + + + + + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql index c6a935cfc4d..eedbcd875af 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/sql-files/h2.sql @@ -477,6 +477,18 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( ); -- END OF POLICY AND DEVICE GROUP MAPPING -- +-- METADATA TABLE -- +CREATE TABLE IF NOT EXISTS DM_METADATA ( + METADATA_ID INT AUTO_INCREMENT NOT NULL, + DATA_TYPE VARCHAR(16) NOT NULL, + METADATA_KEY VARCHAR(128) NOT NULL, + METADATA_VALUE VARCHAR(4000) NOT NULL, + TENANT_ID INTEGER NOT NULL, + PRIMARY KEY (METADATA_ID), + CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) + ); +-- END OF METADATA TABLE -- + -- DASHBOARD RELATED VIEWS -- CREATE VIEW POLICY_COMPLIANCE_INFO AS SELECT diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java index de7a16c0b11..f134f02ee8d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TypeXDeviceManagementService.java @@ -45,6 +45,7 @@ import org.wso2.carbon.device.mgt.common.StartupOperationConfig; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.general.GeneralConfig; import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; +import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; @@ -137,4 +138,7 @@ public class TypeXDeviceManagementService implements DeviceManagementService { public DeviceEnrollmentInvitationDetails getDeviceEnrollmentInvitationDetails() { return null; } + + @Override + public License getLicenseConfig() { return null; } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 2de968cb81f..d7d68c2fcc7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -568,7 +568,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( METADATA_ID INT AUTO_INCREMENT NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(512) NOT NULL, + METADATA_VALUE VARCHAR(8000) NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (METADATA_ID), CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 28f36b63ff0..c70277074af 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -609,7 +609,7 @@ CREATE TABLE DM_METADATA ( METADATA_ID INTEGER IDENTITY(1,1) NOT NULL, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(512) NOT NULL, + METADATA_VALUE VARCHAR(8000) NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (METADATA_ID), CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 56cb0022b3e..71d7f4f5f3a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -625,7 +625,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( METADATA_ID INTEGER NOT NULL AUTO_INCREMENT, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(512) NOT NULL, + METADATA_VALUE VARCHAR(8000) NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (METADATA_ID), UNIQUE KEY METADATA_KEY_TENANT_ID (METADATA_KEY,TENANT_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 42b32d5ab27..de19680e81b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -959,7 +959,7 @@ CREATE TABLE DM_METADATA ( METADATA_ID NUMBER(10) NOT NULL, DATA_TYPE VARCHAR2(16) NOT NULL, METADATA_KEY VARCHAR2(128) NOT NULL, - METADATA_VALUE VARCHAR2(512) NOT NULL, + METADATA_VALUE VARCHAR2(8000) NOT NULL, TENANT_ID INTEGER NOT NULL, CONSTRAINT PK_DM_METADATA PRIMARY KEY (METADATA_ID), CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 9e3408577a1..db431497e8a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -625,7 +625,7 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( METADATA_ID BIGSERIAL PRIMARY KEY, DATA_TYPE VARCHAR(16) NOT NULL, METADATA_KEY VARCHAR(128) NOT NULL, - METADATA_VALUE VARCHAR(512) NOT NULL, + METADATA_VALUE VARCHAR(8000) NOT NULL, TENANT_ID INTEGER NOT NULL, CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE(METADATA_KEY, TENANT_ID) );