Add service template types DSL
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / dsl / BluePrintDSL.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.core.dsl
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
21 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
22
23 fun serviceTemplate(name: String, version: String, author: String, tags: String,
24                     block: ServiceTemplateBuilder.() -> Unit): ServiceTemplate {
25     return ServiceTemplateBuilder(name, version, author, tags).apply(block).build()
26 }
27
28 // Input Function
29
30 fun getInput(inputKey: String): JsonNode {
31     return """{"get_input": "$inputKey"}""".jsonAsJsonType()
32 }
33
34 fun getAttribute(attributeName: String): JsonNode {
35     return """{"get_attribute": ["SELF", "$attributeName"]}""".jsonAsJsonType()
36 }
37
38 fun getAttribute(attributeName: String, jsonPath: String): JsonNode {
39     return """{"get_attribute": ["SELF", "$attributeName", "$jsonPath"]}""".jsonAsJsonType()
40 }
41
42 fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String): JsonNode {
43     return """{"get_attribute": ["$nodeTemplateName", "$attributeName"]}""".jsonAsJsonType()
44 }
45
46 fun getNodeTemplateAttribute(nodeTemplateName: String, attributeName: String, jsonPath: String): JsonNode {
47     return """{"get_attribute": ["$nodeTemplateName", "$attributeName", "$jsonPath]}""".jsonAsJsonType()
48 }
49
50 // Property Function
51
52 fun getProperty(propertyName: String): JsonNode {
53     return """{"get_property": ["SELF", "$propertyName"]}""".jsonAsJsonType()
54 }
55
56 fun getProperty(propertyName: String, jsonPath: String): JsonNode {
57     return """{"get_property": ["SELF", "$propertyName", "$jsonPath"]}""".jsonAsJsonType()
58 }
59
60 fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String): JsonNode {
61     return """{"get_property": ["$nodeTemplateName", "$propertyName"]}""".jsonAsJsonType()
62 }
63
64 fun getNodeTemplateProperty(nodeTemplateName: String, propertyName: String, jsonPath: String): JsonNode {
65     return """{"get_property": ["$nodeTemplateName", "$propertyName", "$jsonPath]}""".jsonAsJsonType()
66 }
67
68 // Artifact Function
69
70 fun getArtifact(artifactName: String): JsonNode {
71     return """{"get_artifact": ["SELF", "$artifactName"]}""".jsonAsJsonType()
72 }
73
74 fun getNodeTemplateArtifact(nodeTemplateName: String, artifactName: String): JsonNode {
75     return """{"get_artifact": ["$nodeTemplateName", "$artifactName"]}""".jsonAsJsonType()
76 }