use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport 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());
}
}
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 getPMMLDocumentsAsync.
public Promise<Map<JSITImport, PMMLDocumentMetadata>> getPMMLDocumentsAsync(final Metadata metadata, final List<JSITImport> imports) {
if (!imports.isEmpty()) {
return loadPMMLDefinitions().then(otherDefinitions -> {
final Map<JSITImport, PMMLDocumentMetadata> importDefinitions = new HashMap<>();
for (final Map.Entry<String, PMMLDocumentMetadata> entry : otherDefinitions.entrySet()) {
final PMMLDocumentMetadata def = entry.getValue();
findImportByPMMLDocument(FileUtils.getFileName(def.getPath()), imports).ifPresent(anImport -> {
final JSITImport foundImported = Js.uncheckedCast(anImport);
importDefinitions.put(foundImported, def);
});
}
return promises.resolve(importDefinitions);
});
}
return promises.resolve(Collections.emptyMap());
}
Aggregations