Skip to content

Commit

Permalink
Add support for input data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Dec 19, 2024
1 parent 0745ca7 commit 7f97ac1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/functions/addUsersToAudience.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<parameter name="customAudienceId" description="The ID of the custom audience."/>
<!-- Request Body Parameter List -->
<parameter name="properties" description="Custom audience users properties."/>
<parameter name="inputStructure" description="The structure of the input data."/>
<sequence>
<class name="org.wso2.carbon.facebook.ads.connector.FacebookDataClassMediator"/>

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/functions/removeUsersFromAudience.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<parameter name="customAudienceId" description="The ID of the custom audience."/>
<!-- Request Body Parameter List -->
<parameter name="properties" description="Custom audience users properties."/>
<parameter name="inputStructure" description="The structure of the input data."/>
<sequence>
<class name="org.wso2.carbon.facebook.ads.connector.FacebookDataClassMediator"/>

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/uischema/addUsersToAudience.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Structure of the user data to be added."
}
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/uischema/removeUsersFromAudience.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Structure of the user data to be removed."
}
}
]
}
Expand Down

0 comments on commit 7f97ac1

Please sign in to comment.