-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support multiple readers in the mapping-template component #21
Conversation
@@ -148,36 +144,46 @@ else if ((params.resourceCustomFunctions() == null) && (params.customFunctions ! | |||
formatter = Util.createFormatter(params.formatterFormat()); | |||
} | |||
|
|||
TemplateExecutor templateExecutor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move TemplateExecutor as a field of the class MaptTemplateProducer to reuse the same instance across multiple executions of the same route
camel-chimera-mapping-template/src/main/java/com/cefriel/rdf/MaptTemplateProcessor.java
Outdated
Show resolved
Hide resolved
camel-chimera-mapping-template/src/main/java/com/cefriel/rdf/MaptTemplateProcessor.java
Show resolved
Hide resolved
exchange.getMessage().setBody(resultFilePath, String.class); | ||
} | ||
} | ||
// if filename is not specified then the result of applying template is stored in the exchange body as string | ||
else { | ||
if (params.query() != null) { | ||
Map<String,String> result = templateExecutor.executeMappingParametric(reader, ResourceAccessor.open(params.template(), exchange), ResourceAccessor.open(params.query(), exchange), templateMap, formatter, usedTemplateFunctions); | ||
Map<String,String> result; | ||
if (reader != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in other invocations to the mapping-template
, avoid repeated code blocks. Change as:
Map<String, Reader> readers; //Check where defined and if we need to define it again
if (reader != null)
readers = Map.of("reader", reader);
result = templateExecutor.executeMappingParametric(readers,
ResourceAccessor.open(params.template(), exchange),
ResourceAccessor.open(params.query(), exchange));
exchange.getMessage().setBody(result, Map.class); | ||
|
||
} else { | ||
String result = templateExecutor.executeMapping(reader, ResourceAccessor.open(params.template(), exchange), templateMap, formatter, usedTemplateFunctions); | ||
String result; | ||
if (reader != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, define readers
map at the beginning and then perform calls without checking reader
every time
Adds an endpoint to the mapping template component "mapt://readers?..." that expects as input an exchange whose body contains a
Map<String,Reader>
ofReaders
.If accepted, it should be merged only after cefriel/mapping-template#27.