Add device status filter service for sub-tenants

rm-10378
Pramila Niroshan 12 months ago
parent ca3e12da31
commit 2453459882

@ -24,4 +24,6 @@ public interface TenantManagerService {
void addDefaultRoles(TenantInfoBean tenantInfoBean) throws TenantMgtException;
void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException;
void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException;
}

@ -36,4 +36,11 @@ public interface TenantManager {
* @throws TenantMgtException Throws when error occurred while adding default application categories
*/
void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException;
/**
* Add default device status filters to a tenant described by the tenant info bean
* @param tenantInfoBean The info bean that provides tenant info
* @throws TenantMgtException Throws when error occurred while adding default application categories
*/
void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException;
}

@ -98,6 +98,21 @@ public class TenantManagerImpl implements TenantManager {
}
}
@Override
public void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException {
initTenantFlow(tenantInfoBean);
try {
TenantMgtDataHolder.getInstance().getDeviceStatusManagementService().
addDefaultDeviceStatusFilterIfNotExist(tenantInfoBean.getTenantId());
} catch (MetadataManagementException e) {
String msg = "Error occurred while adding default device status filter";
log.error(msg, e);
throw new TenantMgtException(msg, e);
} finally {
endTenantFlow();
}
}
private void initTenantFlow(TenantInfoBean tenantInfoBean) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();

@ -33,4 +33,9 @@ public class TenantManagerServiceImpl implements TenantManagerService {
public void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException {
TenantMgtDataHolder.getInstance().getTenantManager().addDefaultAppCategories(tenantInfoBean);
}
@Override
public void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException {
TenantMgtDataHolder.getInstance().getTenantManager().addDefaultDeviceStatusFilters(tenantInfoBean);
}
}

@ -18,6 +18,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.DeviceStatusManagementService;
import io.entgra.device.mgt.core.tenant.mgt.core.TenantManager;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.WhiteLabelManagementService;
import org.wso2.carbon.user.core.service.RealmService;
@ -32,6 +33,8 @@ public class TenantMgtDataHolder {
private RealmService realmService;
private DeviceStatusManagementService deviceStatusManagementService;
public RealmService getRealmService() {
return realmService;
}
@ -67,4 +70,12 @@ public class TenantMgtDataHolder {
public static TenantMgtDataHolder getInstance() {
return instance;
}
public DeviceStatusManagementService getDeviceStatusManagementService() {
return deviceStatusManagementService;
}
public void setDeviceStatusManagementService(DeviceStatusManagementService deviceStatusManagementService) {
this.deviceStatusManagementService = deviceStatusManagementService;
}
}

@ -18,6 +18,8 @@
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.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerService;
import io.entgra.device.mgt.core.tenant.mgt.core.TenantManager;
import io.entgra.device.mgt.core.tenant.mgt.core.impl.TenantManagerImpl;
@ -64,6 +66,10 @@ public class TenantMgtServiceComponent {
componentContext.getBundleContext().registerService(WhiteLabelManagementServiceImpl.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");

@ -38,6 +38,7 @@ public class DeviceMgtTenantListener implements TenantMgtListener {
try {
tenantManager.addDefaultRoles(tenantInfoBean);
tenantManager.addDefaultAppCategories(tenantInfoBean);
tenantManager.addDefaultDeviceStatusFilters(tenantInfoBean);
} catch (TenantMgtException e) {
String msg = "Error occurred while executing tenant creation flow";
log.error(msg, e);

Loading…
Cancel
Save