feature/use-case-acceptance-tests-2 #117

Merged
hsh-michaelhoennig merged 38 commits from feature/use-case-acceptance-tests-2 into master 2024-11-05 13:58:39 +01:00
Showing only changes of commit 96e740f0d5 - Show all commits

View File

@ -6,6 +6,7 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -121,19 +122,24 @@ public class TemplateResolver {
skipChar('}');
}
private Object propVal(final String name) {
if (name.endsWith(IF_NOT_FOUND_SYMBOL)) {
final String pureName = name.substring(0, name.length() - IF_NOT_FOUND_SYMBOL.length());
private Object propVal(final String nameExpression) {
if (nameExpression.endsWith(IF_NOT_FOUND_SYMBOL)) {
final String pureName = nameExpression.substring(0, nameExpression.length() - IF_NOT_FOUND_SYMBOL.length());
return properties.get(pureName);
} else if (name.contains(IF_NOT_FOUND_SYMBOL)) {
final var parts = StringUtils.split(name, IF_NOT_FOUND_SYMBOL);
final var head = properties.get(parts[0]);
final var tail = properties.get(parts[1]);
return head != null ? head : tail; // FIXME: What if tail is null as well?
} else if (nameExpression.contains(IF_NOT_FOUND_SYMBOL)) {
final var parts = StringUtils.split(nameExpression, IF_NOT_FOUND_SYMBOL);
return Arrays.stream(parts).filter(Objects::nonNull).findFirst().orElseGet(() -> {
if ( parts[parts.length-1].isEmpty() ) {
// => whole expression ends with IF_NOT_FOUND_SYMBOL, thus last null element was optional
return null;
}
// => last alternative element in expression was null and not optional
throw new IllegalStateException("Missing required value in property-chain: " + nameExpression);
});
} else {
final var val = properties.get(name);
final var val = properties.get(nameExpression);
if (val == null) {
throw new IllegalStateException("Missing required property: " + name);
throw new IllegalStateException("Missing required property: " + nameExpression);
}
return val;
}