|
|
@ -22,11 +22,13 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
|
|
|
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.pull.notification.PullNotificationSubscriber;
|
|
|
|
|
|
|
|
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.push.notification.PushNotificationProvider;
|
|
|
@ -35,9 +37,7 @@ import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
|
|
|
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
|
|
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
|
|
|
@ -51,12 +51,9 @@ import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
|
|
|
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
|
|
|
|
|
|
|
|
|
|
@ -158,9 +155,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
|
|
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
|
|
|
deviceTypeIdentifier);
|
|
|
|
deviceTypeIdentifier);
|
|
|
|
if (operationManager != null) {
|
|
|
|
if (operationManager != null) {
|
|
|
|
Collection<NotificationStrategy> notificationStrategies = operationManager.getNotificationStrategyMap()
|
|
|
|
NotificationStrategy notificationStrategy = operationManager.getNotificationStrategy();
|
|
|
|
.values();
|
|
|
|
if (notificationStrategy != null) {
|
|
|
|
for (NotificationStrategy notificationStrategy : notificationStrategies) {
|
|
|
|
|
|
|
|
notificationStrategy.undeploy();
|
|
|
|
notificationStrategy.undeploy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operationManagerRepository.removeOperationManager(deviceTypeIdentifier);
|
|
|
|
operationManagerRepository.removeOperationManager(deviceTypeIdentifier);
|
|
|
@ -217,9 +213,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
|
|
|
|
provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
|
|
|
|
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
|
|
|
|
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
|
|
|
|
if (!cachedDefinition.equals(dbStoredDefinition)) {
|
|
|
|
if (!cachedDefinition.equals(dbStoredDefinition)) {
|
|
|
|
DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder
|
|
|
|
DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder.getInstance()
|
|
|
|
.getInstance().getDeviceTypeGeneratorService()
|
|
|
|
.getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
|
|
|
|
.populateDeviceManagementService(type, deviceTypeMetaDefinition);
|
|
|
|
|
|
|
|
if (deviceTypeManagerService == null) {
|
|
|
|
if (deviceTypeManagerService == null) {
|
|
|
|
log.error("Failing to retrieve the device type service for " + type);
|
|
|
|
log.error("Failing to retrieve the device type service for " + type);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -253,7 +248,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
|
|
|
|
|
|
|
|
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
|
|
|
|
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
List<PushNotificationConfig> pushNoteConfigs = deviceManagementService.getPushNotificationConfigs();
|
|
|
|
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
@ -267,10 +262,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pushNoteConfigs != null) {
|
|
|
|
if (pushNoteConfig != null) {
|
|
|
|
Map<String, NotificationStrategy> notificationStrategyMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
NotificationStrategy defaultNotificationStrategy = null;
|
|
|
|
|
|
|
|
for (PushNotificationConfig pushNoteConfig : pushNoteConfigs) {
|
|
|
|
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
if (provider == null) {
|
|
|
|
if (provider == null) {
|
|
|
@ -279,28 +271,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
if (pushNoteConfig.isDefault()) {
|
|
|
|
|
|
|
|
if (defaultNotificationStrategy == null) {
|
|
|
|
|
|
|
|
defaultNotificationStrategy = notificationStrategy;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Multiple push notification strategies are set as default. Only one strategy can " +
|
|
|
|
|
|
|
|
"be set as default for the device type: '" + deviceTypeIdentifier
|
|
|
|
|
|
|
|
.getDeviceType() + "'.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationStrategyMap.put(pushNoteConfig.getType(), notificationStrategy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (defaultNotificationStrategy != null) {
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(),
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(), notificationStrategy));
|
|
|
|
defaultNotificationStrategy, notificationStrategyMap));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"No registered default push notification provider found for the device type: '" + deviceTypeIdentifier
|
|
|
|
|
|
|
|
.getDeviceType() + "'.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
|
|
|
|