Search in sources :

Example 1 with DMNPackageImpl

use of org.kie.dmn.core.impl.DMNPackageImpl in project drools by kiegroup.

the class DMNWeaverService method merge.

@Override
public void merge(KieBase kieBase, KiePackage kiePkg, DMNPackage dmnpkg) {
    Map<ResourceType, ResourceTypePackage> map = ((InternalKnowledgePackage) kiePkg).getResourceTypePackages();
    DMNPackageImpl existing = (DMNPackageImpl) map.get(ResourceType.DMN);
    if (existing == null) {
        existing = new DMNPackageImpl(dmnpkg.getNamespace());
        map.put(ResourceType.DMN, existing);
    }
    for (Map.Entry<String, DMNModel> entry : dmnpkg.getAllModels().entrySet()) {
        existing.addModel(entry.getKey(), entry.getValue());
    }
    existing.addProfiles(((DMNPackageImpl) dmnpkg).getProfiles());
}
Also used : DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) ResourceType(org.kie.api.io.ResourceType) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) Map(java.util.Map) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 2 with DMNPackageImpl

use of org.kie.dmn.core.impl.DMNPackageImpl in project drools by kiegroup.

the class DMNAssemblerService method compileResourceToModel.

private DMNModel compileResourceToModel(KnowledgeBuilderImpl kbuilderImpl, DMNCompiler dmnCompiler, Resource resource, Collection<DMNModel> dmnModels) {
    DMNModel model = dmnCompiler.compile(resource, dmnModels);
    if (model != null) {
        String namespace = model.getNamespace();
        PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(new PackageDescr(namespace));
        InternalKnowledgePackage kpkgs = pkgReg.getPackage();
        kpkgs.addCloningResource(DMN_COMPILER_CACHE_KEY, dmnCompiler);
        Map<ResourceType, ResourceTypePackage> rpkg = kpkgs.getResourceTypePackages();
        DMNPackageImpl dmnpkg = (DMNPackageImpl) rpkg.get(ResourceType.DMN);
        if (dmnpkg == null) {
            dmnpkg = new DMNPackageImpl(namespace);
            rpkg.put(ResourceType.DMN, dmnpkg);
        } else {
            if (dmnpkg.getModel(model.getName()) != null) {
                kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.ERROR, resource, namespace, "Duplicate model name " + model.getName() + " in namespace " + namespace));
                logger.error("Duplicate model name {} in namespace {}", model.getName(), namespace);
            }
        }
        dmnpkg.addModel(model.getName(), model);
        dmnpkg.addProfiles(kbuilderImpl.getCachedOrCreate(DMN_PROFILES_CACHE_KEY, () -> getDMNProfiles(kbuilderImpl)));
    } else {
        kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.ERROR, resource, "Unable to compile DMN model for the resource"));
        logger.error("Unable to compile DMN model for resource {}", resource.getSourcePath());
    }
    return model;
}
Also used : PackageRegistry(org.drools.compiler.compiler.PackageRegistry) DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) ResourceType(org.kie.api.io.ResourceType) DMNKnowledgeBuilderError(org.kie.dmn.core.impl.DMNKnowledgeBuilderError) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 3 with DMNPackageImpl

use of org.kie.dmn.core.impl.DMNPackageImpl in project drools by kiegroup.

the class DMNAssemblerService method addResourceAfterRules.

@Override
public void addResourceAfterRules(Object kbuilder, Resource resource, ResourceType type, ResourceConfiguration configuration) throws Exception {
    logger.warn("invoked legacy addResourceAfterRules (no control on the order of the assembler compilation): {}", resource.getSourcePath());
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    DMNCompiler dmnCompiler = kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
    Collection<DMNModel> dmnModels = new ArrayList<>();
    for (PackageRegistry pr : kbuilderImpl.getPackageRegistry().values()) {
        ResourceTypePackage resourceTypePackage = pr.getPackage().getResourceTypePackages().get(ResourceType.DMN);
        if (resourceTypePackage != null) {
            DMNPackageImpl dmnpkg = (DMNPackageImpl) resourceTypePackage;
            dmnModels.addAll(dmnpkg.getAllModels().values());
        }
    }
    compileResourceToModel(kbuilderImpl, dmnCompiler, resource, null, dmnModels);
}
Also used : ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ArrayList(java.util.ArrayList) DMNCompiler(org.kie.dmn.api.core.DMNCompiler) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 4 with DMNPackageImpl

