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;
}
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;
}
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);
}
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;
}
Aggregations