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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations