Search in sources :

Example 11 with JSITDefinitions

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions in project kie-wb-common by kiegroup.

the class DMNMarshallerService method marshall.

public void marshall(final Diagram diagram, final ServiceCallback<String> contentServiceCallback) {
    final DMN12MarshallCallback jsCallback = result -> {
        final String xml;
        final String prefix = "<?xml version=\"1.0\" ?>";
        if (result.startsWith(prefix)) {
            xml = result;
        } else {
            xml = prefix + result;
        }
        contentServiceCallback.onSuccess(xml);
    };
    if (Objects.isNull(diagram)) {
        contentServiceCallback.onError(new ClientRuntimeError("The Diagram cannot be null."));
        return;
    }
    final Graph graph = diagram.getGraph();
    if (Objects.isNull(graph)) {
        contentServiceCallback.onError(new ClientRuntimeError("The Diagram graph cannot be null."));
        return;
    }
    try {
        final JSITDefinitions jsitDefinitions = dmnMarshaller.marshall();
        final DMN12 dmn12 = Js.uncheckedCast(JsUtils.newWrappedInstance());
        JsUtils.setNameOnWrapped(dmn12, makeJSINameForDMN12());
        JsUtils.setValueOnWrapped(dmn12, jsitDefinitions);
        final JavaScriptObject namespaces = createNamespaces(jsitDefinitions.getOtherAttributes(), jsitDefinitions.getNamespace());
        MainJs.marshall(dmn12, namespaces, jsCallback);
    } catch (final Exception e) {
        contentServiceCallback.onError(new ClientRuntimeError("Error during the marshaller: " + e.getMessage()));
    }
}
Also used : DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) Promises(org.uberfire.client.promise.Promises) HashMap(java.util.HashMap) GWT(com.google.gwt.core.client.GWT) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Inject(javax.inject.Inject) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) PathFactory(org.uberfire.backend.vfs.PathFactory) Js(jsinterop.base.Js) JSIName(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JSIName) Map(java.util.Map) Observes(javax.enterprise.event.Observes) DMNShapeSet(org.kie.workbench.common.dmn.client.DMNShapeSet) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Path(org.uberfire.backend.vfs.Path) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) MainJs(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) JSONString(com.google.gwt.json.client.JSONString) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) DMNUnmarshaller(org.kie.workbench.common.dmn.client.marshaller.unmarshall.DMNUnmarshaller) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DMNDiagramFactory(org.kie.workbench.common.dmn.api.factory.DMNDiagramFactory) DMN12(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) JsUtils(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JsUtils) Dependent(javax.enterprise.context.Dependent) DMNGraphUtils(org.kie.workbench.common.dmn.client.marshaller.common.DMNGraphUtils) DMNMarshaller(org.kie.workbench.common.dmn.client.marshaller.marshall.DMNMarshaller) MetadataImpl(org.kie.workbench.common.stunner.core.diagram.MetadataImpl) DRGDiagramUtils(org.kie.workbench.common.dmn.client.docks.navigator.drds.DRGDiagramUtils) QName(javax.xml.namespace.QName) JSONObject(com.google.gwt.json.client.JSONObject) DMNDiagramSelected(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramSelected) StringUtils(org.kie.workbench.common.stunner.core.util.StringUtils) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) DMN12MarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12MarshallCallback) Node(org.kie.workbench.common.stunner.core.graph.Node) DMN12MarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12MarshallCallback) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DMN12(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) JSONString(com.google.gwt.json.client.JSONString) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)

Example 12 with JSITDefinitions

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions in project kie-wb-common by kiegroup.

the class ImportConverter method wbFromDMN.

public static Import wbFromDMN(final JSITImport dmn, final JSITDefinitions definitions, final PMMLDocumentMetadata pmmlDocument) {
    final Import result = createWBImport(dmn, definitions, pmmlDocument);
    final Map<QName, String> additionalAttributes = new HashMap<>();
    final Map<javax.xml.namespace.QName, String> otherAttributes = JSITUnaryTests.getOtherAttributesMap(dmn);
    for (Map.Entry<javax.xml.namespace.QName, String> entry : otherAttributes.entrySet()) {
        additionalAttributes.put(QNamePropertyConverter.wbFromDMN(entry.getKey().toString()), entry.getValue());
    }
    result.setAdditionalAttributes(additionalAttributes);
    final String name = dmn.getName();
    final String description = dmn.getDescription();
    result.setId(IdPropertyConverter.wbFromDMN(dmn.getId()));
    result.setName(new Name(name));
    result.setDescription(DescriptionPropertyConverter.wbFromDMN(description));
    NameSpaceUtils.extractNamespacesKeyedByPrefix(dmn).forEach((key, value) -> result.getNsContext().put(key, value));
    return result;
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) HashMap(java.util.HashMap) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) HashMap(java.util.HashMap) Map(java.util.Map) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 13 with JSITDefinitions

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions in project kie-wb-common by kiegroup.

