Skip to content

Commit bcc0eb1

Browse files
committed
qute
Signed-off-by: Attila Mészáros <[email protected]>
1 parent dd29a99 commit bcc0eb1

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
11
package io.csviri.operator.resourceglue.templating;
22

3-
import java.io.StringReader;
4-
import java.io.StringWriter;
53
import java.util.HashMap;
64
import java.util.Map;
75

86
import io.csviri.operator.resourceglue.Utils;
97
import io.csviri.operator.resourceglue.customresource.glue.Glue;
108
import io.javaoperatorsdk.operator.api.reconciler.Context;
9+
import io.quarkus.qute.Engine;
10+
import io.quarkus.qute.Template;
1111

1212
import com.fasterxml.jackson.databind.ObjectMapper;
13-
import com.github.mustachejava.DefaultMustacheFactory;
14-
import com.github.mustachejava.MustacheFactory;
1513

1614
public class GenericTemplateHandler {
17-
private static final ObjectMapper objectMapper = new ObjectMapper();
18-
private static final MustacheFactory mustacheFactory = new DefaultMustacheFactory();
15+
1916
public static final String WORKFLOW_METADATA_KEY = "glueMetadata";
2017

18+
private static final ObjectMapper objectMapper = new ObjectMapper();
19+
private static final Engine engine = Engine.builder().addDefaults().build();
2120

2221
public String processTemplate(String template, Glue primary,
2322
Context<Glue> context) {
2423

25-
// to precompile?
26-
var mustache = mustacheFactory.compile(new StringReader(template), "desired");
24+
Template hello = engine.parse(template);
2725

28-
var mustacheContext = createMustacheContextWithResources(primary, context);
29-
return mustache.execute(new StringWriter(), mustacheContext).toString();
26+
return hello.data(createDataWithResources(primary, context)).render();
3027
}
3128

32-
private static Map<String, Map> createMustacheContextWithResources(Glue primary,
29+
@SuppressWarnings("rawtypes")
30+
private static Map<String, Map> createDataWithResources(Glue primary,
3331
Context<Glue> context) {
32+
Map<String, Map> res = new HashMap<>();
3433
var actualResourcesByName = Utils.getActualResourcesByNameInWorkflow(context, primary);
3534

36-
Map<String, Map> mustacheContext = new HashMap<>();
37-
38-
actualResourcesByName.entrySet().stream().forEach(e -> mustacheContext.put(e.getKey(),
39-
e.getValue() == null ? null : objectMapper.convertValue(e.getValue(), Map.class)));
35+
actualResourcesByName.forEach((key, value) -> res.put(key,
36+
value == null ? null : objectMapper.convertValue(value, Map.class)));
4037

41-
mustacheContext.put(WORKFLOW_METADATA_KEY,
38+
res.put(WORKFLOW_METADATA_KEY,
4239
objectMapper.convertValue(primary.getMetadata(), Map.class));
4340

44-
return mustacheContext;
41+
return res;
4542
}
4643
}

0 commit comments

Comments
 (0)