Search in sources :

Example 6 with Decision

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

the class DMNXMLLoaderTest method test0004_multiple_extensions.

@Test
public void test0004_multiple_extensions() throws Exception {
    DMNMarshaller marshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DecisionServicesExtensionRegister()));
    final InputStream is = this.getClass().getResourceAsStream("0004-decision-services_multiple_extensions.dmn");
    final InputStreamReader isr = new InputStreamReader(is);
    final Definitions def = marshaller.unmarshal(isr);
    assertThat(def.getExtensionElements().getAny().size(), is(1));
// if arrived here, means it did not fail with exception while trying to unmarshall unknown rss extension element, hence it just skipped it.
}
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) Test(org.junit.Test)

Example 7 with Decision

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

the class DMNCompilerImpl method resolveTypeRef.

public DMNType resolveTypeRef(DMNModelImpl dmnModel, DMNNode node, NamedElement model, DMNModelInstrumentedBase localElement, QName typeRef) {
    if (typeRef != null) {
        QName nsAndName = getNamespaceAndName(localElement, dmnModel.getImportAliasesForNS(), typeRef);
        DMNType type = dmnModel.getTypeRegistry().resolveType(nsAndName.getNamespaceURI(), nsAndName.getLocalPart());
        if (type == null && DMNModelInstrumentedBase.URI_FEEL.equals(nsAndName.getNamespaceURI())) {
            if (model instanceof Decision && ((Decision) model).getExpression() instanceof DecisionTable) {
                DecisionTable dt = (DecisionTable) ((Decision) model).getExpression();
                if (dt.getOutput().size() > 1) {
                    // implicitly define a type for the decision table result
                    CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), model.getName() + "_Type", model.getId(), dt.getHitPolicy().isMultiHit());
                    for (OutputClause oc : dt.getOutput()) {
                        DMNType fieldType = resolveTypeRef(dmnModel, node, model, oc, oc.getTypeRef());
                        compType.addField(oc.getName(), fieldType);
                    }
                    dmnModel.getTypeRegistry().registerType(compType);
                    return compType;
                } else if (dt.getOutput().size() == 1) {
                    return resolveTypeRef(dmnModel, node, model, dt.getOutput().get(0), dt.getOutput().get(0).getTypeRef());
                }
            }
        } else if (type == null) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, localElement, dmnModel, null, null, Msg.UNKNOWN_TYPE_REF_ON_NODE, typeRef.toString(), localElement.getParentDRDElement().getIdentifierString());
        }
        return type;
    }
    return dmnModel.getTypeRegistry().resolveType(DMNModelInstrumentedBase.URI_FEEL, BuiltInType.UNKNOWN.getName());
}
Also used : OutputClause(org.kie.dmn.model.v1_1.OutputClause) DecisionTable(org.kie.dmn.model.v1_1.DecisionTable) QName(javax.xml.namespace.QName) Decision(org.kie.dmn.model.v1_1.Decision) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 8 with Decision

use of org.kie.dmn.model.v1_1.Decision 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)

Aggregations

Decision (org.kie.dmn.model.v1_1.Decision)4 Definitions (org.kie.dmn.model.v1_1.Definitions)4 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 Test (org.junit.Test)3 DMNType (org.kie.dmn.api.core.DMNType)3 DMNMarshaller (org.kie.dmn.api.marshalling.v1_1.DMNMarshaller)3 QName (javax.xml.namespace.QName)2 DecisionServicesExtensionRegister (org.kie.dmn.backend.marshalling.v1_1.xstream.extensions.DecisionServicesExtensionRegister)2 DMNElement (org.kie.dmn.model.v1_1.DMNElement)2 LiteralExpression (org.kie.dmn.model.v1_1.LiteralExpression)2 XStream (com.thoughtworks.xstream.XStream)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)1