项目作者: dvare

项目描述 :
A Lightweight Java business rule engine.
高级语言: Java
项目地址: git://github.com/dvare/dvare-rules.git
创建时间: 2016-08-13T17:24:17Z
项目社区:https://github.com/dvare/dvare-rules

开源协议:MIT License

下载


Dvare Rules

A Light weight Java business rule engine.

Current version

  • The current stable version is 1.1 : Maven Central
  • The current snapshot version is 1.2-SNAPSHOT : Build Status
    In order to use snapshot versions, you need to add the following maven repository in your pom.xml:
  1. <repository>
  2. <id>ossrh</id>
  3. <url>https://oss.sonatype.org/content/repositories/snapshots</url>
  4. </repository>

Maven dependency:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.dvare</groupId>
  4. <artifactId>dvare-rules</artifactId>
  5. <version>1.1</version>
  6. </dependency>
  7. </dependencies>

Example

  1. @Rule(name = "Dvare Rule")
  2. public class DvareRule {
  3. private static Logger logger = Logger.getLogger(DvareRule.class);
  4. @Before
  5. public void beforeCondition() {
  6. logger.info("Before Condition ");
  7. }
  8. @Condition
  9. public boolean condition(@Fact("rule") String rule, @Fact("person")Person person,
  10. @RuleEngineType DvareRuleEngine textualRuleEngine) throws InterpretException {
  11. return textualRuleEngine.register(rule, Person.class, person);
  12. }
  13. @After
  14. public void afterCondition() {
  15. logger.info("After Condition ");
  16. }
  17. @Success
  18. public void success() {
  19. logger.info("Rule Successfully Run");
  20. }
  21. @Fail
  22. public void fail() {
  23. logger.error("Rule Failed");
  24. }
  25. }
  26. public class DvareRuleExample {
  27. private static Logger logger = Logger.getLogger(DvareRule.class);
  28. public static void main(String args[]) throws IllegalRuleException {
  29. Person male = new Person();
  30. male.setAge(25);
  31. male.setGender("Male");
  32. male.setTitle("Mr");
  33. Facts facts = new Facts();
  34. facts.add("rule", "age between [ 20 , 30 ] And title = 'Mr' And gender = 'Male'");
  35. facts.add("person", male);
  36. RuleEngine ruleEngine = new RuleEngineBuilder().facts(facts).build();
  37. DvareRule dvareRule = new DvareRule();
  38. ruleEngine.registerRule(dvareRule);
  39. ruleEngine.fireRules();
  40. boolean result = ruleEngine.getResult(dvareRule).getResult();
  41. System.out.println(result);
  42. }
  43. }

License

Dvare rules is released under the MIT license.

  1. The MIT License (MIT)
  2. Copyright (c) 2016-2017 DVARE (Data Validation and Aggregation Rule Engine)
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Sogiftware.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.