2 * Copyright © 2018 IBM.
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.
17 package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils
19 import org.apache.commons.collections.MapUtils
20 import org.apache.commons.lang3.StringUtils
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate
22 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
23 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
24 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
25 import org.slf4j.LoggerFactory
28 object ResourceDictionaryUtils {
29 private val log = LoggerFactory.getLogger(ResourceDictionaryUtils::class.java)
32 fun populateSourceMapping(resourceAssignment: ResourceAssignment,
33 resourceDefinition: ResourceDefinition) {
35 if (StringUtils.isBlank(resourceAssignment.dictionarySource)) {
37 if (MapUtils.isNotEmpty(resourceDefinition.sources)) {
38 val source = findFirstSource(resourceDefinition.sources)
40 // Populate and Assign First Source
41 if (StringUtils.isNotBlank(source)) {
42 // Set Dictionary Source
43 resourceAssignment.dictionarySource = source
45 resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
47 log.info("auto map resourceAssignment : {}", resourceAssignment)
49 resourceAssignment.dictionarySource = ResourceDictionaryConstants.SOURCE_INPUT
55 fun findFirstSource(sources: Map<String, NodeTemplate>): String? {
56 var source: String? = null
57 if (MapUtils.isNotEmpty(sources)) {
58 source = sources.keys.stream().findFirst().get()