68.2 How to pass raw data to custom class for processing with custom code?
Learning Objective:- This unit describes:-
- How to pass raw data to a custom class (message creation) for processing?
1. How to pass raw data to a custom class (Message Creation) for processing?
Our Skyvva Tool supports XML, CSV, and JSON file formats by default. However, if you have complex XML, JSON, or other raw data structures that our tool cannot read in your payload, you will need to use a custom class to build your logic and read your raw data structure to create the SKYVVA Message yourself.
Here is a sample payload in a data format that our standard cannot read:
status: success code: '200' message: completed data:
- Id: ba228042-793a-4289-b0cb-57a661c11ff5
- Id: f062cfad-a38c-4a4c-b8b0-788a8ae5910e
- Id: 250c739a-4ab8-4ba8-997b-a184bec568d7
- Id: 91282b68-0894-4439-bb56-c27df3cf8cf1
- Id: e03fxb30-c925-4c63-9e6c-e2b974c3fe39
- Id: e03fcc30-c925-4c63-9e3c-e2b974c3fe38
- Id: 30e65a2e-2a0e-4a53-893e-01d30b725204
- Id: 5a948bfb-7441-4d63-9d47-a38ab611d2fa
- Id: 93e3b363-0e08-425d-b659-7122ef3c9e34
2. The procedure to pass raw data to a custom class (Message Creation) for processing with custom code:-
The procedure is given below with an example:-
2.1. Create MetaData, Repository and Message Type:-
2.2. Create Integration:-
2.3. Create custom class :
- The custom code is given below to pass raw data (create the message):-
List
Map
public override IServicesUtil.IMessageResult createMessage(AbstractIntegrationV3.DtoRequestBody dtoRequestBody,
AbstractIntegrationV3.DtoStructure dtoStr){
AbstractIntegrationV3.DtoInterface dtoIntfStructure = getInterfaceStructure();
// custom transaction
if(String.isBlank(dtoRequestBody.transactionId))dtoRequestBody.transactionId='YAML-Data-'+System.now().getTime();
// parse yaml payload to map// here using your own logic
Map
System.debug('>>dataAsMap: '+dataAsMap);
// i know exactly my data contain data node as array //{"NodeX":[{},{}]} List
// create mesage from root createMsg((Map
// overide create message logic public override IMessage__c invokeNewMessage( String rootId, String parentId, String transId, Boolean hasChild, Integer lv, String hPath, Boolean isRoot, Interfaces__c mInft, Map
// just using skyvva default message setting IMessage__c msg=super.invokeNewMessage(rootId,parentId,transId,hasChild,lv,hPath,isRoot,mInft,idata); msg.Name='IM#YAML-Data-'+System.now().getTime()+'---'+indexMsg; return msg; }
// hierarchy message creation void createMsg(Map
// ignore array or object, ingore childen datas if(valueX instanceof List
// System.debug('>>createMsg>idata: '+JSON.serializePretty(idata));
// get parent message if current creation is child IMessage__c parentMsg=mapParentIntfMsg.get(dtoIntfStructure.parentIntfId);
// current message, invoke create message setting IMessage__c msg = invokeNewMessage(rootMsg?.External_Id2__c,parentMsg?.External_Id2__c,transactionId,false,level,null,isRoot,super.mIntf.get(dtoIntfStructure.intfId),idata);
// save parent interface to message mapParentIntfMsg.put(dtoIntfStructure.intfId,msg);
// if current is root levelt then set it to children if(isRoot)rootMsg=msg; else {
// mark parent and grand parent as has child rootMsg.HasChild__c=true; parentMsg.HasChild__c=true; }
// create children message for(AbstractIntegrationV3.DtoInterface tmp : dtoIntfStructure.child){
// System.debug('>>createMsg>tmp.sourceObject: '+tmp.sourceObject); Object obj = objectX.get(tmp.sourceObject); if(obj==null){ // ingore case for (String field : objectX.keySet()) {
// find child node if(tmp.sourceObject.equalsIgnoreCase(field)){ obj = objectX.get(field); } } }
// System.debug('>>createMsg>obj: '+obj); // child message if(obj instanceof Map
// child message array else if(obj instanceof List
// logic parsing raw data --------------satrt
Map
void readByLine(String line,Map
// read children Integer nextLvl=indexOfNextLevel; while(!lines.isEmpty() && getIndexOfElement(lines.get(0))==nextLvl){ if(isElement(lines.get(0))){ child=new Map
- Copy and paste this code into the custom class. This example code will enable the reading of the data structure.
2.4. Create Interface:
- In the Runtime Configuration Section of the Interface page we need to select two things which are shown in the picture given below:-
- To enable custom processing, check the 'Custom Processing' option. Once you have checked this option, you will be able to use a custom class for this interface. A custom Apex class is required to handle the specific processing for this interface.
- You also need to enter the custom processing class that you have created with the logic mentioned above.
- In the Custom Processing section, you need to select the block that you want to custom
- Select 'Message Creation' on "Custom Block to replace the SKYVVA Block". This is the block that you need to customize.
2.5. Do Mapping:
2.6. Call via V4/integrate
- After calling V4/integrate, it will read raw data and create the message.