use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12 in project kie-wb-common by kiegroup.
the class DMNMarshallerService method unmarshall.
public void unmarshall(final Metadata metadata, final String xml, final ServiceCallback<Diagram> callback) {
setOnDiagramLoad(callback);
setMetadata(metadata);
try {
final DMN12UnmarshallCallback jsCallback = dmn12 -> {
final JSITDefinitions definitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
dmnUnmarshaller.unmarshall(getMetadata(), definitions).then(graph -> {
final String fileName = getMetadata().getPath().getFileName();
onDiagramLoad(dmnDiagramFactory.build(fileName, getMetadata(), graph));
return promises.resolve();
});
};
MainJs.unmarshall(xml, "", jsCallback);
} catch (final Exception e) {
GWT.log(e.getMessage(), e);
callback.onError(new ClientRuntimeError(new DiagramParsingException(getMetadata(), xml)));
}
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12 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.DMN12 in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsService method getDRGElements.
public void getDRGElements(final String dmnXml, final ServiceCallback<List<DRGElement>> callback) {
final DMN12UnmarshallCallback jsCallback = dmn12 -> {
final JSITDefinitions dmnDefinitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
callback.onSuccess(modelToStunnerConverter.makeNodes(dmnDefinitions, new HashMap<>(), false, (a, b) -> {
/* Nothing. */
}).stream().map(e -> getDRGElement(e.getNode())).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
};
MainJs.unmarshall(dmnXml, "", jsCallback);
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12 in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsService method getDMNDefinitions.
public void getDMNDefinitions(final String dmnXml, final ServiceCallback<JSITDefinitions> callback) {
final DMN12UnmarshallCallback jsCallback = dmn12 -> {
final JSITDefinitions dmnDefinitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
callback.onSuccess(dmnDefinitions);
};
MainJs.unmarshall(dmnXml, "", jsCallback);
}
Aggregations