Search in sources :

Example 6 with DMNPackageImpl

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

the class DMNWeaverService method merge.

@Override
public void merge(KiePackage kiePkg, DMNPackage dmnpkg) {
    ResourceTypePackageRegistry registry = ((InternalKnowledgePackage) kiePkg).getResourceTypePackages();
    DMNPackageImpl existing = registry.computeIfAbsent(ResourceType.DMN, rt -> new DMNPackageImpl(dmnpkg.getNamespace()));
    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) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) Map(java.util.Map) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 7 with DMNPackageImpl

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

the class DMNAssemblerService method addResourcesAfterRules.

@Override
public void addResourcesAfterRules(Object kbuilder, Collection<ResourceWithConfiguration> resources, ResourceType type) throws Exception {
    EvalHelper.clearGenericAccessorCache();
    KnowledgeBuilderImpl kbuilderImpl = (KnowledgeBuilderImpl) kbuilder;
    DMNCompilerImpl dmnCompiler = (DMNCompilerImpl) kbuilderImpl.getCachedOrCreate(DMN_COMPILER_CACHE_KEY, () -> getCompiler(kbuilderImpl));
    DMNMarshaller dmnMarshaller = dmnCompiler.getMarshaller();
    List<DMNResource> dmnResources = new ArrayList<>();
    for (ResourceWithConfiguration r : resources) {
        Definitions definitions = dmnMarshaller.unmarshal(r.getResource().getReader());
        DMNResource dmnResource = new DMNResource(definitions, r);
        dmnResources.add(dmnResource);
    }
    Collection<DMNModel> dmnModels = new ArrayList<>();
    // KIE API: KieContainer upgrade using KieContainer#updateToVersion -based DMN Import resolution strategy
    if (kbuilderImpl.getKnowledgeBase() != null) {
        for (InternalKnowledgePackage pr : kbuilderImpl.getKnowledgeBase().getPackagesMap().values()) {
            ResourceTypePackage resourceTypePackage = pr.getResourceTypePackages().get(ResourceType.DMN);
            if (resourceTypePackage != null) {
                DMNPackageImpl dmnpkg = (DMNPackageImpl) resourceTypePackage;
                dmnModels.addAll(dmnpkg.getAllModels().values());
            }
        }
    }
    // Workbench: InternalKieBuilder#createFileSet#build -based DMN Import resolution strategy
    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());
        }
    }
    enrichDMNResourcesWithImportsDependencies(dmnResources, dmnModels);
    List<DMNResource> sortedDmnResources = DMNResourceDependenciesSorter.sort(dmnResources);
    for (DMNResource dmnRes : sortedDmnResources) {
        DMNModel dmnModel = internalAddResource(kbuilderImpl, dmnCompiler, dmnRes, dmnModels);
        dmnModels.add(dmnModel);
    }
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) ResourceWithConfiguration(org.kie.api.io.ResourceWithConfiguration) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

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