Search in sources :

Example 6 with InputData

use of org.kie.dmn.model.v1_1.InputData in project drools by kiegroup.

the class InputDataConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    InputData id = (InputData) parent;
    if (id.getVariable() != null) {
        writeChildrenNode(writer, context, id.getVariable(), VARIABLE);
    }
}
Also used : InputData(org.kie.dmn.model.v1_1.InputData)

Example 7 with InputData

use of org.kie.dmn.model.v1_1.InputData in project drools by kiegroup.

the class InputDataCompiler method compileNode.

@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
    InputData input = (InputData) de;
    InputDataNodeImpl idn = new InputDataNodeImpl(input);
    if (input.getVariable() != null) {
        DMNCompilerHelper.checkVariableName(model, input, input.getName());
        DMNType type = compiler.resolveTypeRef(model, idn, de, input.getVariable(), input.getVariable().getTypeRef());
        idn.setType(type);
    } else {
        idn.setType(DMNTypeRegistry.UNKNOWN);
        DMNCompilerHelper.reportMissingVariable(model, de, input, Msg.MISSING_VARIABLE_FOR_INPUT);
    }
    model.addInput(idn);
}
Also used : InputData(org.kie.dmn.model.v1_1.InputData) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 8 with InputData

use of org.kie.dmn.model.v1_1.InputData in project drools by kiegroup.

the class DecisionServiceConverter method parseElements.

@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        Object object = null;
        String nodeName = reader.getNodeName();
        if (nodeName.equals(INPUT_DATA)) {
            // Patch because the tag name inputData is used in both decision services and as a DRG Element
            DMNElementReference ref = new DMNElementReference();
            ref.setHref(reader.getAttribute("href"));
            object = ref;
        } else {
            // Default behaviour
            object = readItem(reader, context, null);
        }
        if (object instanceof DMNModelInstrumentedBase) {
            ((DMNModelInstrumentedBase) object).setParent((DMNModelInstrumentedBase) parent);
            ((DMNModelInstrumentedBase) parent).addChildren((DMNModelInstrumentedBase) object);
        }
        reader.moveUp();
        assignChildElement(parent, nodeName, object);
    }
}
Also used : DMNElementReference(org.kie.dmn.model.v1_1.DMNElementReference) DMNModelInstrumentedBase(org.kie.dmn.model.v1_1.DMNModelInstrumentedBase)

Example 9 with InputData

use of org.kie.dmn.model.v1_1.InputData in project drools by kiegroup.

the class DMNExtensionRegisterTest method testUsingSystemProperty.

@Test
public void testUsingSystemProperty() {
    try {
        System.setProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", FirstNameLastNameProfile.class.getCanonicalName());
        assertEquals(FirstNameLastNameProfile.class.getCanonicalName(), System.getProperty("org.kie.dmn.profiles.FirstNameLastNameProfile"));
        DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0001-input-data-string-with-extensions.dmn", this.getClass());
        DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
        assertThat(dmnModel, notNullValue());
        assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
        assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
        InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
        assertEquals("First Name", inputData1.getName());
        DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
        assertTrue(id1elements != null);
        assertEquals(1, id1elements.getAny().size());
        FirstNameDescription firstNameDescription = (FirstNameDescription) id1elements.getAny().get(0);
        assertTrue(firstNameDescription.getContent().equals("First name in latin characters"));
        InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
        assertEquals("Last Name", inputData2.getName());
        DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
        assertTrue(id2elements != null);
        assertEquals(1, id2elements.getAny().size());
        LastNameDescription lastNameDescription = (LastNameDescription) id2elements.getAny().get(0);
        assertTrue(lastNameDescription.getContent().equals("Last name in latin characters"));
    } catch (Exception e) {
        LOG.error("{}", e.getLocalizedMessage(), e);
        throw e;
    } finally {
        System.clearProperty("org.kie.dmn.profiles.FirstNameLastNameProfile");
        assertNull(System.getProperty("org.kie.dmn.profiles.FirstNameLastNameProfile"));
    }
}
Also used : DMNElement(org.kie.dmn.model.v1_1.DMNElement) InputData(org.kie.dmn.model.v1_1.InputData) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

InputData (org.kie.dmn.model.v1_1.InputData)7 Test (org.junit.Test)4 DMNElement (org.kie.dmn.model.v1_1.DMNElement)4 DMNModel (org.kie.dmn.api.core.DMNModel)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 KieServices (org.kie.api.KieServices)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 Results (org.kie.api.builder.Results)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 KieContainer (org.kie.api.runtime.KieContainer)2 Definitions (org.kie.dmn.model.v1_1.Definitions)2 XStream (com.thoughtworks.xstream.XStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 DMNType (org.kie.dmn.api.core.DMNType)1 DMNExtensionRegister (org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister)1 DMNMarshaller (org.kie.dmn.api.marshalling.v1_1.DMNMarshaller)1 InputDataNodeImpl (org.kie.dmn.core.ast.InputDataNodeImpl)1 DMNElementReference (org.kie.dmn.model.v1_1.DMNElementReference)1