Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce communication data converter #3712

Closed
Tracked by #3707
de-jcup opened this issue Dec 6, 2024 · 0 comments · Fixed by #3895
Closed
Tracked by #3707

Introduce communication data converter #3712

de-jcup opened this issue Dec 6, 2024 · 0 comments · Fixed by #3895

Comments

@de-jcup
Copy link
Member

de-jcup commented Dec 6, 2024

Situation

When we want to communicate with external endpoints (for example: calling a REST service of an AI endpoint) we want to have this configurable.

Wanted

An easy way to define the way to communicate with an external service in a customizable way.

Solution

We differ here between send and receive and provide a communication data converter which can be configured.

Out of scope

Here we only provide simple key mapping without substructure creation.
Means we do currently not handle complex keys with parent child structures

As an example:

{
    "result" : {
        "status" : "OK",
        "message" : "some message inside child structure"
    }
}

which could be provided by a key like "result.status" is currently not supported.

If it becomes necessary we will address this in another issue.

Converter config syntax

{
    "send" : {
        "targetType" : "$type",
        "mapping" : {
         "$sourceKey" : "$destinationKey"
        }
    },

    "receive" : {
        "sourceType" : "$type",
        "mapping" : {
         "$sourceKey" : "$destinationKey"
        }
    } 
   
}

Example

{
    "send" : {
        "targetType" : "JSON",
        "mapping" : {
          "cweId" : "cwe_id",
          "language" : "lang",
          "details" : "cwe_details"
        }
    },

    "receive" : {
        "sourceType" : "JSON",
        "mapping" : {
          "error" : "result_problem",
          "status" : "result_status",
          "description" : "content"
        }
    } 
}

Usage

CommunicationDataConverter converter = new CommunicationDataConverter(config);

val requestData = new HashMap<String,String>();
requestData.put("cweId", "79");
requestData.put("language", "java");
requestData.put("details", "some technical details about the cwe problem");

String jsonToSend = converter.convertForSending(data);

String jsonReceived = serviceXyz.fetchLoadByJsonContent(jsonToSend);

Map<String, String> resultMappingData= converter.convertFromReceived(jsonReceived);
String content = resultMappingData.get("content");
String status = resultMappingData.get("result_status")
@de-jcup de-jcup changed the title Introduce communication templates (read+write) Introduce communication templates Dec 6, 2024
@de-jcup de-jcup changed the title Introduce communication templates Introduce communication data converter Feb 18, 2025
de-jcup added a commit that referenced this issue Feb 19, 2025
…mmunication-data-converter

Introduce communcation data converter #3712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant