Search in sources :

Example 41 with Definitions

use of org.kie.workbench.common.dmn.api.definition.v1_1.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;
}
Also used : Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition)

Example 42 with Definitions

use of org.kie.workbench.common.dmn.api.definition.v1_1.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;
}
Also used : XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createTrustingXStream(org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream) Definitions(org.kie.dmn.model.v1_1.Definitions) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 43 with Definitions

use of org.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project drools by kiegroup.

the class DMNXMLLoaderTest method testLoadingExample.

@Test
@Ignore("No unmarshaller implemented")
public void testLoadingExample() {
    final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
    final InputStream is = this.getClass().getResourceAsStream("/src/test/resources/ch11example.xml");
    final InputStreamReader isr = new InputStreamReader(is);
    final Object o = DMNMarshaller.unmarshal(isr);
    final Definitions root = (Definitions) o;
    assertNotNull(root);
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.v1_1.Definitions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 44 with Definitions

use of org.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project drools by kiegroup.

the class DMNXMLLoaderTest method testLoadingDecisionServices.

@Test
public void testLoadingDecisionServices() {
    final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DecisionServicesExtensionRegister()));
    final InputStream is = this.getClass().getResourceAsStream("0004-decision-services.dmn");
    final InputStreamReader isr = new InputStreamReader(is);
    final Definitions def = DMNMarshaller.unmarshal(isr);
    assertThat(def.getDecisionService().size(), is(2));
    DecisionService decisionService1 = def.getDecisionService().get(0);
    assertThat(decisionService1.getId(), is("_70386614-9838-420b-a2ae-ff901ada63fb"));
    assertThat(decisionService1.getName(), is("A Only Knowing B and C"));
    assertThat(decisionService1.getDescription(), is("Description of A (BC)"));
    assertThat(decisionService1.getOutputDecision().size(), is(1));
    assertThat(decisionService1.getEncapsulatedDecision().size(), is(0));
    assertThat(decisionService1.getInputDecision().size(), is(2));
    assertThat(decisionService1.getInputData().size(), is(0));
    assertThat(decisionService1.getOutputDecision().get(0).getHref(), is("#_c2b44706-d479-4ceb-bb74-73589d26dd04"));
    DecisionService decisionService2 = def.getDecisionService().get(1);
    assertThat(decisionService2.getId(), is("_4620ef13-248a-419e-bc68-6b601b725a03"));
    assertThat(decisionService2.getName(), is("A only as output knowing D and E"));
    assertThat(decisionService2.getOutputDecision().size(), is(1));
    assertThat(decisionService2.getEncapsulatedDecision().size(), is(2));
    assertThat(decisionService2.getInputDecision().size(), is(0));
    assertThat(decisionService2.getInputData().size(), is(2));
    assertThat(decisionService2.getInputData().get(0).getHref(), is("#_bcea16fb-6c19-4bde-b37d-73407002c064"));
    assertThat(decisionService2.getInputData().get(1).getHref(), is("#_207b9195-a441-47f2-9414-2fad64b463f9"));
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) DecisionServicesExtensionRegister(org.kie.dmn.backend.marshalling.v1_1.xstream.extensions.DecisionServicesExtensionRegister) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.v1_1.Definitions) DecisionService(org.kie.dmn.model.v1_1.DecisionService) Test(org.junit.Test)

Example 45 with Definitions

use of org.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project drools by kiegroup.

the class DMNXMLLoaderTest method testLoadingDishDecision.

@Test
@Ignore("No unmarshaller implemented")
public void testLoadingDishDecision() {
    final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
    final InputStream is = this.getClass().getResourceAsStream("/src/test/resources/dish-decision.xml");
    final InputStreamReader isr = new InputStreamReader(is);
    final Object o = DMNMarshaller.unmarshal(isr);
    final Definitions root = (Definitions) o;
    assertNotNull(root);
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.v1_1.Definitions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Definitions (org.eclipse.bpmn2.Definitions)25 Definitions (org.kie.dmn.model.v1_1.Definitions)22 Test (org.junit.Test)20 Process (org.eclipse.bpmn2.Process)13 IOException (java.io.IOException)9 InputStreamReader (java.io.InputStreamReader)9 DMNMarshaller (org.kie.dmn.api.marshalling.v1_1.DMNMarshaller)8 Graph (org.kie.workbench.common.stunner.core.graph.Graph)8 InputStream (java.io.InputStream)7 DMNModel (org.kie.dmn.api.core.DMNModel)7 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)7 Path (org.uberfire.backend.vfs.Path)7 List (java.util.List)6 RootElement (org.eclipse.bpmn2.RootElement)6 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)6 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)5 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)5 Matchers.anyString (org.mockito.Matchers.anyString)5