diff options
author | Dan Timoney <dtimoney@att.com> | 2019-07-09 18:03:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-07-09 18:03:50 +0000 |
commit | 4cf076f5c2362a257824e79e79f907a9a161b340 (patch) | |
tree | b7792614c206ddb6d528ba1830017e6067d75685 /ms/controllerblueprints | |
parent | c272399c4adaf583e3c616651f7aca319b9423c2 (diff) | |
parent | 49552ce33c9b675a1cbb53d631d81fbe5ceab21c (diff) |
Merge "Velocity template engine implement a separate instance"
Diffstat (limited to 'ms/controllerblueprints')
3 files changed, 17 insertions, 16 deletions
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<String, Any>, 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<String, Any>, 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<String, Any> = 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 @@ <onap.logger.slf4j>1.2.2</onap.logger.slf4j> <powermock.version>1.7.4</powermock.version> <mockk.version>1.9</mockk.version> - <jinja.version>2.5.0</jinja.version> + <jinja.version>2.5.1</jinja.version> + <velocity.version>1.7</velocity.version> </properties> <dependencyManagement> <dependencies> @@ -103,7 +104,7 @@ <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> - <version>1.7</version> + <version>${velocity.version}</version> </dependency> <dependency> <groupId>com.hubspot.jinjava</groupId> |