use of org.apache.zeppelin.display.ui.OptionInput in project zeppelin by apache.
the class Input method getSimpleQuery.
public static String getSimpleQuery(Map<String, Object> params, String script, boolean noteForm) {
String replaced = script;
Pattern pattern = noteForm ? VAR_NOTE_PTN : VAR_PTN;
Matcher match = pattern.matcher(replaced);
while (match.find()) {
int first = match.start();
if (!noteForm && first > 0 && replaced.charAt(first - 1) == '$') {
continue;
}
Input input = getInputForm(match);
Object value;
if (params.containsKey(input.name)) {
value = params.get(input.name);
} else {
value = input.getDefaultValue();
}
String expanded;
if (value instanceof Object[] || value instanceof Collection) {
// multi-selection
OptionInput optionInput = (OptionInput) input;
String delimiter = input.argument;
if (delimiter == null) {
delimiter = DEFAULT_DELIMITER;
}
Collection<Object> checked = value instanceof Collection ? (Collection<Object>) value : Arrays.asList((Object[]) value);
List<Object> validChecked = new LinkedList<>();
for (Object o : checked) {
// filter out obsolete checked values
if (optionInput.getOptions() != null) {
for (ParamOption option : optionInput.getOptions()) {
if (option.getValue().equals(o)) {
validChecked.add(o);
break;
}
}
}
}
if (validChecked.isEmpty()) {
expanded = StringUtils.join(checked, delimiter);
} else {
params.put(input.name, validChecked);
expanded = StringUtils.join(validChecked, delimiter);
}
} else {
// single-selection
expanded = StringUtils.defaultString((String) value, "");
}
replaced = match.replaceFirst(expanded);
match = pattern.matcher(replaced);
}
return replaced;
}
Aggregations