Revert "Add multiple push notification support and transport config for features"

This reverts commit ad9ec1f994.
revert-70aa11f8
warunalakshitha 7 years ago
parent a3c5118d5e
commit 61f6fdeca9

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceTypeManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceTypeManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
@ -37,9 +38,9 @@ import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
@Path("/device-types") @Path("/device-types")
@ -78,7 +79,7 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
if (fm == null) { if (fm == null) {
return Response.status(Response.Status.NOT_FOUND).entity( return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " + new ErrorResponse.ErrorResponseBuilder().setMessage("No feature manager is " +
"registered with the given type '" + type + "'").build()).build(); "registered with the given type '" + type + "'").build()).build();
} }
features = fm.getFeatures(); features = fm.getFeatures();
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -132,7 +133,6 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
/** /**
* This cleans up the configs that should not be exposed to iot users. * This cleans up the configs that should not be exposed to iot users.
*
* @param deviceType * @param deviceType
* @return * @return
*/ */
@ -140,13 +140,9 @@ public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementServ
DeviceTypeMetaDefinition metaDefinition = deviceType.getDeviceTypeMetaDefinition(); DeviceTypeMetaDefinition metaDefinition = deviceType.getDeviceTypeMetaDefinition();
if (metaDefinition != null) { if (metaDefinition != null) {
metaDefinition.setInitialOperationConfig(null); metaDefinition.setInitialOperationConfig(null);
if (metaDefinition.getPushNotificationConfigs() != null) { if (metaDefinition.getPushNotificationConfig() != null) {
List<PushNotificationConfig> pushNotificationConfigs = new LinkedList<>(); metaDefinition.setPushNotificationConfig(new PushNotificationConfig(metaDefinition.
for (PushNotificationConfig pushNotificationConfig : metaDefinition.getPushNotificationConfigs()) { getPushNotificationConfig().getType(), false, null));
pushNotificationConfigs.add(new PushNotificationConfig(pushNotificationConfig.getType(), false,
false, null));
}
metaDefinition.setPushNotificationConfigs(pushNotificationConfigs);
} }
deviceType.setDeviceTypeMetaDefinition(metaDefinition); deviceType.setDeviceTypeMetaDefinition(metaDefinition);
} }

