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