Skip to content

Commit c109751

Browse files
committed
Support for default_table (#117)
Missing tests still
1 parent e2207ac commit c109751

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

lib/src/main/java/com/imsweb/staging/engine/DecisionEngine.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ public Result process(Schema schema, Map<String, String> context) {
621621

622622
// if value not supplied, use the default or defaultTable and set it back into the context; if not supplied and no default, set the input the blank
623623
if (value == null) {
624+
value = "";
624625
if (input.getDefault() != null)
625626
value = translateValue(input.getDefault(), context);
626627
else if (input.getDefaultTable() != null) {
@@ -630,12 +631,26 @@ else if (input.getDefaultTable() != null) {
630631
continue;
631632
}
632633

633-
// lookup default from table
634+
// look up default value from table
634635
List<? extends Endpoint> endpoints = matchTable(defaultTable, context);
635-
value = "";
636+
if (endpoints != null) {
637+
value = endpoints.stream()
638+
.filter(endpoint -> EndpointType.VALUE.equals(endpoint.getType()))
639+
.filter(endpoint -> endpoint.getResultKey().equals(input.getKey()))
640+
.map(endpoint -> translateValue(endpoint.getValue(), context))
641+
.findFirst()
642+
.orElse(null);
643+
}
644+
645+
if (value == null) {
646+
result.addError(new ErrorBuilder(Type.MATCH_NOT_FOUND)
647+
.message("Default table " + input.getDefaultTable() + " did not find a match")
648+
.key(input.getKey())
649+
.build());
650+
continue;
651+
}
652+
636653
}
637-
else
638-
value = "";
639654

640655
context.put(input.getKey(), value);
641656
}

0 commit comments

Comments
 (0)