@ -39,10 +39,6 @@ public class Feature implements Serializable {
"Features allow you to perform operations on any device type, " + "Features allow you to perform operations on any device type, " +
"such as android, iOS or windows..", required = true ) "such as android, iOS or windows..", required = true )
private String deviceType; private String deviceType;
@ApiModelProperty(name = "pushNotificationProviderType", value = "Provides push notification provider for the " +
"feature. If not set default push notification strategy will be used.")
private String pushNotificationType;
@ApiModelProperty(name = "metadataEntries", value = "Properties related to features.", required = true ) @ApiModelProperty(name = "metadataEntries", value = "Properties related to features.", required = true )
private List<MetadataEntry> metadataEntries; private List<MetadataEntry> metadataEntries;
@ -91,15 +87,6 @@ public class Feature implements Serializable {
this.deviceType = deviceType; this.deviceType = deviceType;
} }
@XmlElement
public String getPushNotificationType() {
return pushNotificationType;
}
public void setPushNotificationType(String pushNotificationType) {
this.pushNotificationType = pushNotificationType;
}
@XmlElement @XmlElement
public String getDescription() { public String getDescription() {
return description; return description;

@ -25,7 +25,6 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy; import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* This represents the Device Operation management functionality which should be implemented by * This represents the Device Operation management functionality which should be implemented by
@ -108,23 +107,12 @@ public interface OperationManager {
* Operation manger implementation can have a push notification stratergy * Operation manger implementation can have a push notification stratergy
* @param notificationStrategy eg: mqtt/xmpp * @param notificationStrategy eg: mqtt/xmpp
*/ */
void setDefaultNotificationStrategy(NotificationStrategy notificationStrategy); void setNotificationStrategy(NotificationStrategy notificationStrategy);
/** /**
* retrive the push notification strategy. * retrive the push notification strategy.
* @return NotificationStrategy * @return NotificationStrategy
*/ */
NotificationStrategy getDefaultNotificationStrategy(); NotificationStrategy getNotificationStrategy();
/**
* Set notification strategy map which contains feature code to notification strategy map
* @param notificationStrategyMap
*/
public void setNotificationStrategyMap(Map<String, NotificationStrategy> notificationStrategyMap);
/**
* Provides notification strategy Map
* @return Map which contains mapping for feature code to notification strategy
*/
public Map<String, NotificationStrategy> getNotificationStrategyMap();
} }

@ -27,15 +27,12 @@ public class PushNotificationConfig {
private String type; private String type;
private boolean isScheduled; private boolean isScheduled;
private boolean isDefault;
Map<String, String> properties; Map<String, String> properties;
public PushNotificationConfig(String type, boolean isScheduled, boolean isDefault, Map<String, String> public PushNotificationConfig(String type, boolean isScheduled, Map<String, String> properties) {
properties) {
this.type = type; this.type = type;
this.properties = properties; this.properties = properties;
this.isScheduled = isScheduled; this.isScheduled = isScheduled;
this.isDefault = isDefault;
} }
@XmlElement(name = "Type", required = true) @XmlElement(name = "Type", required = true)
@ -48,11 +45,6 @@ public class PushNotificationConfig {
return isScheduled; return isScheduled;
} }
@XmlElement(name = "Default")
public boolean isDefault() {
return isDefault;
}
public Map<String, String> getProperties() { public Map<String, String> getProperties() {
return properties; return properties;
} }

@ -24,8 +24,6 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import java.util.List;
/** /**
* Composite interface that acts as the SPI exposing all device management as well as application management * Composite interface that acts as the SPI exposing all device management as well as application management
* functionalities. * functionalities.
@ -44,7 +42,7 @@ public interface DeviceManagementService {
ProvisioningConfig getProvisioningConfig(); ProvisioningConfig getProvisioningConfig();
List<PushNotificationConfig> getPushNotificationConfigs(); PushNotificationConfig getPushNotificationConfig();
PolicyMonitoringManager getPolicyMonitoringManager(); PolicyMonitoringManager getPolicyMonitoringManager();

@ -2,6 +2,7 @@ package org.wso2.carbon.device.mgt.common.type.mgt;
import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -12,7 +13,7 @@ public class DeviceTypeMetaDefinition {
private List<String> properties; private List<String> properties;
private List<Feature> features; private List<Feature> features;
private boolean claimable; private boolean claimable;
private List<PushNotificationConfig> pushNotificationConfigs; private PushNotificationConfig pushNotificationConfig;
private boolean policyMonitoringEnabled; private boolean policyMonitoringEnabled;
private InitialOperationConfig initialOperationConfig; private InitialOperationConfig initialOperationConfig;
private License license; private License license;
@ -50,13 +51,13 @@ public class DeviceTypeMetaDefinition {
this.claimable = isClaimable; this.claimable = isClaimable;
} }
public List<PushNotificationConfig> getPushNotificationConfigs() { public PushNotificationConfig getPushNotificationConfig() {
return pushNotificationConfigs; return pushNotificationConfig;
} }
public void setPushNotificationConfigs( public void setPushNotificationConfig(
List<PushNotificationConfig> pushNotificationConfigs) { PushNotificationConfig pushNotificationConfig) {
this.pushNotificationConfigs = pushNotificationConfigs; this.pushNotificationConfig = pushNotificationConfig;
} }
public boolean isPolicyMonitoringEnabled() { public boolean isPolicyMonitoringEnabled() {

@ -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);
@ -208,7 +204,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
long updatedTimestamp = provider.getTimestamp(); long updatedTimestamp = provider.getTimestamp();
if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) { if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) {
try { try {
DeviceType deviceType = DeviceManagerUtil.getDeviceType(type, tenantId); DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId);
DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition(); DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
if (deviceTypeMetaDefinition != null) { if (deviceTypeMetaDefinition != null) {
Gson gson = new Gson(); Gson gson = new Gson();
@ -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,40 +262,17 @@ 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<>(); PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
NotificationStrategy defaultNotificationStrategy = null; .getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
for (PushNotificationConfig pushNoteConfig : pushNoteConfigs) { if (provider == null) {
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);
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,
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(),
defaultNotificationStrategy, notificationStrategyMap));
} else {
throw new DeviceManagementException( throw new DeviceManagementException(
"No registered default push notification provider found for the device type: '" + deviceTypeIdentifier "No registered push notification provider found for the type: '" +
.getDeviceType() + "'."); pushNoteConfig.getType() + "'.");
} }
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(), notificationStrategy));
} else { } else {
operationManagerRepository.addOperationManager(deviceTypeIdentifier, operationManagerRepository.addOperationManager(deviceTypeIdentifier,
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType())); new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
@ -405,7 +377,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
String deviceTypeName; String deviceTypeName;
synchronized (providers) { synchronized (providers) {
for (DeviceManagementServiceHolder deviceManagementServiceHolder : providers.values()) { for (DeviceManagementServiceHolder deviceManagementServiceHolder : providers.values()) {
DeviceManagementService provider = deviceManagementServiceHolder.getDeviceManagementService(); DeviceManagementService provider= deviceManagementServiceHolder.getDeviceManagementService();
try { try {
provider.init(); provider.init();
deviceTypeName = provider.getType(); deviceTypeName = provider.getType();

@ -25,8 +25,6 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.MonitoringOperation;
import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationRequest;
@ -66,7 +64,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated * This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
@ -85,10 +82,8 @@ public class OperationManagerImpl implements OperationManager {
private OperationDAO operationDAO; private OperationDAO operationDAO;
private DeviceDAO deviceDAO; private DeviceDAO deviceDAO;
private EnrollmentDAO enrollmentDAO; private EnrollmentDAO enrollmentDAO;
private Map<String, NotificationStrategy> notificationStrategyMap; private NotificationStrategy notificationStrategy;
private NotificationStrategy defaultNotificationStrategy;
private String deviceType; private String deviceType;
private FeatureManager featureManager;
public OperationManagerImpl() { public OperationManagerImpl() {
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO(); commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
@ -101,35 +96,22 @@ public class OperationManagerImpl implements OperationManager {
enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
} }
public OperationManagerImpl(String deviceType) throws DeviceManagementException { public OperationManagerImpl(String deviceType) {
this(); this();
this.deviceType = deviceType; this.deviceType = deviceType;
featureManager = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.getFeatureManager(deviceType);
} }
public NotificationStrategy getDefaultNotificationStrategy() { public NotificationStrategy getNotificationStrategy() {
return defaultNotificationStrategy; return notificationStrategy;
} }
public void setDefaultNotificationStrategy(NotificationStrategy defaultNotificationStrategy) { public void setNotificationStrategy(NotificationStrategy notificationStrategy) {
this.defaultNotificationStrategy = defaultNotificationStrategy; this.notificationStrategy = notificationStrategy;
} }
public Map<String, NotificationStrategy> getNotificationStrategyMap() { public OperationManagerImpl(String deviceType, NotificationStrategy notificationStrategy) {
return notificationStrategyMap;
}
public void setNotificationStrategyMap(Map<String, NotificationStrategy> notificationStrategyMap) {
this.notificationStrategyMap = notificationStrategyMap;
}
public OperationManagerImpl(String deviceType, NotificationStrategy defaultNotificationStrategy, Map<String,
NotificationStrategy> notificationStrategyMap) throws
DeviceManagementException {
this(deviceType); this(deviceType);
this.defaultNotificationStrategy = defaultNotificationStrategy; this.notificationStrategy = notificationStrategy;
this.notificationStrategyMap = notificationStrategyMap;
} }
@Override @Override
@ -167,17 +149,8 @@ public class OperationManagerImpl implements OperationManager {
boolean isNotRepeated = false; boolean isNotRepeated = false;
boolean isScheduled = false; boolean isScheduled = false;
// check whether device list is greater than batch size notification strategy has enable to send push // check whether device list is greater than batch size notification strategy has enable to send push
// notification using scheduler task // notification using scheduler task
NotificationStrategy notificationStrategy = null;
Feature feature = featureManager.getFeature(operation.getCode());
if (feature != null && feature.getPushNotificationType() != null) {
notificationStrategy = notificationStrategyMap.get(feature.getPushNotificationType());
}
if (notificationStrategy == null) {
notificationStrategy = defaultNotificationStrategy;
}
if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). if (DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceList.size() && getPushNotificationConfiguration().getSchedulerBatchSize() <= authorizedDeviceList.size() &&
notificationStrategy != null) { notificationStrategy != null) {
@ -224,15 +197,13 @@ public class OperationManagerImpl implements OperationManager {
operation.setId(operationId); operation.setId(operationId);
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
notificationStrategy.execute(new NotificationContext(deviceId, operation)); notificationStrategy.execute(new NotificationContext(deviceId, operation));
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED);
.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED);
} catch (PushNotificationExecutionFailedException e) { } catch (PushNotificationExecutionFailedException e) {
log.error("Error occurred while sending push notifications to " + log.error("Error occurred while sending push notifications to " +
deviceId.getType() + " device carrying id '" + deviceId.getType() + " device carrying id '" +
deviceId + "'", e); deviceId + "'", e);
// Reschedule if push notification failed. // Reschedule if push notification failed.
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
} }
} }
} }
@ -259,9 +230,6 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while adding operation", e); throw new OperationManagementException("Error occurred while adding operation", e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating the transaction", e); throw new OperationManagementException("Error occurred while initiating the transaction", e);
} catch (DeviceManagementException e) {
throw new OperationManagementException("Error occurred while getting feature for given operation code :"
+ operation.getCode(), e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
@ -274,7 +242,7 @@ public class OperationManagerImpl implements OperationManager {
//Add the invalid DeviceIds //Add the invalid DeviceIds
for (String id : deviceIdValidationResult.getErrorDeviceIdList()) { for (String id : deviceIdValidationResult.getErrorDeviceIdList()) {
activityStatus = new ActivityStatus(); activityStatus = new ActivityStatus();
activityStatus.setDeviceIdentifier(new DeviceIdentifier(id, deviceType)); activityStatus.setDeviceIdentifier(new DeviceIdentifier(id,deviceType));
activityStatus.setStatus(ActivityStatus.Status.INVALID); activityStatus.setStatus(ActivityStatus.Status.INVALID);
activityStatuses.add(activityStatus); activityStatuses.add(activityStatus);
} }

@ -28,7 +28,6 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import java.util.List; import java.util.List;
import java.util.Map;
public class PushNotificationBasedOperationManager implements OperationManager { public class PushNotificationBasedOperationManager implements OperationManager {
@ -143,24 +142,13 @@ public class PushNotificationBasedOperationManager implements OperationManager {
} }
@Override @Override
public void setDefaultNotificationStrategy(NotificationStrategy notificationStrategy) { public void setNotificationStrategy(NotificationStrategy notificationStrategy) {
} }
@Override @Override
public NotificationStrategy getDefaultNotificationStrategy() { public NotificationStrategy getNotificationStrategy() {
return null; return notificationProvider;
} }
@Override
public void setNotificationStrategyMap(Map<String, NotificationStrategy> notificationStrategyMap) {
}
@Override
public Map<String, NotificationStrategy> getNotificationStrategyMap() {
return null;
}
} }

@ -21,8 +21,6 @@ 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.Feature;
import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext; import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
@ -85,24 +83,12 @@ public class PushNotificationSchedulerTask implements Runnable {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(operationMapping.getTenantId(), true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(operationMapping.getTenantId(), true);
// Get notification strategy for given device type // Get notification strategy for given device type
NotificationStrategy notificationStrategy = null; NotificationStrategy notificationStrategy = provider.getNotificationStrategyByDeviceType
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping (operationMapping.getDeviceIdentifier().getType());
.getOperationId());
FeatureManager featureManager = provider.getFeatureManager(operationMapping.getDeviceIdentifier().getType());
Feature feature = featureManager.getFeature(operation.getCode());
if (feature != null) {
Map<String, NotificationStrategy> notificationStrategyListByDeviceType = provider.getNotificationStrategyListByDeviceType(operationMapping.getDeviceIdentifier().getType());
if (notificationStrategyListByDeviceType != null && feature.getPushNotificationType() != null) {
notificationStrategy = notificationStrategyListByDeviceType.get(feature.getPushNotificationType());
}
}
if (notificationStrategy == null) {
notificationStrategy = provider.getDefaultNotificationStrategyByDeviceType(operationMapping.getDeviceIdentifier()
.getType());
}
// Send the push notification on given strategy // Send the push notification on given strategy
notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(), notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(),
operation)); provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping
.getOperationId())));
operationMapping.setPushNotificationStatus(Operation.PushNotificationStatus.COMPLETED); operationMapping.setPushNotificationStatus(Operation.PushNotificationStatus.COMPLETED);
operationsCompletedList.add(operationMapping); operationsCompletedList.add(operationMapping);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {

@ -39,9 +39,7 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Proxy class for all Device Management related operations that take the corresponding plugin type in * Proxy class for all Device Management related operations that take the corresponding plugin type in
@ -473,10 +471,7 @@ public interface DeviceManagementProviderService {
* @return Notification Strategy for device type * @return Notification Strategy for device type
* @throws DeviceManagementException * @throws DeviceManagementException
*/ */
NotificationStrategy getDefaultNotificationStrategyByDeviceType(String deviceType) throws DeviceManagementException; NotificationStrategy getNotificationStrategyByDeviceType(String deviceType) throws DeviceManagementException;
Map<String, NotificationStrategy> getNotificationStrategyListByDeviceType(String deviceType) throws
DeviceManagementException;
License getLicense(String deviceType, String languageCode) throws DeviceManagementException; License getLicense(String deviceType, String languageCode) throws DeviceManagementException;

@ -28,6 +28,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.FeatureManager; import org.wso2.carbon.device.mgt.common.FeatureManager;
import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
@ -52,8 +55,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
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.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
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.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
@ -68,7 +69,6 @@ import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
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.PluginInitializationListener; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
@ -1449,24 +1449,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public NotificationStrategy getDefaultNotificationStrategyByDeviceType(String deviceType) throws public NotificationStrategy getNotificationStrategyByDeviceType(String deviceType) throws DeviceManagementException {
DeviceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
OperationManager operationManager = pluginRepository.getOperationManager(deviceType, tenantId);
if (operationManager != null) {
return operationManager.getDefaultNotificationStrategy();
} else {
throw new DeviceManagementException("Cannot find operation manager for given device type :" + deviceType);
}
}
@Override
public Map<String, NotificationStrategy> getNotificationStrategyListByDeviceType(String deviceType) throws
DeviceManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
OperationManager operationManager = pluginRepository.getOperationManager(deviceType, tenantId); OperationManager operationManager = pluginRepository.getOperationManager(deviceType, tenantId);
if (operationManager != null) { if (operationManager != null) {
return operationManager.getNotificationStrategyMap(); return operationManager.getNotificationStrategy();
} else { } else {
throw new DeviceManagementException("Cannot find operation manager for given device type :" + deviceType); throw new DeviceManagementException("Cannot find operation manager for given device type :" + deviceType);
} }
@ -1696,8 +1683,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementService dms = DeviceManagementService dms =
pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId()); pluginRepository.getDeviceManagementService(deviceIdentifier.getType(), this.getTenantId());
if (dms == null) { if (dms == null) {
String message = "Device type '" + deviceIdentifier.getType() + "' does not have an associated device " + String message = "Device type '" + deviceIdentifier.getType() + "' does not have an associated device management " +
"management " + "plugin registered within the framework"; "plugin registered within the framework";
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(message); log.debug(message);
} }

