Search code examples
javadrools

how to send the output from drools to java


Below is the drools i'm using based on conditions

import com.sample.TestExample;
import com.sample.TestExample.Message;

rule "Hello World"
when
    m : Message( product == Message.tv, myMessage : message )
then
    System.out.println(Message.tv);
    System.out.println("Product Spec is:: Service.TV_SAT"); // This output i want send back to java       
end

rule "GoodBye"
when
    n  : Message( product == Message.smart, myMessage : message )
then
    System.out.println(Message.smart);
    System.out.println("Product Spec is:: Service.SMARTOFFICE");  // This output i want send back to java   
end

rule "Else condition"
when
    e  : Message(product != TestExample.productClass)
then
    System.out.println(TestExample.productClass);
    System.out.println("in drools else condition"); // This output i want send back to java   
end 

i tried using set and get methods, but it's not working.

Any help will be appreciated :-)


Solution

  • Hi My code is working after making the below changes in java code

    public static class Message {

        private String message;
    
        public static String product;
        public static String tv="TV_SAT";
        public static String smart="SMART_OFFICE";
    
        public static String productSpec;
    
        public static int status;
    
        public String getProduct(){
            return Message.product;
        }
    
        public String getMessage() {
            return this.message;
        }
    
        public void setMessage(String message) {
            this.message = message;
        }
    
        public void setProduct(String product){
            Message.product=product;
        }
    
        public void setProductSpec(String product){
    
            Message.productSpec=product;
        }
    
        public String getProductSpec(){
    
            return
                    Message.productSpec;
    
        }
    }