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