Controller Blueprints Microservice 07/63107/1
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Mon, 27 Aug 2018 17:29:51 +0000 (17:29 +0000)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Mon, 27 Aug 2018 17:29:51 +0000 (17:29 +0000)
Optimise model type repository search for DB and file in blueprint repo service.

Change-Id: If5458e218b723d3fff451789a73a667dd75bc91c
Issue-ID: CCSDK-487
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
17 files changed:
ms/controllerblueprints/application/load/model_type/node_type/source-db.json [new file with mode: 0644]
ms/controllerblueprints/application/load/model_type/node_type/source-default.json [new file with mode: 0644]
ms/controllerblueprints/application/load/model_type/node_type/source-input.json [new file with mode: 0644]
ms/controllerblueprints/application/load/model_type/node_type/source-rest.json [new file with mode: 0644]
ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json [new file with mode: 0644]
ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ApplicationExceptionHandler.java
ms/controllerblueprints/modules/core/pom.xml
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintEnhancerService.kt
ms/controllerblueprints/modules/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoService.kt
ms/controllerblueprints/modules/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRepoFileServiceTest.kt
ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java
ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDictionaryValidationService.kt
ms/controllerblueprints/modules/service/load/resource_dictionary/input-source.json
ms/controllerblueprints/modules/service/load/resource_dictionary/v4-ip-type.json
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json

diff --git a/ms/controllerblueprints/application/load/model_type/node_type/source-db.json b/ms/controllerblueprints/application/load/model_type/node_type/source-db.json
new file mode 100644 (file)
index 0000000..661a950
--- /dev/null
@@ -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/application/load/model_type/node_type/source-default.json b/ms/controllerblueprints/application/load/model_type/node_type/source-default.json
new file mode 100644 (file)
index 0000000..13e234e
--- /dev/null
@@ -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/application/load/model_type/node_type/source-input.json b/ms/controllerblueprints/application/load/model_type/node_type/source-input.json
new file mode 100644 (file)
index 0000000..126ea30
--- /dev/null
@@ -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/application/load/model_type/node_type/source-rest.json b/ms/controllerblueprints/application/load/model_type/node_type/source-rest.json
new file mode 100644 (file)
index 0000000..f8dd8b6
--- /dev/null
@@ -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/application/load/model_type/node_type/tosca.nodes.ResourceSource.json b/ms/controllerblueprints/application/load/model_type/node_type/tosca.nodes.ResourceSource.json
new file mode 100644 (file)
index 0000000..2ef553e
--- /dev/null
@@ -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
index d02be5c..d9380a2 100644 (file)
@@ -16,6 +16,8 @@
 \r
 package org.onap.ccsdk.apps.controllerblueprints;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.common.ErrorMessage;\r
 import org.springframework.http.HttpStatus;\r
@@ -28,14 +30,17 @@ import org.springframework.web.context.request.WebRequest;
 @ControllerAdvice\r
 @RestController\r
 public class ApplicationExceptionHandler {\r
+    private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationExceptionHandler.class);\r
     @ExceptionHandler(Exception.class)\r
     public final ResponseEntity<ErrorMessage> handleAllExceptions(Exception ex, WebRequest request) {\r
+        log.error("Application Exception", ex);\r
         ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getLocalizedMessage());\r
         return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);\r
     }\r
 \r
     @ExceptionHandler(BluePrintException.class)\r
     public final ResponseEntity<ErrorMessage> handleBlueprintException(BluePrintException ex, WebRequest request) {\r
+        log.error("Application Blueprint Exception", ex);\r
         ErrorMessage exceptionResponse = new ErrorMessage( ex.getMessage(), ex.getCode(), ex.getLocalizedMessage());\r
         return new ResponseEntity<>(exceptionResponse, HttpStatus.INTERNAL_SERVER_ERROR);\r
     }\r
index 51b3af3..ba38de6 100644 (file)
             <groupId>com.fasterxml.jackson.module</groupId>\r
             <artifactId>jackson-module-jsonSchema</artifactId>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>io.projectreactor</groupId>\r
+            <artifactId>reactor-core</artifactId>\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.yaml</groupId>\r
             <artifactId>snakeyaml</artifactId>\r