the class ImportConverter method createWBImport.

private static Import createWBImport(final JSITImport dmn, final JSITDefinitions definitions, final PMMLDocumentMetadata pmmlDocument) {
    final LocationURI locationURI = new LocationURI(dmn.getLocationURI());
    if (Objects.equals(DMNImportTypes.DMN, determineImportType(dmn.getImportType()))) {
        final ImportDMN result = new ImportDMN(dmn.getNamespace(), locationURI, dmn.getImportType());
        result.setDrgElementsCount(countDefinitionElement(definitions, d -> d.getDrgElement().size()));
        result.setItemDefinitionsCount(countDefinitionElement(definitions, d -> d.getItemDefinition().size()));
        return result;
    } else if (Objects.equals(DMNImportTypes.PMML, determineImportType(dmn.getImportType()))) {
        final ImportPMML result = new ImportPMML(dmn.getNamespace(), locationURI, dmn.getImportType());
        result.setModelCount(countDefinitionElement(pmmlDocument, document -> document.getModels().size()));
        return result;
    } else {
        return new Import(dmn.getNamespace(), locationURI, dmn.getImportType());
    }
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) HashMap(java.util.HashMap) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Function(java.util.function.Function) DMNImportTypes.determineImportType(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType) Objects(java.util.Objects) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Import(org.kie.workbench.common.dmn.api.definition.model.Import) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) NameSpaceUtils(org.kie.workbench.common.dmn.client.marshaller.common.NameSpaceUtils) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) Map(java.util.Map) Optional(java.util.Optional) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) XMLConstants(javax.xml.XMLConstants) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 14 with JSITDefinitions

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method testGetExistingNode.

@Test
public void testGetExistingNode() {
    final JSITDecision nodeDRGElement = makeDecision("id1");
    final JSITDecision definitionsDRGElement1 = makeDecision("id1");
    final JSITDecision definitionsDRGElement2 = makeDecision("id2");
    final JSITDecision definitionsDRGElement3 = makeDecision("id3");
    final DMNMarshaller dmnMarshaller = new DMNMarshaller();
    final JSITDefinitions definitions = spy(new JSITDefinitions());
    final List<JSITDRGElement> definitionsDRGElements = new ArrayList<>(asList(definitionsDRGElement1, definitionsDRGElement2, definitionsDRGElement3));
    doReturn(definitionsDRGElements).when(definitions).getDrgElement();
    final Optional<JSITDRGElement> existingNode = dmnMarshaller.getExistingNode(definitions, nodeDRGElement);
    assertTrue(existingNode.isPresent());
    assertEquals(definitionsDRGElement1, existingNode.get());
}
Also used : JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) ArrayList(java.util.ArrayList) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Test(org.junit.Test)

Example 15 with JSITDefinitions

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method testAddNodeToDefinitionsIfNotPresentWhenNodeIsPresent.

@Test
public void testAddNodeToDefinitionsIfNotPresentWhenNodeIsPresent() {
    final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
    final Optional<JSITDRGElement> existingNode = Optional.of(mock(JSITDRGElement.class));
    final JSITDefinitions definitions = mock(JSITDefinitions.class);
    final JSITDRGElement node = mock(JSITDRGElement.class);
    doReturn(existingNode).when(dmnMarshaller).getExistingNode(definitions, node);
    doNothing().when(dmnMarshaller).addNodeToDefinitions(node, definitions);
    dmnMarshaller.addNodeToDefinitionsIfNotPresent(node, definitions);
    verify(dmnMarshaller, never()).addNodeToDefinitions(node, definitions);
}
Also used : JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Test(org.junit.Test)

Aggregations

JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)18 HashMap (java.util.HashMap)14 Map (java.util.Map)13 ArrayList (java.util.ArrayList)12 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)12 JSITDRGElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement)10 Inject (javax.inject.Inject)8 Js (jsinterop.base.Js)8 JSITItemDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)8 Objects (java.util.Objects)7 Optional (java.util.Optional)7 QName (javax.xml.namespace.QName)7 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)7 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)7 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)7 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)6 MainJs (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs)6