Search in sources :

Example 1 with FunctionItem

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

the class FunctionItemConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    FunctionItem ii = (FunctionItem) parent;
    String typeRef = reader.getAttribute(OUTPUT_TYPE_REF);
    ii.setOutputTypeRef(MarshallingUtils.parseQNameString(typeRef));
}
Also used : TFunctionItem(org.kie.dmn.model.v1_3.TFunctionItem) FunctionItem(org.kie.dmn.model.api.FunctionItem)

Example 2 with FunctionItem

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

the class DecisionServiceCompiler method checkFnConsistency.

private void checkFnConsistency(DMNModelImpl model, DecisionServiceNodeImpl ni, DMNType type, List<DecisionNode> outputDecisions) {
    SimpleFnTypeImpl fnType = ((SimpleFnTypeImpl) type);
    FunctionItem fi = fnType.getFunctionItem();
    if (fi.getParameters().size() != ni.getInputParameters().size()) {
        MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_COUNT_MISMATCH_COMPILING, ni.getName(), fi.getParameters().size(), ni.getInputParameters().size());
        return;
    }
    for (int i = 0; i < fi.getParameters().size(); i++) {
        InformationItem fiII = fi.getParameters().get(i);
        String fpName = ni.getInputParameters().keySet().stream().skip(i).findFirst().orElse(null);
        if (!fiII.getName().equals(fpName)) {
            List<String> fiParamNames = fi.getParameters().stream().map(InformationItem::getName).collect(Collectors.toList());
            List<String> funcDefParamNames = ni.getInputParameters().keySet().stream().collect(Collectors.toList());
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_NAMES_MISMATCH_COMPILING, ni.getName(), fiParamNames, funcDefParamNames);
            return;
        }
        QName fiQname = fiII.getTypeRef();
        QName fdQname = null;
        DMNNode fpDMNNode = ni.getInputParameters().get(fpName);
        if (fpDMNNode instanceof InputDataNodeImpl) {
            fdQname = ((InputDataNodeImpl) fpDMNNode).getInputData().getVariable().getTypeRef();
        } else if (fpDMNNode instanceof DecisionNodeImpl) {
            fdQname = ((DecisionNodeImpl) fpDMNNode).getDecision().getVariable().getTypeRef();
        }
        if (fiQname != null && fdQname != null && !fiQname.equals(fdQname)) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiII.getName(), fiQname, fdQname);
        }
    }
    QName fiReturnType = fi.getOutputTypeRef();
    if (ni.getDecisionService().getOutputDecision().size() == 1) {
        QName fdReturnType = outputDecisions.get(0).getDecision().getVariable().getTypeRef();
        if (fiReturnType != null && fdReturnType != null && !fiReturnType.equals(fdReturnType)) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiReturnType, fdReturnType);
        }
    } else if (ni.getDecisionService().getOutputDecision().size() > 1) {
        final Function<QName, QName> lookupFn = (in) -> DMNCompilerImpl.getNamespaceAndName(ni.getDecisionService(), model.getImportAliasesForNS(), in, model.getNamespace());
        LinkedHashMap<String, QName> fdComposite = new LinkedHashMap<>();
        for (DecisionNode dn : outputDecisions) {
            fdComposite.put(dn.getName(), lookupFn.apply(dn.getDecision().getVariable().getTypeRef()));
        }
        final QName lookup = lookupFn.apply(fiReturnType);
        Optional<ItemDefNodeImpl> composite = model.getItemDefinitions().stream().filter(id -> id.getModelNamespace().equals(lookup.getNamespaceURI()) && id.getName().equals(lookup.getLocalPart())).map(ItemDefNodeImpl.class::cast).findFirst();
        if (!composite.isPresent()) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), lookup, fdComposite);
            return;
        }
        LinkedHashMap<String, QName> fiComposite = new LinkedHashMap<>();
        for (ItemDefinition ic : composite.get().getItemDef().getItemComponent()) {
            fiComposite.put(ic.getName(), lookupFn.apply(ic.getTypeRef()));
        }
        if (!fiComposite.equals(fdComposite)) {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiComposite, fdComposite);
        }
    }
}
Also used : MsgUtil(org.kie.dmn.core.util.MsgUtil) DMNType(org.kie.dmn.api.core.DMNType) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) DMNMessage(org.kie.dmn.api.core.DMNMessage) SimpleFnTypeImpl(org.kie.dmn.core.impl.SimpleFnTypeImpl) LoggerFactory(org.slf4j.LoggerFactory) ItemDefNodeImpl(org.kie.dmn.core.ast.ItemDefNodeImpl) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNDecisionServiceFunctionDefinitionEvaluator(org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) Logger(org.slf4j.Logger) DMNNode(org.kie.dmn.api.core.ast.DMNNode) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) Collectors(java.util.stream.Collectors) FunctionItem(org.kie.dmn.model.api.FunctionItem) List(java.util.List) DSFormalParameter(org.kie.dmn.core.ast.DMNDecisionServiceFunctionDefinitionEvaluator.DSFormalParameter) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) Optional(java.util.Optional) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) QName(javax.xml.namespace.QName) DRGElement(org.kie.dmn.model.api.DRGElement) InformationItem(org.kie.dmn.model.api.InformationItem) Msg(org.kie.dmn.core.util.Msg) DecisionService(org.kie.dmn.model.api.DecisionService) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) Optional(java.util.Optional) QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) InformationItem(org.kie.dmn.model.api.InformationItem) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) SimpleFnTypeImpl(org.kie.dmn.core.impl.SimpleFnTypeImpl) LinkedHashMap(java.util.LinkedHashMap) Function(java.util.function.Function) DMNNode(org.kie.dmn.api.core.ast.DMNNode) FunctionItem(org.kie.dmn.model.api.FunctionItem) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl) ItemDefNodeImpl(org.kie.dmn.core.ast.ItemDefNodeImpl)

