From 49552ce33c9b675a1cbb53d631d81fbe5ceab21c Mon Sep 17 00:00:00 2001 From: Steve Siani Date: Mon, 8 Jul 2019 12:33:43 -0400 Subject: Velocity template engine implement a separate instance Issue-ID: CCSDK-1457 Signed-off-by: Steve Siani Change-Id: I8fd9918df5e03e1f7c0cdcf4bc63ddc5846195b8 --- .../core/service/BluePrintJinjaTemplateService.kt | 13 +++---------- .../core/service/BluePrintVelocityTemplateService.kt | 15 +++++++++++---- ms/controllerblueprints/parent/pom.xml | 5 +++-- 3 files changed, 17 insertions(+), 16 deletions(-) (limited to 'ms/controllerblueprints') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt index baddd6a12..a06fb99ff 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt @@ -19,22 +19,16 @@ package org.onap.ccsdk.cds.controllerblueprints.core.service import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper -import com.google.common.io.Resources import com.hubspot.jinjava.Jinjava -import com.hubspot.jinjava.interpret.Context +import com.hubspot.jinjava.JinjavaConfig import com.hubspot.jinjava.interpret.JinjavaInterpreter -import com.hubspot.jinjava.loader.ClasspathResourceLocator import com.hubspot.jinjava.loader.ResourceLocator import com.hubspot.jinjava.loader.ResourceNotFoundException import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintJsonNodeFactory -import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.removeNullNode -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service import java.io.IOException import java.nio.charset.Charset import java.nio.file.Files.readAllBytes @@ -70,8 +64,7 @@ object BluePrintJinjaTemplateService { additionalContext: MutableMap, bluePrintPathConfiguration: BluePrintPathConfiguration, artifactName: String, artifactVersion: String): String { - - + return generateContent(template, json, ignoreJsonNull, @@ -81,7 +74,7 @@ object BluePrintJinjaTemplateService { fun generateContent(template: String, json: String, ignoreJsonNull: Boolean, additionalContext: MutableMap, resourceLocator: ResourceLocator? = null): String { - val jinJava = Jinjava() + val jinJava = Jinjava(JinjavaConfig()) if (resourceLocator != null) { jinJava.resourceLocator = resourceLocator } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt index 43e6d221f..2d3c35de7 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.apache.commons.lang3.BooleanUtils import org.apache.commons.lang3.StringUtils import org.apache.velocity.VelocityContext -import org.apache.velocity.app.Velocity +import org.apache.velocity.app.VelocityEngine import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintJsonNodeFactory import org.onap.ccsdk.cds.controllerblueprints.core.removeNullNode @@ -57,7 +57,15 @@ object BluePrintVelocityTemplateService { fun generateContent(template: String, jsonNode: JsonNode?, ignoreJsonNull: Boolean = false, additionalContext: MutableMap = mutableMapOf()): String { - Velocity.init() + /* + * create a new instance of the velocity engine + */ + val velocity = VelocityEngine() + + /* + * initialize the engine + */ + velocity.init() val velocityContext = VelocityContext() velocityContext.put("StringUtils", StringUtils::class.java) @@ -76,9 +84,8 @@ object BluePrintVelocityTemplateService { } val stringWriter = StringWriter() - Velocity.evaluate(velocityContext, stringWriter, "TemplateData", template) + velocity.evaluate(velocityContext, stringWriter, "TemplateData", template) stringWriter.flush() return stringWriter.toString() - } } diff --git a/ms/controllerblueprints/parent/pom.xml b/ms/controllerblueprints/parent/pom.xml index 236dcc1dc..6f8405e9a 100644 --- a/ms/controllerblueprints/parent/pom.xml +++ b/ms/controllerblueprints/parent/pom.xml @@ -43,7 +43,8 @@ 1.2.2 1.7.4 1.9 - 2.5.0 + 2.5.1 + 1.7 @@ -103,7 +104,7 @@ org.apache.velocity velocity - 1.7 + ${velocity.version} com.hubspot.jinjava -- cgit 1.2.3-korg