Skip to content

Commit

Permalink
Merge pull request #1431 from CloudSlang/praveen-prompt
Browse files Browse the repository at this point in the history
CloudSlang Prompts should no longer pop-up to end-users for inputs with value
  • Loading branch information
praveenkumar-aa authored Jun 4, 2024
2 parents 4c6a4e2 + 4e2692e commit 6ea3f58
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public Map<String, Value> bindInputs(List<Input> inputs,
Set<SystemProperty> systemProperties,
List<Input> missingInputs,
boolean useEmptyValuesForPrompts,
Map<String, Prompt> prompts) {
Map<String, Prompt> prompts,
boolean isCslangPromptEnabled) {
Map<String, Value> resultContext = new LinkedHashMap<>();

// we do not want to change original context map
Expand All @@ -70,7 +71,7 @@ public Map<String, Value> bindInputs(List<Input> inputs,
input = overridePromptSettingIfExists(prompts, input);

bindInput(input, srcContext, actualPromptContext, resultContext,
systemProperties, missingInputs, useEmptyValuesForPrompts);
systemProperties, missingInputs, useEmptyValuesForPrompts, isCslangPromptEnabled);
}

return resultContext;
Expand All @@ -79,7 +80,7 @@ public Map<String, Value> bindInputs(List<Input> inputs,
private void bindInput(Input input, Map<String, ? extends Value> context,
Map<String, Value> promptContext, Map<String, Value> targetContext,
Set<SystemProperty> systemProperties, List<Input> missingInputs,
boolean useEmptyValuesForPrompts) {
boolean useEmptyValuesForPrompts, boolean isCslangPromptEnabled) {
Value value;

String inputName = input.getName();
Expand All @@ -104,15 +105,26 @@ private void bindInput(Input input, Map<String, ? extends Value> context,
}

if (input.hasPrompt()) {
if (useEmptyValuesForPrompts) {
if (isNull(value)) {
value = createEmptyValue(input);
if (!isCslangPromptEnabled) {
if (isNull(value) || isEmpty(value)) {
if (useEmptyValuesForPrompts) {
value = createEmptyValue(input);
} else if (isNull(promptValue)) {
resolvePromptExpressions(input, context, targetContext, systemProperties);
missingInputs.add(createMissingInput(input, value));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,16 @@ public void startExecutable(@Param(ScoreLangConstants.EXECUTABLE_INPUTS_KEY) Lis
Map<String, Value> magicVariables = magicVariableHelper.getGlobalContext(executionRuntimeServices);
List<Input> missingInputs = new ArrayList<>();
ReadOnlyContextAccessor context = new ReadOnlyContextAccessor(callArguments, magicVariables);
boolean isCslangPromptEnabled = executionRuntimeServices.getCslangPromptsEnabledFlag();
Map<String, Value> boundInputValues = inputsBinding.bindInputs(
newExecutableInputs,
context.getMergedContexts(),
promptedValues,
runEnv.getSystemProperties(),
missingInputs,
isTrue(useEmptyValuesForPrompts),
promptArguments);
promptArguments,
isCslangPromptEnabled);

boolean continueToNext = true;
if (systemContext.containsKey(ScoreLangConstants.USER_INTERRUPT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private Map<String, Value> bindInputs(List<Input> inputs, Map<String, Value> con
Map<String, Value> promptArgs,
Set<SystemProperty> systemProperties, List<Input> missingInputs) {
return inputsBinding.bindInputs(inputs, context, promptArgs, systemProperties, missingInputs,
false, new HashMap<>());
false, new HashMap<>(), true);
}

private Map<String, Value> bindInputs(List<Input> inputs, Map<String, Value> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ public void testStartWithInput() {
Map<String, Value> 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(), anyBoolean()))
.thenReturn(resultMap);
executableSteps.startExecutable(inputs, runEnv, new HashMap<String, Value>(),
executableSteps
.startExecutable(inputs, runEnv, new HashMap<String, Value>(),
new ExecutionRuntimeServices(), "", 2L, ExecutableType.FLOW, new SystemContext(), false);

Map<String, Value> opVars = runEnv.getStack().popContext().getImmutableViewOfVariables();
Expand Down Expand Up @@ -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(), anyBoolean()))
.thenReturn(resultMap);
executableSteps.startExecutable(inputs, runEnv, new HashMap<String, Value>(),
runtimeServices, "dockerizeStep", 2L, ExecutableType.FLOW, new SystemContext(), false);
Expand Down

0 comments on commit 6ea3f58

Please sign in to comment.