@Override public SearchResponse apply(SearchResponse searchResponse) { final List<ResultMessageSummary> summaries = searchResponse.messages().stream() .map(summary -> { if (requireAllFields && !usedVariables.stream().allMatch(variable -> summary.message().containsKey(variable.name))) { return summary; } final String formattedString = template.transform(summary.message(), Locale.ENGLISH); if (formattedString == null) { return summary; } final Message message = new Message(ImmutableMap.copyOf(summary.message())); message.addField(targetField, formattedString); return summary.toBuilder().message(message.getFields()).build(); }) .collect(Collectors.toList()); return searchResponse.toBuilder().messages(summaries).build(); } }
@Inject public FormatStringDecorator(@Assisted Decorator decorator, Engine templateEngine) { final String formatString = (String) requireNonNull(decorator.config().get(CK_FORMAT_STRING), CK_FORMAT_STRING + " cannot be null"); this.targetField = (String) requireNonNull(decorator.config().get(CK_TARGET_FIELD), CK_TARGET_FIELD + " cannot be null"); requireAllFields = (boolean) requireNonNull(decorator.config().get(CK_REQUIRE_ALL_FIELDS), CK_REQUIRE_ALL_FIELDS + " cannot be null"); template = requireNonNull(templateEngine, "templateEngine").getTemplate(formatString); usedVariables = template.getUsedVariableDescriptions(); }
/** * Gets all variables used in the given template. */ public synchronized Set<String> getUsedVariables(String template) { Template templateImpl = getTemplate(template, null); return templateImpl.getUsedVariables(); }
public synchronized List<ErrorEntry> getStaticErrors(String template) { Template templateImpl = getTemplate(template, null); return templateImpl.getStaticErrors(); }
/** * Gets all variables used in the given template. * * @deprecated use {@link #getUsedVariableDescriptions(String)} instead */ @Deprecated() public synchronized Set<String> getUsedVariables(String template) { Template templateImpl = getTemplate(template, null); return templateImpl.getUsedVariables(); }
String transformInternal(String template, Locale locale, String sourceName, Map<String, Object> model, ModelAdaptor modelAdaptor, ProcessListener processListener) { Template templateImpl = getTemplate(template, sourceName); String output = templateImpl.transform(model, locale, modelAdaptor, processListener); return output; }
/** * Gets all variables used in the given template as a detailed description. * */ public synchronized List<VariableDescription> getUsedVariableDescriptions(String template) { Template templateImpl = getTemplate(template, null); return templateImpl.getUsedVariableDescriptions(); }
String transformInternal(String template, Locale locale, String sourceName, Map<String, Object> model, ModelAdaptor modelAdaptor, ProcessListener processListener) { if (template == null) { return null; } Template templateImpl = getTemplate(template, sourceName); String output = templateImpl.transform(model, locale, modelAdaptor, processListener); return output; }
@Inject public FormatStringDecorator(@Assisted Decorator decorator, Engine templateEngine) { final String formatString = (String) requireNonNull(decorator.config().get(CK_FORMAT_STRING), CK_FORMAT_STRING + " cannot be null"); this.targetField = (String) requireNonNull(decorator.config().get(CK_TARGET_FIELD), CK_TARGET_FIELD + " cannot be null"); requireAllFields = (boolean) requireNonNull(decorator.config().get(CK_REQUIRE_ALL_FIELDS), CK_REQUIRE_ALL_FIELDS + " cannot be null"); template = requireNonNull(templateEngine, "templateEngine").getTemplate(formatString); usedVariables = template.getUsedVariableDescriptions(); }
@Override public SearchResponse apply(SearchResponse searchResponse) { final List<ResultMessageSummary> summaries = searchResponse.messages().stream() .map(summary -> { if (requireAllFields && !usedVariables.stream().allMatch(variable -> summary.message().containsKey(variable.name))) { return summary; } final String formattedString = template.transform(summary.message(), Locale.ENGLISH); if (formattedString == null) { return summary; } final Message message = new Message(ImmutableMap.copyOf(summary.message())); message.addField(targetField, formattedString); return summary.toBuilder().message(message.getFields()).build(); }) .collect(Collectors.toList()); return searchResponse.toBuilder().messages(summaries).build(); } }