use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method getImportDefinitionsAsync.
public Promise<Map<JSITImport, JSITDefinitions>> getImportDefinitionsAsync(final Metadata metadata, final List<JSITImport> imports) {
if (!imports.isEmpty()) {
return loadDMNDefinitions().then(otherDefinitions -> {
final Map<JSITImport, JSITDefinitions> importDefinitions = new HashMap<>();
for (final Map.Entry<String, JSITDefinitions> entry : otherDefinitions.entrySet()) {
final JSITDefinitions def = Js.uncheckedCast(entry.getValue());
findImportByDefinitions(def, imports).ifPresent(anImport -> {
final JSITImport foundImported = Js.uncheckedCast(anImport);
importDefinitions.put(foundImported, def);
});
}
return promises.resolve(importDefinitions);
});
}
return promises.resolve(Collections.emptyMap());
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelper method getDrgElementsWithNamespace.
private List<JSITDRGElement> getDrgElementsWithNamespace(final JSITDefinitions definitions, final JSITImport anImport) {
final List<JSITDRGElement> result = new ArrayList<>();
final List<JSITDRGElement> drgElements = definitions.getDrgElement();
for (int i = 0; i < drgElements.size(); i++) {
final JSITDRGElement drgElement = Js.uncheckedCast(drgElements.get(i));
final JSITDRGElement element = Js.uncheckedCast(drgElementWithNamespace(drgElement, anImport));
result.add(element);
}
return result;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelperTest method getPMMLDocumentsAsync.
@Test
public void getPMMLDocumentsAsync() {
final PMMLDocumentMetadata pmmlDocumentMetadata = new PMMLDocumentMetadata(PMML_PATH, PMML_FILE, PMML.getDefaultNamespace(), Collections.emptyList());
when(dmnImportsContentService.getModelsPMMLFilesURIs()).thenReturn(promises.resolve(new String[] { PMML_PATH }));
when(dmnImportsContentService.loadFile(PMML_PATH)).thenReturn(promises.resolve(PMML_CONTENT));
doReturn(promises.resolve(pmmlDocumentMetadata)).when(dmnImportsContentService).getPMMLDocumentMetadata(PMML_PATH);
final List<JSITImport> imports = new ArrayList<>();
final JSITImport jsImportMock = mock(JSITImport.class);
when(jsImportMock.getLocationURI()).thenReturn(PMML_FILE);
imports.add(jsImportMock);
final Promise<Map<JSITImport, PMMLDocumentMetadata>> returnPromise = importsHelper.getPMMLDocumentsAsync(metadataMock, imports);
returnPromise.then(def -> {
assertEquals(1, def.size());
assertEquals(PMML_PATH, def.get(jsImportMock).getPath());
assertEquals(PMML_FILE, def.get(jsImportMock).getName());
assertEquals(PMML.getDefaultNamespace(), def.get(jsImportMock).getImportType());
assertEquals(0, def.get(jsImportMock).getModels().size());
return promises.resolve();
}).catch_(i -> {
fail("Promise should've been resolved!");
return promises.resolve();
});
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport 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.webapp.kogito.marshaller.js.model.dmn12.JSITImport in project kie-wb-common by kiegroup.
the class DMNUnmarshaller method getWbImportedItemDefinitions.
private List<ItemDefinition> getWbImportedItemDefinitions(final Map<JSITImport, JSITDefinitions> importDefinitions) {
final List<ItemDefinition> definitions = new ArrayList<>();
final List<JSITItemDefinition> importedDefinitions = dmnMarshallerImportsHelper.getImportedItemDefinitions(importDefinitions);
for (int i = 0; i < importedDefinitions.size(); i++) {
final JSITItemDefinition definition = Js.uncheckedCast(importedDefinitions.get(i));
final ItemDefinition converted = ItemDefinitionPropertyConverter.wbFromDMN(definition);
if (converted != null) {
converted.setAllowOnlyVisualChange(true);
definitions.add(converted);
}
}
return definitions;
}
Aggregations