Customizations
-
The processors can be customized to suit the needs of the destination.
-
The customizations can include
-
Customize a use case processor
-
Change in payload structure.
-
Combining / chaining two or more processors.
-
Customizing a use case processor
All the OOTB processors for use cases are based on the common base processor AsyncBaseProcessor OR SynchronousBaseProcessor.
SynchronousBaseProcessor is responsible to execute multiple processors in given sequence.
Any processor can extend the base processor AsyncBaseProcessor OR SynchronousBaseProcessor and provide a custom implementation of the methods mentioned in the below table.
Customization |
Method(s) |
Description |
1. Description of the job |
constructor() |
Information about the job. |
2. Authentication |
authenticate() |
Authentication to be used for connecting to the destination. |
3. Token |
fetchToken() |
Token to be used for connecting to the destination. |
4. Create Payload |
createPayload(props) |
The payload to be send to the destination. The props argument can be a map with key, value pairs. |
5. Destination |
fetchDestination() |
Details of the destination. |
6. Send Payload |
sendPayload() |
Send the payload to the destination. |
7. On Success |
onSuccess() |
Operations to be carried out on the success of a job. |
8. On Failure |
onFailure() |
Operations to be carried out on the failure of a job. |
| If the processor does not extend the base processor AsyncBaseProcessor OR SynchronousBaseProcessor , then the processor is responsible to carry out all the operations mentioned in the above table, in the order they are needed. |
Customizing BaseProcessor
-
The logic of data generation, connection and delivery of payload to the destination lies in the processor.
-
Below is the example of the structure of a customized processor.
//@include:technia/d365/processor/CustomProcessor
const configurationProperties = {
"config1": "ABC",
"config2": "000001234"
};
new CustomProcessor().execute(configurationProperties);
//@include:technia/common/processor/BaseProcessor
class CustomProcessor extends BaseProcessor {
constructor() {
super();
}
fetchToken() {
// Create the destination handler to fetch the token if required.
}
generatePayload(configurationProperties) {
// Implement how to fetch the required details from ObjectId and generate the destination supported payload.
}
createPayload(configProps) {
// Call generate payload and set the payload with destination handler.
}
fetchDestination() {
// Implement and fetch destinaiton details from environment variable or configuration properties.
}
sendPayload() {
// Call send method of destination handler.
}
onSuccess() {
// Process the response if the operation is success.
}
onFailure() {
// Process the response if the operation is failure.
}
}
Customizing Payload
-
The logic of data generation lies in the generatePayload() method of the processor.
-
generatePayload() method can either be rewritten or can be called for base structure of the payload.
-
Below is the example of modifying the value of a specific key in the payload.
-
//@include:technia/d365/processor/CustomProcessor
const configurationProperties = {
"config1": "ABC",
"config2": "000001234"
};
new CustomProcessor().execute(configurationProperties);
//@include:technia/common/processor/ExistingProcessor
class CustomProcessor extends ExistingProcessor {
createPayload(configProps) {
const payload = this.generatePayload(configProps);
payload.ReasonForChangeText = "New Batch - 2023"; // Change a particular value of payload
const payloadAsString = JSON.stringify(payload);
context.result().data(payloadAsString, 'application/json', 'payload.json');
}
}