summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/resource-dict/src/main/kotlin
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2018-08-26 16:20:04 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2018-08-26 16:20:04 -0400
commit48c15ed0d02d98acac81773d84e928d0bd5ff07d (patch)
tree0a9e7bfad8689014e2e86984c1dc1d0dc7e4378f /ms/controllerblueprints/modules/resource-dict/src/main/kotlin
parent7b23a92a3d079940193eaf141ff8494851b49d61 (diff)
Controller Blueprints Microservice
Add Standardized resource definition in Initial data loading and Dictionary management services. Change-Id: Ib33ba2ecf3cb1e1fb9b5dea71532e6bc8280bcbb Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/resource-dict/src/main/kotlin')
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt2
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt62
2 files changed, 63 insertions, 1 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
index c2c8094b9..525ed9a42 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinition.kt
@@ -44,7 +44,7 @@ open class ResourceDefinition{
lateinit var resourcePath: String
@JsonProperty(value = "sources", required = true)
- var sources: MutableMap<String, NodeTemplate>? = null
+ lateinit var sources: MutableMap<String, NodeTemplate>
@JsonProperty("decryption-rules")
var decryptionRules: MutableList<DecryptionRule>? = null
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
new file mode 100644
index 000000000..e08c09c8e
--- /dev/null
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils
+
+import org.apache.commons.collections.MapUtils
+import org.apache.commons.lang3.StringUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
+import org.slf4j.LoggerFactory
+
+
+object ResourceDictionaryUtils {
+ private val log = LoggerFactory.getLogger(ResourceDictionaryUtils::class.java)
+
+ @JvmStatic
+ fun populateSourceMapping(resourceAssignment: ResourceAssignment,
+ resourceDefinition: ResourceDefinition) {
+
+ if (StringUtils.isBlank(resourceAssignment.dictionarySource)) {
+
+ if (MapUtils.isNotEmpty(resourceDefinition.sources)) {
+ val source = findFirstSource(resourceDefinition.sources)
+
+ // Populate and Assign First Source
+ if (StringUtils.isNotBlank(source)) {
+ // Set Dictionary Source
+ resourceAssignment.dictionarySource = source
+ } else {
+ resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
+ }
+ log.info("auto map resourceAssignment : {}", resourceAssignment)
+ }else {
+ resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
+ }
+ }
+ }
+
+ @JvmStatic
+ fun findFirstSource(sources: Map<String, NodeTemplate>): String? {
+ var source: String? = null
+ if (MapUtils.isNotEmpty(sources)) {
+ source = sources.keys.stream().findFirst().get()
+ }
+ return source
+ }
+} \ No newline at end of file