Migrate ccsdk/apps to ccsdk/cds
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceAssignmentRuntimeService.kt
1 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
2
3 import com.fasterxml.jackson.databind.JsonNode
4 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
5 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
6 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
7
8 class ResourceAssignmentRuntimeService(private var id: String, private var bluePrintContext: BluePrintContext)
9     : DefaultBluePrintRuntimeService(id, bluePrintContext) {
10
11     private lateinit var resolutionId: String
12     private var resourceStore: MutableMap<String, JsonNode> = hashMapOf()
13
14     fun createUniqueId(key: String) {
15         resolutionId = "$id-$key"
16     }
17
18     fun cleanResourceStore() {
19         resourceStore.clear()
20     }
21
22     fun putResolutionStore(key: String, value: JsonNode) {
23         resourceStore[key] = value
24     }
25
26     fun getResolutionStore(key: String): JsonNode {
27         return resourceStore[key]
28                 ?: throw BluePrintProcessorException("failed to get execution property ($key)")
29     }
30
31     fun checkResolutionStore(key: String): Boolean {
32         return resourceStore.containsKey(key)
33     }
34
35     fun getJsonNodeFromResolutionStore(key: String): JsonNode {
36         return getResolutionStore(key)
37     }
38
39     fun getStringFromResolutionStore(key: String): String? {
40         return getResolutionStore(key).asText()
41     }
42
43     fun getBooleanFromResolutionStore(key: String): Boolean? {
44         return getResolutionStore(key).asBoolean()
45     }
46
47     fun getIntFromResolutionStore(key: String): Int? {
48         return getResolutionStore(key).asInt()
49     }
50
51     fun getDoubleFromResolutionStore(key: String): Double? {
52         return getResolutionStore(key).asDouble()
53     }
54
55     fun putDictionaryStore(key: String, value: JsonNode) {
56         resourceStore["dictionary-$key"] = value
57     }
58
59     fun getDictionaryStore(key: String): JsonNode {
60         return resourceStore["dictionary-$key"]
61                 ?: throw BluePrintProcessorException("failed to get execution property (dictionary-$key)")
62     }
63
64     fun checkDictionaryStore(key: String): Boolean {
65         return resourceStore.containsKey("dictionary-$key")
66     }
67
68     fun getJsonNodeFromDictionaryStore(key: String): JsonNode {
69         return getResolutionStore("dictionary-$key")
70     }
71
72     fun getStringFromDictionaryStore(key: String): String? {
73         return getResolutionStore("dictionary-$key").asText()
74     }
75
76     fun getBooleanFromDictionaryStore(key: String): Boolean? {
77         return getResolutionStore("dictionary-$key").asBoolean()
78     }
79
80     fun getIntFromDictionaryStore(key: String): Int? {
81         return getResolutionStore("dictionary-$key").asInt()
82     }
83
84     fun getDoubleFromDictionaryStore(key: String): Double? {
85         return getResolutionStore("dictionary-$key").asDouble()
86     }
87
88 }