File tree Expand file tree Collapse file tree
src/main/java/com/baeldung/easyrules
java/com/baeldung/openltablets
src/main/java/com/baeldung/rulebook Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+ <modelVersion>4.0.0</modelVersion>
4+
5+ <groupId>com.baeldung.easyrules</groupId>
6+ <artifactId>easy-rules</artifactId>
7+ <version>1.0</version>
8+
9+ <name>easy-rules</name>
10+
11+ <parent>
12+ <groupId>com.baeldung</groupId>
13+ <artifactId>parent-modules</artifactId>
14+ <version>1.0.0-SNAPSHOT</version>
15+ </parent>
16+
17+ <dependencies>
18+ <dependency>
19+ <groupId>org.jeasy</groupId>
20+ <artifactId>easy-rules-core</artifactId>
21+ <version>3.0.0</version>
22+ </dependency>
23+ </dependencies>
24+ </project>
Original file line number Diff line number Diff line change 1+ package com.baeldung.easyrules;
2+
3+ import org.jeasy.rules.annotation.Action;
4+ import org.jeasy.rules.annotation.Condition;
5+ import org.jeasy.rules.annotation.Rule;
6+
7+ @Rule(name = "Hello World rule", description = "Always say hello world")
8+ public class HelloWorldRule {
9+
10+ @Condition
11+ public boolean when() {
12+ return true;
13+ }
14+
15+ @Action
16+ public void then() throws Exception {
17+ System.out.println("hello world");
18+ }
19+
20+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.easyrules;
2+
3+ import org.jeasy.rules.api.Facts;
4+ import org.jeasy.rules.api.Rules;
5+ import org.jeasy.rules.api.RulesEngine;
6+ import org.jeasy.rules.core.DefaultRulesEngine;
7+
8+ public class Launcher {
9+ public static void main(String... args) {
10+ // create facts
11+ Facts facts = new Facts();
12+
13+ // create rules
14+ Rules rules = new Rules();
15+ rules.register(new HelloWorldRule());
16+
17+ // create a rules engine and fire rules on known facts
18+ RulesEngine rulesEngine = new DefaultRulesEngine();
19+ rulesEngine.fire(rules, facts);
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+ <modelVersion>4.0.0</modelVersion>
4+
5+ <groupId>com.baeldung.openltablets</groupId>
6+ <artifactId>openl-tablets</artifactId>
7+ <version>1.0</version>
8+
9+ <name>openl-tablets</name>
10+
11+ <parent>
12+ <groupId>com.baeldung</groupId>
13+ <artifactId>parent-modules</artifactId>
14+ <version>1.0.0-SNAPSHOT</version>
15+ </parent>
16+
17+ <dependencies>
18+ <dependency>
19+ <groupId>org.openl</groupId>
20+ <artifactId>org.openl.core</artifactId>
21+ <version>5.19.4</version>
22+ </dependency>
23+ <dependency>
24+ <groupId>org.openl.rules</groupId>
25+ <artifactId>org.openl.rules</artifactId>
26+ <version>5.19.4</version>
27+ </dependency>
28+ </dependencies>
29+ </project>
Original file line number Diff line number Diff line change 1+ package com.baeldung.openltablets.model;
2+
3+ public class Case {
4+
5+ private User user;
6+ private int hourOfDay;
7+
8+ public User getUser() {
9+ return user;
10+ }
11+
12+ public void setUser(final User user) {
13+ this.user = user;
14+ }
15+
16+ public int getHourOfDay() {
17+ return hourOfDay;
18+ }
19+
20+ public void setHourOfDay(final int hourOfDay) {
21+ this.hourOfDay = hourOfDay;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.openltablets.model;
2+
3+ public enum Greeting {
4+
5+ GOOD_MORNING("Good Morning"),
6+ GOOD_AFTERNOON("Good Afternoon"),
7+ GOOD_EVENING("Good Evening"),
8+ GOOD_NIGHT("Good Night");
9+
10+ private final String literal;
11+
12+ private Greeting(final String literal) {
13+ this.literal = literal;
14+ }
15+
16+ public String getLiteral() {
17+ return literal;
18+ }
19+
20+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.openltablets.model;
2+
3+ public class User {
4+
5+ private String name;
6+
7+ public String getName() {
8+ return name;
9+ }
10+
11+ public void setName(final String name) {
12+ this.name = name;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.openltablets.rules;
2+
3+ import com.baeldung.openltablets.model.Case;
4+
5+ public interface IRule {
6+ void helloUser(final Case aCase, final Response response);
7+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.openltablets.rules;
2+
3+
4+ import java.time.LocalDateTime;
5+
6+ import org.openl.rules.runtime.RulesEngineFactory;
7+ import org.openl.runtime.EngineFactory;
8+
9+ import com.baeldung.openltablets.model.Case;
10+ import com.baeldung.openltablets.model.User;
11+
12+ public class Main {
13+ private IRule instance;
14+
15+ public static void main(String[] args) {
16+ Main rules = new Main();
17+ User user = new User();
18+ user.setName("Donald Duck");
19+ Case aCase = new Case();
20+ aCase.setUser(user);
21+ aCase.setHourOfDay(23);
22+ rules.process(aCase);
23+ }
24+
25+ public void process(Case aCase) {
26+ final EngineFactory<IRule> engineFactory = new RulesEngineFactory<IRule>(getClass().getClassLoader()
27+ .getResource("openltablets/HelloUser.xls"), IRule.class);
28+ instance = engineFactory.newEngineInstance();
29+ instance.helloUser(aCase, new Response());
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.openltablets.rules;
2+
3+ import java.util.HashMap;
4+ import java.util.Map;
5+
6+ public class Response {
7+ private String result;
8+ private Map<String, String> map = new HashMap<>();
9+
10+ public Response() { }
11+
12+ public String getResult() {
13+ return result;
14+ }
15+
16+ public void setResult(final String s) {
17+ result = s;
18+ }
19+
20+ public Map<String, String> getMap() {
21+ return map;
22+ }
23+
24+ }
You can’t perform that action at this time.
0 commit comments