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 templates #3712

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

Introduce communication templates #3712

de-jcup opened this issue Dec 6, 2024 · 0 comments

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 READ and WRITE templates.

Template 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.level",
          "description" : "content"
        }
    } 
}

Usage

CommunicationTemplate template = templateFactory.createFromFile("communicate-ai.json");

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

String jsonToSend = template.processSend(data);

//  ...
// REST done, result returned as "resultText"
// ...

Map<String, String> resultMappingData= template.processReceive(resultText);
String content = resultMappingData.get("content");
@de-jcup de-jcup changed the title Introduce communication templates (read+write) Introduce communication templates Dec 6, 2024
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

No branches or pull requests

1 participant