From ca395c635569bc70c16397a25dc46d7a9f0629a4 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 --- .../core/data/BluePrintModel.kt | 19 ++- .../load/model_type/node_type/source-db.json | 4 +- .../load/model_type/node_type/source-default.json | 2 +- .../load/model_type/node_type/source-input.json | 2 +- .../load/model_type/node_type/source-rest.json | 7 +- .../resource/dict/ResourceDictionaryConstants.java | 5 + .../dict/utils/ResourceDictionaryUtils.java | 129 --------------- .../resource/dict/ResourceDefinition.kt | 2 +- .../resource/dict/utils/ResourceDictionaryUtils.kt | 62 +++++++ .../dict/util/ResourceDictionaryUtilsTest.java | 178 --------------------- .../dict/utils/ResourceDictionaryUtilsTest.java | 79 +++++++++ .../load/model_type/node_type/source-db.json | 44 +++++ .../load/model_type/node_type/source-default.json | 18 +++ .../load/model_type/node_type/source-input.json | 18 +++ .../load/model_type/node_type/source-rest.json | 61 +++++++ .../node_type/tosca.nodes.ResourceSource.json | 5 + .../load/resource_dictionary/db-source.json | 25 +-- .../load/resource_dictionary/input-source.json | 16 +- .../load/resource_dictionary/v4-ip-type.json | 29 ++-- .../service/AutoResourceMappingService.java | 7 +- .../service/DataBaseInitService.java | 25 ++- .../service/ResourceDictionaryService.java | 37 +++-- .../service/rs/ResourceDictionaryRestTest.java | 9 +- .../resourcedictionary/default_definition.json | 34 ++-- 24 files changed, 409 insertions(+), 408 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 delete mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java create mode 100644 ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json create mode 100644 ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json (limited to 'ms/controllerblueprints') diff --git a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt index a10f6d30..b78a594f 100644 --- a/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt +++ b/ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/data/BluePrintModel.kt @@ -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. @@ -19,6 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.core.data import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.ApiModelProperty /** * @@ -59,7 +61,7 @@ A constraint clause defines an operation along with one or more compatible value */ class ConstraintClause { @get:JsonProperty("equal") - var equal: Any? = null + var equal: JsonNode? = null @get:JsonProperty("greater_than") var greaterThan: Any? = null @get:JsonProperty("greater_or_equal") @@ -71,15 +73,15 @@ class ConstraintClause { @get:JsonProperty("in_range") var inRange: Any? = null @get:JsonProperty("valid_values") - var validValues: MutableList? = null + var validValues: MutableList? = null @get:JsonProperty("length") var length: Any? = null @get:JsonProperty("min_length") var minLength: Any? = null @get:JsonProperty("max_length") var maxLength: Any? = null - @get:JsonProperty("pattern") var pattern: String? = null + var schema: String? = null } /* @@ -157,12 +159,13 @@ class PropertyDefinition { var required: Boolean? = null lateinit var type: String @get:JsonProperty("default") - var defaultValue: Any? = null + var defaultValue: JsonNode? = null var status: String? = null var constraints: MutableList? = null @get:JsonProperty("entry_schema") var entrySchema: EntrySchema? = null - var value: Any? = null + @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values") + var value: JsonNode? = null } @@ -182,7 +185,7 @@ class AttributeDefinition { var description: String? = null lateinit var type: String @JsonProperty("default") - var _default: Any? = null + var _default: JsonNode? = null var status: String? = null @JsonProperty("entry_schema") var entry_schema: String? = null @@ -346,7 +349,7 @@ A Data Type definition defines the schema for new named datatypes in TOSCA. */ class DataType : EntityType(){ - var constraints: MutableList>? = null + var constraints: MutableList? = null } /* @@ -481,7 +484,7 @@ class SubstitutionMapping { class EntrySchema { lateinit var type: String - var constraints: MutableList>? = null + var constraints: MutableList? = null } class InterfaceAssignment { diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json index 7ebeaa82..661a9503 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-db.json @@ -7,7 +7,7 @@ "type": "string", "constraints": [ { - "validValues": [ + "valid_values": [ "SQL", "PLSQL" ] @@ -33,7 +33,7 @@ } }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json index dd0bffcc..13e234e1 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-default.json @@ -7,7 +7,7 @@ "type": "string" }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json index 99c4691c..126ea30b 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-input.json @@ -7,7 +7,7 @@ "type": "string" }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" diff --git a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json index e77020ec..f8dd8b6f 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json +++ b/ms/controllerblueprints/modules/resource-dict/load/model_type/node_type/source-rest.json @@ -8,8 +8,7 @@ "default": "JSON", "constraints": [ { - "validValues": [ - "XML", + "valid_values": [ "JSON" ] } @@ -29,7 +28,7 @@ "default": "JSON_PATH", "constraints": [ { - "validValues": [ + "valid_values": [ "JSON_PATH", "JSON_POINTER" ] @@ -51,7 +50,7 @@ } }, "key-dependencies": { - "required": false, + "required": true, "type": "list", "entry_schema": { "type": "string" 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 1af42c59..96ab1ee1 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 4f9467f0..00000000 --- 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 c2c8094b..525ed9a4 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 00000000..e08c09c8 --- /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 diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java deleted file mode 100644 index b6ac103e..00000000 --- a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/util/ResourceDictionaryUtilsTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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. - * 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.util; - - -import org.junit.Assert; -import org.junit.Test; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -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.*; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -public class ResourceDictionaryUtilsTest { - private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); - - @Test - public void validateSingleInputSource() { - try { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceInput sourceInput = new SourceInput(); - source.put(ResourceDictionaryConstants.SOURCE_INPUT, sourceInput); - dictionaryDefinition.setSource(source); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - Assert.assertNotNull("Resource assignment input source is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment input source property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment input source property type is missing ", - resourceAssignment.getProperty().getType()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void validateSingleDbSource() { - try { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-db-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceDb sourceDb = new SourceDb(); - sourceDb.setBase("sdnc_connection"); - source.put(ResourceDictionaryConstants.SOURCE_DB, sourceDb); - dictionaryDefinition.setSource(source); - - Map dependency = new HashMap<>(); - DictionaryDependency dependencyDb = new DictionaryDependency(); - dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name")); - dependency.put(ResourceDictionaryConstants.SOURCE_DB, dependencyDb); - dictionaryDefinition.setDependency(dependency); - - DecryptionRule decryptionRule = new DecryptionRule(); - decryptionRule.setDecryptType("sample Type"); - decryptionRule.setPath("$."); - decryptionRule.setRule("Sample Rule"); - decryptionRule.setSources(Arrays.asList("vnf-id")); - dictionaryDefinition.setDecryptionRules(Arrays.asList(decryptionRule)); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - Assert.assertNotNull("Resource assignment db source source is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment db source source property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment db source source property type is missing ", - resourceAssignment.getProperty().getType()); - - Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies()); - Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2, - resourceAssignment.getDependencies().size()); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testSourceDefault() { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceDefault sourceDefault = new SourceDefault(); - source.put(ResourceDictionaryConstants.SOURCE_DEFAULT, sourceDefault); - dictionaryDefinition.setSource(source); - - Map dependency = new HashMap<>(); - DictionaryDependency dependencyDefault = new DictionaryDependency(); - dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ResourceDictionaryConstants.SOURCE_DEFAULT, dependencyDefault); - dictionaryDefinition.setDependency(dependency); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - - Assert.assertNotNull("Resource assignment default source is missing ", - resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment default source property is missing ", - resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment default source property type is missing ", - resourceAssignment.getProperty().getType()); - } - - @Test - public void testSourceMdsal() { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName("test-input-key"); - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType("string"); - resourceAssignment.setProperty(propertyDefinition); - - DictionaryDefinition dictionaryDefinition = new DictionaryDefinition(); - dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING); - - Map source = new HashMap<>(); - SourceMdsal sourceMdsal = new SourceMdsal(); - source.put(ResourceDictionaryConstants.SOURCE_MDSAL,sourceMdsal); - dictionaryDefinition.setSource(source); - - Map dependency = new HashMap<>(); - DictionaryDependency dependencyMdsal = new DictionaryDependency(); - dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"})); - dependency.put(ResourceDictionaryConstants.SOURCE_MDSAL, dependencyMdsal); - dictionaryDefinition.setDependency(dependency); - - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - - Assert.assertNotNull("Resource assignment mdsal source is missing ", resourceAssignment.getDictionarySource()); - Assert.assertNotNull("Resource assignment mdsal source property is missing ", resourceAssignment.getProperty()); - Assert.assertNotNull("Resource assignment mdsal source property type is missing ", - resourceAssignment.getProperty().getType()); - } - -} diff --git a/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java new file mode 100644 index 00000000..2a207e09 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtilsTest.java @@ -0,0 +1,79 @@ +/* + * 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. + * 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.junit.Assert; +import org.junit.Test; +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.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +public class ResourceDictionaryUtilsTest { + private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void testPopulateSourceMapping() { + + ResourceAssignment resourceAssignment = new ResourceAssignment(); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + Map sources = new HashMap<>(); + resourceDefinition.setSources(sources); + // To Check Empty Source + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource()); + + // To Check First Source + resourceAssignment.setDictionarySource(null); + sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource()); + + // To Check Assigned Source + resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_DB); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_DB, resourceAssignment.getDictionarySource()); + + } + + @Test + public void testFindFirstSource() { + //To check if Empty Source + Map sources = new HashMap<>(); + String firstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertNull("Source populated, which is not expected.", firstSource); + + // TO check the first Source + sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate()); + String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource); + + // TO check the multiple Source + sources.put(ResourceDictionaryConstants.SOURCE_DB, new NodeTemplate()); + String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources); + Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource); + + } + +} diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json new file mode 100644 index 00000000..661a9503 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-db.json @@ -0,0 +1,44 @@ +{ + "description": "This is Database Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": true, + "type": "string", + "constraints": [ + { + "valid_values": [ + "SQL", + "PLSQL" + ] + } + ] + }, + "query": { + "required": true, + "type": "string" + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json new file mode 100644 index 00000000..13e234e1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-default.json @@ -0,0 +1,18 @@ +{ + "description": "This is Default Resource Source Node Type", + "version": "1.0.0", + "properties": { + "key": { + "required": false, + "type": "string" + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json new file mode 100644 index 00000000..126ea30b --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-input.json @@ -0,0 +1,18 @@ +{ + "description": "This is Input Resource Source Node Type", + "version": "1.0.0", + "properties": { + "key": { + "required": false, + "type": "string" + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json new file mode 100644 index 00000000..f8dd8b6f --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/source-rest.json @@ -0,0 +1,61 @@ +{ + "description": "This is Rest Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": false, + "type": "string", + "default": "JSON", + "constraints": [ + { + "valid_values": [ + "JSON" + ] + } + ] + }, + "url-path": { + "required": true, + "type": "string" + }, + "path": { + "required": true, + "type": "string" + }, + "expression-type": { + "required": false, + "type": "string", + "default": "JSON_PATH", + "constraints": [ + { + "valid_values": [ + "JSON_PATH", + "JSON_POINTER" + ] + } + ] + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json new file mode 100644 index 00000000..2ef553e2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/load/model_type/node_type/tosca.nodes.ResourceSource.json @@ -0,0 +1,5 @@ +{ + "description": "TOSCA base type for Resource Sources", + "version": "1.0.0", + "derived_from": "tosca.nodes.Root" +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json index 86252354..cd4e282b 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/db-source.json @@ -1,20 +1,25 @@ { "name": "bundle-id", - "description": "name of the ", + "property" :{ + "description": "name of the ", + "type": "string" + }, "resource-type": "ONAP", "resource-path": "vnf/bundle-id", "updated-by": "brindasanth@onap.com", - "data-type": "String", "tags": "bundle-id, brindasanth@onap.com", - "source": { + "sources": { "db": { - "query": "SELECT bundle-id FROM DEVICE_PROFILE WHERE profile_name = :profile_name", - "input-key-mapping": { - "profile_name": "profile_name" - }, - "output-key-mapping": { - "db-country": "country", - "db-state": "state" + "type": "source-db", + "properties": { + "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "db-country": "country", + "db-state": "state" + } } } }, diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json index 35736b66..c34c252b 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json @@ -1,17 +1,19 @@ { "name": "action-name", + "property" :{ + "description": "name of the ", + "type": "string" + }, "resource-path": "action-name", "resource-type": "ONAP", - "description": "To be provided", - "valid-values": null, - "sample-value": null, "updated-by": "brindasanth@onap.com", "tags": null, - "default": null, - "data-type": "string", - "source": { + "sources": { "input": { - "key": "action-name" + "type": "source-input", + "properties": { + "key": "action-name" + } } } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json index c6c0f985..349183bd 100644 --- a/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json +++ b/ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json @@ -1,14 +1,19 @@ { - "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com", - "name": "v4-ip-type", - "description": "To be provided", - "updated-by": "brindasanth@onap.com", - "resource-type": "ONAP", - "resource-path": "vnf/v4-ip-type", - "data-type": "string", - "source": { - "input": { - - } - } + "name": "v4-ip-type", + "property": { + "description": "name of the ", + "type": "string" + }, + "resource-path": "vnf/v4-ip-type", + "resource-type": "ONAP", + "updated-by": "brindasanth@onap.com", + "tags": null, + "sources": { + "input": { + "type": "source-input", + "properties": { + "key": "v4-ip-type" + } + } + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 6b09c81f..2c443783 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.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. @@ -22,7 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; @@ -102,7 +103,7 @@ public class AutoResourceMappingService { ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) { - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class); if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { @@ -186,7 +187,7 @@ public class AutoResourceMappingService { } if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); PropertyDefinition property = new PropertyDefinition(); property.setRequired(true); ResourceAssignment resourceAssignment = new ResourceAssignment(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 9ab319cb..3a5c4fde 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.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. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -26,7 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType; import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; @@ -160,26 +162,21 @@ public class DataBaseInitService { fileName = file.getFilename(); log.trace("Loading : {}", fileName); String definitionContent = getResourceContent(file); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(definitionContent, DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = + JacksonUtils.readValue(definitionContent, ResourceDefinition.class); if (dictionaryDefinition != null) { + Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition"); ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); resourceDictionary.setName(dictionaryDefinition.getName()); resourceDictionary.setDefinition(definitionContent); - if (dictionaryDefinition.getValidValues() != null) - resourceDictionary - .setValidValues(String.valueOf(dictionaryDefinition.getValidValues())); - - if (dictionaryDefinition.getSampleValue() != null) - resourceDictionary - .setValidValues(String.valueOf(dictionaryDefinition.getSampleValue())); - resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); - resourceDictionary.setDataType(dictionaryDefinition.getDataType()); - resourceDictionary.setEntrySchema(dictionaryDefinition.getEntrySchema()); - resourceDictionary.setDescription(dictionaryDefinition.getDescription()); + resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); + resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType()); + if(dictionaryDefinition.getProperty().getEntrySchema() != null){ + resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType()); + } resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy()); if (StringUtils.isBlank(dictionaryDefinition.getTags())) { resourceDictionary.setTags( diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index b9567db1..4bb87d7f 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.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. @@ -18,8 +19,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator; @@ -108,24 +111,32 @@ public class ResourceDictionaryService { if (resourceDictionary != null) { ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - if (dictionaryDefinition == null) { + if (resourceDefinition == null) { throw new BluePrintException( "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); } - dictionaryDefinition.setName(resourceDictionary.getName()); - dictionaryDefinition.setResourcePath(resourceDictionary.getResourcePath()); - dictionaryDefinition.setResourceType(resourceDictionary.getResourceType()); - dictionaryDefinition.setDataType(resourceDictionary.getDataType()); - dictionaryDefinition.setEntrySchema(resourceDictionary.getEntrySchema()); - dictionaryDefinition.setTags(resourceDictionary.getTags()); - dictionaryDefinition.setDescription(resourceDictionary.getDescription()); - dictionaryDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + resourceDefinition.setName(resourceDictionary.getName()); + resourceDefinition.setResourcePath(resourceDictionary.getResourcePath()); + resourceDefinition.setResourceType(resourceDictionary.getResourceType()); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(resourceDictionary.getDataType()); + propertyDefinition.setDescription(resourceDictionary.getDescription()); + if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){ + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setType(resourceDictionary.getEntrySchema()); + propertyDefinition.setEntrySchema(entrySchema); + }else{ + propertyDefinition.setEntrySchema(null); + } + resourceDefinition.setTags(resourceDictionary.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true); + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); resourceDictionary.setDefinition(definitionContent); Optional dbResourceDictionaryData = diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java index 73d6eca9..8257dc36 100644 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.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. @@ -50,14 +51,6 @@ public class ResourceDictionaryRestTest { @Autowired protected ResourceDictionaryRest resourceDictionaryRest; - @Before - public void setUp() { - SourceDeserializer.registerSource("db", SourceDb.class); - SourceDeserializer.registerSource("input", SourceInput.class); - SourceDeserializer.registerSource("mdsal", SourceMdsal.class); - SourceDeserializer.registerSource("default", SourceDefault.class); - } - @Test public void test01SaveDataDictionary() throws Exception { String definition = IOUtils.toString( diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json index 2b392054..986ba706 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json +++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json @@ -1,19 +1,19 @@ { - "name": "v4-aggregat-list", - "description": "This collection v4-aggregate list", - "valid-values": null, - "sample-value": null, - "updated-by": "Brinda Santh (bs2796)", - "resource-type": "ONAP", - "resource-path": "/v4-aggregat-list", - "data-type": "list", - "entry-schema": "dt-v4-aggregate", - "tags": null, - "default": null, - "source": { - "input": { - - } - }, - "candidate-dependency": null + "name": "v4-aggregat-list", + "property": { + "description": "name of the ", + "type": "list", + "entry_schema": { + "type": "dt-v4-aggregate" + } + }, + "updated-by": "Brinda Santh (bs2796)", + "resource-type": "ONAP", + "resource-path": "/v4-aggregat-list", + "tags": null, + "sources": { + "input": { + "type": "source-input" + } + } } \ No newline at end of file -- cgit 1.2.3-korg