From 60b2539cd45d4957489862d8915ef75c0dcfd225 Mon Sep 17 00:00:00 2001 From: Praveen kumar A A Date: Fri, 24 May 2024 13:35:48 +0530 Subject: [PATCH 1/6] cslang-prompt --- .../lang/runtime/bindings/InputsBinding.java | 38 ++++++++++++++----- .../steps/ExecutableExecutionData.java | 4 +- .../runtime/bindings/InputsBindingTest.java | 2 +- .../runtime/steps/ExecutableStepsTest.java | 9 +++-- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java index 2dd9468d6e..af8c498d25 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java @@ -57,7 +57,8 @@ public Map bindInputs(List inputs, Set systemProperties, List missingInputs, boolean useEmptyValuesForPrompts, - Map prompts) { + Map prompts, + Boolean isCslangPromptEnabled) { Map resultContext = new LinkedHashMap<>(); // we do not want to change original context map @@ -70,7 +71,7 @@ public Map bindInputs(List inputs, input = overridePromptSettingIfExists(prompts, input); bindInput(input, srcContext, actualPromptContext, resultContext, - systemProperties, missingInputs, useEmptyValuesForPrompts); + systemProperties, missingInputs, useEmptyValuesForPrompts, isCslangPromptEnabled); } return resultContext; @@ -79,7 +80,7 @@ public Map bindInputs(List inputs, private void bindInput(Input input, Map context, Map promptContext, Map targetContext, Set systemProperties, List missingInputs, - boolean useEmptyValuesForPrompts) { + boolean useEmptyValuesForPrompts, Boolean isCslangPromptEnabled) { Value value; String inputName = input.getName(); @@ -104,15 +105,32 @@ private void bindInput(Input input, Map context, } if (input.hasPrompt()) { - if (useEmptyValuesForPrompts) { + if (!isCslangPromptEnabled) { if (isNull(value)) { - value = createEmptyValue(input); + if (useEmptyValuesForPrompts) { + value = createEmptyValue(input); + } + else { + resolvePromptExpressions(input, context, targetContext, systemProperties); + missingInputs.add(createMissingInput(input, value)); + return; + } + } + else if (isEmpty(value)) { + missingInputs.add(input); + return; + } + } + else { + if (useEmptyValuesForPrompts) { + if (isNull(value)) { + value = createEmptyValue(input); + } + } else if (isNull(promptValue)) { + resolvePromptExpressions(input, context, targetContext, systemProperties); + missingInputs.add(createMissingInput(input, value)); + return; } - } else if (isNull(promptValue)) { - resolvePromptExpressions(input, context, targetContext, systemProperties); - - missingInputs.add(createMissingInput(input, value)); - return; } } else if (input.isRequired() && isEmpty(value)) { missingInputs.add(input); diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java index a30f15c6ef..6b3a727bd7 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java @@ -185,6 +185,7 @@ public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) Lis Map magicVariables = magicVariableHelper.getGlobalContext(executionRuntimeServices); List missingInputs = new ArrayList<>(); ReadOnlyContextAccessor context = new ReadOnlyContextAccessor(callArguments, magicVariables); + Boolean isCslangPromptEnabled = executionRuntimeServices.getCslangPromptsEnabledFlag(); Map boundInputValues = inputsBinding.bindInputs( newExecutableInputs, context.getMergedContexts(), @@ -192,7 +193,8 @@ public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) Lis runEnv.getSystemProperties(), missingInputs, isTrue(useEmptyValuesForPrompts), - promptArguments); + promptArguments, + isCslangPromptEnabled); boolean continueToNext = true; if (systemContext.containsKey(ScoreLangConstants.USER_INTERRUPT)) { diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java index 48d8b56f12..7e2012546b 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/bindings/InputsBindingTest.java @@ -515,7 +515,7 @@ private Map bindInputs(List inputs, Map con Map promptArgs, Set systemProperties, List missingInputs) { return inputsBinding.bindInputs(inputs, context, promptArgs, systemProperties, missingInputs, - false, new HashMap<>()); + false, new HashMap<>(), true); } private Map bindInputs(List inputs, Map context) { diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java index 2a2f32b962..d93e68a6a5 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java @@ -138,9 +138,11 @@ public void testStartWithInput() { Map resultMap = new HashMap<>(); resultMap.put("input1", ValueFactory.create(5)); - when(inputsBinding.bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap())) + when(inputsBinding + .bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), true)) .thenReturn(resultMap); - executableSteps.startExecutable(inputs, runEnv, new HashMap(), + executableSteps + .startExecutable(inputs, runEnv, new HashMap(), new ExecutionRuntimeServices(), "", 2L, ExecutableType.FLOW, new SystemContext(), false); Map opVars = runEnv.getStack().popContext().getImmutableViewOfVariables(); @@ -168,7 +170,8 @@ public void testBoundInputEvent() { resultMap.put("input1", ValueFactory.create(inputs.get(0).getValue())); resultMap.put("input2", ValueFactory.create(inputs.get(1).getValue())); - when(inputsBinding.bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap())) + when(inputsBinding + .bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), true)) .thenReturn(resultMap); executableSteps.startExecutable(inputs, runEnv, new HashMap(), runtimeServices, "dockerizeStep", 2L, ExecutableType.FLOW, new SystemContext(), false); From 79dabd72990ca88628388e52dc91aa7268437ca3 Mon Sep 17 00:00:00 2001 From: Praveen kumar A A Date: Thu, 30 May 2024 15:44:09 +0530 Subject: [PATCH 2/6] worked on review comments - logic change for empty values during prompt --- .../lang/runtime/bindings/InputsBinding.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java index af8c498d25..6ebf621f7e 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java @@ -106,22 +106,16 @@ private void bindInput(Input input, Map context, if (input.hasPrompt()) { if (!isCslangPromptEnabled) { - if (isNull(value)) { + if (isNull(value) || isEmpty(value)) { if (useEmptyValuesForPrompts) { value = createEmptyValue(input); - } - else { + } else { resolvePromptExpressions(input, context, targetContext, systemProperties); missingInputs.add(createMissingInput(input, value)); return; } } - else if (isEmpty(value)) { - missingInputs.add(input); - return; - } - } - else { + } else { if (useEmptyValuesForPrompts) { if (isNull(value)) { value = createEmptyValue(input); From 4f51a423a7a884ceab0fb008b75f784f3453a43f Mon Sep 17 00:00:00 2001 From: Praveen kumar A A Date: Thu, 30 May 2024 16:10:41 +0530 Subject: [PATCH 3/6] fixed unit tests --- .../io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java index d93e68a6a5..1649e9546b 100644 --- a/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java +++ b/cloudslang-runtime/src/test/java/io/cloudslang/lang/runtime/steps/ExecutableStepsTest.java @@ -139,7 +139,7 @@ public void testStartWithInput() { resultMap.put("input1", ValueFactory.create(5)); when(inputsBinding - .bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), true)) + .bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), anyBoolean())) .thenReturn(resultMap); executableSteps .startExecutable(inputs, runEnv, new HashMap(), @@ -171,7 +171,7 @@ public void testBoundInputEvent() { resultMap.put("input2", ValueFactory.create(inputs.get(1).getValue())); when(inputsBinding - .bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), true)) + .bindInputs(eq(inputs), anyMap(), anyMap(), anySet(), anyList(), anyBoolean(), anyMap(), anyBoolean())) .thenReturn(resultMap); executableSteps.startExecutable(inputs, runEnv, new HashMap(), runtimeServices, "dockerizeStep", 2L, ExecutableType.FLOW, new SystemContext(), false); From 66e7575a173bd739e7bb9a93c38067567f4c2621 Mon Sep 17 00:00:00 2001 From: Praveen kumar A A Date: Thu, 30 May 2024 20:32:07 +0530 Subject: [PATCH 4/6] use primitive. Avoid Boolean reference type that could introduce nulls. --- .../io/cloudslang/lang/runtime/bindings/InputsBinding.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java index 6ebf621f7e..4ec90ca825 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java @@ -58,7 +58,7 @@ public Map bindInputs(List inputs, List missingInputs, boolean useEmptyValuesForPrompts, Map prompts, - Boolean isCslangPromptEnabled) { + boolean isCslangPromptEnabled) { Map resultContext = new LinkedHashMap<>(); // we do not want to change original context map @@ -80,7 +80,7 @@ public Map bindInputs(List inputs, private void bindInput(Input input, Map context, Map promptContext, Map targetContext, Set systemProperties, List missingInputs, - boolean useEmptyValuesForPrompts, Boolean isCslangPromptEnabled) { + boolean useEmptyValuesForPrompts, boolean isCslangPromptEnabled) { Value value; String inputName = input.getName(); From 33d1cd7618f0aad3f7705f9f6d62a90f6a604c70 Mon Sep 17 00:00:00 2001 From: Praveen kumar A A Date: Fri, 31 May 2024 11:53:38 +0530 Subject: [PATCH 5/6] use primitive. Avoid Boolean reference type that could introduce nulls. --- .../cloudslang/lang/runtime/steps/ExecutableExecutionData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java index 6b3a727bd7..2384412875 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/steps/ExecutableExecutionData.java @@ -185,7 +185,7 @@ public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) Lis Map magicVariables = magicVariableHelper.getGlobalContext(executionRuntimeServices); List missingInputs = new ArrayList<>(); ReadOnlyContextAccessor context = new ReadOnlyContextAccessor(callArguments, magicVariables); - Boolean isCslangPromptEnabled = executionRuntimeServices.getCslangPromptsEnabledFlag(); + boolean isCslangPromptEnabled = executionRuntimeServices.getCslangPromptsEnabledFlag(); Map boundInputValues = inputsBinding.bindInputs( newExecutableInputs, context.getMergedContexts(), From 4e2692e7d98bb7f693eed46ef933b8f891d3626d Mon Sep 17 00:00:00 2001 From: Praveen kumar A A Date: Tue, 4 Jun 2024 09:59:22 +0530 Subject: [PATCH 6/6] implemented the feedback --- .../java/io/cloudslang/lang/runtime/bindings/InputsBinding.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java index 4ec90ca825..26ecdcc7c3 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/InputsBinding.java @@ -109,7 +109,7 @@ private void bindInput(Input input, Map context, if (isNull(value) || isEmpty(value)) { if (useEmptyValuesForPrompts) { value = createEmptyValue(input); - } else { + } else if (isNull(promptValue)) { resolvePromptExpressions(input, context, targetContext, systemProperties); missingInputs.add(createMissingInput(input, value)); return;