@ -24,8 +24,6 @@ import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubsc
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.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import java.util.List;
public class TestDeviceManagementService implements DeviceManagementService { public class TestDeviceManagementService implements DeviceManagementService {
private String providerType; private String providerType;
@ -65,7 +63,8 @@ public class TestDeviceManagementService implements DeviceManagementService {
return new ProvisioningConfig(tenantDomain, false); return new ProvisioningConfig(tenantDomain, false);
} }
public List<PushNotificationConfig> getPushNotificationConfigs() { @Override
public PushNotificationConfig getPushNotificationConfig() {
return null; return null;
} }

@ -22,10 +22,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager; import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
import org.wso2.carbon.device.mgt.common.InitialOperationConfig; import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.MonitoringOperation;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
@ -42,14 +42,12 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyM
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriberConfig; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriberConfig;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProviders;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TaskConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt.DefaultPolicyMonitoringManager; import org.wso2.carbon.device.mgt.extensions.device.type.template.policy.mgt.DefaultPolicyMonitoringManager;
import org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification.PullNotificationSubscriberLoader; import org.wso2.carbon.device.mgt.extensions.device.type.template.pull.notification.PullNotificationSubscriberLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -62,7 +60,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private static final Log log = LogFactory.getLog(DeviceTypeManagerService.class); private static final Log log = LogFactory.getLog(DeviceTypeManagerService.class);
private DeviceManager deviceManager; private DeviceManager deviceManager;
private List<PushNotificationConfig> pushNotificationConfigs; private PushNotificationConfig pushNotificationConfig;
private ProvisioningConfig provisioningConfig; private ProvisioningConfig provisioningConfig;
private String type; private String type;
private OperationMonitoringTaskConfig operationMonitoringConfigs; private OperationMonitoringTaskConfig operationMonitoringConfigs;
@ -77,7 +75,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.setProvisioningConfig(deviceTypeConfigIdentifier.getTenantDomain(), deviceTypeConfiguration); this.setProvisioningConfig(deviceTypeConfigIdentifier.getTenantDomain(), deviceTypeConfiguration);
this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceTypeConfiguration); this.deviceManager = new DeviceTypeManager(deviceTypeConfigIdentifier, deviceTypeConfiguration);
this.setType(deviceTypeConfiguration.getName()); this.setType(deviceTypeConfiguration.getName());
this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProviders()); this.populatePushNotificationConfig(deviceTypeConfiguration.getPushNotificationProvider());
this.operationMonitoringConfigs = new OperationMonitoringTaskConfig(); this.operationMonitoringConfigs = new OperationMonitoringTaskConfig();
this.setOperationMonitoringConfig(deviceTypeConfiguration); this.setOperationMonitoringConfig(deviceTypeConfiguration);
this.initialOperationConfig = new InitialOperationConfig(); this.initialOperationConfig = new InitialOperationConfig();
@ -94,7 +92,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
} }
@Override @Override
public OperationMonitoringTaskConfig getOperationMonitoringConfig() { public OperationMonitoringTaskConfig getOperationMonitoringConfig(){
return operationMonitoringConfigs; return operationMonitoringConfigs;
} }
@ -122,42 +120,35 @@ public class DeviceTypeManagerService implements DeviceManagementService {
public void init() throws DeviceManagementException { public void init() throws DeviceManagementException {
} }
private void populatePushNotificationConfig(PushNotificationProviders pushNotificationProviders) { private void populatePushNotificationConfig(PushNotificationProvider pushNotificationProvider) {
if (pushNotificationProviders != null) { if (pushNotificationProvider != null) {
pushNotificationConfigs = new LinkedList<>(); if (pushNotificationProvider.isFileBasedProperties()) {
List<PushNotificationProvider> notificationProviders = pushNotificationProviders.getPushNotificationProviders(); Map<String, String> staticProps = new HashMap<>();
for (PushNotificationProvider pushNotificationProvider : notificationProviders) { ConfigProperties configProperties = pushNotificationProvider.getConfigProperties();
if (pushNotificationProvider != null) { if (configProperties != null) {
if (pushNotificationProvider.isFileBasedProperties()) { List<Property> properties = configProperties.getProperty();
Map<String, String> staticProps = new HashMap<>(); if (properties != null && properties.size() > 0) {
ConfigProperties configProperties = pushNotificationProvider.getConfigProperties(); for (Property property : properties) {
if (configProperties != null) { staticProps.put(property.getName(), property.getValue());
List<Property> properties = configProperties.getProperty();
if (properties != null && properties.size() > 0) {
for (Property property : properties) {
staticProps.put(property.getName(), property.getValue());
}
}
} }
pushNotificationConfigs.add(new PushNotificationConfig(pushNotificationProvider.getType(), }
pushNotificationProvider.isScheduled(), pushNotificationProvider.isDefault(), staticProps)); }
} else { pushNotificationConfig = new PushNotificationConfig(pushNotificationProvider.getType(),
try { pushNotificationProvider.isScheduled(), staticProps);
PlatformConfiguration deviceTypeConfig = deviceManager.getConfiguration(); } else {
if (deviceTypeConfig != null) { try {
List<ConfigurationEntry> configuration = deviceTypeConfig.getConfiguration(); PlatformConfiguration deviceTypeConfig = deviceManager.getConfiguration();
if (configuration.size() > 0) { if (deviceTypeConfig != null) {
Map<String, String> properties = this.getConfigProperty(configuration); List<ConfigurationEntry> configuration = deviceTypeConfig.getConfiguration();
pushNotificationConfigs.add(new PushNotificationConfig( if (configuration.size() > 0) {
pushNotificationProvider.getType(), pushNotificationProvider.isScheduled(), Map<String, String> properties = this.getConfigProperty(configuration);
pushNotificationProvider.isDefault(), pushNotificationConfig = new PushNotificationConfig(
properties)); pushNotificationProvider.getType(), pushNotificationProvider.isScheduled(),
} properties);
}
} catch (DeviceManagementException e) {
log.error("Unable to get the " + type + " platform configuration from registry.");
} }
} }
} catch (DeviceManagementException e) {
log.error("Unable to get the " + type + " platform configuration from registry.");
} }
} }
} }
@ -178,8 +169,9 @@ public class DeviceTypeManagerService implements DeviceManagementService {
return provisioningConfig; return provisioningConfig;
} }
public List<PushNotificationConfig> getPushNotificationConfigs() { @Override
return pushNotificationConfigs; public PushNotificationConfig getPushNotificationConfig() {
return pushNotificationConfig;
} }
@Override @Override

@ -29,16 +29,15 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ConfigP
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Features; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Features;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.License;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyMonitoring; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PolicyMonitoring;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Properties;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Property;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ProvisioningConfig; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.ProvisioningConfig;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriberConfig; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PullNotificationSubscriberConfig;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProvider;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.PushNotificationProviders;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -85,7 +84,6 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple
configFeature.setCode(feature.getCode()); configFeature.setCode(feature.getCode());
configFeature.setDescription(feature.getDescription()); configFeature.setDescription(feature.getDescription());
configFeature.setName(feature.getName()); configFeature.setName(feature.getName());
configFeature.setPushNotificationType(feature.getPushNotificationType());
if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) { if (feature.getMetadataEntries() != null && feature.getMetadataEntries().size() > 0) {
List<String> metaValues = new ArrayList<>(); List<String> metaValues = new ArrayList<>();
for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) { for (Feature.MetadataEntry metadataEntry : feature.getMetadataEntries()) {
@ -117,37 +115,29 @@ public class HTTPDeviceTypeManagerService extends DeviceTypeManagerService imple
provisioningConfig.setSharedWithAllTenants(false); provisioningConfig.setSharedWithAllTenants(false);
deviceTypeConfiguration.setProvisioningConfig(provisioningConfig); deviceTypeConfiguration.setProvisioningConfig(provisioningConfig);
List<PushNotificationConfig> pushNotificationConfigs = deviceTypeMetaDefinition PushNotificationConfig pushNotificationConfig = deviceTypeMetaDefinition.getPushNotificationConfig();
.getPushNotificationConfigs(); if (pushNotificationConfig != null) {
if (pushNotificationConfigs != null) { PushNotificationProvider pushNotificationProvider = new PushNotificationProvider();
List<PushNotificationProvider> pushNotificationProviderList = new LinkedList<>(); pushNotificationProvider.setType(pushNotificationConfig.getType());
PushNotificationProviders pushNotificationProviders = new PushNotificationProviders(); //default schedule value will be true.
for (PushNotificationConfig pushNotificationConfig : pushNotificationConfigs) { pushNotificationProvider.setScheduled(true);
PushNotificationProvider pushNotificationProvider = new PushNotificationProvider(); if (pushNotificationConfig.getProperties() != null &&
pushNotificationProvider.setType(pushNotificationConfig.getType()); pushNotificationConfig.getProperties().size() > 0) {
//default schedule value will be true. ConfigProperties configProperties = new ConfigProperties();
pushNotificationProvider.setScheduled(true); List<Property> properties = new ArrayList<>();
if (pushNotificationConfig.getProperties() != null && for (Map.Entry<String, String> entry : pushNotificationConfig.getProperties().entrySet()) {
pushNotificationConfig.getProperties().size() > 0) { Property property = new Property();
ConfigProperties configProperties = new ConfigProperties(); property.setName(entry.getKey());
List<Property> properties = new ArrayList<>(); property.setValue(entry.getValue());
for (Map.Entry<String, String> entry : pushNotificationConfig.getProperties().entrySet()) { properties.add(property);
Property property = new Property();
property.setName(entry.getKey());
property.setValue(entry.getValue());
properties.add(property);
}
configProperties.addProperties(properties);
pushNotificationProvider.setConfigProperties(configProperties);
} }
pushNotificationProvider.setFileBasedProperties(true); configProperties.addProperties(properties);
pushNotificationProviderList.add(pushNotificationProvider); pushNotificationProvider.setConfigProperties(configProperties);
} }
pushNotificationProviders.addPushNotificationProviders(pushNotificationProviderList); pushNotificationProvider.setFileBasedProperties(true);
deviceTypeConfiguration.setPushNotificationProviders(pushNotificationProviders); deviceTypeConfiguration.setPushNotificationProvider(pushNotificationProvider);
} }
// This is commented until the task registration handling issue is solved // This is commented until the task registration handling issue is solved
// OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceTypeMetaDefinition.getTaskConfig(); // OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceTypeMetaDefinition.getTaskConfig();
// if (operationMonitoringTaskConfig != null) { // if (operationMonitoringTaskConfig != null) {

@ -41,7 +41,6 @@ import java.util.List;
* &lt;element name="Features" type="{}Features"/> * &lt;element name="Features" type="{}Features"/>
* &lt;element name="ProvisioningConfig" type="{}ProvisioningConfig"/> * &lt;element name="ProvisioningConfig" type="{}ProvisioningConfig"/>
* &lt;element name="PushNotificationProviderConfig" type="{}PushNotificationProviderConfig"/> * &lt;element name="PushNotificationProviderConfig" type="{}PushNotificationProviderConfig"/>
* &lt;element name="PullNotificationSubscriberConfig" type="{}PullNotificationSubscriberConfig"/>
* &lt;element name="License" type="{}License"/> * &lt;element name="License" type="{}License"/>
* &lt;element name="DataSource" type="{}DataSource"/> * &lt;element name="DataSource" type="{}DataSource"/>
* &lt;element name="PolicyMonitoring" type="{}PolicyMonitoring"/> * &lt;element name="PolicyMonitoring" type="{}PolicyMonitoring"/>
@ -66,8 +65,8 @@ public class DeviceTypeConfiguration {
protected Features features; protected Features features;
@XmlElement(name = "ProvisioningConfig", required = true) @XmlElement(name = "ProvisioningConfig", required = true)
protected ProvisioningConfig provisioningConfig; protected ProvisioningConfig provisioningConfig;
@XmlElement(name = "PushNotificationProviderConfigs", required = true) @XmlElement(name = "PushNotificationProviderConfig", required = true)
protected PushNotificationProviders pushNotificationProviders; protected PushNotificationProvider pushNotificationProvider;
@XmlElement(name = "PullNotificationSubscriberConfig", required = true) @XmlElement(name = "PullNotificationSubscriberConfig", required = true)
protected PullNotificationSubscriberConfig pullNotificationSubscriberConfig; protected PullNotificationSubscriberConfig pullNotificationSubscriberConfig;
@XmlElement(name = "License", required = true) @XmlElement(name = "License", required = true)
@ -246,23 +245,23 @@ public class DeviceTypeConfiguration {
} }
/** /**
* Gets the value of the pushNotificationProviders property. * Gets the value of the pushNotificationProvider property.
* *
* @return possible object is * @return possible object is
* {@link PushNotificationProvider } * {@link PushNotificationProvider }
*/ */
public PushNotificationProviders getPushNotificationProviders() { public PushNotificationProvider getPushNotificationProvider() {
return pushNotificationProviders; return pushNotificationProvider;
} }
/** /**
* Sets the value of the pushNotificationProviders property. * Sets the value of the pushNotificationProvider property.
* *
* @param value allowed object is * @param value allowed object is
* {@link PushNotificationProvider } * {@link PushNotificationProvider }
*/ */
public void setPushNotificationProviders(PushNotificationProviders value) { public void setPushNotificationProvider(PushNotificationProvider value) {
this.pushNotificationProviders = value; this.pushNotificationProvider = value;
} }
/** /**

@ -42,7 +42,6 @@ import java.util.List;
* &lt;element name="Operation" type="{}Operation"/> * &lt;element name="Operation" type="{}Operation"/>
* &lt;/sequence> * &lt;/sequence>
* &lt;attribute name="code" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="code" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="pushNotificationType" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction> * &lt;/restriction>
* &lt;/complexContent> * &lt;/complexContent>
* &lt;/complexType> * &lt;/complexType>
@ -69,8 +68,6 @@ public class Feature {
@XmlElementWrapper(name = "MetaData") @XmlElementWrapper(name = "MetaData")
@XmlElement(name = "Property", required = true) @XmlElement(name = "Property", required = true)
protected List<String> metaData; protected List<String> metaData;
@XmlAttribute(name = "pushNotificationType")
protected String pushNotificationType;
/** /**
* Gets the value of the name property. * Gets the value of the name property.
@ -175,28 +172,4 @@ public class Feature {
public void setMetaData(List<String> metaData) { public void setMetaData(List<String> metaData) {
this.metaData = metaData; this.metaData = metaData;
} }
/**
* Gets the value of the pushNotificationType property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getPushNotificationType() {
return pushNotificationType;
}
/**
* Sets the value of the pushNotificationType property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setPushNotificationType(String value) {
this.pushNotificationType = value;
}
} }

@ -39,8 +39,6 @@ import javax.xml.bind.annotation.XmlType;
* &lt;element name="ConfigProperties" type="{}ConfigProperties"/> * &lt;element name="ConfigProperties" type="{}ConfigProperties"/>
* &lt;/sequence> * &lt;/sequence>
* &lt;attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" /> * &lt;attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="isScheduled" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;attribute name="default" type="{http://www.w3.org/2001/XMLSchema}string" />
* &lt;/restriction> * &lt;/restriction>
* &lt;/complexContent> * &lt;/complexContent>
* &lt;/complexType> * &lt;/complexType>
@ -63,8 +61,6 @@ public class PushNotificationProvider {
protected String type; protected String type;
@XmlAttribute(name = "isScheduled") @XmlAttribute(name = "isScheduled")
protected boolean isScheduled; protected boolean isScheduled;
@XmlAttribute(name = "default")
protected boolean isDefault;
/** /**
* Gets the value of the fileBasedProperties property. * Gets the value of the fileBasedProperties property.
@ -156,30 +152,4 @@ public class PushNotificationProvider {
public void setScheduled(boolean scheduled) { public void setScheduled(boolean scheduled) {
isScheduled = scheduled; isScheduled = scheduled;
} }
/**
* Gets the value of the isDefault property.
* This property will be used to determine whether the given push notification will be used as Default for
* features which do not have push notification provider config
*
* @return
* possible object is
* {@link Boolean }
*
*/
public boolean isDefault() {
return isDefault;
}
/**
* Sets the value of the isDefault property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public void setDefault(boolean isDefault) {
isScheduled = isDefault;
}
} }

@ -1,74 +0,0 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.extensions.device.type.template.config;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import java.util.ArrayList;
import java.util.List;
/**
* <p>Java class for PushNotificationProviders complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="PushNotificationProviders">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="PushNotificationProvider" type="{}PushNotificationProvider"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PushNotificationProviders", propOrder = {
"pushNotificationProviders"
})
public class PushNotificationProviders {
@XmlElement(name = "PushNotificationProviderConfig")
protected List<PushNotificationProvider> pushNotificationProviders;
/**
* Gets the value of the pushNotificationProviders property.
*
* @return
* possible object is
* {@link PushNotificationProvider }
*
*/
public List<PushNotificationProvider> getPushNotificationProviders() {
if (pushNotificationProviders == null) {
pushNotificationProviders = new ArrayList<PushNotificationProvider>();
}
return this.pushNotificationProviders;
}
public void addPushNotificationProviders(List<PushNotificationProvider> pushNotificationProviders) {
this.pushNotificationProviders = pushNotificationProviders;
}
}

@ -50,7 +50,6 @@ public class ConfigurationBasedFeatureManager implements FeatureManager {
deviceFeature.setCode(feature.getCode()); deviceFeature.setCode(feature.getCode());
deviceFeature.setName(feature.getName()); deviceFeature.setName(feature.getName());
deviceFeature.setDescription(feature.getDescription()); deviceFeature.setDescription(feature.getDescription());
deviceFeature.setPushNotificationType(feature.getPushNotificationType());
Operation operation = feature.getOperation(); Operation operation = feature.getOperation();
List<Feature.MetadataEntry> metadataEntries = null; List<Feature.MetadataEntry> metadataEntries = null;
if (feature.getMetaData() != null) { if (feature.getMetaData() != null) {

Loading…
Cancel
Save