Add properties to ResolutionSummary 74/102874/2
authorJozsef Csongvai <jozsef.csongvai@bell.ca>
Tue, 3 Mar 2020 15:08:59 +0000 (10:08 -0500)
committerKAPIL SINGAL <ks220y@att.com>
Tue, 3 Mar 2020 17:26:58 +0000 (17:26 +0000)
Also wrapping ResolutionSummary response to ease integration with SDNC.

Issue-ID: CCSDK-2038
Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
Change-Id: Ic1b8959e22ef795065d37664fb60f100af235a90

ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
ms/blueprintsprocessor/modules/blueprints/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt

index 6922192..7bb757b 100644 (file)
@@ -42,6 +42,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeServ
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.PropertyDefinitionUtils.Companion.hasLogProtect
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.DictionaryMetadataEntry
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResolutionSummary
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
@@ -203,15 +204,22 @@ class ResourceAssignmentUtils {
             resourceDefinitions: Map<String, ResourceDefinition>
         ): String {
             val resolutionSummaryList = resourceAssignments.map {
-                val payload = resourceDefinitions[it.name]
-                        ?.sources?.get(it.dictionarySource)?.properties?.get("resolved-payload")
+                val definition = resourceDefinitions[it.name]
+                val payload = definition?.sources?.get(it.dictionarySource)
+                        ?.properties?.get("resolved-payload")
+                val metadata = definition?.property?.metadata
+                        ?.map { e -> DictionaryMetadataEntry(e.key, e.value) }
+                        ?.toMutableList() ?: mutableListOf()
+                val description = definition?.property?.description
                 ResolutionSummary(
-                        it.name, it.property?.value, it.property?.required,
-                        it.property?.type, it.keyIdentifiers, it.dictionaryName,
-                        payload, it.dictionarySource, it.status, it.message
+                        it.name, it.property?.value, it.property?.required, it.property?.type,
+                        it.keyIdentifiers, description, metadata, it.dictionaryName,
+                        it.dictionarySource, payload, it.status, it.message
                 )
             }
-            return JacksonUtils.getJson(resolutionSummaryList, includeNull = true)
+            // Wrapper needed for integration with SDNC
+            val data = mapOf("resolution-summary" to resolutionSummaryList)
+            return JacksonUtils.getJson(data, includeNull = true)
         }
 
         private fun useDefaultValueIfNull(
index 0a12540..d5c4318 100644 (file)
@@ -256,7 +256,8 @@ class ResourceResolutionServiceTest {
                     props
             )
         }.let {
-            val list = JacksonUtils.getListFromJson(it, ResolutionSummary::class.java)
+            val summaries = JacksonUtils.jsonNode(it)["resolution-summary"]
+            val list = JacksonUtils.getListFromJsonNode(summaries, ResolutionSummary::class.java)
             assertEquals(list.size, 3)
         }
     }
index da3b9c2..9df8fb7 100644 (file)
@@ -167,23 +167,35 @@ class ResourceAssignmentUtilsTest {
             properties = mutableMapOf("resolved-payload" to JacksonUtils.jsonNode("{\"mock\": true}"))
         }
         resourceDefinition.sources = mutableMapOf("input" to nodeTemplate)
+        resourceDefinition.property = PropertyDefinition().apply {
+            this.description = "pnf-id"
+            this.metadata = mutableMapOf("aai-path" to "//path/in/aai")
+        }
 
         val result = ResourceAssignmentUtils.generateResolutionSummaryData(
                 listOf(resourceAssignment), mapOf("pnf-id" to resourceDefinition))
 
         assertEquals("""
-            [{
-                "name":"pnf-id",
-                "value":null,
-                "required":null,
-                "type":"string",
-                "key-identifiers":[],
-                "dictionary-name":"pnf-id",
-                "request-payload":{"mock":true},
-                "dictionary-source":"input",
-                "status":null,
-                "message":null
-            }]
+            {
+                "resolution-summary":[
+                    {
+                        "name":"pnf-id",
+                        "value":null,
+                        "required":null,
+                        "type":"string",
+                        "key-identifiers":[],
+                        "dictionary-description":"pnf-id",
+                        "dictionary-metadata":[
+                            {"name":"aai-path","value":"//path/in/aai"}
+                        ],
+                        "dictionary-name":"pnf-id",
+                        "dictionary-source":"input",
+                        "request-payload":{"mock":true},
+                        "status":null,
+                        "message":null
+                    }
+                ]
+            }
         """.replace("\n|\\s".toRegex(), ""), result)
     }
 
index f34099e..77025c5 100644 (file)
@@ -106,7 +106,7 @@ open class ResourceAssignment {
 }
 
 data class KeyIdentifier(val name: String, val value: JsonNode)
-
+data class DictionaryMetadataEntry(val name: String, val value: String)
 /**
  * Data class for exposing summary of resource resolution
  */
@@ -117,12 +117,16 @@ data class ResolutionSummary(
     val type: String?,
     @JsonProperty("key-identifiers")
     val keyIdentifiers: MutableList<KeyIdentifier>,
+    @JsonProperty("dictionary-description")
+    val dictionaryDescription: String?,
+    @JsonProperty("dictionary-metadata")
+    val dictionaryMetadata: MutableList<DictionaryMetadataEntry>,
     @JsonProperty("dictionary-name")
     val dictionaryName: String?,
-    @JsonProperty("request-payload")
-    val requestPayload: JsonNode?,
     @JsonProperty("dictionary-source")
     val dictionarySource: String?,
+    @JsonProperty("request-payload")
+    val requestPayload: JsonNode?,
     @JsonProperty("status")
     val status: String?,
     @JsonProperty("message")