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

Support multiple readers in the mapping-template component #21

Merged
merged 8 commits into from
Dec 3, 2024

Conversation

AuPath
Copy link
Collaborator

@AuPath AuPath commented Jul 23, 2024

Adds an endpoint to the mapping template component "mapt://readers?..." that expects as input an exchange whose body contains a Map<String,Reader> of Readers.

If accepted, it should be merged only after cefriel/mapping-template#27.

@AuPath AuPath requested a review from marioscrock July 23, 2024 14:39
@AuPath AuPath self-assigned this Jul 23, 2024
@@ -148,36 +144,46 @@ else if ((params.resourceCustomFunctions() == null) && (params.customFunctions !
formatter = Util.createFormatter(params.formatterFormat());
}

TemplateExecutor templateExecutor;
Copy link
Member

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

@AuPath AuPath requested a review from marioscrock July 30, 2024 13:47
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) {
Copy link
Member

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) {
Copy link
Member

@marioscrock marioscrock Oct 1, 2024

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

@AuPath AuPath requested a review from marioscrock November 12, 2024 14:31
@AuPath AuPath merged commit 2a14db2 into master Dec 3, 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

Successfully merging this pull request may close these issues.

3 participants