MySQL Workbench
 sql >> Base de Dados >  >> Database Tools >> MySQL Workbench

Integrando a bancada de trabalho do Drool 6 com o aplicativo Java


Primeiro crie o aplicativo Java, inclua todas as dependências binárias baseadas no drools 6. Para isso, você pode criar o aplicativo java orientado pelo Maven. inclua as seguintes dependências no arquivo POM.xml. Ele fará o download de todas as dependências em seu repositório local do maven.
<parent>
    <groupId>org.drools</groupId>
    <artifactId>drools-multiproject</artifactId>
    <version>6.0.1.Final</version>
</parent>
 <dependencies>      
    <!-- Internal dependencies -->
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.kie</groupId>
        <artifactId>kie-ci</artifactId>            
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-decisiontables</artifactId>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-templates</artifactId>
    </dependency>

    <!-- Needed for logging -->
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>    
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
    </dependency>
    <dependency><!-- For example app logging: configure in src/java/resources/logback.xml -->
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
</dependencies>

também especifique o perfil em pom.xml :
<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>guvnor-m2-repo</id>
                <name>Drools Workbench Repository Group</name>
                <url>http://localhost:4040/kie-drools-wb-distribution-wars-6.0.1.Final-tomcat7.0/maven2/</url>
                <layout>default</layout>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </releases>
            </repository>
        </repositories>
    </profile>
</profiles>

Em main.java
public static void main(String[] args) {
    ReleaseIdImpl releaseId = new ReleaseIdImpl("groupId", "artifactId", "LATEST");

    KieServices ks = KieServices.Factory.get();

    KieContainer kieContainer = ks.newKieContainer(releaseId);

    KieScanner kScanner = ks.newKieScanner(kieContainer);
    kScanner.start(10000L);             
    Scanner scanner = new Scanner(System.in);
    while (true) {
        runRule(kieContainer);
        System.out.println("Press enter in order to run the test again....");
        scanner.nextLine();
    }
  }
   private static void runRule(KieContainer kieKontainer) {
    KieSession newKieSession = kieKontainer.newKieSession();

    //Initiate POJO on which you want to define rule like
    //BankLoan bankLoan = new BankLoan();
      //  bankLoan.setLoanAmount(10000);
       // bankLoan.setLoanPeriod(11);

      //Insert into kieSession
       newKieSession.insert(bankLoan);

    int result = newKieSession.fireAllRules();
    newKieSession.dispose();
}