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>
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
import com.fasterxml.jackson.annotation.JsonIgnore\r
import com.fasterxml.jackson.annotation.JsonProperty\r
import com.fasterxml.jackson.databind.JsonNode\r
+import io.swagger.annotations.ApiModelProperty\r
\r
/**\r
*\r
*/\r
class ConstraintClause {\r
@get:JsonProperty("equal")\r
- var equal: Any? = null\r
+ var equal: JsonNode? = null\r
@get:JsonProperty("greater_than")\r
var greaterThan: Any? = null\r
@get:JsonProperty("greater_or_equal")\r
@get:JsonProperty("in_range")\r
var inRange: Any? = null\r
@get:JsonProperty("valid_values")\r
- var validValues: MutableList<Any>? = null\r
+ var validValues: MutableList<JsonNode>? = null\r
@get:JsonProperty("length")\r
var length: Any? = null\r
@get:JsonProperty("min_length")\r
var minLength: Any? = null\r
@get:JsonProperty("max_length")\r
var maxLength: Any? = null\r
- @get:JsonProperty("pattern")\r
var pattern: String? = null\r
+ var schema: String? = null\r
}\r
\r
/*\r
var required: Boolean? = null\r
lateinit var type: String\r
@get:JsonProperty("default")\r
- var defaultValue: Any? = null\r
+ var defaultValue: JsonNode? = null\r
var status: String? = null\r
var constraints: MutableList<ConstraintClause>? = null\r
@get:JsonProperty("entry_schema")\r
var entrySchema: EntrySchema? = null\r
- var value: Any? = null\r
+ @get:ApiModelProperty(notes = "Property Value, It may be raw JSON or primitive data type values")\r
+ var value: JsonNode? = null\r
}\r
\r
\r
var description: String? = null\r
lateinit var type: String\r
@JsonProperty("default")\r
- var _default: Any? = null\r
+ var _default: JsonNode? = null\r
var status: String? = null\r
@JsonProperty("entry_schema")\r
var entry_schema: String? = null\r
*/\r
\r
class DataType : EntityType(){\r
- var constraints: MutableList<MutableMap<String, Any>>? = null\r
+ var constraints: MutableList<ConstraintClause>? = null\r
}\r
\r
/*\r
\r
class EntrySchema {\r
lateinit var type: String\r
- var constraints: MutableList<MutableMap<String, Any>>? = null\r
+ var constraints: MutableList<ConstraintClause>? = null\r
}\r
\r
class InterfaceAssignment {\r
"type": "string",
"constraints": [
{
- "validValues": [
+ "valid_values": [
"SQL",
"PLSQL"
]
}
},
"key-dependencies": {
- "required": false,
+ "required": true,
"type": "list",
"entry_schema": {
"type": "string"
"type": "string"
},
"key-dependencies": {
- "required": false,
+ "required": true,
"type": "list",
"entry_schema": {
"type": "string"
"type": "string"
},
"key-dependencies": {
- "required": false,
+ "required": true,
"type": "list",
"entry_schema": {
"type": "string"
"default": "JSON",
"constraints": [
{
- "validValues": [
- "XML",
+ "valid_values": [
"JSON"
]
}
"default": "JSON_PATH",
"constraints": [
{
- "validValues": [
+ "valid_values": [
"JSON_PATH",
"JSON_POINTER"
]
}
},
"key-dependencies": {
- "required": false,
+ "required": true,
"type": "list",
"entry_schema": {
"type": "string"
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
public static final String SOURCE_DEFAULT = "default";\r
public static final String SOURCE_DB = "db";\r
public static final String SOURCE_MDSAL = "mdsal";\r
+\r
+ public static final String PROPERTY_INPUT_KEY_MAPPING = "input-key-mapping";\r
+ public static final String PROPERTY_OUTPUT_KEY_MAPPING = "output-key-mapping";\r
+ public static final String PROPERTY_KEY_DEPENDENCY = "key-dependency";\r
}\r
+++ /dev/null
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils;\r
-\r
-import org.apache.commons.collections.MapUtils;\r
-import org.apache.commons.lang3.StringUtils;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.Map;\r
-import java.util.Optional;\r
-import java.util.function.Supplier;\r
-\r
-/**\r
- * ResourceDictionaryUtils.java Purpose to provide ResourceDictionaryUtils\r
- *\r
- * @author Brinda Santh\r
- * @version 1.0\r
- */\r
-public class ResourceDictionaryUtils {\r
-\r
- private ResourceDictionaryUtils() {\r
- // Do nothing\r
- }\r
-\r
- private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtils.class);\r
-\r
- /**\r
- * This Method is to assign the source name to the Dictionary Definition Check to see if the source\r
- * definition is not present then assign, if more than one source then assign only one first source.\r
- *\r
- * @param resourceAssignment\r
- * @param dictionaryDefinition\r
- */\r
- @SuppressWarnings("squid:S3776")\r
- public static void populateSourceMapping(ResourceAssignment resourceAssignment,\r
- DictionaryDefinition dictionaryDefinition) {\r
-\r
- if (resourceAssignment != null && dictionaryDefinition != null\r
- && StringUtils.isBlank(resourceAssignment.getDictionarySource())) {\r
-\r
- // Overwrite the Property Definitions from Dictionary\r
- setProperty(resourceAssignment, dictionaryDefinition);\r
-\r
- Map<String, ResourceSource> dictionarySource = dictionaryDefinition.getSource();\r
- Map<String, DictionaryDependency> dictionaryDependencyMap = dictionaryDefinition.getDependency();\r
-\r
- if (MapUtils.isNotEmpty(dictionarySource)) {\r
- String source = findFirstSource(dictionarySource);\r
-\r
- // Populate and Assign First Source\r
- if (StringUtils.isNotBlank(source)) {\r
- // Set Dictionary Source\r
- resourceAssignment.setDictionarySource(source);\r
-\r
- if (MapUtils.isNotEmpty(dictionaryDependencyMap)) {\r
- // Set Dependencies\r
- DictionaryDependency dictionaryDependency = dictionaryDependencyMap.get(source);\r
- if (dictionaryDependency != null) {\r
- resourceAssignment.setDependencies(dictionaryDependency.getNames());\r
- }\r
- }\r
- } else {\r
- resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT);\r
- }\r
- log.info("auto map resourceAssignment : {}", resourceAssignment);\r
- }\r
- }\r
- }\r
-\r
- public static <T> Optional<T> resolve(Supplier<T> resolver) {\r
- try {\r
- T result = resolver.get();\r
- return Optional.ofNullable(result);\r
- } catch (NullPointerException e) {\r
- return Optional.empty();\r
- }\r
- }\r
-\r
- private static String findFirstSource(Map<String, ResourceSource> dictionarySource) {\r
- String source = null;\r
- if (MapUtils.isNotEmpty(dictionarySource)) {\r
- source = dictionarySource.keySet().stream().findFirst().get();\r
- }\r
- return source;\r
- }\r
-\r
- /**\r
- * Overriding ResourceAssignment Properties with properties defined in Dictionary\r
- */\r
- private static void setProperty(ResourceAssignment resourceAssignment, DictionaryDefinition dictionaryDefinition) {\r
- if (StringUtils.isNotBlank(dictionaryDefinition.getDataType())) {\r
- PropertyDefinition property = resourceAssignment.getProperty();\r
- if (property == null) {\r
- property = new PropertyDefinition();\r
- }\r
- property.setDefaultValue(dictionaryDefinition.getDefaultValue());\r
- property.setType(dictionaryDefinition.getDataType());\r
- if (StringUtils.isNotBlank(dictionaryDefinition.getEntrySchema())) {\r
- EntrySchema entrySchema = new EntrySchema();\r
- entrySchema.setType(dictionaryDefinition.getEntrySchema());\r
- property.setEntrySchema(entrySchema);\r
- }\r
- resourceAssignment.setProperty(property);\r
- }\r
- }\r
-\r
-}\r
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
--- /dev/null
+/*
+ * 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
+++ /dev/null
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.controllerblueprints.resource.dict.util;\r
-\r
-\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.Arrays;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-public class ResourceDictionaryUtilsTest {\r
- private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);\r
-\r
- @Test\r
- public void validateSingleInputSource() {\r
- try {\r
- ResourceAssignment resourceAssignment = new ResourceAssignment();\r
- resourceAssignment.setName("test-input-key");\r
- PropertyDefinition propertyDefinition = new PropertyDefinition();\r
- propertyDefinition.setType("string");\r
- resourceAssignment.setProperty(propertyDefinition);\r
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();\r
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);\r
-\r
- Map<String, ResourceSource> source = new HashMap<>();\r
- SourceInput sourceInput = new SourceInput();\r
- source.put(ResourceDictionaryConstants.SOURCE_INPUT, sourceInput);\r
- dictionaryDefinition.setSource(source);\r
-\r
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);\r
- Assert.assertNotNull("Resource assignment input source is missing ",\r
- resourceAssignment.getDictionarySource());\r
- Assert.assertNotNull("Resource assignment input source property is missing ",\r
- resourceAssignment.getProperty());\r
- Assert.assertNotNull("Resource assignment input source property type is missing ",\r
- resourceAssignment.getProperty().getType());\r
-\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- @Test\r
- public void validateSingleDbSource() {\r
- try {\r
- ResourceAssignment resourceAssignment = new ResourceAssignment();\r
- resourceAssignment.setName("test-db-key");\r
- PropertyDefinition propertyDefinition = new PropertyDefinition();\r
- propertyDefinition.setType("string");\r
- resourceAssignment.setProperty(propertyDefinition);\r
-\r
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();\r
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);\r
-\r
- Map<String, ResourceSource> source = new HashMap<>();\r
- SourceDb sourceDb = new SourceDb();\r
- sourceDb.setBase("sdnc_connection");\r
- source.put(ResourceDictionaryConstants.SOURCE_DB, sourceDb);\r
- dictionaryDefinition.setSource(source);\r
-\r
- Map<String, DictionaryDependency> dependency = new HashMap<>();\r
- DictionaryDependency dependencyDb = new DictionaryDependency();\r
- dependencyDb.setNames(Arrays.asList("vnf-id", "vnf-name"));\r
- dependency.put(ResourceDictionaryConstants.SOURCE_DB, dependencyDb);\r
- dictionaryDefinition.setDependency(dependency);\r
-\r
- DecryptionRule decryptionRule = new DecryptionRule();\r
- decryptionRule.setDecryptType("sample Type");\r
- decryptionRule.setPath("$.");\r
- decryptionRule.setRule("Sample Rule");\r
- decryptionRule.setSources(Arrays.asList("vnf-id"));\r
- dictionaryDefinition.setDecryptionRules(Arrays.asList(decryptionRule));\r
-\r
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);\r
- Assert.assertNotNull("Resource assignment db source source is missing ",\r
- resourceAssignment.getDictionarySource());\r
- Assert.assertNotNull("Resource assignment db source source property is missing ",\r
- resourceAssignment.getProperty());\r
- Assert.assertNotNull("Resource assignment db source source property type is missing ",\r
- resourceAssignment.getProperty().getType());\r
-\r
- Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies());\r
- Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2,\r
- resourceAssignment.getDependencies().size());\r
-\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- @Test\r
- public void testSourceDefault() {\r
- ResourceAssignment resourceAssignment = new ResourceAssignment();\r
- resourceAssignment.setName("test-input-key");\r
- PropertyDefinition propertyDefinition = new PropertyDefinition();\r
- propertyDefinition.setType("string");\r
- resourceAssignment.setProperty(propertyDefinition);\r
-\r
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();\r
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);\r
-\r
- Map<String, ResourceSource> source = new HashMap<>();\r
- SourceDefault sourceDefault = new SourceDefault();\r
- source.put(ResourceDictionaryConstants.SOURCE_DEFAULT, sourceDefault);\r
- dictionaryDefinition.setSource(source);\r
-\r
- Map<String, DictionaryDependency> dependency = new HashMap<>();\r
- DictionaryDependency dependencyDefault = new DictionaryDependency();\r
- dependencyDefault.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"}));\r
- dependency.put(ResourceDictionaryConstants.SOURCE_DEFAULT, dependencyDefault);\r
- dictionaryDefinition.setDependency(dependency);\r
-\r
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);\r
-\r
- Assert.assertNotNull("Resource assignment default source is missing ",\r
- resourceAssignment.getDictionarySource());\r
- Assert.assertNotNull("Resource assignment default source property is missing ",\r
- resourceAssignment.getProperty());\r
- Assert.assertNotNull("Resource assignment default source property type is missing ",\r
- resourceAssignment.getProperty().getType());\r
- }\r
-\r
- @Test\r
- public void testSourceMdsal() {\r
- ResourceAssignment resourceAssignment = new ResourceAssignment();\r
- resourceAssignment.setName("test-input-key");\r
- PropertyDefinition propertyDefinition = new PropertyDefinition();\r
- propertyDefinition.setType("string");\r
- resourceAssignment.setProperty(propertyDefinition);\r
-\r
- DictionaryDefinition dictionaryDefinition = new DictionaryDefinition();\r
- dictionaryDefinition.setDataType(BluePrintConstants.DATA_TYPE_STRING);\r
-\r
- Map<String, ResourceSource> source = new HashMap<>();\r
- SourceMdsal sourceMdsal = new SourceMdsal();\r
- source.put(ResourceDictionaryConstants.SOURCE_MDSAL,sourceMdsal);\r
- dictionaryDefinition.setSource(source);\r
-\r
- Map<String, DictionaryDependency> dependency = new HashMap<>();\r
- DictionaryDependency dependencyMdsal = new DictionaryDependency();\r
- dependencyMdsal.setNames(Arrays.asList(new String[]{"vnf-id", "vnf-name"}));\r
- dependency.put(ResourceDictionaryConstants.SOURCE_MDSAL, dependencyMdsal);\r
- dictionaryDefinition.setDependency(dependency);\r
-\r
- ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition);\r
-\r
- Assert.assertNotNull("Resource assignment mdsal source is missing ", resourceAssignment.getDictionarySource());\r
- Assert.assertNotNull("Resource assignment mdsal source property is missing ", resourceAssignment.getProperty());\r
- Assert.assertNotNull("Resource assignment mdsal source property type is missing ",\r
- resourceAssignment.getProperty().getType());\r
- }\r
-\r
-}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils;\r
+\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+public class ResourceDictionaryUtilsTest {\r
+ private static final Logger log = LoggerFactory.getLogger(ResourceDictionaryUtilsTest.class);\r
+\r
+ @Test\r
+ public void testPopulateSourceMapping() {\r
+\r
+ ResourceAssignment resourceAssignment = new ResourceAssignment();\r
+ ResourceDefinition resourceDefinition = new ResourceDefinition();\r
+ Map<String, NodeTemplate> sources = new HashMap<>();\r
+ resourceDefinition.setSources(sources);\r
+ // To Check Empty Source\r
+ ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);\r
+ Assert.assertEquals("Expected Empty source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, resourceAssignment.getDictionarySource());\r
+\r
+ // To Check First Source\r
+ resourceAssignment.setDictionarySource(null);\r
+ sources.put(ResourceDictionaryConstants.SOURCE_DEFAULT, new NodeTemplate());\r
+ ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);\r
+ Assert.assertEquals("Expected First source Default, but.", ResourceDictionaryConstants.SOURCE_DEFAULT, resourceAssignment.getDictionarySource());\r
+\r
+ // To Check Assigned Source\r
+ resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_DB);\r
+ ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition);\r
+ Assert.assertEquals("Expected Assigned source DB, but.", ResourceDictionaryConstants.SOURCE_DB, resourceAssignment.getDictionarySource());\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testFindFirstSource() {\r
+ //To check if Empty Source\r
+ Map<String, NodeTemplate> sources = new HashMap<>();\r
+ String firstSource = ResourceDictionaryUtils.findFirstSource(sources);\r
+ Assert.assertNull("Source populated, which is not expected.", firstSource);\r
+\r
+ // TO check the first Source\r
+ sources.put(ResourceDictionaryConstants.SOURCE_INPUT, new NodeTemplate());\r
+ String inputFirstSource = ResourceDictionaryUtils.findFirstSource(sources);\r
+ Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, inputFirstSource);\r
+\r
+ // TO check the multiple Source\r
+ sources.put(ResourceDictionaryConstants.SOURCE_DB, new NodeTemplate());\r
+ String multipleFirstSource = ResourceDictionaryUtils.findFirstSource(sources);\r
+ Assert.assertEquals("Expected source Input, but.", ResourceDictionaryConstants.SOURCE_INPUT, multipleFirstSource);\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "description": "TOSCA base type for Resource Sources",
+ "version": "1.0.0",
+ "derived_from": "tosca.nodes.Root"
+}
\ No newline at end of file
{\r
"name": "bundle-id",\r
- "description": "name of the ",\r
+ "property" :{\r
+ "description": "name of the ",\r
+ "type": "string"\r
+ },\r
"resource-type": "ONAP",\r
"resource-path": "vnf/bundle-id",\r
"updated-by": "brindasanth@onap.com",\r
- "data-type": "String",\r
"tags": "bundle-id, brindasanth@onap.com",\r
- "source": {\r
+ "sources": {\r
"db": {\r
- "query": "SELECT bundle-id FROM DEVICE_PROFILE WHERE profile_name = :profile_name",\r
- "input-key-mapping": {\r
- "profile_name": "profile_name"\r
- },\r
- "output-key-mapping": {\r
- "db-country": "country",\r
- "db-state": "state"\r
+ "type": "source-db",\r
+ "properties": {\r
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",\r
+ "input-key-mapping": {\r
+ "profile_name": "profile_name"\r
+ },\r
+ "output-key-mapping": {\r
+ "db-country": "country",\r
+ "db-state": "state"\r
+ }\r
}\r
}\r
},\r
{\r
"name": "action-name",\r
+ "property" :{\r
+ "description": "name of the ",\r
+ "type": "string"\r
+ },\r
"resource-path": "action-name",\r
"resource-type": "ONAP",\r
- "description": "To be provided",\r
- "valid-values": null,\r
- "sample-value": null,\r
"updated-by": "brindasanth@onap.com",\r
"tags": null,\r
- "default": null,\r
- "data-type": "string",\r
- "source": {\r
+ "sources": {\r
"input": {\r
- "key": "action-name"\r
+ "type": "source-input",\r
+ "properties": {\r
+ "key": "action-name"\r
+ }\r
}\r
}\r
}
\ No newline at end of file
{\r
- "tags": "v4-ip-type, tosca.datatypes.Root, data_type, brindasanth@onap.com",\r
- "name": "v4-ip-type",\r
- "description": "To be provided",\r
- "updated-by": "brindasanth@onap.com",\r
- "resource-type": "ONAP",\r
- "resource-path": "vnf/v4-ip-type",\r
- "data-type": "string",\r
- "source": {\r
- "input": {\r
- \r
- }\r
- }\r
+ "name": "v4-ip-type",\r
+ "property": {\r
+ "description": "name of the ",\r
+ "type": "string"\r
+ },\r
+ "resource-path": "vnf/v4-ip-type",\r
+ "resource-type": "ONAP",\r
+ "updated-by": "brindasanth@onap.com",\r
+ "tags": null,\r
+ "sources": {\r
+ "input": {\r
+ "type": "source-input",\r
+ "properties": {\r
+ "key": "v4-ip-type"\r
+ }\r
+ }\r
+ }\r
}
\ No newline at end of file
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse;\r
ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName());\r
if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) {\r
\r
- DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), DictionaryDefinition.class);\r
+ ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class);\r
\r
if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName())\r
&& StringUtils.isBlank(resourceAssignment.getDictionaryName())) {\r
}\r
if (dictionaries != null) {\r
for (ResourceDictionary resourcedictionary : dictionaries) {\r
- DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), DictionaryDefinition.class);\r
+ ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class);\r
PropertyDefinition property = new PropertyDefinition();\r
property.setRequired(true);\r
ResourceAssignment resourceAssignment = new ResourceAssignment();\r
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
\r
package org.onap.ccsdk.apps.controllerblueprints.service;\r
\r
+import com.google.common.base.Preconditions;\r
import org.apache.commons.collections.CollectionUtils;\r
import org.apache.commons.io.IOUtils;\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType;\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType;\r
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
fileName = file.getFilename();\r
log.trace("Loading : {}", fileName);\r
String definitionContent = getResourceContent(file);\r
- DictionaryDefinition dictionaryDefinition =\r
- JacksonUtils.readValue(definitionContent, DictionaryDefinition.class);\r
+ ResourceDefinition dictionaryDefinition =\r
+ JacksonUtils.readValue(definitionContent, ResourceDefinition.class);\r
if (dictionaryDefinition != null) {\r
+ Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition");\r
ResourceDictionary resourceDictionary = new ResourceDictionary();\r
resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath());\r
resourceDictionary.setName(dictionaryDefinition.getName());\r
resourceDictionary.setDefinition(definitionContent);\r
\r
- if (dictionaryDefinition.getValidValues() != null)\r
- resourceDictionary\r
- .setValidValues(String.valueOf(dictionaryDefinition.getValidValues()));\r
-\r
- if (dictionaryDefinition.getSampleValue() != null)\r
- resourceDictionary\r
- .setValidValues(String.valueOf(dictionaryDefinition.getSampleValue()));\r
-\r
resourceDictionary.setResourceType(dictionaryDefinition.getResourceType());\r
- resourceDictionary.setDataType(dictionaryDefinition.getDataType());\r
- resourceDictionary.setEntrySchema(dictionaryDefinition.getEntrySchema());\r
- resourceDictionary.setDescription(dictionaryDefinition.getDescription());\r
+ resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription());\r
+ resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType());\r
+ if(dictionaryDefinition.getProperty().getEntrySchema() != null){\r
+ resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType());\r
+ }\r
resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy());\r
if (StringUtils.isBlank(dictionaryDefinition.getTags())) {\r
resourceDictionary.setTags(\r
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;\r
import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator;\r
if (resourceDictionary != null) {\r
ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);\r
\r
- DictionaryDefinition dictionaryDefinition =\r
- JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class);\r
+ ResourceDefinition resourceDefinition =\r
+ JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
\r
- if (dictionaryDefinition == null) {\r
+ if (resourceDefinition == null) {\r
throw new BluePrintException(\r
"Resource dictionary definition is not valid content " + resourceDictionary.getDefinition());\r
}\r
\r
- dictionaryDefinition.setName(resourceDictionary.getName());\r
- dictionaryDefinition.setResourcePath(resourceDictionary.getResourcePath());\r
- dictionaryDefinition.setResourceType(resourceDictionary.getResourceType());\r
- dictionaryDefinition.setDataType(resourceDictionary.getDataType());\r
- dictionaryDefinition.setEntrySchema(resourceDictionary.getEntrySchema());\r
- dictionaryDefinition.setTags(resourceDictionary.getTags());\r
- dictionaryDefinition.setDescription(resourceDictionary.getDescription());\r
- dictionaryDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());\r
+ resourceDefinition.setName(resourceDictionary.getName());\r
+ resourceDefinition.setResourcePath(resourceDictionary.getResourcePath());\r
+ resourceDefinition.setResourceType(resourceDictionary.getResourceType());\r
+\r
+ PropertyDefinition propertyDefinition = new PropertyDefinition();\r
+ propertyDefinition.setType(resourceDictionary.getDataType());\r
+ propertyDefinition.setDescription(resourceDictionary.getDescription());\r
+ if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){\r
+ EntrySchema entrySchema = new EntrySchema();\r
+ entrySchema.setType(resourceDictionary.getEntrySchema());\r
+ propertyDefinition.setEntrySchema(entrySchema);\r
+ }else{\r
+ propertyDefinition.setEntrySchema(null);\r
+ }\r
+ resourceDefinition.setTags(resourceDictionary.getTags());\r
+ resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());\r
\r
- String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true);\r
+ String definitionContent = JacksonUtils.getJson(resourceDefinition, true);\r
resourceDictionary.setDefinition(definitionContent);\r
\r
Optional<ResourceDictionary> dbResourceDictionaryData =\r
/*\r
* Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
@Autowired\r
protected ResourceDictionaryRest resourceDictionaryRest;\r
\r
- @Before\r
- public void setUp() {\r
- SourceDeserializer.registerSource("db", SourceDb.class);\r
- SourceDeserializer.registerSource("input", SourceInput.class);\r
- SourceDeserializer.registerSource("mdsal", SourceMdsal.class);\r
- SourceDeserializer.registerSource("default", SourceDefault.class);\r
- }\r
-\r
@Test\r
public void test01SaveDataDictionary() throws Exception {\r
String definition = IOUtils.toString(\r
{\r
- "name": "v4-aggregat-list",\r
- "description": "This collection v4-aggregate list",\r
- "valid-values": null,\r
- "sample-value": null,\r
- "updated-by": "Brinda Santh (bs2796)",\r
- "resource-type": "ONAP",\r
- "resource-path": "/v4-aggregat-list",\r
- "data-type": "list",\r
- "entry-schema": "dt-v4-aggregate",\r
- "tags": null,\r
- "default": null,\r
- "source": {\r
- "input": {\r
- \r
- }\r
- },\r
- "candidate-dependency": null\r
+ "name": "v4-aggregat-list",\r
+ "property": {\r
+ "description": "name of the ",\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-v4-aggregate"\r
+ }\r
+ },\r
+ "updated-by": "Brinda Santh (bs2796)",\r
+ "resource-type": "ONAP",\r
+ "resource-path": "/v4-aggregat-list",\r
+ "tags": null,\r
+ "sources": {\r
+ "input": {\r
+ "type": "source-input"\r
+ }\r
+ }\r
}
\ No newline at end of file