Skip to content

Enhance template evaluators#4

Open
ashu82492 wants to merge 1 commit intoappform-io:masterfrom
ashu82492:template-engine-enhancements
Open

Enhance template evaluators#4
ashu82492 wants to merge 1 commit intoappform-io:masterfrom
ashu82492:template-engine-enhancements

Conversation

@ashu82492
Copy link

This pull request introduces enhancements to the template engine system to support additional template evaluation capabilities and improve type handling.

Changes

Bug fix and features

  • Handlebars Object Template Evaluator: Added HandlebarsObjectTemplateEvaluator to support Handlebars template evaluation to return object type. The existing evaluator returned String and subjectId template expected an object (bug).
  • Custom Helper for JSON Value Extraction: Implemented valueFromJson() helper method in CustomHelpers to extract string values from JSON objects. The existing valueFromJsonString method expects String input rather than JsonNode.

Improvements

  • Type Handling: Updated StringSubstitutionTextTemplateEvaluator to use Map<String, Object> instead of Map<String, String> to support nested json payload. The existing implementation was breaking with nested payloads.
  • Workflow Management: Updated subject templates to use handlebars instead of string-replacement.

Test Coverage

  • added tests for the changes.

template(titleTemplate),
template(descriptionTemplate),
template(subjectTemplate))
templateHandlebars(subjectTemplate))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not hardcode to Handlebarstemplate for subject, e should take this as input from the UI and ensure that the default value can be STRING_SUBSTITUTION itself for backward compatibility.

public Optional<String> evaluate(Template template, JsonNode payload) {
return Optional.of(StringSubstitutor.replace(
template.getTemplate(), mapper.convertValue(payload, new TypeReference<Map<String, String>>() {})));
template.getTemplate(), mapper.convertValue(payload, new TypeReference<Map<String, Object>>() {})));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un-related changes, handle it in separate issue & PR

return mapper.readValue(s, clazz);
} catch (Exception e) {
throw new RuntimeException("Failed to parse substituted string to object", e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be conductor exception

""");
String result = evaluator.evaluate(template, payload).orElse(null);
assert result != null;
assert result.equals("Hello Alice, your age is 30, you live in ${place.name}");
Copy link
Contributor

@tusharmndr tusharmndr Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected i.e ${place.name} not replaced ?

public String valueFromJson(Object context, Options options) {
val node = MAPPER.valueToTree(context);
val pointer = (String) options.hash(POINTER);
if (!Strings.isNullOrEmpty(pointer) ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null check on node missing, similar to other methods in the helper
Suggestion:

if (!Strings.isNullOrEmpty(pointer) && null != node && !node.isNull() && !node.isMissingNode()) {

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