From 48c15ed0d02d98acac81773d84e928d0bd5ff07d Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 26 Aug 2018 16:20:04 -0400 Subject: 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 --- .../resource/dict/ResourceDictionaryConstants.java | 5 + .../dict/utils/ResourceDictionaryUtils.java | 129 --------------------- .../resource/dict/ResourceDefinition.kt | 2 +- .../resource/dict/utils/ResourceDictionaryUtils.kt | 62 ++++++++++ 4 files changed, 68 insertions(+), 130 deletions(-) delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.kt (limited to 'ms/controllerblueprints/modules/resource-dict/src/main') diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java index 1af42c590..96ab1ee1a 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -21,4 +22,8 @@ public class ResourceDictionaryConstants { public static final String SOURCE_DEFAULT = "default"; public static final String SOURCE_DB = "db"; public static final String SOURCE_MDSAL = "mdsal"; + + public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping"; + public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping"; + public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency"; } diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java deleted file mode 100644 index 4f9467f05..000000000 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.EntrySchema; -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; - -/** - * ResourceDictionaryUtils.java Purpose to provide ResourceDictionaryUtils - * - * @author Brinda Santh - * @version 1.0 - */ -public class ResourceDictionaryUtils { - - private ResourceDictionaryUtils() { - // Do nothing - } - - private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtils.class); - - /** - * This Method is to assign the source name to the Dictionary Definition Check to see if the source - * definition is not present then assign, if more than one source then assign only one first source. - * - * @param resourceAssignment - * @param dictionaryDefinition - */ - @SuppressWarnings("squid:S3776") - public static void populateSourceMapping(ResourceAssignment resourceAssignment, - DictionaryDefinition dictionaryDefinition) { - - if (resourceAssignment != null && dictionaryDefinition != null - && StringUtils.isBlank(resourceAssignment.getDictionarySource())) { - - // Overwrite the Property Definitions from Dictionary - setProperty(resourceAssignment, dictionaryDefinition); - - Map dictionarySource = dictionaryDefinition.getSource(); - Map dictionaryDependencyMap = dictionaryDefinition.getDependency(); - - if (MapUtils.isNotEmpty(dictionarySource)) { - String source = findFirstSource(dictionarySource); - - // Populate and Assign First Source - if (StringUtils.isNotBlank(source)) { - // Set Dictionary Source - resourceAssignment.setDictionarySource(source); - - if (MapUtils.isNotEmpty(dictionaryDependencyMap)) { - // Set Dependencies - DictionaryDependency dictionaryDependency = dictionaryDependencyMap.get(source); - if (dictionaryDependency != null) { - resourceAssignment.setDependencies(dictionaryDependency.getNames()); - } - } - } else { - resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT); - } - log.info("auto map resourceAssignment : {}", resourceAssignment); - } - } - } - - public static Optional resolve(Supplier resolver) { - try { - T result = resolver.get(); - return Optional.ofNullable(result); - } catch (NullPointerException e) { - return Optional.empty(); - } - } - - private static String findFirstSource(Map dictionarySource) { - String source = null; - if (MapUtils.isNotEmpty(dictionarySource)) { - source = dictionarySource.keySet().stream().findFirst().get(); - } - return source; - } - - /** - * Overriding ResourceAssignment Properties with properties defined in Dictionary - */ - private static void setProperty(ResourceAssignment resourceAssignment, DictionaryDefinition dictionaryDefinition) { - if (StringUtils.isNotBlank(dictionaryDefinition.getDataType())) { - PropertyDefinition property = resourceAssignment.getProperty(); - if (property == null) { - property = new PropertyDefinition(); - } - property.setDefaultValue(dictionaryDefinition.getDefaultValue()); - property.setType(dictionaryDefinition.getDataType()); - if (StringUtils.isNotBlank(dictionaryDefinition.getEntrySchema())) { - EntrySchema entrySchema = new EntrySchema(); - entrySchema.setType(dictionaryDefinition.getEntrySchema()); - property.setEntrySchema(entrySchema); - } - resourceAssignment.setProperty(property); - } - } - -} 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? = null + lateinit var sources: MutableMap @JsonProperty("decryption-rules") var decryptionRules: MutableList? = 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? { + var source: String? = null + if (MapUtils.isNotEmpty(sources)) { + source = sources.keys.stream().findFirst().get() + } + return source + } +} \ No newline at end of file -- cgit 1.2.3-korg