Search in sources :

Example 1 with DMNCompilerImpl

use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.

the class DMNModelImpl method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this.serializedAs = (SerializationFormat) in.readObject();
    this.resource = (Resource) in.readObject();
    String xml = (String) in.readObject();
    if (!(in instanceof DroolsObjectInputStream)) {
        throw new UnsupportedOperationException();
    // TODO assume some defaults
    }
    DroolsObjectInputStream is = (DroolsObjectInputStream) in;
    DMNCompilerImpl compiler = (DMNCompilerImpl) is.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
    List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
    Definitions definitions = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).unmarshal(xml);
    this.definitions = definitions;
    DMNModelImpl compiledModel = (DMNModelImpl) compiler.compile(definitions);
    this.inputs = compiledModel.inputs;
    this.decisions = compiledModel.decisions;
    this.bkms = compiledModel.bkms;
    this.itemDefs = compiledModel.itemDefs;
    this.messages = compiledModel.messages;
    this.types = compiledModel.types;
    this.runtimeTypeCheck = compiledModel.runtimeTypeCheck;
}
Also used : DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNExtensionRegister(org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister)

Example 2 with DMNCompilerImpl

use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.

the class DMNModelImpl method writeExternal.

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(serializedAs);
    out.writeObject(resource);
    if (!(out instanceof DroolsObjectOutputStream)) {
        throw new UnsupportedOperationException();
    // TODO assume some defaults
    }
    DroolsObjectOutputStream os = (DroolsObjectOutputStream) out;
    DMNCompilerImpl compiler = (DMNCompilerImpl) os.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
    List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
    String output = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).marshal(this.definitions);
    out.writeObject(output);
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) DroolsObjectOutputStream(org.drools.core.common.DroolsObjectOutputStream) DMNExtensionRegister(org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister)

Example 3 with DMNCompilerImpl

use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.

the class DMNAssemblerService method addResources.

@Override
public void addResources(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) throws Exception {
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    DMNCompilerImpl dmnCompiler = (DMNCompilerImpl) kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
    DMNMarshaller dmnMarshaller = dmnCompiler.getMarshaller();
    if (resources.size() == 1) {
        // quick path:
        internalAddResource(kbuilderImpl, dmnCompiler, resources.iterator().next(), Collections.emptyList());
        return;
    }
    List<DMNResource> dmnResources = new ArrayList<>();
    for (ResourceWithConfiguration r : resources) {
        Definitions definitions = dmnMarshaller.unmarshal(r.getResource().getReader());
        QName modelID = new QName(definitions.getNamespace(), definitions.getName());
        DMNResource dmnResource = new DMNResource(modelID, r, definitions);
        dmnResources.add(dmnResource);
    }
    // enrich with imports
    for (DMNResource r : dmnResources) {
        for (Import i : r.getDefinitions().getImport()) {
            if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
                Either<String, DMNResource> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnResources, DMNResource::getModelID);
                DMNResource located = resolvedResult.getOrElseThrow(RuntimeException::new);
                r.addDependency(located.getModelID());
            }
        }
    }
    List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
    Collection<DMNModel> dmnModels = new ArrayList<>();
    for (DMNResource dmnRes : sortedDmnResources) {
        DMNModel dmnModel = internalAddResource(kbuilderImpl, dmnCompiler, dmnRes.getResAndConfig(), dmnModels);
        dmnModels.add(dmnModel);
    }
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) Import(org.kie.dmn.model.v1_1.Import) DMNMarshaller(org.kie.dmn.api.marshalling.v1_1.DMNMarshaller) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.v1_1.Definitions) ArrayList(java.util.ArrayList) ResourceWithConfiguration(org.kie.api.io.ResourceWithConfiguration) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 4 with DMNCompilerImpl

use of org.kie.dmn.core.compiler.DMNCompilerImpl in project drools by kiegroup.

the class DMNValidatorImpl method validateCompilation.

private List<DMNMessage> validateCompilation(Definitions dmnModel, DMNMessageManager results) {
    if (dmnModel != null) {
        DMNCompiler compiler = new DMNCompilerImpl(dmnCompilerConfig);
        DMNModel model = compiler.compile(dmnModel);
        if (model != null) {
            return model.getMessages();
        } else {
            MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, dmnModel, results, null, null, Msg.FAILED_VALIDATOR);
        }
    }
    return Collections.emptyList();
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) DMNCompiler(org.kie.dmn.api.core.DMNCompiler) DMNModel(org.kie.dmn.api.core.DMNModel)

Aggregations

DMNCompilerImpl (org.kie.dmn.core.compiler.DMNCompilerImpl)4 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNExtensionRegister (org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister)2 Definitions (org.kie.dmn.model.v1_1.Definitions)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 DroolsObjectInputStream (org.drools.core.common.DroolsObjectInputStream)1 DroolsObjectOutputStream (org.drools.core.common.DroolsObjectOutputStream)1 ResourceWithConfiguration (org.kie.api.io.ResourceWithConfiguration)1 DMNCompiler (org.kie.dmn.api.core.DMNCompiler)1 DMNMarshaller (org.kie.dmn.api.marshalling.v1_1.DMNMarshaller)1 Import (org.kie.dmn.model.v1_1.Import)1