Search in sources :

Example 1 with DMNProfile

use of org.kie.dmn.core.compiler.DMNProfile 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));
    DMNCompilerConfiguration compilerConfig = compilerConfigWithKModulePrefs(kbuilderImpl.getBuilderConfiguration().getChainedProperties(), dmnProfiles);
    return DMNFactory.newCompiler(compilerConfig);
}
Also used : DMNCompilerConfiguration(org.kie.dmn.api.core.DMNCompilerConfiguration) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) ExtendedDMNProfile(org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile)

Example 2 with DMNProfile

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

the class DMNAssemblerService method getDMNProfiles.

private 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)

Example 3 with DMNProfile

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

the class DMNAssemblerService method compilerConfigWithKModulePrefs.

/**
 * Returns a DMNCompilerConfiguration with the specified properties set, and applying the explicited dmnProfiles.
 * @param chainedProperties applies properties --it does not do any classloading nor profile loading based on these properites, just passes the values.
 * @param dmnProfiles applies these DMNProfile(s) to the DMNCompilerConfiguration
 * @return
 */
public static DMNCompilerConfiguration compilerConfigWithKModulePrefs(ChainedProperties chainedProperties, List<DMNProfile> dmnProfiles) {
    DMNCompilerConfigurationImpl config = (DMNCompilerConfigurationImpl) DMNFactory.newCompilerConfiguration();
    Map<String, String> dmnPrefs = new HashMap<>();
    chainedProperties.mapStartsWith(dmnPrefs, ORG_KIE_DMN_PREFIX, true);
    config.setProperties(dmnPrefs);
    for (DMNProfile dmnProfile : dmnProfiles) {
        config.addExtensions(dmnProfile.getExtensionRegisters());
        config.addDRGElementCompilers(dmnProfile.getDRGElementCompilers());
        config.addFEELProfile(dmnProfile);
    }
    return config;
}
Also used : HashMap(java.util.HashMap) 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 DMNProfile

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

the class DMNRuntimeImpl method getProfiles.

public List<DMNProfile> getProfiles() {
    // need list to preserve ordering
    List<DMNProfile> profiles = new ArrayList<>();
    runtime.getKieBase().getKiePackages().forEach(kpkg -> {
        DMNPackageImpl dmnPkg = (DMNPackageImpl) ((InternalKnowledgePackage) kpkg).getResourceTypePackages().get(ResourceType.DMN);
        if (dmnPkg != null) {
            for (DMNProfile p : dmnPkg.getProfiles()) {
                if (!profiles.contains(p)) {
                    profiles.add(p);
                }
            }
        }
    });
    return profiles;
}
Also used : ArrayList(java.util.ArrayList) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

DMNProfile (org.kie.dmn.core.compiler.DMNProfile)4 ExtendedDMNProfile (org.kie.dmn.core.compiler.profiles.ExtendedDMNProfile)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 DMNCompilerConfiguration (org.kie.dmn.api.core.DMNCompilerConfiguration)1 DMNCompilerConfigurationImpl (org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl)1 DMNKnowledgeBuilderError (org.kie.dmn.core.impl.DMNKnowledgeBuilderError)1 ChainedProperties (org.kie.internal.utils.ChainedProperties)1