use of org.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.
the class PMMLAssemblerService method addModels.
protected void addModels(KnowledgeBuilderImpl kbuilderImpl, List<KiePMMLModel> toAdd) {
for (KiePMMLModel kiePMMLModel : toAdd) {
PackageDescr pkgDescr = new PackageDescr(kiePMMLModel.getKModulePackageName());
PackageRegistry pkgReg = kbuilderImpl.getOrCreatePackageRegistry(pkgDescr);
InternalKnowledgePackage kpkgs = pkgReg.getPackage();
ResourceTypePackageRegistry rpkg = kpkgs.getResourceTypePackages();
PMMLPackage pmmlPkg = rpkg.computeIfAbsent(ResourceType.PMML, rtp -> new PMMLPackageImpl());
pmmlPkg.addAll(Collections.singletonList(kiePMMLModel));
if (kiePMMLModel instanceof HasNestedModels) {
addModels(kbuilderImpl, ((HasNestedModels) kiePMMLModel).getNestedModels());
}
}
}
use of org.drools.core.definitions.ResourceTypePackageRegistry 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.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.
the class DMNRuntimeKBWrappingIKB method getModelById.
@Override
public DMNModel getModelById(String namespace, String modelId) {
Objects.requireNonNull(namespace, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "namespace"));
Objects.requireNonNull(modelId, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "modelId"));
InternalKnowledgePackage kpkg = (InternalKnowledgePackage) knowledgeBase.getKiePackage(namespace);
if (kpkg == null) {
return null;
}
ResourceTypePackageRegistry map = kpkg.getResourceTypePackages();
DMNPackage dmnpkg = (DMNPackage) map.get(ResourceType.DMN);
return dmnpkg != null ? dmnpkg.getModelById(modelId) : null;
}
use of org.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.
the class BayesRuntimeImpl method createInstance.
public BayesInstance createInstance(Class cls) {
InternalKnowledgePackage kpkg = (InternalKnowledgePackage) kieBase.getKiePackage(cls.getPackage().getName());
ResourceTypePackageRegistry map = kpkg.getResourceTypePackages();
BayesPackage bayesPkg = (BayesPackage) map.get(ResourceType.BAYES);
JunctionTree jtree = bayesPkg.getJunctionTree(cls.getSimpleName());
return new BayesInstance(jtree, cls);
}
use of org.drools.core.definitions.ResourceTypePackageRegistry in project drools by kiegroup.
the class PMMLWeaverService method merge.
@Override
public void merge(KiePackage kiePkg, PMMLPackage dmnpkg) {
ResourceTypePackageRegistry registry = ((InternalKnowledgePackage) kiePkg).getResourceTypePackages();
PMMLPackageImpl existing = registry.computeIfAbsent(ResourceType.PMML, rt -> new PMMLPackageImpl());
existing.addAll(dmnpkg.getAllModels().values());
}
Aggregations