From 3feb6c70dc82b9289dc0581a20141c44631a34ad Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 9 May 2017 00:54:34 +0530 Subject: [PATCH] created per tenant push notification for each transport type --- .../mqtt/MQTTNotificationStrategy.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java index 8af53af6b2..9a7850e1e5 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/mqtt/MQTTNotificationStrategy.java @@ -52,7 +52,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration(); adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE); mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME); - adapterConfig.setName(mqttAdapterName); + adapterConfig.setMessageFormat(MessageType.TEXT); Map configProperties = new HashMap(); @@ -60,16 +60,23 @@ public class MQTTNotificationStrategy implements NotificationStrategy { if (brokerUrl != null && !brokerUrl.isEmpty()) { configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL, brokerUrl); } - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES)); - configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS, - config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS)); + if (config.getProperties() != null) { + mqttAdapterName = config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_NAME); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_PASSWORD)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES)); + configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS, + config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS)); + } else { + mqttAdapterName = "mqtt.adapter." + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain() + .toLowerCase(); + } + adapterConfig.setName(mqttAdapterName); adapterConfig.setStaticProperties(configProperties); try { MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);