Python executor parameters sorted again. 83/91183/1
authorOleg Mitsura <oleg.mitsura@amdocs.com>
Wed, 10 Jul 2019 19:48:53 +0000 (15:48 -0400)
committerOleg Mitsura <oleg.mitsura@amdocs.com>
Wed, 10 Jul 2019 19:50:39 +0000 (15:50 -0400)
Issue-ID: CCSDK-1468

Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Change-Id: If8eb50fc2e8dfa084e486b02ace163eee1bfac77

ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt

index c45fb88..fa5d882 100644 (file)
@@ -79,16 +79,8 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
         val argsNode = getOptionalOperationInput(INPUT_ARGUMENT_PROPERTIES)?.returnNullIfMissing()
 
         // This prevents unescaping values, as well as quoting the each parameter, in order to allow for spaces in values
-        var args = ""
-        argsNode?.fields()?.forEach {
-            if (it.value.isValueNode) {
-                args = "$args ${it.value}"
-            } else {
-                it.value.fields().forEach { item ->
-                    args = "$args ${item.value}"
-                }
-            }
-        }
+        val args = getOptionalOperationInput(INPUT_ARGUMENT_PROPERTIES)?.returnNullIfMissing()
+            ?.rootFieldsToMap()?.toSortedMap()?.values?.joinToString(" ") { formatNestedJsonNode(it) }
 
         val command = getOperationInput(INPUT_COMMAND).asText()
         var scriptCommand = command.replace(pythonScript.name, pythonScript.absolutePath)
@@ -141,4 +133,14 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
         bluePrintRuntimeService.getBluePrintError()
                 .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}")
     }
+
+    private fun formatNestedJsonNode(node: JsonNode): String {
+        val sb = StringBuilder()
+        if (node.isValueNode) {
+            sb.append(" $node")
+        } else {
+            node.forEach { sb.append(" $it") }
+        }
+        return sb.toString()
+    }
 }
index ab54f56..596ac79 100644 (file)
@@ -135,7 +135,7 @@ fun JsonNode.returnNullIfMissing(): JsonNode? {
  */
 fun JsonNode.rootFieldsToMap(): MutableMap<String, JsonNode> {
     if (this is ObjectNode) {
-        val propertyMap: MutableMap<String, JsonNode> = hashMapOf()
+        val propertyMap: MutableMap<String, JsonNode> = linkedMapOf()
         this.fields().forEach {
             propertyMap[it.key] = it.value
         }