use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class KieContainerImpl method update.
private Results update(final InternalKieModule currentKM, final ReleaseId newReleaseId) {
final InternalKieModule newKM = (InternalKieModule) kr.getKieModule(newReleaseId);
if (newKM == null) {
return null;
}
final KieJarChangeSet cs = currentKM.getChanges(newKM);
List<String> modifiedClassNames = getModifiedClasses(cs);
final boolean modifyingUsedClass = isModifyingUsedClass(modifiedClassNames, getClassLoader());
final List<Class<?>> modifiedClasses = reinitModifiedClasses(newKM, modifiedClassNames, getClassLoader());
final List<String> unchangedResources = getUnchangedResources(newKM, cs);
Map<String, KieBaseModel> currentKieBaseModels = ((KieModuleKieProject) kProject).updateToModule(newKM);
final ResultsImpl results = new ResultsImpl();
List<String> kbasesToRemove = new ArrayList<String>();
for (Entry<String, KieBase> kBaseEntry : kBases.entrySet()) {
String kbaseName = kBaseEntry.getKey();
KieBaseModelImpl newKieBaseModel = (KieBaseModelImpl) kProject.getKieBaseModel(kbaseName);
KieBaseModelImpl currentKieBaseModel = (KieBaseModelImpl) currentKieBaseModels.get(kbaseName);
// if a kbase no longer exists, just remove it from the cache
if (newKieBaseModel == null) {
// have to save for later removal to avoid iteration errors
kbasesToRemove.add(kbaseName);
} else {
final InternalKnowledgeBase kBase = (InternalKnowledgeBase) kBaseEntry.getValue();
KieBaseUpdateContext context = new KieBaseUpdateContext(kProject, kBase, currentKM, newReleaseId, newKM, cs, modifiedClasses, modifyingUsedClass, unchangedResources, results, newKieBaseModel, currentKieBaseModel);
kBase.enqueueModification(currentKM.createKieBaseUpdater(context));
}
}
for (String kbaseToRemove : kbasesToRemove) {
kBases.remove(kbaseToRemove);
}
// remove sessions that no longer exist
this.kSessions.entrySet().removeIf(ksession -> kProject.getKieSessionModel(ksession.getKey()) == null);
this.statelessKSessions.entrySet().removeIf(ksession -> kProject.getKieSessionModel(ksession.getKey()) == null);
return results;
}
use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class KBaseConverter method marshal.
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
KieBaseModelImpl kBase = (KieBaseModelImpl) value;
writer.addAttribute("name", kBase.getName());
writer.addAttribute("default", Boolean.toString(kBase.isDefault()));
if (kBase.getEventProcessingMode() != null) {
writer.addAttribute("eventProcessingMode", kBase.getEventProcessingMode().getMode());
}
if (kBase.getEqualsBehavior() != null) {
writer.addAttribute("equalsBehavior", kBase.getEqualsBehavior().toString().toLowerCase());
}
if (kBase.getMutability() != null) {
writer.addAttribute("mutability", kBase.getMutability().toString().toLowerCase());
}
if (kBase.getDeclarativeAgenda() != null) {
writer.addAttribute("declarativeAgenda", kBase.getDeclarativeAgenda().toString().toLowerCase());
}
if (kBase.getSequential() != null) {
writer.addAttribute("sequential", kBase.getSequential() == YES ? "true" : "false");
}
if (kBase.getSessionsPool() != null) {
writer.addAttribute("sessionsPool", "" + kBase.getSessionsPool().getSize());
}
if (kBase.getBetaRangeIndexOption() != null) {
writer.addAttribute("betaRangeIndex", kBase.getBetaRangeIndexOption().toString().toLowerCase());
}
if (kBase.getScope() != null) {
writer.addAttribute("scope", kBase.getScope());
}
if (!kBase.getPackages().isEmpty()) {
StringBuilder buf = new StringBuilder();
boolean first = true;
for (String pkg : kBase.getPackages()) {
if (first) {
first = false;
} else {
buf.append(", ");
}
buf.append(pkg);
}
writer.addAttribute("packages", buf.toString());
}
if (!kBase.getIncludes().isEmpty()) {
StringBuilder sb = new StringBuilder();
boolean insertComma = false;
for (String include : kBase.getIncludes()) {
if (insertComma) {
sb.append(", ");
}
sb.append(include);
if (!insertComma) {
insertComma = true;
}
}
writer.addAttribute("includes", sb.toString());
}
for (RuleTemplateModel ruleTemplateModel : kBase.getRuleTemplates()) {
writeObject(writer, context, "ruleTemplate", ruleTemplateModel);
}
for (KieSessionModel kSessionModel : kBase.getKieSessionModels().values()) {
writeObject(writer, context, "ksession", kSessionModel);
}
}
use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class KieModuleConverter method unmarshal.
public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
final KieModuleModelImpl kModule = new KieModuleModelImpl();
readNodes(reader, new AbstractXStreamConverter.NodeReader() {
public void onNode(HierarchicalStreamReader reader, String name, String value) {
if ("kbase".equals(name)) {
KieBaseModelImpl kBaseModule = readObject(reader, context, KieBaseModelImpl.class);
kModule.getRawKieBaseModels().put(kBaseModule.getName(), kBaseModule);
kBaseModule.setKModule(kModule);
} else if ("configuration".equals(name)) {
kModule.setConfProps(readPropertyMap(reader, context));
}
}
});
return kModule;
}
use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class DMNRuntimeKBWrappingIKB method getListeners.
@Override
public List<DMNRuntimeEventListener> getListeners() {
if (knowledgeBase != null && knowledgeBase.getKieContainer() instanceof KieContainerImpl) {
KieBaseModelImpl kieBaseModel = (KieBaseModelImpl) ((KieContainerImpl) knowledgeBase.getKieContainer()).getKieProject().getKieBaseModel(knowledgeBase.getId());
ChainedProperties cp = ChainedProperties.getChainedProperties(getRootClassLoader());
Properties kmoduleProperties = new Properties();
kmoduleProperties.putAll(kieBaseModel.getKModule().getConfigurationProperties());
cp.addProperties(kmoduleProperties);
Map<String, String> listenersMap = new HashMap<>();
cp.mapStartsWith(listenersMap, DMNAssemblerService.DMN_RUNTIME_LISTENER_PREFIX, true);
logger.debug("{}", listenersMap);
return listenersMap.values().stream().map(this::loadEventListener).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).collect(Collectors.toList());
} else {
logger.warn("No DMNRuntime Listener can be provided, as created without a reference to KnowledgeBase");
}
return Collections.emptyList();
}
use of org.drools.compiler.kproject.models.KieBaseModelImpl in project drools by kiegroup.
the class CanonicalKieModule method findProcesses.
private List<Process> findProcesses(InternalKieModule kieModule, KieBaseModelImpl kBaseModel) {
List<Process> processes = new ArrayList<>();
Collection<KiePackage> pkgs = kieModule.getKnowledgePackagesForKieBase(kBaseModel.getName());
if (pkgs == null) {
List<Resource> processResources = kieModule.getFileNames().stream().filter(fileName -> {
ResourceType resourceType = determineResourceType(fileName);
return resourceType == ResourceType.DRF || resourceType == ResourceType.BPMN2;
}).map(fileName -> {
final Resource processResource = kieModule.getResource(fileName);
processResource.setResourceType(determineResourceType(fileName));
return processResource;
}).collect(toList());
if (!processResources.isEmpty()) {
KnowledgeBuilderImpl kbuilder = (KnowledgeBuilderImpl) KnowledgeBuilderFactory.newKnowledgeBuilder(createBuilderConfiguration(kBaseModel, moduleClassLoader));
for (Resource processResource : processResources) {
kbuilder.add(processResource, processResource.getResourceType());
}
for (InternalKnowledgePackage knowledgePackage : kbuilder.getPackages()) {
processes.addAll(knowledgePackage.getProcesses());
}
}
} else {
for (KiePackage pkg : pkgs) {
processes.addAll(pkg.getProcesses());
}
}
return processes;
}
Aggregations