@Test void emptyGraphFromEmptyModel() { final DmnModelInstance emptyModel = Dmn.createEmptyModel(); final RequirementGraph requirementGraph = RequirementGraph.from(emptyModel); assertTrue(requirementGraph.vertexSet().isEmpty()); assertTrue(requirementGraph.edgeSet().isEmpty()); }
public static RequirementGraph from(final DmnModelInstance dmnModelInstance) throws IllegalArgumentException { final Collection<Decision> decisions = dmnModelInstance.getModelElementsByType(Decision.class); final Collection<KnowledgeSource> knowledgeSources = dmnModelInstance.getModelElementsByType(KnowledgeSource.class); final Collection<InputData> inputData = dmnModelInstance.getModelElementsByType(InputData.class); final RequirementGraph drg = new RequirementGraph(DefaultEdge.class, dmnModelInstance.getDefinitions()); Stream.of(decisions, knowledgeSources, inputData).flatMap(Collection::stream).forEach(drg::addVertex); for (Decision decision : decisions) { decision.getInformationRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); decision.getAuthorityRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); } for (KnowledgeSource knowledgeSource : knowledgeSources) { knowledgeSource.getAuthorityRequirement().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, knowledgeSource)); } return drg; }
RequirementGraph extends DirectedAcyclicGraph<DrgElement, DefaultEdge> { public static RequirementGraph from(final DmnModelInstance dmnModelInstance) throws IllegalArgumentException { final Collection<Decision> decisions = dmnModelInstance.getModelElementsByType(Decision.class); final Collection<KnowledgeSource> knowledgeSources = dmnModelInstance.getModelElementsByType(KnowledgeSource.class); final Collection<InputData> inputData = dmnModelInstance.getModelElementsByType(InputData.class); final RequirementGraph drg = new RequirementGraph(DefaultEdge.class, dmnModelInstance.getDefinitions()); Stream.of(decisions, knowledgeSources, inputData).flatMap(Collection::stream).forEach(drg::addVertex); for (Decision decision : decisions) { decision.getInformationRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); decision.getAuthorityRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); } for (KnowledgeSource knowledgeSource : knowledgeSources) { knowledgeSource.getAuthorityRequirement().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, knowledgeSource)); } return drg; } }
RequirementGraph extends DirectedAcyclicGraph<DrgElement, DefaultEdge> { public static RequirementGraph from(final DmnModelInstance dmnModelInstance) throws IllegalArgumentException { final Collection<Decision> decisions = dmnModelInstance.getModelElementsByType(Decision.class); final Collection<KnowledgeSource> knowledgeSources = dmnModelInstance.getModelElementsByType(KnowledgeSource.class); final Collection<InputData> inputData = dmnModelInstance.getModelElementsByType(InputData.class); final RequirementGraph drg = new RequirementGraph(DefaultEdge.class, dmnModelInstance.getDefinitions()); Stream.of(decisions, knowledgeSources, inputData).flatMap(Collection::stream).forEach(drg::addVertex); for (Decision decision : decisions) { decision.getInformationRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); decision.getAuthorityRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); } for (KnowledgeSource knowledgeSource : knowledgeSources) { knowledgeSource.getAuthorityRequirement().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, knowledgeSource)); } return drg; } RequirementGraph(Class<? extends DefaultEdge> edgeClass, Definitions definitions); }
RequirementGraph extends DirectedAcyclicGraph<DrgElement, DefaultEdge> { public static RequirementGraph from(final DmnModelInstance dmnModelInstance) throws IllegalArgumentException { final Collection<Decision> decisions = dmnModelInstance.getModelElementsByType(Decision.class); final Collection<KnowledgeSource> knowledgeSources = dmnModelInstance.getModelElementsByType(KnowledgeSource.class); final Collection<InputData> inputData = dmnModelInstance.getModelElementsByType(InputData.class); final RequirementGraph drg = new RequirementGraph(DefaultEdge.class, dmnModelInstance.getDefinitions()); Stream.of(decisions, knowledgeSources, inputData).flatMap(Collection::stream).forEach(drg::addVertex); for (Decision decision : decisions) { decision.getInformationRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); decision.getAuthorityRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); } for (KnowledgeSource knowledgeSource : knowledgeSources) { knowledgeSource.getAuthorityRequirement().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, knowledgeSource)); } return drg; } RequirementGraph(Class<? extends DefaultEdge> edgeClass, Definitions definitions); Definitions getDefinitions(); static RequirementGraph from(final DmnModelInstance dmnModelInstance); }
RequirementGraph extends DirectedAcyclicGraph<DrgElement, DefaultEdge> { public static RequirementGraph from(final DmnModelInstance dmnModelInstance) throws IllegalArgumentException { final Collection<Decision> decisions = dmnModelInstance.getModelElementsByType(Decision.class); final Collection<KnowledgeSource> knowledgeSources = dmnModelInstance.getModelElementsByType(KnowledgeSource.class); final Collection<InputData> inputData = dmnModelInstance.getModelElementsByType(InputData.class); final RequirementGraph drg = new RequirementGraph(DefaultEdge.class, dmnModelInstance.getDefinitions()); Stream.of(decisions, knowledgeSources, inputData).flatMap(Collection::stream).forEach(drg::addVertex); for (Decision decision : decisions) { decision.getInformationRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); decision.getAuthorityRequirements().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, decision)); } for (KnowledgeSource knowledgeSource : knowledgeSources) { knowledgeSource.getAuthorityRequirement().stream() .flatMap(RequirementGraph::collectDrgElements) .forEach(drgElement -> drg.addEdge(drgElement, knowledgeSource)); } return drg; } RequirementGraph(Class<? extends DefaultEdge> edgeClass, Definitions definitions); Definitions getDefinitions(); static RequirementGraph from(final DmnModelInstance dmnModelInstance);  }