From 0039adad53e3a664ce02c82f5d176abedd563c6a Mon Sep 17 00:00:00 2001 From: nipuni Date: Wed, 18 Sep 2024 06:54:16 +0530 Subject: [PATCH] Add improvements for the TenantMgtServiceComponent. --- .../internal/TenantMgtServiceComponent.java | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java index 9bb4f9067c..9c1ae11f43 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java @@ -19,9 +19,7 @@ package io.entgra.device.mgt.core.tenant.mgt.core.internal; import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.WhiteLabelManagementService; -import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.WhiteLabelManagementServiceImpl; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; -import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl; import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService; import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerService; import io.entgra.device.mgt.core.tenant.mgt.core.TenantManager; @@ -44,6 +42,46 @@ public class TenantMgtServiceComponent { private static final Log log = LogFactory.getLog(TenantManagerService.class); + @Reference( + name = "whiteLabelManagement.service", + service = io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.WhiteLabelManagementService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetWhiteLabelManagementService" + ) + protected void setWhiteLabelManagementService(WhiteLabelManagementService whiteLabelManagementService) { + if(log.isDebugEnabled()) { + log.info("WhiteLabelManagementService is binding"); + } + TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService); + } + protected void unsetWhiteLabelManagementService(WhiteLabelManagementService whiteLabelManagementService) { + if(log.isDebugEnabled()) { + log.info("WhiteLabelManagementService is unbinding"); + } + TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(null); + } + + @Reference( + name = "deviceStatusManagement.service", + service = io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService.class, + cardinality = ReferenceCardinality.MANDATORY, + policy = ReferencePolicy.DYNAMIC, + unbind = "unsetDeviceStatusManagementService" + ) + protected void setDeviceStatusManagementService(DeviceStatusManagementService deviceStatusManagementService) { + if(log.isDebugEnabled()) { + log.info("DeviceStatusManagementService is binding"); + } + TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService); + } + protected void unsetDeviceStatusManagementService(DeviceStatusManagementService deviceStatusManagementService) { + if(log.isDebugEnabled()) { + log.info("DeviceStatusManagementService is unbinding"); + } + TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(null); + } + @SuppressWarnings("unused") @Activate protected void activate(ComponentContext componentContext) { @@ -56,14 +94,6 @@ public class TenantMgtServiceComponent { registerService(TenantManagerAdminService.class.getName(), tenantManagerAdminService, null); TenantManager tenantManager = new TenantManagerImpl(); TenantMgtDataHolder.getInstance().setTenantManager(tenantManager); - WhiteLabelManagementService whiteLabelManagementService = new WhiteLabelManagementServiceImpl(); - componentContext.getBundleContext().registerService(WhiteLabelManagementService.class.getName(), - whiteLabelManagementService, null); - TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService); - DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl(); - componentContext.getBundleContext().registerService(DeviceStatusManagementService.class.getName(), - deviceStatusManagementService, null); - TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService); DeviceMgtTenantListener deviceMgtTenantListener = new DeviceMgtTenantListener(); if(log.isDebugEnabled()) { log.info("Tenant management listener is registering");