JAVA-18133 Upgrade drools module to JDK 11
This commit is contained in:
parent
db11ca931d
commit
433877fd70
|
@ -57,10 +57,10 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<http-component-version>4.4.6</http-component-version>
|
||||
<drools-version>7.4.1.Final</drools-version>
|
||||
<apache-poi-version>3.13</apache-poi-version>
|
||||
<opta-planner-version>7.10.0.Final</opta-planner-version>
|
||||
<http-component-version>4.4.16</http-component-version>
|
||||
<drools-version>8.32.0.Final</drools-version>
|
||||
<apache-poi-version>5.2.3</apache-poi-version>
|
||||
<opta-planner-version>8.32.0.Final</opta-planner-version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -11,7 +11,6 @@ public class BackwardChaining {
|
|||
Result result = new BackwardChaining().backwardChaining();
|
||||
System.out.println(result.getValue());
|
||||
result.getFacts()
|
||||
.stream()
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ 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;
|
||||
|
||||
|
@ -19,7 +18,7 @@ public class DroolsBeanFactory {
|
|||
private static final String RULES_PATH = "com/baeldung/drools/rules/";
|
||||
private KieServices kieServices = KieServices.Factory.get();
|
||||
|
||||
private KieFileSystem getKieFileSystem() throws IOException{
|
||||
private KieFileSystem getKieFileSystem() {
|
||||
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
|
||||
List<String> rules = Arrays.asList("BackwardChaining.drl", "SuggestApplicant.drl", "Product_rules.xls");
|
||||
for(String rule:rules) {
|
||||
|
@ -29,7 +28,7 @@ public class DroolsBeanFactory {
|
|||
|
||||
}
|
||||
|
||||
public KieContainer getKieContainer() throws IOException {
|
||||
public KieContainer getKieContainer() {
|
||||
getKieRepository();
|
||||
|
||||
KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem());
|
||||
|
@ -44,11 +43,7 @@ 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() {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<CourseSchedule> {
|
||||
public class ScoreCalculator implements EasyScoreCalculator<CourseSchedule, HardSoftScore> {
|
||||
|
||||
@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<CourseSchedule> {
|
|||
}
|
||||
}
|
||||
|
||||
return HardSoftScore.valueOf(hardScore, softScore);
|
||||
return HardSoftScore.of(hardScore, softScore);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
public SuggestedRole suggestARoleForApplicant(Applicant applicant,SuggestedRole suggestedRole) throws IOException {
|
||||
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;
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ 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 {
|
||||
|
@ -10,8 +9,12 @@ public class ProductService {
|
|||
private KieSession kieSession = new DroolsBeanFactory().getKieSession();
|
||||
|
||||
public Product applyLabelToProduct(Product product){
|
||||
try {
|
||||
kieSession.insert(product);
|
||||
kieSession.fireAllRules();
|
||||
} finally {
|
||||
kieSession.dispose();
|
||||
}
|
||||
System.out.println(product.getLabel());
|
||||
return product;
|
||||
|
||||
|
|
|
@ -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<CourseSchedule> solverFactory = SolverFactory.createFromXmlResource("courseScheduleSolverConfiguration.xml");
|
||||
SolverConfig solverConfig = SolverConfig.createFromXmlResource("courseScheduleSolverConfiguration.xml");
|
||||
SolverFactory<CourseSchedule> solverFactory = SolverFactory.create(solverConfig);
|
||||
Solver<CourseSchedule> solver = solverFactory.buildSolver();
|
||||
CourseSchedule solvedCourseSchedule = solver.solve(unsolvedCourseSchedule);
|
||||
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -342,7 +342,6 @@
|
|||
<module>couchbase</module>
|
||||
<module>custom-pmd</module>
|
||||
|
||||
<module>drools</module>
|
||||
<!-- <module>ethereum</module> --> <!-- JAVA-6001 -->
|
||||
<!-- <module>gradle-modules</module> --> <!-- Not a maven project -->
|
||||
<module>gradle-modules/gradle/maven-to-gradle</module>
|
||||
|
@ -610,7 +609,6 @@
|
|||
<module>core-java-modules</module>
|
||||
<module>couchbase</module>
|
||||
<module>custom-pmd</module>
|
||||
<module>drools</module>
|
||||
<!-- <module>ethereum</module> --> <!-- JAVA-6001 -->
|
||||
<!-- <module>gradle-modules</module> --> <!-- Not a maven project -->
|
||||
<module>gradle-modules/gradle/maven-to-gradle</module>
|
||||
|
@ -927,6 +925,7 @@
|
|||
<module>ddd-contexts</module>
|
||||
<module>deeplearning4j</module>
|
||||
<module>docker-modules</module>
|
||||
<module>drools</module>
|
||||
<module>apache-httpclient-2</module>
|
||||
<module>kubernetes-modules/kubernetes-spring</module>
|
||||
<module>libraries-concurrency</module>
|
||||
|
@ -1136,6 +1135,7 @@
|
|||
<module>ddd-contexts</module>
|
||||
<module>deeplearning4j</module>
|
||||
<module>docker-modules</module>
|
||||
<module>drools</module>
|
||||
<module>apache-httpclient-2</module>
|
||||
<module>kubernetes-modules/kubernetes-spring</module>
|
||||
<module>libraries-concurrency</module>
|
||||
|
|
Loading…
Reference in New Issue