use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths in project kie-wb-common by kiegroup.
the class DecisionServiceConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public org.kie.dmn.model.api.DecisionService dmnFromNode(final Node<View<DecisionService>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final DecisionService source = (DecisionService) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.DecisionService ds = new org.kie.dmn.model.v1_2.TDecisionService();
ds.setId(source.getId().getValue());
ds.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
ds.setName(source.getName().getValue());
final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
if (variable != null) {
variable.setParent(ds);
}
ds.setVariable(variable);
final List<org.kie.dmn.model.api.DMNElementReference> existing_outputDecision = source.getOutputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<org.kie.dmn.model.api.DMNElementReference> existing_encapsulatedDecision = source.getEncapsulatedDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<org.kie.dmn.model.api.DMNElementReference> existing_inputDecision = source.getInputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<org.kie.dmn.model.api.DMNElementReference> existing_inputData = source.getInputData().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<org.kie.dmn.model.api.DMNElementReference> candidate_outputDecision = new ArrayList<>();
final List<org.kie.dmn.model.api.DMNElementReference> candidate_encapsulatedDecision = new ArrayList<>();
final List<org.kie.dmn.model.api.DMNElementReference> candidate_inputDecision = new ArrayList<>();
final List<org.kie.dmn.model.api.DMNElementReference> candidate_inputData = new ArrayList<>();
final List<InputData> reqInputs = new ArrayList<>();
final List<Decision> reqDecisions = new ArrayList<>();
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
for (Edge<?, ?> e : outEdges) {
if (e.getContent() instanceof Child) {
@SuppressWarnings("unchecked") final Node<View<?>, ?> targetNode = e.getTargetNode();
final View<?> targetNodeView = targetNode.getContent();
if (targetNodeView.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) targetNodeView.getDefinition();
if (drgElement instanceof Decision) {
final Decision decision = (Decision) drgElement;
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(new StringBuilder("#").append(decision.getId().getValue()).toString());
if (isOutputDecision(targetNode.getContent(), node.getContent())) {
candidate_outputDecision.add(ri);
} else {
candidate_encapsulatedDecision.add(ri);
}
inspectDecisionForDSReqs(targetNode, reqInputs, reqDecisions);
} else {
throw new UnsupportedOperationException("wrong model definition: a DecisionService is expected to encapsulate only Decision");
}
}
} else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
// this was taken care by the receiving Decision or BKM.
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
reqInputs.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(new StringBuilder("#").append(x.getId().getValue()).toString());
return ri;
}).forEach(candidate_inputData::add);
reqDecisions.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(new StringBuilder("#").append(x.getId().getValue()).toString());
return ri;
}).forEach(candidate_inputDecision::add);
for (org.kie.dmn.model.api.DMNElementReference er : candidate_outputDecision) {
candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
}
for (org.kie.dmn.model.api.DMNElementReference er : candidate_encapsulatedDecision) {
candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
}
reconcileExistingAndCandidate(ds.getInputData(), existing_inputData, candidate_inputData);
reconcileExistingAndCandidate(ds.getInputDecision(), existing_inputDecision, candidate_inputDecision);
reconcileExistingAndCandidate(ds.getEncapsulatedDecision(), existing_encapsulatedDecision, candidate_encapsulatedDecision);
reconcileExistingAndCandidate(ds.getOutputDecision(), existing_outputDecision, candidate_outputDecision);
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, ds);
return ds;
}
Aggregations