use of org.kie.dmn.core.impl.DMNPackageImpl in project drools by kiegroup.

the class DMNAssemblerService method compileResourceToModel.

private DMNModel compileResourceToModel(KnowledgeBuilderImpl kbuilderImpl, DMNCompiler dmnCompiler, Resource resource, DMNResource dmnRes, Collection<DMNModel> dmnModels) {
    DMNModel model = dmnRes != null ? dmnCompiler.compile(dmnRes.getDefinitions(), resource, dmnModels) : dmnCompiler.compile(resource, dmnModels);
    if (model != null) {
        String namespace = model.getNamespace();
        PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(new PackageDescr(namespace));
        InternalKnowledgePackage kpkgs = pkgReg.getPackage();
        kpkgs.addCloningResource(DMN_COMPILER_CACHE_KEY, dmnCompiler);
        ResourceTypePackageRegistry rpkg = kpkgs.getResourceTypePackages();
        DMNPackageImpl dmnpkg = rpkg.computeIfAbsent(ResourceType.DMN, rtp -> new DMNPackageImpl(namespace));
        if (dmnpkg.getModel(model.getName()) != null) {
            kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.ERROR, resource, namespace, "Duplicate model name " + model.getName() + " in namespace " + namespace));
            logger.error("Duplicate model name {} in namespace {}", model.getName(), namespace);
        }
        dmnpkg.addModel(model.getName(), model);
        for (DMNMessage m : model.getMessages()) {
            kbuilderImpl.addBuilderResult(DMNKnowledgeBuilderError.from(resource, namespace, m));
        }
        dmnpkg.addProfiles(kbuilderImpl.getCachedOrCreate(DMN_PROFILES_CACHE_KEY, () -> getDMNProfiles(kbuilderImpl)));
    } else {
        kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.ERROR, resource, "Unable to compile DMN model for the resource"));
        logger.error("Unable to compile DMN model for the resource {}", resource.getSourcePath());
    }
    return model;
}
Also used : ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNKnowledgeBuilderError(org.kie.dmn.core.impl.DMNKnowledgeBuilderError) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 5 with DMNPackageImpl

use of org.kie.dmn.core.impl.DMNPackageImpl in project drools by kiegroup.

the class DMNAssemblerService method addResource.

@Override
public void addResource(Object kbuilder, Resource resource, ResourceType type, ResourceConfiguration configuration) throws Exception {
    logger.warn("invoked legacy addResource (no control on the order of the assembler compilation): " + resource.getSourcePath());
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    DMNCompiler dmnCompiler = kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
    Collection<DMNModel> dmnModels = new ArrayList<>();
    for (PackageRegistry pr : kbuilderImpl.getPackageRegistry().values()) {
        ResourceTypePackage resourceTypePackage = pr.getPackage().getResourceTypePackages().get(ResourceType.DMN);
        if (resourceTypePackage != null) {
            DMNPackageImpl dmnpkg = (DMNPackageImpl) resourceTypePackage;
            dmnModels.addAll(dmnpkg.getAllModels().values());
        }
    }
    compileResourceToModel(kbuilderImpl, dmnCompiler, resource, dmnModels);
}
Also used : PackageRegistry(org.drools.compiler.compiler.PackageRegistry) DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ArrayList(java.util.ArrayList) DMNCompiler(org.kie.dmn.api.core.DMNCompiler) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) DMNModel(org.kie.dmn.api.core.DMNModel)

Aggregations

DMNModel (org.kie.dmn.api.core.DMNModel)7 DMNPackageImpl (org.kie.dmn.core.impl.DMNPackageImpl)7 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)5 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)5 ResourceTypePackageRegistry (org.drools.core.definitions.ResourceTypePackageRegistry)4 ArrayList (java.util.ArrayList)3 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)3 Map (java.util.Map)2 ResourceType (org.kie.api.io.ResourceType)2 DMNCompiler (org.kie.dmn.api.core.DMNCompiler)2 DMNKnowledgeBuilderError (org.kie.dmn.core.impl.DMNKnowledgeBuilderError)2 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 ResourceWithConfiguration (org.kie.api.io.ResourceWithConfiguration)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 DMNMarshaller (org.kie.dmn.api.marshalling.DMNMarshaller)1 DMNCompilerImpl (org.kie.dmn.core.compiler.DMNCompilerImpl)1 Definitions (org.kie.dmn.model.api.Definitions)1