index 64fc57f..8bc0e6e 100644 (file)
@@ -217,21 +217,21 @@ open class BluePrintEnhancerDefaultService(val bluePrintRepoService: BluePrintRe
     }\r
 \r
     open fun populateNodeType(nodeTypeName: String): NodeType {\r
-        val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)\r
+        val nodeType = bluePrintRepoService.getNodeType(nodeTypeName)?.block()\r
                 ?: throw BluePrintException(format("Couldn't get NodeType({}) from repo.", nodeTypeName))\r
         serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType)\r
         return nodeType\r
     }\r
 \r
     open fun populateArtifactType(artifactTypeName: String): ArtifactType {\r
-        val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)\r
+        val artifactType = bluePrintRepoService.getArtifactType(artifactTypeName)?.block()\r
                 ?: throw BluePrintException(format("Couldn't get ArtifactType({}) from repo.", artifactTypeName))\r
         serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType)\r
         return artifactType\r
     }\r
 \r
     open fun populateDataTypes(dataTypeName: String): DataType {\r
-        val dataType = bluePrintRepoService.getDataType(dataTypeName)\r
+        val dataType = bluePrintRepoService.getDataType(dataTypeName)?.block()\r
                 ?: throw BluePrintException(format("Couldn't get DataType({}) from repo.", dataTypeName))\r
         serviceTemplate.dataTypes?.put(dataTypeName, dataType)\r
         return dataType\r
index a529a85..8c44461 100644 (file)
 \r
 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
 \r
+import com.google.common.base.Preconditions\r
 import org.apache.commons.io.FileUtils\r
+import org.apache.commons.lang3.StringUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
+import org.slf4j.Logger\r
+import org.slf4j.LoggerFactory\r
+import reactor.core.publisher.Mono\r
 import java.io.File\r
 import java.io.Serializable\r
 import java.nio.charset.Charset\r
@@ -35,25 +40,27 @@ import java.nio.charset.Charset
 interface BluePrintRepoService : Serializable {\r
 \r
     @Throws(BluePrintException::class)\r
-    fun getNodeType(nodeTypeName: String): NodeType?\r
+    fun getNodeType(nodeTypeName: String): Mono<NodeType>?\r
 \r
     @Throws(BluePrintException::class)\r
-    fun getDataType(dataTypeName: String): DataType?\r
+    fun getDataType(dataTypeName: String): Mono<DataType>?\r
 \r
     @Throws(BluePrintException::class)\r
-    fun getArtifactType(artifactTypeName: String): ArtifactType?\r
+    fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>?\r
 \r
     @Throws(BluePrintException::class)\r
-    fun getRelationshipType(relationshipTypeName: String): RelationshipType?\r
+    fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>?\r
 \r
     @Throws(BluePrintException::class)\r
-    fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition?\r
+    fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>?\r
 \r
 }\r
 \r
 \r
 class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService {\r
 \r
+    private val log: Logger = LoggerFactory.getLogger(BluePrintRepoFileService::class.java)\r
+\r
     val dataTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)\r
     val nodeTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE)\r
     val artifactTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE)\r
