use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNDocumentationDRDsFactory method createDMNDocumentationDRDs.
private List<DMNDocumentationDRD> createDMNDocumentationDRDs(final Diagram diagram) {
final List<DMNDocumentationDRD> dmnDocumentationDRDS = new ArrayList<>();
getNodeStream(diagram).forEach(node -> {
final Object definition = DefinitionUtils.getElementDefinition(node);
if (definition instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) definition;
dmnDocumentationDRDS.add(createDMNDocumentationDRD(diagram, node, drgElement));
}
});
return dmnDocumentationDRDS;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DecisionConverter method dmnFromNode.
@Override
public org.kie.dmn.model.api.Decision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.Decision d = new org.kie.dmn.model.v1_2.TDecision();
d.setId(source.getId().getValue());
d.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
d.setName(source.getName().getValue());
final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
if (variable != null) {
variable.setParent(d);
}
d.setVariable(variable);
final org.kie.dmn.model.api.Expression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
if (expression != null) {
expression.setParent(d);
}
d.setExpression(expression);
d.setQuestion(QuestionPropertyConverter.dmnFromWB(source.getQuestion()));
d.setAllowedAnswers(AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers()));
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredDecision(ri);
d.getInformationRequirement().add(iReq);
} else if (drgElement instanceof BusinessKnowledgeModel) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.getKnowledgeRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
d.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredInput(ri);
d.getInformationRequirement().add(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof Child) {
// Stunner relationship of this Decision be encapsulated by the DecisionService, not managed here.
} else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.getKnowledgeRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, d);
return d;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement 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;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class AssociationConverter method dmnFromWB.
@SuppressWarnings("unchecked")
public static List<JSITAssociation> dmnFromWB(final Node<View<TextAnnotation>, ?> node) {
final TextAnnotation ta = (TextAnnotation) DefinitionUtils.getElementDefinition(node);
final JSITDMNElementReference ta_elementReference = new JSITDMNElementReference();
ta_elementReference.setHref("#" + ta.getId().getValue());
final List<JSITAssociation> result = new ArrayList<>();
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
final JSITDMNElementReference sourceRef = new JSITDMNElementReference();
sourceRef.setHref(getHref(drgElement));
final JSITAssociation adding = new JSITAssociation();
adding.setId(((View<Association>) e.getContent()).getDefinition().getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(((View<Association>) e.getContent()).getDefinition().getDescription()));
description.ifPresent(adding::setDescription);
adding.setSourceRef(sourceRef);
adding.setTargetRef(ta_elementReference);
adding.setAssociationDirection(Js.uncheckedCast(JSITAssociationDirection.NONE.value()));
result.add(adding);
}
}
}
final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
for (Edge<?, ?> e : outEdges) {
final Node<?, ?> targetNode = e.getTargetNode();
if (targetNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) targetNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
final JSITDMNElementReference targetRef = new JSITDMNElementReference();
targetRef.setHref(getHref(drgElement));
final JSITAssociation adding = new JSITAssociation();
adding.setId(((View<Association>) e.getContent()).getDefinition().getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(((View<Association>) e.getContent()).getDefinition().getDescription()));
description.ifPresent(adding::setDescription);
adding.setSourceRef(ta_elementReference);
adding.setTargetRef(targetRef);
adding.setAssociationDirection(Js.uncheckedCast(JSITAssociationDirection.NONE.value()));
result.add(adding);
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DecisionServiceParametersListWidget method refresh.
void refresh() {
clear();
final Node node = getNode(getValue().getDecisionService().getContentDefinitionId());
final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
final List<InputData> inputs = new ArrayList<>();
outEdges.stream().filter(e -> e.getContent() instanceof Child).forEach(e -> getTargetDRGElement(e).ifPresent(drgElement -> {
final Node<View<?>, ?> targetNode = e.getTargetNode();
loadDecisionsFromNode(node, targetNode);
loadInputsFromNode(inputs, targetNode);
loadInputsFromOthersDiagrams(inputs, targetNode);
}));
loadInputsParameters(getSortedInputs(inputs));
loadGroupsElements();
}
Aggregations