Adding intuitive error when specified notification provider is not found

revert-70aa11f8
Rasika Perera 8 years ago
parent 513015c1b5
commit e71d3947cb

@ -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.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; 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.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.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; 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.DeviceManagementServiceComponent;
@ -74,7 +75,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new DeviceManagementException("Error occurred while adding device management provider '" + throw new DeviceManagementException("Error occurred while adding device management provider '" +
deviceType + "'", e); deviceType + "'", e);
} }
if (isSharedWithAllTenants) { if (isSharedWithAllTenants) {
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType); DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType);
@ -137,10 +138,16 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId); deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId);
} }
if (pushNoteConfig != null) { if (pushNoteConfig != null) {
NotificationStrategy notificationStrategy = PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
DeviceManagementDataHolder.getInstance().getPushNotificationProviderRepository().getProvider( .getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
pushNoteConfig.getType()).getNotificationStrategy(pushNoteConfig); 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( operationManagerRepository.addOperationManager(deviceTypeIdentifier, new OperationManagerImpl(
notificationStrategy)); notificationStrategy));
} else { } else {
@ -172,7 +179,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
deviceTypeName = provider.getType().toLowerCase(); deviceTypeName = provider.getType().toLowerCase();
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain()); int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId, provisioningConfig.isSharedWithAllTenants()); DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId,
provisioningConfig.isSharedWithAllTenants());
registerPushNotificationStrategy(provider); registerPushNotificationStrategy(provider);
//TODO: //TODO:
//This is a temporory fix. //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. //until fix that, use following variable to enable and disable of checking user authorization.
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(provider.getType(), DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(provider.getType(),
provider.getDeviceManager().requireDeviceAuthorization()); provider.getDeviceManager()
.requireDeviceAuthorization());
} catch (Throwable e) { } catch (Throwable e) {
/* Throwable is caught intentionally as failure of one plugin - due to invalid start up parameters, /* 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 */ etc - should not block the initialization of other device management providers */
log.error("Error occurred while initializing device management provider '" + log.error("Error occurred while initializing device management provider '" +
provider.getType() + "'", e); provider.getType() + "'", e);
} }
} }
this.isInited = true; this.isInited = true;

Loading…
Cancel
Save