Search in sources :

Example 6 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 NodeEntriesFactory method getAssociations.

private List<JSITAssociation> getAssociations(final JSITDefinitions definitions) {
    final List<JSITAssociation> associations = new ArrayList<>();
    final List<JSITArtifact> artifacts = definitions.getArtifact();
    forEach(artifacts, artifact -> {
        if (JSITAssociation.instanceOf(artifact)) {
            final JSITAssociation association = Js.uncheckedCast(artifact);
            associations.add(association);
        }
    });
    return associations;
}
Also used : JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) JSITArtifact(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITArtifact) ArrayList(java.util.ArrayList)

Example 7 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 DMNMarshallerImportsService method getDRGElements.

public void getDRGElements(final String dmnXml, final ServiceCallback<List<DRGElement>> callback) {
    final DMN12UnmarshallCallback jsCallback = dmn12 -> {
        final JSITDefinitions dmnDefinitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
        callback.onSuccess(modelToStunnerConverter.makeNodes(dmnDefinitions, new HashMap<>(), false, (a, b) -> {
        /* Nothing. */
        }).stream().map(e -> getDRGElement(e.getNode())).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
    };
    MainJs.unmarshall(dmnXml, "", jsCallback);
}
Also used : MainJs(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DefinitionsConverter(org.kie.workbench.common.dmn.client.marshaller.converters.DefinitionsConverter) HashMap(java.util.HashMap) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) Js(jsinterop.base.Js) JsUtils(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JsUtils) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Map(java.util.Map) Optional(java.util.Optional) NodeEntriesFactory(org.kie.workbench.common.dmn.client.marshaller.unmarshall.nodes.NodeEntriesFactory) ApplicationScoped(javax.enterprise.context.ApplicationScoped) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Node(org.kie.workbench.common.stunner.core.graph.Node) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) Optional(java.util.Optional) HashMap(java.util.HashMap) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)

Example 8 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 DefinitionsConverter method wbFromDMN.

