-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DROOLS-1663 Kie DMN doesn't support IMPORT decisions between DMN files (
#1832) * WIP * WIP types * Hardcoded dependency ordering but fixes compilation errors. * With hardcoded dependency order, and hardcoded import, working execution * . * Dependency sorter * import ItemDefinition and BKM from the located import model * . * Refactoring * . * . * Guarding for DMN importType namespace only * Externalize ResourceWithConfiguration interface * Use wide type Collection for collection of resources * Applying PR comments
- Loading branch information
1 parent
03c8c8c
commit aaf8483
Showing
23 changed files
with
772 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,8 @@ public interface DMNNode { | |
|
||
String getName(); | ||
|
||
String getModelNamespace(); | ||
|
||
String getModelName(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/assembler/DMNResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.kie.dmn.core.assembler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.xml.namespace.QName; | ||
|
||
import org.kie.api.io.ResourceWithConfiguration; | ||
import org.kie.dmn.model.v1_1.Definitions; | ||
|
||
public class DMNResource { | ||
|
||
private final QName modelID; | ||
private final ResourceWithConfiguration resAndConfig; | ||
private final Definitions definitions; | ||
private final List<QName> dependencies = new ArrayList<>(); | ||
|
||
public DMNResource(QName modelID, ResourceWithConfiguration resAndConfig, Definitions definitions) { | ||
this.modelID = modelID; | ||
this.resAndConfig = resAndConfig; | ||
this.definitions = definitions; | ||
} | ||
|
||
public QName getModelID() { | ||
return modelID; | ||
} | ||
|
||
public ResourceWithConfiguration getResAndConfig() { | ||
return resAndConfig; | ||
} | ||
|
||
public Definitions getDefinitions() { | ||
return definitions; | ||
} | ||
|
||
public void addDependency(QName dep) { | ||
this.dependencies.add(dep); | ||
} | ||
|
||
public void addDependencies(List<QName> deps) { | ||
this.dependencies.addAll(deps); | ||
} | ||
|
||
public List<QName> getDependencies() { | ||
return dependencies; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DMNResource [modelID=" + modelID + ", resource=" + resAndConfig.getResource().getSourcePath() + "]"; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../kie-dmn-core/src/main/java/org/kie/dmn/core/assembler/DMNResourceDependenciesSorter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.kie.dmn.core.assembler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class DMNResourceDependenciesSorter { | ||
|
||
/** | ||
* Return a new list of DMNResource sorted by dependencies (required dependencies comes first) | ||
*/ | ||
public static List<DMNResource> sort(List<DMNResource> ins) { | ||
// In a graph A -> B -> {C, D} | ||
// showing that A requires B, and B requires C,D | ||
// then a depth-first visit would satisfy required ordering, for example a valid depth first visit is also a valid sort here: C, D, B, A. | ||
Collection<DMNResource> visited = new ArrayList<>(ins.size()); | ||
List<DMNResource> dfv = new ArrayList<>(ins.size()); | ||
|
||
for (DMNResource node : ins) { | ||
if (!visited.contains(node)) { | ||
dfVisit(node, ins, visited, dfv); | ||
} | ||
} | ||
|
||
return dfv; | ||
} | ||
|
||
/** | ||
* Performs a depth first visit, but keeping a separate reference of visited/visiting nodes, _also_ to avoid potential issues of circularities. | ||
*/ | ||
private static void dfVisit(DMNResource node, List<DMNResource> allNodes, Collection<DMNResource> visited, List<DMNResource> dfv) { | ||
if (visited.contains(node)) { | ||
throw new RuntimeException("Circular dependency detected: " + visited + " , and again to: " + node); | ||
} | ||
visited.add(node); | ||
|
||
List<DMNResource> neighbours = node.getDependencies().stream() | ||
.flatMap(dep -> allNodes.stream().filter(r -> r.getModelID().equals(dep))) | ||
.collect(Collectors.toList()); | ||
for (DMNResource n : neighbours) { | ||
if (!visited.contains(n)) { | ||
dfVisit(n, allNodes, visited, dfv); | ||
} | ||
} | ||
|
||
dfv.add(node); | ||
} | ||
} |
Oops, something went wrong.