2 * Copyright © 2019 IBM, Bell Canada.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.ccsdk.cds.controllerblueprints.core.interfaces
18 import com.fasterxml.jackson.core.io.CharTypes
19 import com.fasterxml.jackson.databind.node.JsonNodeFactory
20 import com.fasterxml.jackson.databind.node.TextNode
22 interface BlueprintTemplateService {
25 * Generate dynamique content using Velocity Template or Jinja template
27 * @param template template string content
28 * @param json json string content
29 * @param ignoreJsonNull Ignore Null value in the JSON content
30 * @param additionalContext (Key, value) mutable map for additional variables
31 * @return Content result
34 suspend fun generateContent(template: String, json: String = "", ignoreJsonNull: Boolean = false,
35 additionalContext: MutableMap<String, Any> = mutableMapOf()): String
39 * Customise JsonNodeFactory and TextNode, Since it introduces quotes for string data.
41 open class BluePrintJsonNodeFactory : JsonNodeFactory() {
42 override fun textNode(text: String): TextNode {
43 return BluePrintTextNode(text)
47 open class BluePrintTextNode(v: String) : TextNode(v) {
48 override fun toString(): String {
49 var len = this._value.length
50 len = len + 2 + (len shr 4)
51 val sb = StringBuilder(len)
52 CharTypes.appendQuoted(sb, this._value)