BAEL-812: moving examples to rule-engines folder (#2461)
* spring beans DI examples * fix-1: shortening examples * List of Rules Engines in Java * BAEL-812: Openl-Tablets example added * BAEL-812: artifacts names changed * BAEL-812: moving rule-engines examples to rule-engines folder * BAEL-812: removing evaluation article files * BAEL-812: folder renamed * BAEL-812: folder renamed * BAEL-812: pom.xml - parent added
This commit is contained in:
parent
ee9152a091
commit
f2efbd9a67
24
rule-engines/easy-rules/pom.xml
Normal file
24
rule-engines/easy-rules/pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung.easyrules</groupId>
|
||||
<artifactId>easy-rules</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<name>easy-rules</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jeasy</groupId>
|
||||
<artifactId>easy-rules-core</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package com.baeldung.easyrules;
|
||||
|
||||
import org.jeasy.rules.annotation.Action;
|
||||
import org.jeasy.rules.annotation.Condition;
|
||||
import org.jeasy.rules.annotation.Rule;
|
||||
|
||||
@Rule(name = "Hello World rule", description = "Always say hello world")
|
||||
public class HelloWorldRule {
|
||||
|
||||
@Condition
|
||||
public boolean when() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Action
|
||||
public void then() throws Exception {
|
||||
System.out.println("hello world");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.easyrules;
|
||||
|
||||
import org.jeasy.rules.api.Facts;
|
||||
import org.jeasy.rules.api.Rules;
|
||||
import org.jeasy.rules.api.RulesEngine;
|
||||
import org.jeasy.rules.core.DefaultRulesEngine;
|
||||
|
||||
public class Launcher {
|
||||
public static void main(String... args) {
|
||||
// create facts
|
||||
Facts facts = new Facts();
|
||||
|
||||
// create rules
|
||||
Rules rules = new Rules();
|
||||
rules.register(new HelloWorldRule());
|
||||
|
||||
// create a rules engine and fire rules on known facts
|
||||
RulesEngine rulesEngine = new DefaultRulesEngine();
|
||||
rulesEngine.fire(rules, facts);
|
||||
}
|
||||
}
|
29
rule-engines/openl-tablets/pom.xml
Normal file
29
rule-engines/openl-tablets/pom.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung.openltablets</groupId>
|
||||
<artifactId>openl-tablets</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<name>openl-tablets</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openl</groupId>
|
||||
<artifactId>org.openl.core</artifactId>
|
||||
<version>5.19.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openl.rules</groupId>
|
||||
<artifactId>org.openl.rules</artifactId>
|
||||
<version>5.19.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,23 @@
|
||||
package com.baeldung.openltablets.model;
|
||||
|
||||
public class Case {
|
||||
|
||||
private User user;
|
||||
private int hourOfDay;
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(final User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public int getHourOfDay() {
|
||||
return hourOfDay;
|
||||
}
|
||||
|
||||
public void setHourOfDay(final int hourOfDay) {
|
||||
this.hourOfDay = hourOfDay;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.baeldung.openltablets.model;
|
||||
|
||||
public enum Greeting {
|
||||
|
||||
GOOD_MORNING("Good Morning"),
|
||||
GOOD_AFTERNOON("Good Afternoon"),
|
||||
GOOD_EVENING("Good Evening"),
|
||||
GOOD_NIGHT("Good Night");
|
||||
|
||||
private final String literal;
|
||||
|
||||
private Greeting(final String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.baeldung.openltablets.model;
|
||||
|
||||
public class User {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.baeldung.openltablets.rules;
|
||||
|
||||
import com.baeldung.openltablets.model.Case;
|
||||
|
||||
public interface IRule {
|
||||
void helloUser(final Case aCase, final Response response);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.baeldung.openltablets.rules;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.openl.rules.runtime.RulesEngineFactory;
|
||||
import org.openl.runtime.EngineFactory;
|
||||
|
||||
import com.baeldung.openltablets.model.Case;
|
||||
import com.baeldung.openltablets.model.User;
|
||||
|
||||
public class Main {
|
||||
private IRule instance;
|
||||
|
||||
public static void main(String[] args) {
|
||||
Main rules = new Main();
|
||||
User user = new User();
|
||||
user.setName("Donald Duck");
|
||||
Case aCase = new Case();
|
||||
aCase.setUser(user);
|
||||
aCase.setHourOfDay(23);
|
||||
rules.process(aCase);
|
||||
}
|
||||
|
||||
public void process(Case aCase) {
|
||||
final EngineFactory<IRule> engineFactory = new RulesEngineFactory<IRule>(getClass().getClassLoader()
|
||||
.getResource("openltablets/HelloUser.xls"), IRule.class);
|
||||
instance = engineFactory.newEngineInstance();
|
||||
instance.helloUser(aCase, new Response());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.baeldung.openltablets.rules;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Response {
|
||||
private String result;
|
||||
private Map<String, String> map = new HashMap<>();
|
||||
|
||||
public Response() { }
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(final String s) {
|
||||
result = s;
|
||||
}
|
||||
|
||||
public Map<String, String> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
24
rule-engines/rulebook/pom.xml
Normal file
24
rule-engines/rulebook/pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung.rulebook</groupId>
|
||||
<artifactId>rulebook</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<name>rulebook</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.deliveredtechnologies</groupId>
|
||||
<artifactId>rulebook-core</artifactId>
|
||||
<version>0.6.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
package com.baeldung.rulebook;
|
||||
|
||||
import com.deliveredtechnologies.rulebook.lang.RuleBookBuilder;
|
||||
import com.deliveredtechnologies.rulebook.model.RuleBook;
|
||||
|
||||
public class HelloWorldRule {
|
||||
public RuleBook<Object> defineHelloWorldRules() {
|
||||
|
||||
return RuleBookBuilder.create()
|
||||
.addRule(rule -> rule.withNoSpecifiedFactType()
|
||||
.then(f -> System.out.print("Hello ")))
|
||||
.addRule(rule -> rule.withNoSpecifiedFactType()
|
||||
.then(f -> System.out.println("World")))
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.baeldung.rulebook;
|
||||
|
||||
import com.deliveredtechnologies.rulebook.FactMap;
|
||||
|
||||
public class Launcher {
|
||||
|
||||
public static void main(String[] args) {
|
||||
HelloWorldRule ruleBook = new HelloWorldRule();
|
||||
ruleBook.defineHelloWorldRules()
|
||||
.run(new FactMap<>());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user