Search in sources :

Example 1 with JSIDMNDiagram

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

the class DMNDiagramElementsUtils method ensureDRGElementExists.

public void ensureDRGElementExists(final JSITDefinitions dmnDefinitions) {
    final List<JSIDMNDiagram> dmnDiagrams = getValidDMNDiagrams(dmnDefinitions);
    final Optional<JSIDMNDiagram> drgDiagramElement = findDRGDiagramElement(dmnDiagrams);
    if (drgDiagramElement.isPresent()) {
        return;
    }
    if (dmnDiagrams.size() == 1) {
        renameDiagramElement(dmnDiagrams);
        return;
    }
    final JSIDMNDiagram drg = generateDRGElement(dmnDefinitions);
    dmnDefinitions.getDMNDI().addDMNDiagram(drg);
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)

Example 2 with JSIDMNDiagram

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

the class DMNDiagramElementsUtils method renameDiagramElement.

private void renameDiagramElement(final List<JSIDMNDiagram> dmnDiagramElements) {
    final JSIDMNDiagram dmnDiagramElement = Js.uncheckedCast(dmnDiagramElements.get(0));
    dmnDiagramElement.setName(DRG);
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)

Example 3 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram 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 4 with JSIDMNDiagram

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

the class DefinitionsConverter method getDMNDiagramElements.

private static List<DMNDiagramElement> getDMNDiagramElements(final JSITDefinitions definitions) {
    final List<DMNDiagramElement> dmnDiagramElements = new ArrayList<>();
    final List<JSIDMNDiagram> dmnDiagrams = definitions.getDMNDI().getDMNDiagram();
    forEach(dmnDiagrams, dmnDiagram -> {
        final Id id = new Id(dmnDiagram.getId());
        dmnDiagramElements.add(new DMNDiagramElement(id, new Name(dmnDiagram.getName())));
    });
    return dmnDiagramElements;
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) ArrayList(java.util.ArrayList) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName)

Example 5 with JSIDMNDiagram

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

the class WrapperUtils method getWrappedJSIDMNShape.

public static JSIDMNShape getWrappedJSIDMNShape(final JSIDMNDiagram diagram, final List<String> dmnDiagramElementIds, final Definitions definitionsStunnerPojo, final View<? extends DMNElement> v, final String namespaceURI) {
    final JSIDMNShape unwrappedJSIDMNShape = stunnerToDDExt(diagram, dmnDiagramElementIds, definitionsStunnerPojo, v, namespaceURI);
    final JSIDMNShape toReturn = Js.uncheckedCast(JsUtils.getWrappedElement(unwrappedJSIDMNShape));
    final JSIName jsiName = JSIDMNShape.getJSIName();
    updateJSIName(jsiName, "dmndi", "DMNShape");
    JsUtils.setNameOnWrapped(toReturn, jsiName);
    return toReturn;
}
Also used : JSIName(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JSIName) JSIDMNShape(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)

Aggregations

JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)14 ArrayList (java.util.ArrayList)7 JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)6 Test (org.junit.Test)5 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 Edge (org.kie.workbench.common.stunner.core.graph.Edge)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)4 HashMap (java.util.HashMap)3 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)3 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)3 JSIDMNShape (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)3 Node (org.kie.workbench.common.stunner.core.graph.Node)3 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 DMNViewDefinition (org.kie.workbench.common.dmn.api.definition.DMNViewDefinition)2 Association (org.kie.workbench.common.dmn.api.definition.model.Association)2 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)2