From e71d3947cba6eb7dc369481b8920f304f15cba4f Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Sep 2016 08:57:34 +0530 Subject: [PATCH] Adding intuitive error when specified notification provider is not found --- .../DeviceManagementPluginRepository.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 504d29d5f1..8246c7e283 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 @@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; 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.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; @@ -74,7 +75,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis } } catch (DeviceManagementException e) { throw new DeviceManagementException("Error occurred while adding device management provider '" + - deviceType + "'", e); + deviceType + "'", e); } if (isSharedWithAllTenants) { DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType); @@ -137,10 +138,16 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId); } + if (pushNoteConfig != null) { - NotificationStrategy notificationStrategy = - DeviceManagementDataHolder.getInstance().getPushNotificationProviderRepository().getProvider( - pushNoteConfig.getType()).getNotificationStrategy(pushNoteConfig); + PushNotificationProvider provider = DeviceManagementDataHolder.getInstance() + .getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType()); + if (provider == null) { + throw new DeviceManagementException( + "No registered push notification provider found for the type: '" + + pushNoteConfig.getType() + "'."); + } + NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig); operationManagerRepository.addOperationManager(deviceTypeIdentifier, new OperationManagerImpl( notificationStrategy)); } else { @@ -172,7 +179,8 @@ 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()); + DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId, + provisioningConfig.isSharedWithAllTenants()); registerPushNotificationStrategy(provider); //TODO: //This is a temporory fix. @@ -180,12 +188,13 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis //until fix that, use following variable to enable and disable of checking user authorization. DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(provider.getType(), - provider.getDeviceManager().requireDeviceAuthorization()); + provider.getDeviceManager() + .requireDeviceAuthorization()); } catch (Throwable e) { /* Throwable is caught intentionally as failure of one plugin - due to invalid start up parameters, etc - should not block the initialization of other device management providers */ log.error("Error occurred while initializing device management provider '" + - provider.getType() + "'", e); + provider.getType() + "'", e); } } this.isInited = true;