W dniu 2010-07-29 20:18, BJ Freeman pisze:
Thanks that looks like beanshell or Groovy type of code.
this goes along with the openoffice macro code flexibility.
It has a little different usage. Each rule is fired only when assertions
for rule are true. That means that facts can be fired incrementally when
new facts appear. But it also means that you have to supply facts.
Drools does not opperate on data model but on facts.
Each statement (e.g. OrderLine) must be inserted into so called working
memory as a fact. In example blow the only facts are entities (fact that
they exists), but in more advanced scenario fact can be that some field
changed. That would make possible to
fire some expensive rules only when given field change, but it makes
rules definitions more complicated. It would need braimstorming,
probably with appropriate people in field what is better: RETE rule
engine(aka drools) or functional reactive programming (FRP)
(something like this http://lambda-the-ultimate.org/node/1918 or this
http://www.flapjax-lang.org/tutorial/ ). Functional reactive programming
seems to be more declarative way of things for me.
.
At a business level would like to follow that macro type of
formulation but expose ofbiz services like the Artifacts (webtools)
OfBiz services are stateless. What I think is possible is (optional)
stateful services. I think it is possible to have "live" documents. For
example when we create order we do not go with services to database, but
operate only in memory. Drools or FRP would recalculate document on
change of facts. What is good is that you can have temporary facts (e.g.
line X is discount for line Y). Facts can also retract (be removed) when
condition is no longer valid, so discount line probably could be removed
if condition for it is no longer valid.
Live documets would have folowing advantages:
no problems with temporary documents between saves
much imporved scalabilty (go to database only when save whole document)
possiblity to have one logic to serve UI and for batch/webservices
mode ?
At this point I am aiming this for business person that has little or
no programming knowlege.
Curent DSL for Drools would genereate some noise, I think. There is a
lot of tricks. One I said before, that you must order rules manualy.
Another thing is you have to divide logic into agenda groups (In case
below one agenda group caulcates item and another order summary). Yet
another thing is that you have to say that fact was modified with
modify() statement.
I will use you supplied example to show how the Business Macros will
work.
You are welcome.
Marek Mosiewicz sent the following on 7/29/2010 7:10 AM:
W dniu 2010-07-29 15:14, chris snow pisze:
Hi BJ, I was responding to your comment:
"I like the design of Drool but think we need to go one step higher
and see this as how to run a business."
Guvnor has an abstraction on top of drools that is aimed at the
business user. I don't know enough about drools to comment on how it
would be integrated with the business model. I still have a lot more
learning to do around the subject...
I made some attempts with Drools as engine for future (probably open
source) ERP. But it not like excel. You can write calculation rules but
Drools would not order them automatically based on dependencies. (e.g.
calc line total before sum of order). But in many ways it is very
powerful tool.
There are example rules for simple Order (I could send whole project):
package com.sample
import com.sample.Order;
import com.sample.OrderItem
import com.sample.OrderTaxLine;
import com.sample.OrderTaxSummary;
import com.sample.OrderDiscount;
import com.sample.Product;
import com.sample.Tax;
import com.sample.TaxCalculator;
import com.sample.Discount;
import com.sample.DiscountCalculator;
dialect "java"
function Tax calcTax(int customerId,int productId) {
return TaxCalculator.calculateTax(customerId,productId);
}
rule "order item price"
dialect "mvel"
agenda-group "Items"
lock-on-active true
salience 9
when
$item : OrderItem();
then
modify($item){
setPrice($item.product.price);
}
end
rule "order item amountNetto"
dialect "mvel"
lock-on-active true
agenda-group "Items"
salience 8
when
$item : OrderItem();
then
modify($item){
setAmountNetto($item.price * $item.quantity);
}
end
rule "order item tax"
dialect "mvel"
lock-on-active true
agenda-group "Items"
salience 7
when
$item : OrderItem();
then
modify($item){
setTaxes(calcTax($item.order.partyDelivery.partyId.intValue(),$item.product.productId.intValue()));
}
end
rule "order item amountTax"
dialect "mvel"
lock-on-active true
agenda-group "Items"
salience 6
when
$item : OrderItem();
then
modify($item){
setAmountTax($item.tax.rateTax * $item.amountNetto);
}
end
rule "order item amountBrutto"
dialect "mvel"
lock-on-active true
agenda-group "Items"
salience 5
when
$item : OrderItem();
then
modify($item){
setAmountBrutto($item.amountNetto + $item.amountTax);
}
end
rule "Switch to Order"
dialect "mvel"
lock-on-active true
agenda-group "Items"
salience -100000
when
$item : OrderItem();
then
drools.setFocus("Order");
end
rule "order calucations"
dialect "mvel"
lock-on-active true
agenda-group "Order"
salience 4
when
$order : Order();
$amountTax : Number() from accumulate (OrderItem( order==$order,
amountTax!=null,$amount:amountTax), sum($amount));
then
$order.amountTax = $amountTax;
end
rule "order calucations 2"
dialect "mvel"
lock-on-active true
agenda-group "Order"
salience 3
when
$order : Order();
$amountNetto : Number() from accumulate (OrderItem( order==$order,
amountNetto!=null, $amount:amountNetto), sum($amount));
then
$order.amountNetto = $amountNetto;
end
rule "order calucations 3"
dialect "mvel"
lock-on-active true
agenda-group "Order"
salience 2
when
$order : Order(amountTax !=null,amountNetto!=null);
then
$order.amountBrutto = ($order.amountTax + $order.amountNetto);
end
Maybe facts assertions should not be like above "OrderLine exists" but
e.g. "quantity of order line changed"