use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNUnmarshaller method unmarshall.
private Promise<Graph> unmarshall(final Metadata metadata, final JSITDefinitions dmnDefinitions, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>();
final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
if (Objects.nonNull(uuid)) {
hasComponentWidthsMap.put(uuid, hcw);
}
};
// Check before the DRG creation ('ensureDRGElementExists').
final boolean isDMNDIPresent = Optional.ofNullable(dmnDefinitions.getDMNDI()).isPresent();
ensureDRGElementExists(dmnDefinitions);
final Definitions wbDefinitions = DefinitionsConverter.wbFromDMN(dmnDefinitions, importDefinitions, pmmlDocuments);
final List<NodeEntry> nodeEntries = modelToStunnerConverter.makeNodes(dmnDefinitions, importDefinitions, isDMNDIPresent, hasComponentWidthsConsumer);
final List<JSITDecisionService> dmnDecisionServices = getDecisionServices(nodeEntries);
// Ensure all locations are updated to relative for Stunner
nodeEntries.forEach(e -> PointUtils.convertToRelativeBounds(e.getNode()));
final Map<String, Diagram> stunnerDiagramsById = new HashMap<>();
final Map<String, DMNDiagramElement> dmnDiagramsById = new HashMap<>();
for (final DMNDiagramElement dmnDiagramElement : wbDefinitions.getDiagramElements()) {
final String dmnDiagramId = dmnDiagramElement.getId().getValue();
final Diagram value = factoryManager.newDiagram(dmnDiagramId, BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata);
stunnerDiagramsById.put(dmnDiagramId, value);
dmnDiagramsById.put(dmnDiagramId, dmnDiagramElement);
}
final DMNDiagramsSessionState state = dmnDiagramsSession.setState(metadata, stunnerDiagramsById, dmnDiagramsById);
nodeEntries.forEach(nodeEntry -> {
final String diagramId = nodeEntry.getDiagramId();
final Graph graph = stunnerDiagramsById.get(diagramId).getGraph();
graph.addNode(nodeEntry.getNode());
});
final Graph drgGraph = state.getDRGDiagram().getGraph();
loadImportedItemDefinitions(wbDefinitions, importDefinitions);
for (final Diagram value : stunnerDiagramsById.values()) {
final Node<?, ?> dmnDiagramRoot = DMNGraphUtils.findDMNDiagramRoot(value.getGraph());
((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(wbDefinitions);
nodeEntries.forEach(nodeEntry -> {
if (Objects.equals(stunnerDiagramsById.get(nodeEntry.getDiagramId()), value)) {
connectRootWithChild(dmnDiagramRoot, nodeEntry.getNode());
}
});
}
// Only connect Nodes to the Diagram that are not referenced by DecisionServices
final List<String> references = new ArrayList<>();
final List<JSITDecisionService> lstDecisionServices = new ArrayList<>(dmnDecisionServices);
for (int iDS = 0; iDS < lstDecisionServices.size(); iDS++) {
final JSITDecisionService jsiDecisionService = Js.uncheckedCast(lstDecisionServices.get(iDS));
final List<JSITDMNElementReference> jsiEncapsulatedDecisions = jsiDecisionService.getEncapsulatedDecision();
if (Objects.nonNull(jsiEncapsulatedDecisions)) {
for (int i = 0; i < jsiEncapsulatedDecisions.size(); i++) {
final JSITDMNElementReference jsiEncapsulatedDecision = Js.uncheckedCast(jsiEncapsulatedDecisions.get(i));
references.add(jsiEncapsulatedDecision.getHref());
}
}
final List<JSITDMNElementReference> jsiOutputDecisions = jsiDecisionService.getOutputDecision();
if (Objects.nonNull(jsiOutputDecisions)) {
for (int i = 0; i < jsiOutputDecisions.size(); i++) {
final JSITDMNElementReference jsiOutputDecision = Js.uncheckedCast(jsiOutputDecisions.get(i));
references.add(jsiOutputDecision.getHref());
}
}
}
// Copy ComponentWidths information
final List<JSITComponentsWidthsExtension> extensions = findComponentsWidthsExtensions(dmnDefinitions.getDMNDI().getDMNDiagram());
extensions.forEach(componentsWidthsExtension -> {
// can be imported from another diagram but the extension is not imported or present in this diagram.
if (Objects.nonNull(componentsWidthsExtension.getComponentWidths())) {
hasComponentWidthsMap.entrySet().forEach(es -> {
final List<JSITComponentWidths> jsiComponentWidths = componentsWidthsExtension.getComponentWidths();
for (int i = 0; i < jsiComponentWidths.size(); i++) {
final JSITComponentWidths jsiWidths = Js.uncheckedCast(jsiComponentWidths.get(i));
if (Objects.equals(jsiWidths.getDmnElementRef(), es.getKey())) {
final List<Double> widths = es.getValue().getComponentWidths();
if (Objects.nonNull(jsiWidths.getWidth())) {
widths.clear();
for (int w = 0; w < jsiWidths.getWidth().size(); w++) {
final double width = jsiWidths.getWidth().get(w).doubleValue();
widths.add(width);
}
}
}
}
});
}
});
return promises.resolve(drgGraph);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNUnmarshaller method connectRootWithChild.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void connectRootWithChild(final Node dmnDiagramRoot, final Node child) {
final String uuid = UUID.uuid();
final Edge<Child, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Child());
connectEdge(edge, dmnDiagramRoot, child);
final Definitions definitions = ((DMNDiagram) ((View) dmnDiagramRoot.getContent()).getDefinition()).getDefinitions();
final DMNModelInstrumentedBase childDRG = (DMNModelInstrumentedBase) ((View) child.getContent()).getDefinition();
childDRG.setParent(definitions);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method loadNodes.
private Promise<List<DMNIncludedNode>> loadNodes(final Map<String, JSITDefinitions> existingDefinitions, final DMNIncludedModel model, final List<DMNIncludedNode> result) {
String filePath = "";
for (final Map.Entry<String, JSITDefinitions> entry : existingDefinitions.entrySet()) {
filePath = entry.getKey();
final JSITDefinitions definitions = Js.uncheckedCast(entry.getValue());
if (Objects.equals(model.getNamespace(), definitions.getNamespace())) {
break;
}
}
if (isEmpty(filePath)) {
return promises.resolve();
}
final String path = filePath;
return dmnImportsContentService.loadFile(path).then(content -> promises.create((success, fail) -> dmnImportsService.getDRGElements(content, new ServiceCallback<List<DRGElement>>() {
@Override
public void onSuccess(final List<DRGElement> drgElements) {
final List<DMNIncludedNode> nodes = drgElements.stream().map(node -> includedModelFactory.makeDMNIncludeNode(path, model, node)).collect(Collectors.toList());
result.addAll(nodes);
success.onInvoke(nodes);
}
@Override
public void onError(final ClientRuntimeError error) {
LOGGER.log(Level.SEVERE, error.getMessage());
fail.onInvoke(error);
}
})));
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNMarshaller method withIncludedModels.
Node<?, ?> withIncludedModels(final Node<?, ?> node, final Definitions definitionsStunnerPojo) {
final Object elementDefinition = getElementDefinition(node);
final List<Import> diagramImports = definitionsStunnerPojo.getImport();
if (!(elementDefinition instanceof DRGElement) || diagramImports.isEmpty()) {
return node;
}
final DRGElement drgElement = (DRGElement) elementDefinition;
final Optional<Definitions> nodeDefinitions = getDefinitions(drgElement);
if (!nodeDefinitions.isPresent()) {
return node;
}
final List<Import> nodeImports = nodeDefinitions.get().getImport();
updateNodeImports(diagramImports, nodeImports);
return node;
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNGraphUtilsTest method testGetDefinitions.
@Test
public void testGetDefinitions() {
final Definitions expectedDefinitions = mock(Definitions.class);
when(dmnDiagramsSession.getDRGDiagram()).thenReturn(diagram);
when(dmnDiagramUtils.getDefinitions(diagram)).thenReturn(expectedDefinitions);
final Definitions actualDefinitions = utils.getModelDefinitions();
assertNotNull(actualDefinitions);
assertEquals(expectedDefinitions, actualDefinitions);
}
Aggregations