|
|
@ -22,13 +22,11 @@ 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.pull.notification.PullNotificationSubscriber;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
|
|
|
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;
|
|
|
@ -37,7 +35,9 @@ 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,9 +51,12 @@ 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 {
|
|
|
|
|
|
|
|
|
|
|
@ -155,8 +158,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
|
|
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
|
|
|
deviceTypeIdentifier);
|
|
|
|
deviceTypeIdentifier);
|
|
|
|
if (operationManager != null) {
|
|
|
|
if (operationManager != null) {
|
|
|
|
NotificationStrategy notificationStrategy = operationManager.getNotificationStrategy();
|
|
|
|
Collection<NotificationStrategy> notificationStrategies = operationManager.getNotificationStrategyMap()
|
|
|
|
if (notificationStrategy != null) {
|
|
|
|
.values();
|
|
|
|
|
|
|
|
for (NotificationStrategy notificationStrategy : notificationStrategies) {
|
|
|
|
notificationStrategy.undeploy();
|
|
|
|
notificationStrategy.undeploy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operationManagerRepository.removeOperationManager(deviceTypeIdentifier);
|
|
|
|
operationManagerRepository.removeOperationManager(deviceTypeIdentifier);
|
|
|
@ -213,8 +217,9 @@ 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.getInstance()
|
|
|
|
DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder
|
|
|
|
.getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
|
|
|
|
.getInstance().getDeviceTypeGeneratorService()
|
|
|
|
|
|
|
|
.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;
|
|
|
@ -248,7 +253,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
|
|
|
|
|
|
|
|
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
|
|
|
|
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
|
|
|
|
List<PushNotificationConfig> pushNoteConfigs = deviceManagementService.getPushNotificationConfigs();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
@ -262,7 +267,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pushNoteConfig != null) {
|
|
|
|
if (pushNoteConfigs != 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) {
|
|
|
@ -271,8 +279,28 @@ 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(), notificationStrategy));
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(),
|
|
|
|
|
|
|
|
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()));
|
|
|
|