public static Definitions wbFromDMN(final JSITDefinitions dmn, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Name name = new Name(dmn.getName());
    final String namespace = dmn.getNamespace();
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Definitions result = new Definitions();
    result.setId(id);
    result.setName(name);
    result.setNamespace(new Text(namespace));
    result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace);
    result.setExpressionLanguage(ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage()));
    result.setTypeLanguage(dmn.getTypeLanguage());
    result.setDmnDiagramElements(getDMNDiagramElements(dmn));
    result.setDescription(description);
    final Map<String, String> namespaces = NameSpaceUtils.extractNamespacesKeyedByPrefix(dmn);
    for (Entry<String, String> kv : namespaces.entrySet()) {
        String mappedURI = kv.getValue();
        switch(mappedURI) {
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN;
                break;
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL;
                break;
            case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE:
                mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE;
                break;
        }
        if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            result.getNsContext().putIfAbsent(kv.getKey(), mappedURI);
        } else {
            result.getNsContext().put(kv.getKey(), mappedURI);
        }
    }
    final List<JSITItemDefinition> jsiItemDefinitions = dmn.getItemDefinition();
    for (int i = 0; i < jsiItemDefinitions.size(); i++) {
        final JSITItemDefinition jsiItemDefinition = Js.uncheckedCast(jsiItemDefinitions.get(i));
        final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(jsiItemDefinition);
        if (Objects.nonNull(itemDefConverted)) {
            itemDefConverted.setParent(result);
            result.getItemDefinition().add(itemDefConverted);
        }
    }
    final List<JSITImport> jsiImports = dmn.getImport();
    for (int i = 0; i < jsiImports.size(); i++) {
        final JSITImport jsiImport = Js.uncheckedCast(jsiImports.get(i));
        final JSITDefinitions definitions = Js.uncheckedCast(importDefinitions.get(jsiImport));
        final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(jsiImport);
        final Import importConverted = ImportConverter.wbFromDMN(jsiImport, definitions, pmmlDocument);
        if (Objects.nonNull(importConverted)) {
            importConverted.setParent(result);
            result.getImport().add(importConverted);
        }
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Example 9 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 DefinitionsConverter method dmnFromWB.

public static JSITDefinitions dmnFromWB(final Definitions wb, final boolean ignoreImportedItemDefinition) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final JSITDefinitions result = new JSITDefinitions();
    // TODO currently DMN wb UI does not offer feature to set these required DMN properties, setting some hardcoded defaults for now.
    final String defaultId = Objects.nonNull(wb.getId()) ? wb.getId().getValue() : UUID.uuid();
    final String defaultName = Objects.nonNull(wb.getName()) ? wb.getName().getValue() : UUID.uuid(8);
    final JSIDMNDI dmnDMNDI = new JSIDMNDI();
    final String defaultNamespace = !StringUtils.isEmpty(wb.getNamespace().getValue()) ? wb.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
    result.setDMNDI(dmnDMNDI);
    result.setId(defaultId);
    result.setName(defaultName);
    result.setNamespace(defaultNamespace);
    final List<DMNDiagramElement> dmnDiagramElements = wb.getDiagramElements();
    final List<JSIDMNDiagram> jsidmnDiagrams = getJSIDMNDiagrams(dmnDiagramElements);
    dmnDMNDI.setDMNDiagram(jsidmnDiagrams);
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    final String typeLanguage = wb.getTypeLanguage();
    final String expressionLanguage = ExpressionLanguagePropertyConverter.dmnFromWB(wb.getExpressionLanguage());
    if (!StringUtils.isEmpty(typeLanguage)) {
        result.setTypeLanguage(typeLanguage);
    }
    if (!StringUtils.isEmpty(expressionLanguage)) {
        result.setExpressionLanguage(expressionLanguage);
    }
    final Map<QName, String> otherAttributes = new HashMap<>();
    wb.getNsContext().forEach((k, v) -> {
        // See https://github.com/highsource/jsonix/issues/227
        if (!Objects.equals(k, DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
            otherAttributes.put(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, k, XMLConstants.DEFAULT_NS_PREFIX), v);
        }
    });
    result.setOtherAttributes(otherAttributes);
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getItemDefinition())) {
        result.setItemDefinition(new ArrayList<>());
    }
    for (ItemDefinition itemDef : wb.getItemDefinition()) {
        if (ignoreImportedItemDefinition) {
            if (itemDef.isAllowOnlyVisualChange()) {
                continue;
            }
        }
        final JSITItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.dmnFromWB(itemDef);
        result.addItemDefinition(itemDefConverted);
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getImport())) {
        result.setImport(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getDrgElement())) {
        result.setDrgElement(new ArrayList<>());
    }
    // Add because it is present in the original JSON when unmarshalling
    if (Objects.isNull(result.getArtifact())) {
        result.setArtifact(new ArrayList<>());
    }
    for (Import i : wb.getImport()) {
        final JSITImport importConverted = ImportConverter.dmnFromWb(i);
        result.addImport(importConverted);
    }
    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(javax.xml.namespace.QName) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) JSIDMNDI(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDI) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)

Example 10 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 unmarshall.

public void unmarshall(final Metadata metadata, final String xml, final ServiceCallback<Diagram> callback) {
    setOnDiagramLoad(callback);
    setMetadata(metadata);
    try {
        final DMN12UnmarshallCallback jsCallback = dmn12 -> {
            final JSITDefinitions definitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
            dmnUnmarshaller.unmarshall(getMetadata(), definitions).then(graph -> {
                final String fileName = getMetadata().getPath().getFileName();
                onDiagramLoad(dmnDiagramFactory.build(fileName, getMetadata(), graph));
                return promises.resolve();
            });
        };
        MainJs.unmarshall(xml, "", jsCallback);
    } catch (final Exception e) {
        GWT.log(e.getMessage(), e);
        callback.onError(new ClientRuntimeError(new DiagramParsingException(getMetadata(), xml)));
    }
}
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) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) 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)

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