Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

This data is a request body, post to my controller:

@RequestMapping(value = "/orders", method= RequestMethod.POST)
public void getOrderRequest(@RequestBody Order order){
// use Drools to calculate and return the result

Here is the entity class:

public class Order{
    private Integer amount;
    private String destination;
    private Float price;
    // getters and setters

I use Drools to calculate the price(fake code):

package rules
import entity.Order
rule "rule1"
    no-loop true
    lock-on-active true
    salience 1
        $s : Order(amount <= 50 && destination=="A") 
        $s.setPrice(1000);
        update($s);
rule "rule2"
    no-loop true
    lock-on-active true
    salience 1
        $s : Order(amount > 50 && destination=="A") 
        $s.setPrice(2000);
        update($s);

This works fine.All rules can be changed and worked without restarting my REST service.

Here is a scenario , a new field added to the order JSON:

{ "amount": 100,
  "destination":"A",
  "customer":"Trump"

Add a new rule: If the customer is Trump, then double the price:

rule "rule3"
    no-loop true
    lock-on-active true
    salience 1
        $s : Order(customer == "Trump") 
        $s.setPrice(price * 2);
        update($s);

But I have to add a new variable to my Order class and restart my service.

I wonder that is there any way to make it happen without restarting my REST service ?

Or can I just handle JSON data dynamically with other BRMSs ?

If you manage to add values from JSON into Map then you can write your rule like this:

rule "rule3"
    no-loop true
    lock-on-active true
    salience 1
        $s : Order(fields["customer"] == "Trump") 
        $s.setPrice(price * 2);
        update($s);
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.