Velocity template engine implement a separate instance 37/91037/3
authorSteve Siani <alphonse.steve.siani.djissitchi@ibm.com>
Mon, 8 Jul 2019 16:33:43 +0000 (12:33 -0400)
committerDan Timoney <dtimoney@att.com>
Tue, 9 Jul 2019 17:39:52 +0000 (17:39 +0000)
Issue-ID: CCSDK-1457
Signed-off-by: Steve Siani <alphonse.steve.siani.djissitchi@ibm.com>
Change-Id: I8fd9918df5e03e1f7c0cdcf4bc63ddc5846195b8

components/parent/pom.xml
ms/blueprintsprocessor/parent/pom.xml
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintJinjaTemplateService.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt
ms/controllerblueprints/parent/pom.xml

index 0ecf94a..4411b84 100644 (file)
@@ -42,6 +42,8 @@
         <h2database.version>1.4.197</h2database.version>
         <onap.logger.slf4j>1.2.2</onap.logger.slf4j>
         <mockk.version>1.9</mockk.version>
+        <velocity.version>1.7</velocity.version>
+        <jinja.version>2.5.1</jinja.version>
     </properties>
     <dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>org.apache.velocity</groupId>
                 <artifactId>velocity</artifactId>
-                <version>1.7</version>
+                <version>${velocity.version}</version>
             </dependency>
             <dependency>
                 <groupId>com.google.guava</groupId>
                 <artifactId>guava</artifactId>
                 <version>${guava.version}</version>
             </dependency>
+            <dependency>
+                <groupId>com.hubspot.jinjava</groupId>
+                <artifactId>jinjava</artifactId>
+                <version>${jinja.version}</version>
+            </dependency>
 
             <!-- Kotlin Dependencies -->
             <dependency>
index 686be49..601fee3 100755 (executable)
@@ -52,7 +52,8 @@
         <powermock.version>1.7.4</powermock.version>
         <mockk.version>1.9</mockk.version>
         <dmaap.client.version>1.1.5</dmaap.client.version>
-        <jinja.version>2.5.0</jinja.version>
+        <jinja.version>2.5.1</jinja.version>
+        <velocity.version>1.7</velocity.version>
         <mockkserver.version>5.5.1</mockkserver.version>
     </properties>
     <dependencyManagement>
             <dependency>
                 <groupId>org.apache.velocity</groupId>
                 <artifactId>velocity</artifactId>
-                <version>1.7</version>
+                <version>${velocity.version}</version>
                 <exclusions>
                     <exclusion>
                         <groupId>org.slf4j</groupId>
index baddd6a..a06fb99 100644 (file)
@@ -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
         }
index 43e6d22..2d3c35d 100644 (file)
@@ -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()
-
     }
 }
index 236dcc1..6f8405e 100644 (file)
@@ -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>
             <dependency>
                 <groupId>org.apache.velocity</groupId>
                 <artifactId>velocity</artifactId>
-                <version>1.7</version>
+                <version>${velocity.version}</version>
             </dependency>
             <dependency>
                 <groupId>com.hubspot.jinjava</groupId>