Search in sources :

Example 1 with DMNKnowledgeBuilderError

use of org.kie.dmn.core.impl.DMNKnowledgeBuilderError 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 2 with DMNKnowledgeBuilderError

use of org.kie.dmn.core.impl.DMNKnowledgeBuilderError 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 3 with DMNKnowledgeBuilderError

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

the class DMNAssemblerService method getCompiler.

private DMNCompiler getCompiler(KnowledgeBuilderImpl kbuilderImpl) {
    List<DMNProfile> dmnProfiles = kbuilderImpl.getCachedOrCreate(DMN_PROFILES_CACHE_KEY, () -> getDMNProfiles(kbuilderImpl));
    DMNCompilerConfigurationImpl compilerConfiguration;
    // Beware: compilerConfiguration can't be cached in DMNAssemblerService
    if (externalCompilerConfiguration == null) {
        compilerConfiguration = compilerConfigWithKModulePrefs(kbuilderImpl.getRootClassLoader(), kbuilderImpl.getBuilderConfiguration().getChainedProperties(), dmnProfiles, (DMNCompilerConfigurationImpl) DMNFactory.newCompilerConfiguration());
    } else {
        compilerConfiguration = externalCompilerConfiguration;
    }
    if (isStrictMode(kbuilderImpl.getBuilderConfiguration().getChainedProperties())) {
        compilerConfiguration.setProperty(RuntimeTypeCheckOption.PROPERTY_NAME, "true");
    }
    try {
        applyDecisionLogicCompilerFactory(kbuilderImpl.getRootClassLoader(), compilerConfiguration);
    } catch (Exception e) {
        kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.WARNING, "Trying to load a non-existing DMNDecisionLogicCompilerFactory " + e.getLocalizedMessage()));
        logger.error("Trying to load a non-existing DMNDecisionLogicCompilerFactory {}", e.getLocalizedMessage(), e);
        kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.WARNING, "DMN Compiler configuration contained errors, will fall-back to defaults."));
        logger.warn("DMN Compiler configuration contained errors, will fall-back to defaults.");
    }
    return DMNFactory.newCompiler(compilerConfiguration);
}
Also used : DMNKnowledgeBuilderError(org.kie.dmn.core.impl.DMNKnowledgeBuilderError) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) ExtendedDMNProfile(org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile) DMNCompilerConfigurationImpl(org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl)

Example 4 with DMNKnowledgeBuilderError

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

the class DMNAssemblerService method getDMNProfiles.

protected List<DMNProfile> getDMNProfiles(KnowledgeBuilderImpl kbuilderImpl) {
    ChainedProperties chainedProperties = kbuilderImpl.getBuilderConfiguration().getChainedProperties();
    List<DMNProfile> dmnProfiles = new ArrayList<>();
    dmnProfiles.addAll(getDefaultDMNProfiles(chainedProperties));
    Map<String, String> dmnProfileProperties = new HashMap<>();
    chainedProperties.mapStartsWith(dmnProfileProperties, DMN_PROFILE_PREFIX, false);
    if (!dmnProfileProperties.isEmpty()) {
        try {
            for (Map.Entry<String, String> dmnProfileProperty : dmnProfileProperties.entrySet()) {
                DMNProfile dmnProfile = (DMNProfile) kbuilderImpl.getRootClassLoader().loadClass(dmnProfileProperty.getValue()).newInstance();
                dmnProfiles.add(dmnProfile);
            }
            return dmnProfiles;
        } catch (Exception e) {
            kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.WARNING, "Trying to load a non-existing Kie DMN profile " + e.getLocalizedMessage()));
            logger.error("Trying to load a non-existing Kie DMN profile {}", e.getLocalizedMessage(), e);
            kbuilderImpl.addBuilderResult(new DMNKnowledgeBuilderError(ResultSeverity.WARNING, "DMN Compiler configuration contained errors, will fall-back using empty-configuration compiler."));
            logger.warn("DMN Compiler configuration contained errors, will fall-back using empty-configuration compiler.");
        }
    }
    return dmnProfiles;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChainedProperties(org.kie.internal.utils.ChainedProperties) DMNKnowledgeBuilderError(org.kie.dmn.core.impl.DMNKnowledgeBuilderError) HashMap(java.util.HashMap) Map(java.util.Map) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) ExtendedDMNProfile(org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile)

Aggregations

DMNKnowledgeBuilderError (org.kie.dmn.core.impl.DMNKnowledgeBuilderError)4 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNProfile (org.kie.dmn.core.compiler.DMNProfile)2 ExtendedDMNProfile (org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile)2 DMNPackageImpl (org.kie.dmn.core.impl.DMNPackageImpl)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 ResourceTypePackageRegistry (org.drools.core.definitions.ResourceTypePackageRegistry)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 ResourceTypePackage (org.kie.api.internal.io.ResourceTypePackage)1 ResourceType (org.kie.api.io.ResourceType)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 DMNCompilerConfigurationImpl (org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl)1 ChainedProperties (org.kie.internal.utils.ChainedProperties)1