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 marshall.
public void marshall(final Diagram diagram, final ServiceCallback<String> contentServiceCallback) {
final DMN12MarshallCallback jsCallback = result -> {
final String xml;
final String prefix = "<?xml version=\"1.0\" ?>";
if (result.startsWith(prefix)) {
xml = result;
} else {
xml = prefix + result;
}
contentServiceCallback.onSuccess(xml);
};
if (Objects.isNull(diagram)) {
contentServiceCallback.onError(new ClientRuntimeError("The Diagram cannot be null."));
return;
}
final Graph graph = diagram.getGraph();
if (Objects.isNull(graph)) {
contentServiceCallback.onError(new ClientRuntimeError("The Diagram graph cannot be null."));
return;
}
try {
final JSITDefinitions jsitDefinitions = dmnMarshaller.marshall();
final DMN12 dmn12 = Js.uncheckedCast(JsUtils.newWrappedInstance());
JsUtils.setNameOnWrapped(dmn12, makeJSINameForDMN12());
JsUtils.setValueOnWrapped(dmn12, jsitDefinitions);
final JavaScriptObject namespaces = createNamespaces(jsitDefinitions.getOtherAttributes(), jsitDefinitions.getNamespace());
MainJs.marshall(dmn12, namespaces, jsCallback);
} catch (final Exception e) {
contentServiceCallback.onError(new ClientRuntimeError("Error during the marshaller: " + e.getMessage()));
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions 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.JSITDefinitions 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.JSITDefinitions in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testGetExistingNode.
@Test
public void testGetExistingNode() {
final JSITDecision nodeDRGElement = makeDecision("id1");
final JSITDecision definitionsDRGElement1 = makeDecision("id1");
final JSITDecision definitionsDRGElement2 = makeDecision("id2");
final JSITDecision definitionsDRGElement3 = makeDecision("id3");
final DMNMarshaller dmnMarshaller = new DMNMarshaller();
final JSITDefinitions definitions = spy(new JSITDefinitions());
final List<JSITDRGElement> definitionsDRGElements = new ArrayList<>(asList(definitionsDRGElement1, definitionsDRGElement2, definitionsDRGElement3));
doReturn(definitionsDRGElements).when(definitions).getDrgElement();
final Optional<JSITDRGElement> existingNode = dmnMarshaller.getExistingNode(definitions, nodeDRGElement);
assertTrue(existingNode.isPresent());
assertEquals(definitionsDRGElement1, existingNode.get());
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method testAddNodeToDefinitionsIfNotPresentWhenNodeIsPresent.
@Test
public void testAddNodeToDefinitionsIfNotPresentWhenNodeIsPresent() {
final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
final Optional<JSITDRGElement> existingNode = Optional.of(mock(JSITDRGElement.class));
final JSITDefinitions definitions = mock(JSITDefinitions.class);
final JSITDRGElement node = mock(JSITDRGElement.class);
doReturn(existingNode).when(dmnMarshaller).getExistingNode(definitions, node);
doNothing().when(dmnMarshaller).addNodeToDefinitions(node, definitions);
dmnMarshaller.addNodeToDefinitionsIfNotPresent(node, definitions);
verify(dmnMarshaller, never()).addNodeToDefinitions(node, definitions);
}
Aggregations