diff --git a/drools/pom.xml b/drools/pom.xml
index daaf1fa8a7..ff121d7838 100644
--- a/drools/pom.xml
+++ b/drools/pom.xml
@@ -57,10 +57,10 @@
- 4.4.6
- 7.4.1.Final
- 3.13
- 7.10.0.Final
+ 4.4.16
+ 8.32.0.Final
+ 5.2.3
+ 8.32.0.Final
\ No newline at end of file
diff --git a/drools/src/main/java/com/baeldung/drools/backward_chaining/BackwardChaining.java b/drools/src/main/java/com/baeldung/drools/backward_chaining/BackwardChaining.java
index 6f15ee510b..3baabbeb0f 100644
--- a/drools/src/main/java/com/baeldung/drools/backward_chaining/BackwardChaining.java
+++ b/drools/src/main/java/com/baeldung/drools/backward_chaining/BackwardChaining.java
@@ -11,7 +11,6 @@ public class BackwardChaining {
Result result = new BackwardChaining().backwardChaining();
System.out.println(result.getValue());
result.getFacts()
- .stream()
.forEach(System.out::println);
}
diff --git a/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java b/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java
index cf5d56f246..bbc1f3170a 100644
--- a/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java
+++ b/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java
@@ -10,26 +10,25 @@ import org.kie.internal.builder.DecisionTableConfiguration;
import org.kie.internal.builder.DecisionTableInputType;
import org.kie.internal.builder.KnowledgeBuilderFactory;
import org.kie.internal.io.ResourceFactory;
-import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class DroolsBeanFactory {
private static final String RULES_PATH = "com/baeldung/drools/rules/";
- private KieServices kieServices=KieServices.Factory.get();
+ private KieServices kieServices = KieServices.Factory.get();
- private KieFileSystem getKieFileSystem() throws IOException{
+ private KieFileSystem getKieFileSystem() {
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
- List rules=Arrays.asList("BackwardChaining.drl","SuggestApplicant.drl","Product_rules.xls");
- for(String rule:rules){
+ List rules = Arrays.asList("BackwardChaining.drl", "SuggestApplicant.drl", "Product_rules.xls");
+ for(String rule:rules) {
kieFileSystem.write(ResourceFactory.newClassPathResource(rule));
}
return kieFileSystem;
}
- public KieContainer getKieContainer() throws IOException {
+ public KieContainer getKieContainer() {
getKieRepository();
KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem());
@@ -44,14 +43,10 @@ public class DroolsBeanFactory {
private void getKieRepository() {
final KieRepository kieRepository = kieServices.getRepository();
- kieRepository.addKieModule(new KieModule() {
- public ReleaseId getReleaseId() {
- return kieRepository.getDefaultReleaseId();
- }
- });
+ kieRepository.addKieModule(kieRepository::getDefaultReleaseId);
}
- public KieSession getKieSession(){
+ public KieSession getKieSession() {
getKieRepository();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
@@ -59,7 +54,6 @@ public class DroolsBeanFactory {
kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/SuggestApplicant.drl"));
kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/Product_rules.xls"));
-
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
@@ -67,7 +61,6 @@ public class DroolsBeanFactory {
KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kContainer.newKieSession();
-
}
public KieSession getKieSession(Resource dt) {
diff --git a/drools/src/main/java/com/baeldung/drools/optaplanner/CourseSchedule.java b/drools/src/main/java/com/baeldung/drools/optaplanner/CourseSchedule.java
index 7b2ba117a1..d0ae5318b9 100644
--- a/drools/src/main/java/com/baeldung/drools/optaplanner/CourseSchedule.java
+++ b/drools/src/main/java/com/baeldung/drools/optaplanner/CourseSchedule.java
@@ -6,7 +6,7 @@ import java.util.List;
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
-import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty;
+import org.optaplanner.core.api.domain.solution.ProblemFactCollectionProperty;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
import org.slf4j.Logger;
diff --git a/drools/src/main/java/com/baeldung/drools/optaplanner/ScoreCalculator.java b/drools/src/main/java/com/baeldung/drools/optaplanner/ScoreCalculator.java
index 86501cdccd..c9d2b4df99 100644
--- a/drools/src/main/java/com/baeldung/drools/optaplanner/ScoreCalculator.java
+++ b/drools/src/main/java/com/baeldung/drools/optaplanner/ScoreCalculator.java
@@ -2,14 +2,13 @@ package com.baeldung.drools.optaplanner;
import java.util.HashSet;
-import org.optaplanner.core.api.score.Score;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
-import org.optaplanner.core.impl.score.director.easy.EasyScoreCalculator;
+import org.optaplanner.core.api.score.calculator.EasyScoreCalculator;
-public class ScoreCalculator implements EasyScoreCalculator {
+public class ScoreCalculator implements EasyScoreCalculator {
@Override
- public Score calculateScore(CourseSchedule courseSchedule) {
+ public HardSoftScore calculateScore(CourseSchedule courseSchedule) {
int hardScore = 0;
int softScore = 0;
@@ -27,6 +26,6 @@ public class ScoreCalculator implements EasyScoreCalculator {
}
}
- return HardSoftScore.valueOf(hardScore, softScore);
+ return HardSoftScore.of(hardScore, softScore);
}
}
diff --git a/drools/src/main/java/com/baeldung/drools/service/ApplicantService.java b/drools/src/main/java/com/baeldung/drools/service/ApplicantService.java
index f74298ef05..06f84358b0 100644
--- a/drools/src/main/java/com/baeldung/drools/service/ApplicantService.java
+++ b/drools/src/main/java/com/baeldung/drools/service/ApplicantService.java
@@ -3,19 +3,20 @@ package com.baeldung.drools.service;
import com.baeldung.drools.config.DroolsBeanFactory;
import com.baeldung.drools.model.Applicant;
import com.baeldung.drools.model.SuggestedRole;
-import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
-import java.io.IOException;
-
public class ApplicantService {
- KieSession kieSession=new DroolsBeanFactory().getKieSession();
+ KieSession kieSession = new DroolsBeanFactory().getKieSession();
- public SuggestedRole suggestARoleForApplicant(Applicant applicant,SuggestedRole suggestedRole) throws IOException {
- kieSession.insert(applicant);
- kieSession.setGlobal("suggestedRole",suggestedRole);
- kieSession.fireAllRules();
+ public SuggestedRole suggestARoleForApplicant(Applicant applicant,SuggestedRole suggestedRole) {
+ try {
+ kieSession.insert(applicant);
+ kieSession.setGlobal("suggestedRole", suggestedRole);
+ kieSession.fireAllRules();
+ } finally {
+ kieSession.dispose();
+ }
System.out.println(suggestedRole.getRole());
return suggestedRole;
diff --git a/drools/src/main/java/com/baeldung/drools/service/ProductService.java b/drools/src/main/java/com/baeldung/drools/service/ProductService.java
index be5e43ed7b..401f5a600f 100644
--- a/drools/src/main/java/com/baeldung/drools/service/ProductService.java
+++ b/drools/src/main/java/com/baeldung/drools/service/ProductService.java
@@ -2,18 +2,21 @@ package com.baeldung.drools.service;
import com.baeldung.drools.config.DroolsBeanFactory;
import com.baeldung.drools.model.Product;
-import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
public class ProductService {
- private KieSession kieSession=new DroolsBeanFactory().getKieSession();
+ private KieSession kieSession = new DroolsBeanFactory().getKieSession();
public Product applyLabelToProduct(Product product){
- kieSession.insert(product);
- kieSession.fireAllRules();
+ try {
+ kieSession.insert(product);
+ kieSession.fireAllRules();
+ } finally {
+ kieSession.dispose();
+ }
System.out.println(product.getLabel());
- return product;
+ return product;
}
diff --git a/drools/src/test/java/com/baeldung/drools/optaplanner/OptaPlannerUnitTest.java b/drools/src/test/java/com/baeldung/drools/optaplanner/OptaPlannerUnitTest.java
index 1880e30b86..2165cdda1f 100644
--- a/drools/src/test/java/com/baeldung/drools/optaplanner/OptaPlannerUnitTest.java
+++ b/drools/src/test/java/com/baeldung/drools/optaplanner/OptaPlannerUnitTest.java
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.optaplanner.core.api.solver.Solver;
import org.optaplanner.core.api.solver.SolverFactory;
+import org.optaplanner.core.config.solver.SolverConfig;
public class OptaPlannerUnitTest {
@@ -21,14 +22,14 @@ public class OptaPlannerUnitTest {
unsolvedCourseSchedule.getLectureList().add(new Lecture());
}
- unsolvedCourseSchedule.getPeriodList().addAll(Arrays.asList(new Integer[] { 1, 2, 3 }));
- unsolvedCourseSchedule.getRoomList().addAll(Arrays.asList(new Integer[] { 1, 2 }));
+ unsolvedCourseSchedule.getPeriodList().addAll(Arrays.asList(1, 2, 3));
+ unsolvedCourseSchedule.getRoomList().addAll(Arrays.asList(1, 2));
}
@Test
public void test_whenCustomJavaSolver() {
-
- SolverFactory solverFactory = SolverFactory.createFromXmlResource("courseScheduleSolverConfiguration.xml");
+ SolverConfig solverConfig = SolverConfig.createFromXmlResource("courseScheduleSolverConfiguration.xml");
+ SolverFactory solverFactory = SolverFactory.create(solverConfig);
Solver solver = solverFactory.buildSolver();
CourseSchedule solvedCourseSchedule = solver.solve(unsolvedCourseSchedule);
diff --git a/pom.xml b/pom.xml
index 8b395d44f1..62c9a36a3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -342,7 +342,6 @@
couchbase
custom-pmd
- drools
gradle-modules/gradle/maven-to-gradle
@@ -610,7 +609,6 @@
core-java-modules
couchbase
custom-pmd
- drools
gradle-modules/gradle/maven-to-gradle
@@ -927,6 +925,7 @@
ddd-contexts
deeplearning4j
docker-modules
+ drools
apache-httpclient-2
kubernetes-modules/kubernetes-spring
libraries-concurrency
@@ -1136,6 +1135,7 @@
ddd-contexts
deeplearning4j
docker-modules
+ drools
apache-httpclient-2
kubernetes-modules/kubernetes-spring
libraries-concurrency