Search in sources :

Example 11 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class DiagramElementExtensionConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    if (extensionRegisters.size() == 0) {
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            // skipping nodeName
            reader.moveUp();
        }
    } else {
        // do as default behavior, but in case cannot unmarshall an extension element child, just skip it.
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            try {
                Object object = readItem(reader, context, null);
                if (object instanceof DMNModelInstrumentedBase) {
                    ((KieDMNModelInstrumentedBase) object).setParent(obj);
                    ((KieDMNModelInstrumentedBase) obj).addChildren((KieDMNModelInstrumentedBase) object);
                }
                assignChildElement(obj, nodeName, object);
            } catch (CannotResolveClassException e) {
                // do nothing; I tried to convert the extension element child with the converters, but no converter is registered for this child.
                LOG.debug("Tried to convert the extension element child {}, but no converter is registered for this child.", nodeName);
            }
            reader.moveUp();
        }
    }
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

Example 12 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class DMNDecisionTableRuntimeTest method testQMarkAndNullShouldNotThrowNPEs.

@Test
public void testQMarkAndNullShouldNotThrowNPEs() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("questionmarkunarytest/qmarkMatches.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_D1CF8332-8443-41C8-B214-D282B82C7632", "qmarkMatches");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    List<NullPointerException> feelNPEs = new ArrayList<>();
    DMNRuntimeImpl runtimeImpl = (DMNRuntimeImpl) runtime;
    runtimeImpl.setDMNResultImplFactory(new DMNResultImplFactory() {

        @Override
        public DMNResultImpl newDMNResultImpl(DMNModel model) {
            return new DMNResultImpl(model) {

                @Override
                public DMNMessage addMessage(Severity severity, String message, DMNMessageType messageType, DMNModelInstrumentedBase source, FEELEvent feelEvent) {
                    if (feelEvent.getSourceException() instanceof NullPointerException) {
                        feelNPEs.add((NullPointerException) feelEvent.getSourceException());
                    }
                    return super.addMessage(severity, message, messageType, source, feelEvent);
                }
            };
        }
    });
    final DMNContext context = DMNFactory.newContext();
    context.set("MyInput", null);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
    assertThat("while it's okay to have error-ed on evaluation of FEEL, there should not be any sort of NPEs when reporting the human friendly message", feelNPEs.isEmpty(), is(true));
}
Also used : DMNResultImpl(org.kie.dmn.core.impl.DMNResultImpl) DMNResult(org.kie.dmn.api.core.DMNResult) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) ArrayList(java.util.ArrayList) DMNContext(org.kie.dmn.api.core.DMNContext) Severity(org.kie.dmn.api.core.DMNMessage.Severity) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) DMNResultImplFactory(org.kie.dmn.core.impl.DMNResultImplFactory) DMNMessage(org.kie.dmn.api.core.DMNMessage) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 13 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase 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 TDMNElementReference();
            ref.setHref(reader.getAttribute("href"));
            object = ref;
        } else {
            // Default behaviour
            object = readItem(reader, context, null);
        }
        if (object instanceof DMNModelInstrumentedBase) {
            ((KieDMNModelInstrumentedBase) object).setParent((KieDMNModelInstrumentedBase) parent);
            ((KieDMNModelInstrumentedBase) parent).addChildren((KieDMNModelInstrumentedBase) object);
        }
        reader.moveUp();
        assignChildElement(parent, nodeName, object);
    }
}
Also used : DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase)

Example 14 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class DiagramElementExtensionConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    if (extensionRegisters.size() == 0) {
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            // skipping nodeName
            reader.moveUp();
        }
    } else {
        // do as default behavior, but in case cannot unmarshall an extension element child, just skip it.
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            String nodeName = reader.getNodeName();
            try {
                Object object = readItem(reader, context, null);
                if (object instanceof DMNModelInstrumentedBase) {
                    ((KieDMNModelInstrumentedBase) object).setParent(obj);
                    ((KieDMNModelInstrumentedBase) obj).addChildren((KieDMNModelInstrumentedBase) object);
                }
                assignChildElement(obj, nodeName, object);
            } catch (CannotResolveClassException e) {
                // do nothing; I tried to convert the extension element child with the converters, but no converter is registered for this child.
                LOG.debug("Tried to convert the extension element child {}, but no converter is registered for this child.", nodeName);
            }
            reader.moveUp();
        }
    }
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase) CannotResolveClassException(com.thoughtworks.xstream.mapper.CannotResolveClassException)

Example 15 with DMNModelInstrumentedBase

use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.

the class DMNBaseConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    DMNModelInstrumentedBase obj = createModelObject();
    assignAttributes(reader, obj);
    parseElements(reader, context, obj);
    return obj;
}
Also used : DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) KieDMNModelInstrumentedBase(org.kie.dmn.model.v1_3.KieDMNModelInstrumentedBase)

Aggregations

DMNModelInstrumentedBase (org.kie.dmn.model.api.DMNModelInstrumentedBase)22 CannotResolveClassException (com.thoughtworks.xstream.mapper.CannotResolveClassException)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)6 Reader (java.io.Reader)5 StringReader (java.io.StringReader)5 List (java.util.List)5 Definitions (org.kie.dmn.model.api.Definitions)5 KieDMNModelInstrumentedBase (org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 XStream (com.thoughtworks.xstream.XStream)4 AbstractPullReader (com.thoughtworks.xstream.io.xml.AbstractPullReader)4 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)4 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)4 StaxWriter (com.thoughtworks.xstream.io.xml.StaxWriter)4 TypeHierarchyPermission (com.thoughtworks.xstream.security.TypeHierarchyPermission)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 Map (java.util.Map)4