Skip to content
Snippets Groups Projects
Commit 2bcea534 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add map with all vdmn elements and their ids + Add better navigation through...

Add map with all vdmn elements and their ids + Add better navigation through the vdmn object structure.
parent dc7ea56d
Branches
Tags
No related merge requests found
Showing
with 99 additions and 22 deletions
......@@ -24,4 +24,12 @@ public interface VDmnColumn extends VDmnElement {
default ColumnId getColumnId() {
return (ColumnId) getId();
}
default VDmnDecision getDmnDecision() {
return getDmnDecisionTable().getDmnDecision();
}
default VDmnDefinition getDmnDefinition() {
return getDmnDecisionTable().getDmnDefinition();
}
}
......@@ -5,11 +5,11 @@ import java.util.List;
public interface VDmnDecision extends VDmnNode {
List<VDmnNode> getDmnInformationRequirements();
VDmnDecisionTable getDmnDecisionTable();
default DecisionId getDecisionId() {
return (DecisionId) getId();
}
List<VDmnNode> getInformationRequirements();
VDmnDecisionTable getDmnDecisionTable();
}
......@@ -8,14 +8,10 @@ import org.camunda.bpm.model.dmn.HitPolicy;
public interface VDmnDecisionTable extends VDmnElement {
VDmnDecision getDecision();
VDmnDecision getDmnDecision();
HitPolicy getHitPolicy();
default DecisionTableId getDecisionTableId() {
return (DecisionTableId) getId();
}
List<VDmnOutputColumn> getOutputColumns();
List<VDmnInputColumn> getInputColumns();
......@@ -27,4 +23,12 @@ public interface VDmnDecisionTable extends VDmnElement {
.map(VDmnRule::getRuleId)
.collect(Collectors.toList()); // TODO optimize (e.g. cache)
}
default DecisionTableId getDecisionTableId() {
return (DecisionTableId) getId();
}
default VDmnDefinition getDmnDefinition() {
return getDmnDecision().getDmnDefinition();
}
}
package de.unikoblenz.fgbks.core.dmn.domain.vdmn;
import de.unikoblenz.fgbks.core.dmn.domain.ids.AbstractId;
import de.unikoblenz.fgbks.core.dmn.domain.ids.DefinitionId;
import java.util.List;
......@@ -9,6 +10,8 @@ public interface VDmnDefinition extends VDmnElement {
List<VDmnInputData> getDmnInputData();
VDmnElement getElementById(AbstractId id);
default DefinitionId getDefinitionId() {
return (DefinitionId) getId();
}
......
......@@ -8,13 +8,21 @@ public interface VDmnRule extends VDmnElement {
RowNumber getRowNumber();
default RuleId getRuleId() {
return (RuleId) getId();
}
VDmnDecisionTable getDmnDecisionTable();
List<VDmnInputValue> getDmnInputValues();
List<VDmnOutputValue> getDmnOutputValues();
default RuleId getRuleId() {
return (RuleId) getId();
}
default VDmnDecision getDmnDecision() {
return getDmnDecisionTable().getDmnDecision();
}
default VDmnDefinition getDmnDefinition() {
return getDmnDecision().getDmnDefinition();
}
}
......@@ -26,15 +26,15 @@ public interface VDmnValue extends VDmnElement {
}
default DefinitionId getDefinitionId() {
return getDmnColumn().getDmnDecisionTable().getDecision().getDmnDefinition().getDefinitionId();
return getDmnDefinition().getDefinitionId();
}
default DecisionId getDecisionId() {
return getDmnColumn().getDmnDecisionTable().getDecision().getDecisionId();
return getDmnDecision().getDecisionId();
}
default DecisionTableId getDecisionTableId() {
return getDmnColumn().getDmnDecisionTable().getDecisionTableId();
return getDmnDecisionTable().getDecisionTableId();
}
default VTypeRef getTypeRef() {
......@@ -56,4 +56,16 @@ public interface VDmnValue extends VDmnElement {
default boolean isOutputValue() {
return getDmnColumn() instanceof VDmnOutputColumn;
}
default VDmnDecisionTable getDmnDecisionTable() {
return getDmnColumn().getDmnDecisionTable();
}
default VDmnDecision getDmnDecision() {
return getDmnDecisionTable().getDmnDecision();
}
default VDmnDefinition getDmnDefinition() {
return getDmnDecision().getDmnDefinition();
}
}
......@@ -11,6 +11,4 @@ public abstract class AbstractVDmnElement implements VDmnElement {
public AbstractId getId() {
return id;
}
// TODO: add tostring
}
......@@ -22,7 +22,7 @@ public class VDmnDecisionImpl extends AbstractVDmnNode implements VDmnDecision {
}
@Override
public List<VDmnNode> getInformationRequirements() {
public List<VDmnNode> getDmnInformationRequirements() {
return Collections.unmodifiableList(informationRequirements);
}
......
......@@ -27,7 +27,7 @@ public class VDmnDecisionTableImpl extends AbstractVDmnElement implements VDmnDe
}
@Override
public VDmnDecision getDecision() {
public VDmnDecision getDmnDecision() {
return dmnDecision;
}
......
package de.unikoblenz.fgbks.core.dmn.domain.vdmn.impl;
import de.unikoblenz.fgbks.core.dmn.domain.ids.AbstractId;
import de.unikoblenz.fgbks.core.dmn.domain.ids.DefinitionId;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnDecision;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnDecisionTable;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnDefinition;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnElement;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnInputData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.Validate;
public class VDmnDefinitionImpl extends AbstractVDmnElement implements VDmnDefinition {
private List<VDmnDecision> dmnDecisions;
private List<VDmnInputData> dmnInputData;
private Map<AbstractId, VDmnElement> elements;
private VDmnDefinitionImpl() {
dmnDecisions = new ArrayList<>();
dmnInputData = new ArrayList<>();
elements = new HashMap<>();
}
@Override
......@@ -29,6 +36,11 @@ public class VDmnDefinitionImpl extends AbstractVDmnElement implements VDmnDefin
return Collections.unmodifiableList(dmnInputData);
}
@Override
public VDmnElement getElementById(AbstractId id) {
return elements.get(Validate.notNull(id));
}
public static Builder getBuilder() {
return new VDmnDefinitionImpl().new Builder();
}
......@@ -67,5 +79,37 @@ public class VDmnDefinitionImpl extends AbstractVDmnElement implements VDmnDefin
super.validate();
Validate.notNull(value.id);
}
@Override
public VDmnDefinitionImpl build() {
// save all Ids and elements in the element map
// add the definition
value.elements.put(getId(), this.value);
// add the input data
value.getDmnInputData().forEach(inData -> value.elements.put(inData.getId(), inData));
// add all decisions
for (VDmnDecision decision : value.getDmnDecisions()) {
value.elements.put(decision.getId(), decision);
// add the decision table
VDmnDecisionTable table = decision.getDmnDecisionTable();
value.elements.put(table.getId(), table);
// add columns
table.getInputColumns().forEach(column -> value.elements.put(column.getId(), column));
table
.getInputColumns()
.forEach(column -> value.elements.put(column.getInputExpressionId(), column));
table.getOutputColumns().forEach(column -> value.elements.put(column.getId(), column));
// add rules
table.getRules().forEach(rule -> value.elements.put(rule.getId(), rule));
// add input values/enties
table.getInputColumns().stream()
.flatMap(column -> column.getInputValues().stream())
.forEach(iv -> value.elements.put(iv.getId(), iv));
table.getOutputColumns().stream()
.flatMap(column -> column.getDmnOutputValues().stream())
.forEach(iv -> value.elements.put(iv.getId(), iv));
}
return super.build();
}
}
}
......@@ -39,8 +39,8 @@ public class VerificationResultEntryElement extends AbstractResultObject {
public static VerificationResultEntryElement create(VDmnDecisionTable dmnDecisionTable) {
return new VerificationResultEntryElement()
.withIdentifier(dmnDecisionTable.getDecision().getDmnDefinition().getDefinitionId())
.withIdentifier(dmnDecisionTable.getDecision().getDecisionId())
.withIdentifier(dmnDecisionTable.getDmnDefinition().getDefinitionId())
.withIdentifier(dmnDecisionTable.getDmnDecision().getDecisionId())
.withIdentifier(dmnDecisionTable.getDecisionTableId());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment