Search in sources :

Example 1 with JSIDMNDI

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

Aggregations

HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)1 Import (org.kie.workbench.common.dmn.api.definition.model.Import)1 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)1 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)1 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)1 JSITItemDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)1 JSIDMNDI (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDI)1 JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)1