use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class BPMNAnalyzer method read.
public BPMNProcess read(InputStream inputStream) {
Definitions definitions = BPMN2Utils.getDefinitions(inputStream);
Optional<Process> processOptional = findProcess(definitions);
if (!processOptional.isPresent()) {
throw new RuntimeException("Cannot find Process on definitions");
}
Process process = processOptional.get();
BusinessProcessFormModel formModel = new BusinessProcessFormModel(process.getId(), process.getName(), new ArrayList<>());
BPMNProcess bpmmProcess = new BPMNProcess(formModel);
readContainerUserTasks(process, bpmmProcess::addTaskFormModel);
return bpmmProcess;
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method test_diamond.
@Test
public void test_diamond() throws IOException {
// round trip test
roundTripUnmarshalThenMarshalUnmarshal(this.getClass().getResourceAsStream("/diamond.dmn"), this::checkDiamongGraph);
// additionally, check the marshalled is still DMN executable as expected
DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/diamond.dmn"));
DiagramImpl diagram = new DiagramImpl("", null);
diagram.setGraph(g);
String mString = m.marshall(diagram);
final KieServices ks = KieServices.Factory.get();
final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test_diamond", "1.0"), ks.getResources().newByteArrayResource(mString.getBytes()).setTargetPath("src/main/resources/diamond.dmn"));
final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
DMNModel diamondModel = runtime.getModel("http://www.trisotech.com/definitions/_8afa6c24-55c8-43cf-8a02-fdde7fc5d1f2", "three decisions in a diamond shape");
DMNContext dmnContext = runtime.newContext();
dmnContext.set("My Name", "John Doe");
DMNResult dmnResult = runtime.evaluateAll(diamondModel, dmnContext);
assertFalse(dmnResult.getMessages().toString(), dmnResult.hasErrors());
DMNContext result = dmnResult.getContext();
assertEquals("Hello, John Doe.", result.get("My Decision"));
// additionally, check DMN DD/DI for version 1.1
org.kie.dmn.api.marshalling.v1_1.DMNMarshaller dmnMarshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DDExtensionsRegister()));
Definitions definitions = dmnMarshaller.unmarshal(mString);
assertNotNull(definitions.getExtensionElements());
assertNotNull(definitions.getExtensionElements().getAny());
assertEquals(1, definitions.getExtensionElements().getAny().size());
org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram ddRoot = (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram) definitions.getExtensionElements().getAny().get(0);
DMNShape myname = findShapeByDMNI(ddRoot, "_4cd17e52-6253-41d6-820d-5824bf5197f3");
assertBounds(500, 500, 100, 50, myname.getBounds());
assertColor(255, 255, 255, myname.getBgColor());
assertColor(0, 0, 0, myname.getBorderColor());
assertEquals(0.5, myname.getBorderSize().getValue(), 0);
assertDMNStyle("Open Sans", 24, 1, 255, 0, 0, myname.getFontStyle());
DMNShape prefix = findShapeByDMNI(ddRoot, "_e920f38a-293c-41b8-adb3-69d0dc184fab");
assertBounds(300, 400, 100, 50, prefix.getBounds());
assertColor(0, 253, 25, prefix.getBgColor());
assertColor(253, 0, 0, prefix.getBorderColor());
assertEquals(1, prefix.getBorderSize().getValue(), 0);
assertDMNStyle("Times New Roman", 8, 2.5, 70, 60, 50, prefix.getFontStyle());
DMNShape postfix = findShapeByDMNI(ddRoot, "_f49f9c34-29d5-4e72-91d2-f4f92117c8da");
assertBounds(700, 400, 100, 50, postfix.getBounds());
assertColor(247, 255, 0, postfix.getBgColor());
assertColor(0, 51, 255, postfix.getBorderColor());
assertEquals(2, postfix.getBorderSize().getValue(), 0);
assertDMNStyle("Arial", 10, 1.5, 50, 60, 70, postfix.getFontStyle());
DMNShape mydecision = findShapeByDMNI(ddRoot, "_9b061fc3-8109-42e2-9fe4-fc39c90b654e");
assertBounds(487.5, 275, 125, 75, mydecision.getBounds());
assertColor(255, 255, 255, mydecision.getBgColor());
assertColor(0, 0, 0, mydecision.getBorderColor());
assertEquals(0.5, mydecision.getBorderSize().getValue(), 0);
assertDMNStyle("Monospaced", 32, 3.5, 55, 66, 77, mydecision.getFontStyle());
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class DMNMarshaller method marshall.
@Override
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
Graph<?, Node<View, ?>> g = diagram.getGraph();
Map<String, org.kie.dmn.model.v1_1.DRGElement> nodes = new HashMap<>();
Map<String, org.kie.dmn.model.v1_1.TextAnnotation> textAnnotations = new HashMap<>();
@SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
Definitions definitionsStunnerPojo = dmnDiagramRoot.getContent().getDefinition().getDefinitions();
org.kie.dmn.model.v1_1.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
if (definitions.getExtensionElements() == null) {
definitions.setExtensionElements(new org.kie.dmn.model.v1_1.Definitions.ExtensionElements());
}
org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram dmnDDDMNDiagram = new org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram();
definitions.getExtensionElements().getAny().add(dmnDDDMNDiagram);
for (Node<?, ?> node : g.nodes()) {
if (node.getContent() instanceof View<?>) {
View<?> view = (View<?>) node.getContent();
if (view.getDefinition() instanceof DRGElement) {
DRGElement n = (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) view.getDefinition();
nodes.put(n.getId().getValue(), stunnerToDMN(node));
dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
} else if (view.getDefinition() instanceof TextAnnotation) {
TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node));
dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
List<org.kie.dmn.model.v1_1.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
definitions.getArtifact().addAll(associations);
}
}
}
nodes.values().forEach(definitions.getDrgElement()::add);
textAnnotations.values().forEach(definitions.getArtifact()::add);
String marshalled = marshaller.marshal(definitions);
return marshalled;
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class DefinitionsConverter method dmnFromWB.
public static org.kie.dmn.model.v1_1.Definitions dmnFromWB(final Definitions wb) {
if (wb == null) {
return null;
}
org.kie.dmn.model.v1_1.Definitions result = new org.kie.dmn.model.v1_1.Definitions();
// TODO currently DMN wb UI does not offer feature to set these required DMN properties, setting some hardcoded defaults for now.
String defaultId = (wb.getId() != null) ? wb.getId().getValue() : UUID.uuid();
String defaulName = (wb.getName() != null) ? wb.getName().getValue() : UUID.uuid(8);
String defaultNamespace = (wb.getNamespace() != null) ? wb.getNamespace() : "https://github.com/kiegroup/drools/kie-dmn";
result.setId(defaultId);
result.setName(defaulName);
result.setNamespace(defaultNamespace);
result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
result.getNsContext().putAll(wb.getNsContext());
for (ItemDefinition itemDef : wb.getItemDefinition()) {
org.kie.dmn.model.v1_1.ItemDefinition itemDefConvered = ItemDefinitionPropertyConverter.dmnFromWB(itemDef);
result.getItemDefinition().add(itemDefConvered);
}
// Need manually setup custom namespace URI if the diagram was created from the UI.
if (!result.getPrefixForNamespaceURI(DMNDiagram.DMNV11_DD).isPresent()) {
result.getNsContext().put("dmndi", DMNDiagram.DMNV11_DD);
}
if (!result.getPrefixForNamespaceURI(DMNDiagram.DMNV11_DC).isPresent()) {
result.getNsContext().put("dc", DMNDiagram.DMNV11_DC);
}
if (!result.getPrefixForNamespaceURI(DMNDiagram.DMNV11_DI).isPresent()) {
result.getNsContext().put("di", DMNDiagram.DMNV11_DI);
}
return result;
}
use of org.eclipse.bpmn2.Definitions in project drools by kiegroup.
the class XStreamMarshaller method unmarshal.
@Override
public Definitions unmarshal(Reader isr) {
try {
XStream xStream = newXStream();
Definitions def = (Definitions) xStream.fromXML(isr);
return def;
} catch (Exception e) {
logger.error("Error unmarshalling DMN model from reader.", e);
}
return null;
}
Aggregations