Skip to content

Commit e2755ca

Browse files
authored
Merge pull request #134 from imsweb/feature/decision-engine-improvements
DecisionEngine cleanup
2 parents d93d1ec + a077442 commit e2755ca

2 files changed

Lines changed: 291 additions & 14 deletions

File tree

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Map.Entry;
17+
import java.util.Objects;
1718
import java.util.Set;
1819
import java.util.regex.Matcher;
1920
import java.util.regex.Pattern;
@@ -46,16 +47,17 @@ public class DecisionEngine {
4647
// string to use for blank or null in error strings
4748
public static final String _BLANK_OUTPUT = "<blank>";
4849
private static final Pattern _TEMPLATE_REFERENCE = Pattern.compile("\\{\\{(.*?)}}");
49-
private DataProvider _provider;
50+
private final DataProvider _provider;
5051

5152
private static final String _CONTEXT_MISSING_MESSAGE = "Context must not be missing";
5253

5354
/**
5455
* Construct the decision engine with the passed data provider
5556
* @param provider a DataProvider
57+
* @throws NullPointerException if provider is null
5658
*/
5759
public DecisionEngine(DataProvider provider) {
58-
setProvider(provider);
60+
_provider = Objects.requireNonNull(provider, "Provider must not be null");
5961
}
6062

6163
/**
@@ -218,14 +220,6 @@ public DataProvider getProvider() {
218220
return _provider;
219221
}
220222

221-
/**
222-
* Sets the provider and initiaizes all definitions and tables
223-
* @param provider a DataProvider
224-
*/
225-
public void setProvider(DataProvider provider) {
226-
_provider = provider;
227-
}
228-
229223
/**
230224
* Given a mapping and a context, check the inclusion/exclusion tables to see if mapping should be processed
231225
* @param mapping a Mapping
@@ -646,6 +640,10 @@ public Result process(String schemaId, Map<String, String> context) {
646640

647641
/**
648642
* Using the supplied context, process a schema. The results will be added to the context.
643+
* <p>
644+
* Input-mapping destination keys on a table path are temporary aliases scoped to that path. They are added before the path is processed and removed afterward. An input-mapping
645+
* destination must therefore not be used to preserve a pre-existing context value; any previous value with the same key is overwritten and is not restored.
646+
* </p>
649647
* @param schema a schema
650648
* @param context a Map containing the context
651649
* @return a Result
@@ -666,8 +664,10 @@ public Result process(Schema schema, Map<String, String> context) {
666664
String value = context.get(input.getKey());
667665

668666
// 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
669-
if (value == null)
670-
context.put(input.getKey(), getDefault(input, context, result));
667+
if (value == null) {
668+
value = getDefault(input, context, result);
669+
context.put(input.getKey(), value);
670+
}
671671

672672
// validate value against associated table if supplied; if a value is not supplied, or blank, there is no need to validate it against the table
673673
if (value != null && !value.isEmpty() && input.getTable() != null) {
@@ -845,7 +845,7 @@ protected boolean process(String mappingId, String tableId, TablePath path, Resu
845845
for (Endpoint endpoint : endpoints) {
846846
if (EndpointType.STOP.equals(endpoint.getType()))
847847
continueProcessing = false;
848-
else if (EndpointType.JUMP.equals(endpoint.getType()))
848+
else if (EndpointType.JUMP.equals(endpoint.getType()) && continueProcessing)
849849
continueProcessing = process(mappingId, endpoint.getValue(), path, result, stack);
850850
else if (EndpointType.ERROR.equals(endpoint.getType())) {
851851
String message = endpoint.getValue();

0 commit comments

Comments
 (0)