From 9995f4293eaa912f525277c982a66a8f5d218d5d Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 5 Jan 2017 12:24:04 +0530 Subject: [PATCH] Default values set for push notification dynamic configuration --- .../mqtt/MQTTNotificationStrategy.java | 2 +- .../pom.xml | 3 ++- .../xmpp/XMPPNotificationStrategy.java | 18 +++++++++++++++--- .../internal/util/XMPPAdapterConstants.java | 1 + 4 files changed, 19 insertions(+), 5 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 4229bc5337..1f707aafa5 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 @@ -85,7 +85,7 @@ public class MQTTNotificationStrategy implements NotificationStrategy { } else { String topic = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true) + "/" + ctx.getDeviceId().getType() + "/" + ctx.getDeviceId().getId() + "/" + operation.getType() - + "/" + operation.getCode(); + .toString().toLowerCase() + "/" + operation.getCode(); dynamicProperties.put("topic", topic); if (operation.getPayLoad() == null) { operation.setPayLoad(""); diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 4d283f80b7..5844654123 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -143,7 +143,8 @@ org.wso2.carbon.event.output.adapter.core, org.wso2.carbon.event.output.adapter.core.exception, org.osgi.framework, - org.wso2.carbon.core + org.wso2.carbon.core, + org.wso2.carbon.device.mgt.common.* diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java index 0e82bec7ce..0d7229a193 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/XMPPNotificationStrategy.java @@ -39,8 +39,13 @@ public class XMPPNotificationStrategy implements NotificationStrategy { private static final String XMPP_CLIENT_JID = "xmpp.client.jid"; private static final String XMPP_CLIENT_SUBJECT = "xmpp.client.subject"; public static final String XMPP_CLIENT_MESSAGE_TYPE = "xmpp.client.messageType"; + private static final String DYNAMIC_PROPERTY_JID = "jid"; + private static final String DYNAMIC_PROPERTY_SUBJECT = "subject"; + private static final String DYNAMIC_PROPERTY_MSGTYPE = "messageType"; private String xmppAdapterName; private static final Log log = LogFactory.getLog(XMPPNotificationStrategy.class); + private String subDomain; + public XMPPNotificationStrategy(PushNotificationConfig config) { @@ -61,6 +66,7 @@ public class XMPPNotificationStrategy implements NotificationStrategy { xmppAdapterProperties.put(XMPPAdapterConstants.XMPP_ADAPTER_PROPERTY_JID, config.getProperty( XMPPAdapterConstants.XMPP_ADAPTER_PROPERTY_JID)); outputEventAdapterConfiguration.setStaticProperties(xmppAdapterProperties); + subDomain = config.getProperty(XMPPAdapterConstants.XMPP_ADAPTER_PROPERTY_SUBDOMAIN); try { XMPPDataHolder.getInstance().getOutputEventAdapterService().create(outputEventAdapterConfiguration); } catch (OutputEventAdapterException e) { @@ -77,9 +83,15 @@ public class XMPPNotificationStrategy implements NotificationStrategy { public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException { Map dynamicProperties = new HashMap<>(); Properties properties = ctx.getOperation().getProperties(); - dynamicProperties.put("jid", properties.getProperty(XMPP_CLIENT_JID)); - dynamicProperties.put("subject", properties.getProperty(XMPP_CLIENT_SUBJECT)); - dynamicProperties.put("messageType", properties.getProperty(XMPP_CLIENT_MESSAGE_TYPE)); + if (properties != null & properties.size() > 0) { + dynamicProperties.put(DYNAMIC_PROPERTY_JID, properties.getProperty(XMPP_CLIENT_JID)); + dynamicProperties.put(DYNAMIC_PROPERTY_SUBJECT, properties.getProperty(XMPP_CLIENT_SUBJECT)); + dynamicProperties.put(DYNAMIC_PROPERTY_MSGTYPE, properties.getProperty(XMPP_CLIENT_MESSAGE_TYPE)); + } else { + dynamicProperties.put(DYNAMIC_PROPERTY_JID, ctx.getDeviceId().getId() + subDomain); + dynamicProperties.put(DYNAMIC_PROPERTY_SUBJECT, ctx.getOperation().getType().toString()); + dynamicProperties.put(DYNAMIC_PROPERTY_MSGTYPE, XMPPAdapterConstants.CHAT_PROPERTY_KEY); + } XMPPDataHolder.getInstance().getOutputEventAdapterService().publish(xmppAdapterName, dynamicProperties, ctx.getOperation().getPayLoad()); } diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/util/XMPPAdapterConstants.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/util/XMPPAdapterConstants.java index db08e7ae8b..8c4cf7740b 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/util/XMPPAdapterConstants.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/xmpp/internal/util/XMPPAdapterConstants.java @@ -30,6 +30,7 @@ public final class XMPPAdapterConstants { public static final String SUBJECT_PROPERTY_KEY = "subject"; public static final String MESSAGE_TYPE_PROPERTY_KEY = "messageType"; public static final String CHAT_PROPERTY_KEY = "chat"; + public static final String XMPP_ADAPTER_PROPERTY_SUBDOMAIN = "subDomain"; public static final String XMPP_ADAPTER_PROPERTY_HOST = "host"; public static final String XMPP_ADAPTER_PROPERTY_PORT = "port"; public static final String XMPP_ADAPTER_PROPERTY_USERNAME = "username";