0

I have started exploring DROOLS execution engine, so I have not much idea about DROOLS. I have found it very easy while creating a rule for following business rule:

 "Event is large event if number of audience is greater than 1000"

Drools rule will be:

 rule "Large Event"
    when
        event: Event(audience>= 1000 )
    then
        event.setEventType("largeEvent");
  end 

Where Event is a class and audience , eventType are the attributes of the class. But I am getting it difficult while creating a rule, which have conditions other than >, <, ==. Consider the following example:

 Bank verifies customer if customer submits document.

If anyone deal with such type of rules, please help me. Is there any example or document available to learn such type of example.

  • How is the fact that a customer has submitted a (certain) document registered in your customer data? How would you write the condition "customer has submitted document" in Java? Show us this code, and we can show you the rule. – laune Oct 16 '17 at 06:32
  • Thanks for quick response. I have stuck here only, for such type of facts how can I make conditions in java as well as in Drools. Above mentioned example is a plan English text that we have to convert it in drools. But I am completely blank that how can I convert it in condition? – Namrata Choudhary Oct 16 '17 at 06:48
  • You cannot convert "if customer submits document" to code unless you have a lot more. Apart from the issue which document is meant (birth certificate? driver's licence? ...) you need to have a data model where you store information about a customer and documents and other stuff. Do you have any idea about programming and data processing? – laune Oct 16 '17 at 08:56
  • I think I have not convey the question correctly. Simple thing I want to ask is: How can we write drools rule from a plan English text. As far as I go through Drools documentation, It says that we have create POJO classes with their getter and setters. In this case suppose I have two classes Bank and Customer. Can I make drools condition as follows based of above mentioned text : when customer.isSubmitDocument== true then bank.setIsVerifiedCustomer(true) – Namrata Choudhary Oct 16 '17 at 11:11

1 Answers1

1

This is trivial. The only complication was you strange roundabout way of asking a simple question.

rule "Customer has submitted a document"
when
    $b: Bank()
    Customer( submitDocument )
then
    $b.setVerifiedCustomer( true );
end

Note: Although this corresponds to your comment (Why don't you edit your question?) it seems rather silly: why would one set a property of the bank if there is just one customer with a submitted document?

laune
  • 31,114
  • 3
  • 29
  • 42
  • Thanks @laune. It will help me a lot. Can I ask in detail about Customer (submitDocument ) ? What it will do ? Does it call constructor of class Customer ? Is submitDocument is an attribute of class customer ? Again its a trivial doubt , but it will help me understand it in better way. Thanks once again. – Namrata Choudhary Oct 17 '17 at 06:22
  • I was paraphrasing your 'customer.isSubmitDocument'. Typically you would have a field `boolean submitDocument`, a getter isSubmitDocument` and a setter 'setSubmitDocument'. That's the convention. Using the field name alone is enough with Drools DRL to call the getter and return a boolean. – laune Oct 17 '17 at 15:59
  • Thanks laune. I have created drl rule for following condition / *rule 'bank verifies customer' It is obligatory that bank verifies customer if customer is individual && document is eaadhaar */ rule "bank verifies customer" when $cusObj: Customer1(); $iObj: Individual(); $doc: Document(); $eaadhar: EAAdhar(); eval( $iObj instanceof Customer1) eval ($eaadhar instanceof Document ) then System.out.println(bank.isVerifyCustomer()); bank.setVerifyCustomer(true); end Here Individual inherits Customer1 and EAAdhar inherits Document. – Namrata Choudhary Oct 18 '17 at 06:39
  • Please refer attached link https://stackoverflow.com/questions/46804312/how-to-pass-multiple-facts-for-some-sets-of-rules-in-drools – Namrata Choudhary Oct 18 '17 at 06:53