From c2a8159f3d15ba509644d41648dc032985602007 Mon Sep 17 00:00:00 2001 From: Matheusafonsouza Date: Tue, 17 Jan 2023 16:17:32 -0300 Subject: [PATCH] fix: salesforce update kamelet fix --- kamelets/salesforce-update-sink.kamelet.yaml | 41 ++++++++++--------- .../salesforce-update-sink.kamelet.yaml | 41 ++++++++++--------- .../direct-to-salesforce-update-binding.yaml | 8 ++-- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/kamelets/salesforce-update-sink.kamelet.yaml b/kamelets/salesforce-update-sink.kamelet.yaml index d87504d83..defa61a65 100644 --- a/kamelets/salesforce-update-sink.kamelet.yaml +++ b/kamelets/salesforce-update-sink.kamelet.yaml @@ -32,28 +32,21 @@ spec: description: |- Update an object in Salesforce. - The body received must contain a JSON key-value pair for each property to update, for example: `{ "Phone": "1234567890", "Name": "Antonia" }` + The body received must contain a JSON key-value pair for each property to update inside the payload attribute, for example: - The body received must include the `sObjectName` and `sObjectId` properties. + `{ "payload": { "Phone": "1234567890", "Name": "Antonia" } }` + + The body received must include the `sObjectName` and `sObjectId` properties, for example: + + `{ "payload": { "Phone": "1234567890", "Name": "Antonia" }, "sObjectId": "sObjectId", "sObjectName": "sObjectName" }` required: - - sObjectName - - sObjectId - clientId - clientSecret - userName - password type: object properties: - sObjectName: - title: Object Name - description: The type of the Salesforce object. Required if using a key-value pair. - type: string - example: Contact - sObjectId: - title: Object Id - description: The ID of the Salesforce object. Required if using a key-value pair. - type: string loginUrl: title: Login URL description: The Salesforce instance login URL. @@ -91,6 +84,9 @@ spec: in: mediaType: application/json dependencies: + - "camel:core" + - "camel:jsonpath" + - "camel:jackson" - "camel:salesforce" - "camel:kamelet" template: @@ -103,12 +99,17 @@ spec: userName: "{{userName}}" password: "{{password}}" loginUrl: "{{loginUrl}}" - from: + from: uri: kamelet:source steps: - - to: - uri: "{{local-salesforce}}:updateSObject" - parameters: - sObjectId: "{{sObjectId}}" - sObjectName: "{{sObjectName}}" - rawPayload: "true" + - set-property: + name: sObjectId + jsonpath: "$['sObjectId']" + - set-property: + name: sObjectName + jsonpath: "$['sObjectName']" + - transform: + jsonpath: "$['payload']" + - marshal: + json: {} + - toD: "{{local-salesforce}}:updateSObject?sObjectId=${exchangeProperty.sObjectId}&sObjectName=${exchangeProperty.sObjectName}&rawPayload=true" diff --git a/library/camel-kamelets/src/main/resources/kamelets/salesforce-update-sink.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/salesforce-update-sink.kamelet.yaml index d87504d83..defa61a65 100644 --- a/library/camel-kamelets/src/main/resources/kamelets/salesforce-update-sink.kamelet.yaml +++ b/library/camel-kamelets/src/main/resources/kamelets/salesforce-update-sink.kamelet.yaml @@ -32,28 +32,21 @@ spec: description: |- Update an object in Salesforce. - The body received must contain a JSON key-value pair for each property to update, for example: `{ "Phone": "1234567890", "Name": "Antonia" }` + The body received must contain a JSON key-value pair for each property to update inside the payload attribute, for example: - The body received must include the `sObjectName` and `sObjectId` properties. + `{ "payload": { "Phone": "1234567890", "Name": "Antonia" } }` + + The body received must include the `sObjectName` and `sObjectId` properties, for example: + + `{ "payload": { "Phone": "1234567890", "Name": "Antonia" }, "sObjectId": "sObjectId", "sObjectName": "sObjectName" }` required: - - sObjectName - - sObjectId - clientId - clientSecret - userName - password type: object properties: - sObjectName: - title: Object Name - description: The type of the Salesforce object. Required if using a key-value pair. - type: string - example: Contact - sObjectId: - title: Object Id - description: The ID of the Salesforce object. Required if using a key-value pair. - type: string loginUrl: title: Login URL description: The Salesforce instance login URL. @@ -91,6 +84,9 @@ spec: in: mediaType: application/json dependencies: + - "camel:core" + - "camel:jsonpath" + - "camel:jackson" - "camel:salesforce" - "camel:kamelet" template: @@ -103,12 +99,17 @@ spec: userName: "{{userName}}" password: "{{password}}" loginUrl: "{{loginUrl}}" - from: + from: uri: kamelet:source steps: - - to: - uri: "{{local-salesforce}}:updateSObject" - parameters: - sObjectId: "{{sObjectId}}" - sObjectName: "{{sObjectName}}" - rawPayload: "true" + - set-property: + name: sObjectId + jsonpath: "$['sObjectId']" + - set-property: + name: sObjectName + jsonpath: "$['sObjectName']" + - transform: + jsonpath: "$['payload']" + - marshal: + json: {} + - toD: "{{local-salesforce}}:updateSObject?sObjectId=${exchangeProperty.sObjectId}&sObjectName=${exchangeProperty.sObjectName}&rawPayload=true" diff --git a/test/salesforce-sink/direct-to-salesforce-update-binding.yaml b/test/salesforce-sink/direct-to-salesforce-update-binding.yaml index f0fdbaa7c..102793fb9 100644 --- a/test/salesforce-sink/direct-to-salesforce-update-binding.yaml +++ b/test/salesforce-sink/direct-to-salesforce-update-binding.yaml @@ -29,7 +29,11 @@ spec: period: 60000 message: |- { - "Phone": "1234567890" + "payload": { + "Phone": "1234567890" + }, + "sObjectId": "Contact", + "sObjectName": "Contact" } sink: ref: @@ -41,5 +45,3 @@ spec: clientSecret: "${client_secret}" userName: "${userName}" password: "${password}" - sObjectId: "${id}" - sObjectName: "Contact"