From b4cc964574b12f53eaffc8e9dc6c5a7e86d369e5 Mon Sep 17 00:00:00 2001 From: aashikam Date: Thu, 19 Dec 2024 21:22:52 +0530 Subject: [PATCH] Add support for input data structure --- .../ads/connector/FacebookDataClassMediator.java | 13 +++++++++++++ .../connector/FilterAudiencesByNameMediator.java | 3 ++- src/main/resources/functions/addUsersToAudience.xml | 1 + .../resources/functions/removeUsersFromAudience.xml | 1 + src/main/resources/uischema/addUsersToAudience.json | 12 ++++++++++++ .../resources/uischema/removeUsersFromAudience.json | 12 ++++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/wso2/carbon/facebook/ads/connector/FacebookDataClassMediator.java b/src/main/java/org/wso2/carbon/facebook/ads/connector/FacebookDataClassMediator.java index d04f8c4..5d4c38c 100644 --- a/src/main/java/org/wso2/carbon/facebook/ads/connector/FacebookDataClassMediator.java +++ b/src/main/java/org/wso2/carbon/facebook/ads/connector/FacebookDataClassMediator.java @@ -26,10 +26,23 @@ public class FacebookDataClassMediator extends AbstractMediator { public static final String PROPERTIES = "properties"; + public static final String INPUT_STRUCTURE = "inputStructure"; + public static final String FACEBOOK_API_COMPATIBLE = "FACEBOOK_API_COMPATIBLE"; @Override public boolean mediate(MessageContext synCtx) { + String inputStructure = (String) ConnectorUtils.lookupTemplateParamater(synCtx, INPUT_STRUCTURE); String jsonString = (String) ConnectorUtils.lookupTemplateParamater(synCtx, PROPERTIES); + + // set the payload as it is for FACEBOOK_API_COMPATIBLE input structure + // executes if the inputStructure is not given or is empty too + if (FACEBOOK_API_COMPATIBLE.equals(inputStructure) + || inputStructure == null + || inputStructure.trim().isEmpty()) { + synCtx.setProperty(Constants.HASHED_PAYLOAD, jsonString); + return true; + } + if (jsonString == null || jsonString.isEmpty()) { return true; } diff --git a/src/main/java/org/wso2/carbon/facebook/ads/connector/FilterAudiencesByNameMediator.java b/src/main/java/org/wso2/carbon/facebook/ads/connector/FilterAudiencesByNameMediator.java index 2682532..fca67c8 100644 --- a/src/main/java/org/wso2/carbon/facebook/ads/connector/FilterAudiencesByNameMediator.java +++ b/src/main/java/org/wso2/carbon/facebook/ads/connector/FilterAudiencesByNameMediator.java @@ -36,6 +36,7 @@ public class FilterAudiencesByNameMediator extends AbstractMediator { public static final String FILTER_BY_NAME = "filterByName"; public static final String DATA = "data"; public static final String PAGING = "paging"; + public static final String NAME = "name"; @Override public boolean mediate(MessageContext synCtx) { @@ -61,7 +62,7 @@ public boolean mediate(MessageContext synCtx) { for (JsonElement element : dataArray) { if (element.isJsonObject()) { JsonObject dataObj = element.getAsJsonObject(); - JsonElement nameElement = dataObj.get("name"); + JsonElement nameElement = dataObj.get(NAME); if (nameElement != null && nameElement.isJsonPrimitive()) { String name = nameElement.getAsString(); if (name.contains(filterByName)) { diff --git a/src/main/resources/functions/addUsersToAudience.xml b/src/main/resources/functions/addUsersToAudience.xml index cfe34ef..b8491e4 100644 --- a/src/main/resources/functions/addUsersToAudience.xml +++ b/src/main/resources/functions/addUsersToAudience.xml @@ -23,6 +23,7 @@ + diff --git a/src/main/resources/functions/removeUsersFromAudience.xml b/src/main/resources/functions/removeUsersFromAudience.xml index 24e1126..ea4403e 100644 --- a/src/main/resources/functions/removeUsersFromAudience.xml +++ b/src/main/resources/functions/removeUsersFromAudience.xml @@ -23,6 +23,7 @@ + diff --git a/src/main/resources/uischema/addUsersToAudience.json b/src/main/resources/uischema/addUsersToAudience.json index 3190dd6..3019cd5 100644 --- a/src/main/resources/uischema/addUsersToAudience.json +++ b/src/main/resources/uischema/addUsersToAudience.json @@ -50,6 +50,18 @@ "required": "true", "helpTip": "Custom audience users properties." } + }, + { + "type": "attribute", + "value": { + "name": "inputStructure", + "displayName": "Input Data Structure", + "inputType": "comboOrExpression", + "comboValues": ["FACEBOOK_API_COMPATIBLE", "JSON_ARRAY"], + "defaultValue": "JSON_ARRAY", + "required": "false", + "helpTip": "Custom audience users properties." + } } ] } diff --git a/src/main/resources/uischema/removeUsersFromAudience.json b/src/main/resources/uischema/removeUsersFromAudience.json index 185967d..a63ff1d 100644 --- a/src/main/resources/uischema/removeUsersFromAudience.json +++ b/src/main/resources/uischema/removeUsersFromAudience.json @@ -50,6 +50,18 @@ "required": "true", "helpTip": "Custom audience users update properties." } + }, + { + "type": "attribute", + "value": { + "name": "inputStructure", + "displayName": "Input Data Structure", + "inputType": "comboOrExpression", + "comboValues": ["FACEBOOK_API_COMPATIBLE", "JSON_ARRAY"], + "defaultValue": "FACEBOOK_API_COMPATIBLE", + "required": "false", + "helpTip": "Custom audience users properties." + } } ] }