Example 3 with FunctionItem

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

the class FunctionItemConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    FunctionItem ii = (FunctionItem) parent;
    if (ii.getOutputTypeRef() != null) {
        writer.addAttribute(OUTPUT_TYPE_REF, MarshallingUtils.formatQName(ii.getOutputTypeRef(), ii));
    }
}
Also used : TFunctionItem(org.kie.dmn.model.v1_3.TFunctionItem) FunctionItem(org.kie.dmn.model.api.FunctionItem)

Example 4 with FunctionItem

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

the class FunctionItemConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    FunctionItem ii = (FunctionItem) parent;
    for (InformationItem ic : ii.getParameters()) {
        writeChildrenNode(writer, context, ic, PARAMETERS);
    }
}
Also used : InformationItem(org.kie.dmn.model.api.InformationItem) TFunctionItem(org.kie.dmn.model.v1_3.TFunctionItem) FunctionItem(org.kie.dmn.model.api.FunctionItem)

Example 5 with FunctionItem

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

the class FunctionItemConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    FunctionItem ii = (FunctionItem) parent;
    for (InformationItem ic : ii.getParameters()) {
        writeChildrenNode(writer, context, ic, PARAMETERS);
    }
}
Also used : InformationItem(org.kie.dmn.model.api.InformationItem) TFunctionItem(org.kie.dmn.model.v1_4.TFunctionItem) FunctionItem(org.kie.dmn.model.api.FunctionItem)

Aggregations

FunctionItem (org.kie.dmn.model.api.FunctionItem)9 InformationItem (org.kie.dmn.model.api.InformationItem)5 QName (javax.xml.namespace.QName)3 SimpleFnTypeImpl (org.kie.dmn.core.impl.SimpleFnTypeImpl)3 TFunctionItem (org.kie.dmn.model.v1_3.TFunctionItem)3 TFunctionItem (org.kie.dmn.model.v1_4.TFunctionItem)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 DMNType (org.kie.dmn.api.core.DMNType)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Collection (java.util.Collection)1