From 155135a70d54e68b96f85bad03d344be218292f5 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 26 Apr 2017 01:34:57 +0530 Subject: [PATCH] fixed few issues after testing analytics --- .../websocket/WebsocketEventAdapter.java | 39 ++++++++++++------- .../constants/WebsocketConstants.java | 3 ++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java index edf39993a..ed50d9f21 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java @@ -425,23 +425,36 @@ public class WebsocketEventAdapter implements OutputEventAdapter { // fetch the different attribute values received as part of the current event. Set queryParams = queryParamValuePairs.keySet(); for (String aQueryParam : queryParams) { - if (!aQueryParam.equalsIgnoreCase(WebsocketConstants.TOKEN_PARAM)) { - try { - String queryValue = queryParamValuePairs.get(aQueryParam); - if (queryValue != null && !queryValue.trim().isEmpty()) { - JSONObject jsonObject = new JSONObject(jsonMessage); - String eventValue = jsonObject.getString(aQueryParam); - if (eventValue == null || !eventValue.equalsIgnoreCase(queryValue)) { - return false; + try { + + String queryValue = queryParamValuePairs.get(aQueryParam); + if (queryValue != null && !queryValue.trim().isEmpty()) { + JSONObject jsonObject = new JSONObject(jsonMessage); + JSONObject event = jsonObject.getJSONObject(WebsocketConstants.EVENT); + JSONObject data; + if (!event.isNull(WebsocketConstants.META_DATA)) { + data = event.getJSONObject(WebsocketConstants.META_DATA); + if (!data.isNull(aQueryParam)) { + String eventValue = data.get(aQueryParam).toString(); + if (eventValue == null || !eventValue.equalsIgnoreCase(queryValue)) { + return false; + } } + } - } catch (JSONException e) { - if (log.isDebugEnabled()) { - log.debug("Unable validate the stream filter properties for event : " + jsonMessage - + " ", e); + + if (!event.isNull(WebsocketConstants.PAYLOAD_DATA)) { + data = event.getJSONObject(WebsocketConstants.PAYLOAD_DATA); + if (!data.isNull(aQueryParam)) { + String eventValue = data.get(aQueryParam).toString(); + if (eventValue == null || !eventValue.equalsIgnoreCase(queryValue)) { + return false; + } + } } - return false; } + } catch (JSONException e) { + //do nothing - This exception is thrown when the event does not have query parameter. } } } diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java index c5c3c01f2..743e51c21 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java @@ -34,4 +34,7 @@ public class WebsocketConstants { public static final String USERNAME = "username"; public static final String PASSWORD = "password"; public static final String TOKEN_PARAM = "token"; + public static final String META_DATA = "metaData"; + public static final String PAYLOAD_DATA = "payloadData"; + public static final String EVENT = "event"; }