use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DecisionConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITDecision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
final JSITDecision d = new JSITDecision();
d.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(d::setDescription);
d.setName(source.getName().getValue());
final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
d.setVariable(variable);
final JSITExpression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
d.setExpression(expression);
final String question = QuestionPropertyConverter.dmnFromWB(source.getQuestion());
if (!StringUtils.isEmpty(question)) {
d.setQuestion(question);
}
final String allowedAnswers = AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers());
if (!StringUtils.isEmpty(allowedAnswers)) {
d.setAllowedAnswers(allowedAnswers);
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(d.getInformationRequirement())) {
d.setInformationRequirement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(d.getKnowledgeRequirement())) {
d.setKnowledgeRequirement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(d.getAuthorityRequirement())) {
d.setAuthorityRequirement(new ArrayList<>());
}
// 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 JSITInformationRequirement iReq = new JSITInformationRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredDecision(ri);
d.addInformationRequirement(iReq);
} else if (drgElement instanceof BusinessKnowledgeModel) {
final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.addKnowledgeRequirement(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
d.addAuthorityRequirement(iReq);
} else if (drgElement instanceof InputData) {
final JSITInformationRequirement iReq = new JSITInformationRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredInput(ri);
d.addInformationRequirement(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 JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
d.addKnowledgeRequirement(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.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method setInformationItem.
private void setInformationItem(final JSITDRGElement drgElement, final JSITInformationItem informationItem) {
if (JSITDecision.instanceOf(drgElement)) {
final JSITDecision decision = Js.uncheckedCast(drgElement);
decision.setVariable(informationItem);
} else if (JSITInputData.instanceOf(drgElement)) {
final JSITInputData inputData = Js.uncheckedCast(drgElement);
inputData.setVariable(informationItem);
} else if (JSITInvocable.instanceOf(drgElement)) {
final JSITInvocable invocable = Js.uncheckedCast(drgElement);
invocable.setVariable(informationItem);
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method getInformationItem.
private Optional<JSITInformationItem> getInformationItem(final JSITDRGElement drgElement) {
final JSITInformationItem variable;
if (JSITDecision.instanceOf(drgElement)) {
final JSITDecision decision = Js.uncheckedCast(drgElement);
variable = Js.uncheckedCast(decision.getVariable());
} else if (JSITInputData.instanceOf(drgElement)) {
final JSITInputData inputData = Js.uncheckedCast(drgElement);
variable = Js.uncheckedCast(inputData.getVariable());
} else if (JSITInvocable.instanceOf(drgElement)) {
final JSITInvocable invocable = Js.uncheckedCast(drgElement);
variable = Js.uncheckedCast(invocable.getVariable());
} else {
return Optional.empty();
}
return Optional.of(variable);
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class DMNMarshaller method mergeNodeRequirements.
void mergeNodeRequirements(final JSITDRGElement node, final JSITDRGElement existingDRGElement) {
if (instanceOfBusinessKnowledgeModel(node)) {
final JSITBusinessKnowledgeModel existingBkm = Js.uncheckedCast(existingDRGElement);
final JSITBusinessKnowledgeModel nodeBkm = Js.uncheckedCast(node);
existingBkm.setAuthorityRequirement(distinct(nodeBkm.getAuthorityRequirement(), existingBkm.getAuthorityRequirement()));
existingBkm.setKnowledgeRequirement(distinct(nodeBkm.getKnowledgeRequirement(), existingBkm.getKnowledgeRequirement()));
} else if (instanceOfDecision(node)) {
final JSITDecision existingDecision = Js.uncheckedCast(existingDRGElement);
final JSITDecision nodeDecision = Js.uncheckedCast(node);
existingDecision.setAuthorityRequirement(distinct(nodeDecision.getAuthorityRequirement(), existingDecision.getAuthorityRequirement()));
existingDecision.setInformationRequirement(distinct(nodeDecision.getInformationRequirement(), existingDecision.getInformationRequirement()));
existingDecision.setKnowledgeRequirement(distinct(nodeDecision.getKnowledgeRequirement(), existingDecision.getKnowledgeRequirement()));
} else if (instanceOfKnowledgeSource(node)) {
final JSITKnowledgeSource existingKnowledgeSource = Js.uncheckedCast(existingDRGElement);
final JSITKnowledgeSource nodeKnowledgeSource = Js.uncheckedCast(node);
existingKnowledgeSource.setAuthorityRequirement(distinct(nodeKnowledgeSource.getAuthorityRequirement(), existingKnowledgeSource.getAuthorityRequirement()));
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision in project kie-wb-common by kiegroup.
the class NodeConnector method connect.
void connect(final JSIDMNDiagram dmnDiagram, final List<JSIDMNEdge> edges, final List<JSITAssociation> associations, final List<NodeEntry> nodeEntries, final boolean isDMNDIPresent) {
final Map<String, List<NodeEntry>> entriesById = makeNodeIndex(nodeEntries);
final String diagramId = dmnDiagram.getId();
for (final NodeEntry nodeEntry : nodeEntries) {
final JSITDMNElement element = nodeEntry.getDmnElement();
final Node node = nodeEntry.getNode();
// For imported nodes, we don't have its connections
if (nodeEntry.isIncluded()) {
continue;
}
// DMN spec table 2: Requirements
if (JSITDecision.instanceOf(element)) {
final JSITDecision decision = Js.uncheckedCast(element);
final List<JSITInformationRequirement> jsiInformationRequirements = decision.getInformationRequirement();
for (int i = 0; i < jsiInformationRequirements.size(); i++) {
final JSITInformationRequirement ir = Js.uncheckedCast(jsiInformationRequirements.get(i));
connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), entriesById, diagramId, edges, isDMNDIPresent, node);
connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), entriesById, diagramId, edges, isDMNDIPresent, node);
}
final List<JSITKnowledgeRequirement> jsiKnowledgeRequirements = decision.getKnowledgeRequirement();
for (int i = 0; i < jsiKnowledgeRequirements.size(); i++) {
final JSITKnowledgeRequirement kr = Js.uncheckedCast(jsiKnowledgeRequirements.get(i));
connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), entriesById, diagramId, edges, isDMNDIPresent, node);
}
final List<JSITAuthorityRequirement> jsiAuthorityRequirements = decision.getAuthorityRequirement();
for (int i = 0; i < jsiAuthorityRequirements.size(); i++) {
final JSITAuthorityRequirement ar = Js.uncheckedCast(jsiAuthorityRequirements.get(i));
connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), entriesById, diagramId, edges, isDMNDIPresent, node);
}
continue;
}
if (JSITBusinessKnowledgeModel.instanceOf(element)) {
final JSITBusinessKnowledgeModel bkm = Js.uncheckedCast(element);
final List<JSITKnowledgeRequirement> jsiKnowledgeRequirements = bkm.getKnowledgeRequirement();
for (int i = 0; i < jsiKnowledgeRequirements.size(); i++) {
final JSITKnowledgeRequirement kr = Js.uncheckedCast(jsiKnowledgeRequirements.get(i));
connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), entriesById, diagramId, edges, isDMNDIPresent, node);
}
final List<JSITAuthorityRequirement> jsiAuthorityRequirements = bkm.getAuthorityRequirement();
for (int i = 0; i < jsiAuthorityRequirements.size(); i++) {
final JSITAuthorityRequirement ar = Js.uncheckedCast(jsiAuthorityRequirements.get(i));
connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), entriesById, diagramId, edges, isDMNDIPresent, node);
}
continue;
}
if (JSITKnowledgeSource.instanceOf(element)) {
final JSITKnowledgeSource ks = Js.uncheckedCast(element);
final List<JSITAuthorityRequirement> jsiAuthorityRequirements = ks.getAuthorityRequirement();
for (int i = 0; i < jsiAuthorityRequirements.size(); i++) {
final JSITAuthorityRequirement ar = Js.uncheckedCast(jsiAuthorityRequirements.get(i));
connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), entriesById, diagramId, edges, isDMNDIPresent, node);
connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), entriesById, diagramId, edges, isDMNDIPresent, node);
connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), entriesById, diagramId, edges, isDMNDIPresent, node);
}
continue;
}
if (JSITDecisionService.instanceOf(element)) {
final JSITDecisionService ds = Js.uncheckedCast(element);
final List<JSITDMNElementReference> encapsulatedDecisions = ds.getEncapsulatedDecision();
forEach(encapsulatedDecisions, er -> {
final String reqInputID = getId(er);
getNode(nodeEntry, reqInputID, entriesById).ifPresent(requiredNode -> {
connectDSChildEdge(node, requiredNode);
});
});
final List<JSITDMNElementReference> outputDecisions = ds.getOutputDecision();
forEach(outputDecisions, er -> {
final String reqInputID = getId(er);
getNode(nodeEntry, reqInputID, entriesById).ifPresent(requiredNode -> {
connectDSChildEdge(node, requiredNode);
});
});
}
}
forEach(associations, association -> {
final String sourceId = getId(association.getSourceRef());
final String targetId = getId(association.getTargetRef());
final List<NodeEntry> source = entriesById.get(sourceId);
final List<NodeEntry> target = entriesById.get(targetId);
final boolean sourcePresent = source != null && source.size() > 0;
final boolean targetPresent = target != null && target.size() > 0;
if (sourcePresent && targetPresent) {
final NodeEntry sourceEntry = source.get(0);
final NodeEntry targetEntry = target.get(0);
final Node sourceNode = sourceEntry.getNode();
final Node targetNode = targetEntry.getNode();
@SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(diagramId + "#" + association.getId(), ASSOCIATION_ID).asEdge();
final ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
final Id id = new Id(association.getId());
final Description description = new Description(association.getDescription());
final Association definition = new Association(id, description);
connectEdge(myEdge, sourceNode, targetNode);
connectionContent.setDefinition(definition);
connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(targetNode));
connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(sourceNode));
}
});
}
Aggregations