@@ -61,33 +68,47 @@ class BluePrintRepoFileService(val basePath: String) : BluePrintRepoService {
     val relationshipTypePath = basePath.plus(BluePrintConstants.PATH_DIVIDER).plus(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE)\r
     val extension = ".json"\r
 \r
-    override fun getDataType(dataTypeName: String): DataType? {\r
-        val content = FileUtils.readFileToString(File(dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
-                .plus(dataTypeName).plus(extension)), Charset.defaultCharset())\r
-        return JacksonUtils.readValue(content)\r
+    override fun getDataType(dataTypeName: String): Mono<DataType>? {\r
+        val fileName = dataTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
+                .plus(dataTypeName).plus(extension)\r
+        return getModelType(fileName, DataType::class.java)\r
+    }\r
+\r
+    override fun getNodeType(nodeTypeName: String): Mono<NodeType>? {\r
+        val fileName = nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER).plus(nodeTypeName).plus(extension)\r
+        return getModelType(fileName, NodeType::class.java)\r
     }\r
 \r
-    override fun getNodeType(nodeTypeName: String): NodeType? {\r
-        val content = FileUtils.readFileToString(File(nodeTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
-                .plus(nodeTypeName).plus(extension)), Charset.defaultCharset())\r
-        return JacksonUtils.readValue(content)\r
+    override fun getArtifactType(artifactTypeName: String): Mono<ArtifactType>? {\r
+        val fileName = artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
+                .plus(artifactTypeName).plus(extension)\r
+        return getModelType(fileName, ArtifactType::class.java)\r
     }\r
 \r
-    override fun getArtifactType(artifactTypeName: String): ArtifactType? {\r
-        val content = FileUtils.readFileToString(File(artifactTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
-                .plus(artifactTypeName).plus(extension)), Charset.defaultCharset())\r
-        return JacksonUtils.readValue(content)\r
+    override fun getRelationshipType(relationshipTypeName: String): Mono<RelationshipType>? {\r
+        val fileName = relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
+                .plus(relationshipTypeName).plus(extension)\r
+        return getModelType(fileName, RelationshipType::class.java)\r
     }\r
 \r
-    override fun getRelationshipType(relationshipTypeName: String): RelationshipType? {\r
-        val content = FileUtils.readFileToString(File(relationshipTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
-                .plus(relationshipTypeName).plus(extension)), Charset.defaultCharset())\r
-        return JacksonUtils.readValue(content)\r
+    override fun getCapabilityDefinition(capabilityDefinitionName: String): Mono<CapabilityDefinition>? {\r
+        val fileName = capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
+                .plus(capabilityDefinitionName).plus(extension)\r
+        return getModelType(fileName, CapabilityDefinition::class.java)\r
+    }\r
+\r
+    private fun <T> getModelType(fileName: String, valueType: Class<T>): Mono<T> {\r
+        return getFileContent(fileName).map { content ->\r
+            Preconditions.checkArgument(StringUtils.isNotBlank(content),\r
+                    String.format("Failed to get model content for file (%s)", fileName))\r
+\r
+            JacksonUtils.readValue(content, valueType)\r
+                    ?: throw BluePrintException(String.format("Failed to get model file from content for file (%s)", fileName))\r
+\r
+        }\r
     }\r
 \r
-    override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition? {\r
-        val content = FileUtils.readFileToString(File(capabilityTypePath.plus(BluePrintConstants.PATH_DIVIDER)\r
-                .plus(capabilityDefinitionName).plus(extension)), Charset.defaultCharset())\r
-        return JacksonUtils.readValue(content)\r
+    private fun getFileContent(fileName: String): Mono<String> {\r
+        return Mono.just(FileUtils.readFileToString(File(fileName), Charset.defaultCharset()))\r
     }\r
 }
\ No newline at end of file
index 574eae6..4731935 100644 (file)
@@ -18,6 +18,7 @@
 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
 \r
 import org.junit.Test\r
+import java.io.FileNotFoundException\r
 import kotlin.test.assertNotNull\r
 \r
 /**\r
@@ -49,4 +50,11 @@ class BluePrintRepoFileServiceTest {
         val nodeType = bluePrintEnhancerRepoFileService.getArtifactType("artifact-template-velocity")\r
         assertNotNull(nodeType, "Failed to get ArtifactType from repo")\r
     }\r
+\r
+    @Test(expected = FileNotFoundException::class)\r
+    fun testModelNotFound() {\r
+        val bluePrintEnhancerRepoFileService = BluePrintRepoFileService(basePath)\r
+        val dataType = bluePrintEnhancerRepoFileService.getDataType("dt-not-found")\r
+        assertNotNull(dataType, "Failed to get DataType from repo")\r
+    }\r
 }
\ No newline at end of file
index cef1f15..5a1e381 100644 (file)
@@ -1,5 +1,6 @@
 /*
  *  Copyright © 2018 IBM.
+ *  Modifications 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.
@@ -46,7 +47,7 @@ open class ResourceDictionaryDefaultValidationService(val bluePrintRepoService:
         resourceDefinition.sources.forEach { (name, nodeTemplate) ->
             val sourceType = nodeTemplate.type
 
-            val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)
+            val sourceNodeType = bluePrintRepoService.getNodeType(sourceType)?.block()
                     ?: throw BluePrintException(format("Failed to get node type definition for source({})", sourceType))
 
             // Validate Property Name, expression, values and Data Type
index c34c252..610e8fc 100644 (file)
@@ -7,7 +7,7 @@
        "resource-path": "action-name",\r
        "resource-type": "ONAP",\r
        "updated-by": "brindasanth@onap.com",\r
-       "tags": null,\r
+       "tags": "action-name, brindasanth",\r
        "sources": {\r
                "input": {\r
                        "type": "source-input",\r
index 349183b..e7e0600 100644 (file)
@@ -7,7 +7,7 @@
   "resource-path": "vnf/v4-ip-type",\r
   "resource-type": "ONAP",\r
   "updated-by": "brindasanth@onap.com",\r
-  "tags": null,\r
+  "tags": "v4-ip-type, source-input, brindasanth",\r
   "sources": {\r
     "input": {\r
       "type": "source-input",\r
index 4a26119..4c11d8c 100644 (file)
@@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;\r
 import org.springframework.stereotype.Service;\r
+import reactor.core.publisher.Mono;\r
 \r
 import java.util.Optional;\r
 \r
@@ -43,59 +44,51 @@ public class BluePrintRepoDBService implements BluePrintRepoService {
         this.modelTypeRepository = modelTypeRepository;\r
     }\r
 \r
-   \r
     @Override\r
-    public NodeType getNodeType(String nodeTypeName) throws BluePrintException {\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing");\r
-        String content = getModelDefinitions(nodeTypeName);\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing");\r
-        return JacksonUtils.readValue(content, NodeType.class);\r
+    public Mono<NodeType> getNodeType(String nodeTypeName) throws BluePrintException {\r
+        return getModelType(nodeTypeName, NodeType.class);\r
     }\r
 \r
-   \r
     @Override\r
-    public DataType getDataType(String dataTypeName) throws BluePrintException {\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing");\r
-        String content = getModelDefinitions(dataTypeName);\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing");\r
-        return JacksonUtils.readValue(content, DataType.class);\r
+    public Mono<DataType> getDataType(String dataTypeName) throws BluePrintException {\r
+        return getModelType(dataTypeName, DataType.class);\r
     }\r
 \r
-   \r
     @Override\r
-    public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException {\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing");\r
-        String content = getModelDefinitions(artifactTypeName);\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing");\r
-        return JacksonUtils.readValue(content, ArtifactType.class);\r
+    public Mono<ArtifactType> getArtifactType(String artifactTypeName) throws BluePrintException {\r
+        return getModelType(artifactTypeName, ArtifactType.class);\r
     }\r
 \r
-   \r
     @Override\r
-    public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException {\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing");\r
-        String content = getModelDefinitions(relationshipTypeName);\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing");\r
-        return JacksonUtils.readValue(content, RelationshipType.class);\r
+    public Mono<RelationshipType> getRelationshipType(String relationshipTypeName) throws BluePrintException {\r
+        return getModelType(relationshipTypeName, RelationshipType.class);\r
     }\r
 \r
-   \r
     @Override\r
-    public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing");\r
-        String content = getModelDefinitions(capabilityDefinitionName);\r
-        Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing");\r
-        return JacksonUtils.readValue(content, CapabilityDefinition.class);\r
+    public Mono<CapabilityDefinition> getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {\r
+        return getModelType(capabilityDefinitionName, CapabilityDefinition.class);\r
     }\r
 \r
-    private String getModelDefinitions(String modelName) throws BluePrintException {\r
+    private <T> Mono<T> getModelType(String modelName, Class<T> valueClass) throws BluePrintException {\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(modelName),\r
+                "Failed to get model from repo, model name is missing");\r
+\r
+        return getModelDefinitions(modelName).map(content -> {\r
+            Preconditions.checkArgument(StringUtils.isNotBlank(content),\r
+                    String.format("Failed to get model content for model name (%s)", modelName));\r
+                    return JacksonUtils.readValue(content, valueClass);\r
+                }\r
+        );\r
+    }\r
+\r
+    private Mono<String> getModelDefinitions(String modelName) throws BluePrintException {\r
         String modelDefinition = null;\r
-        Optional<ModelType> modelTypedb = modelTypeRepository.findByModelName(modelName);\r
-        if (modelTypedb.isPresent()) {\r
-            modelDefinition = modelTypedb.get().getDefinition();\r
+        Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);\r
+        if (modelTypeDb.isPresent()) {\r
+            modelDefinition = modelTypeDb.get().getDefinition();\r
         } else {\r
             throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName));\r
         }\r
-        return modelDefinition;\r
+        return Mono.just(modelDefinition);\r
     }\r
 }\r
index 5420dd3..629b94c 100644 (file)
@@ -17,6 +17,7 @@
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service;\r
 \r
+import com.google.common.base.Preconditions;\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
@@ -112,60 +113,51 @@ public class ResourceDictionaryService {
      */\r
     public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary)\r
             throws BluePrintException {\r
-        if (resourceDictionary != null) {\r
-            ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);\r
-\r
-            ResourceDefinition resourceDefinition =\r
-                    JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
-            // Check the Source already Present\r
-            resourceDictionaryValidationService.validate(resourceDefinition);\r
-\r
-            if (resourceDefinition == null) {\r
-                throw new BluePrintException(\r
-                        "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition());\r
-            }\r
-\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(resourceDefinition, true);\r
-            resourceDictionary.setDefinition(definitionContent);\r
-\r
-            Optional<ResourceDictionary> dbResourceDictionaryData =\r
-                    resourceDictionaryRepository.findByName(resourceDictionary.getName());\r
-            if (dbResourceDictionaryData.isPresent()) {\r
-                ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();\r
-\r
-                dbResourceDictionary.setName(resourceDictionary.getName());\r
-                dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());\r
-                dbResourceDictionary.setDescription(resourceDictionary.getDescription());\r
-                dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());\r
-                dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());\r
-                dbResourceDictionary.setDataType(resourceDictionary.getDataType());\r
-                dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());\r
-                dbResourceDictionary.setTags(resourceDictionary.getTags());\r
-                dbResourceDictionary.setValidValues(resourceDictionary.getValidValues());\r
-                resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);\r
-            } else {\r
-                resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);\r
-            }\r
+        Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()),\r
+                "Resource Dictionary definition information is missing");\r
+\r
+        ResourceDefinition resourceDefinition =\r
+                JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
+        // Validate the Resource Definitions\r
+        resourceDictionaryValidationService.validate(resourceDefinition);\r
+\r
+        resourceDictionary.setResourceType(resourceDefinition.getResourceType());\r
+        resourceDictionary.setResourcePath(resourceDefinition.getResourcePath());\r
+        resourceDictionary.setTags(resourceDefinition.getTags());\r
+        resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());\r
+        // Set the Property Definitions\r
+        PropertyDefinition propertyDefinition = resourceDefinition.getProperty();\r
+        resourceDictionary.setDescription(propertyDefinition.getDescription());\r
+        resourceDictionary.setDataType(propertyDefinition.getType());\r
+        if(propertyDefinition.getEntrySchema() != null){\r
+            resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType());\r
+        }\r
+\r
+        String definitionContent = JacksonUtils.getJson(resourceDefinition, true);\r
+        resourceDictionary.setDefinition(definitionContent);\r
+\r
+        ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);\r
+\r
+        Optional<ResourceDictionary> dbResourceDictionaryData =\r
+                resourceDictionaryRepository.findByName(resourceDictionary.getName());\r
+        if (dbResourceDictionaryData.isPresent()) {\r
+            ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();\r
+\r
+            dbResourceDictionary.setName(resourceDictionary.getName());\r
+            dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());\r
+            dbResourceDictionary.setDescription(resourceDictionary.getDescription());\r
+            dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());\r
+            dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());\r
+            dbResourceDictionary.setTags(resourceDictionary.getTags());\r
+            dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy());\r
+            dbResourceDictionary.setDataType(resourceDictionary.getDataType());\r
+            dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());\r
+            resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);\r
         } else {\r
-            throw new BluePrintException("Resource Dictionary information is missing");\r
+            resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);\r
         }\r
+\r
         return resourceDictionary;\r
     }\r
 \r
index 986ba70..198823b 100644 (file)
@@ -1,5 +1,5 @@
 {\r
-  "name": "v4-aggregat-list",\r
+  "name": "ipaddress",\r
   "property": {\r
     "description": "name of the ",\r
     "type": "list",\r
@@ -10,7 +10,7 @@
   "updated-by": "Brinda Santh (bs2796)",\r
   "resource-type": "ONAP",\r
   "resource-path": "/v4-aggregat-list",\r
-  "tags": null,\r
+  "tags": "ipaddress",\r
   "sources": {\r
     "input": {\r
       "type": "source-input"\r