Log Message: |
Improved: Migrate product promotion condition and action rule on SOA
(OFBIZ-10370)
Currently promotion rule engine works with :
entities ProductPromoCond et ProductPromoAction
java linear function ProductPromoWorker.checkCondition() (ProductPromoWorker:910) and ProductPromoWorker.performAction (ProductPromoWorker:1423)
Enumeration list to indicate on java function what piece of code to activate the control or action
The problem with this structure is when you want to create a new case of condition or action, you need to modify the framework code base.
We convert the 2 big java leaner function to service representation with one service by case. To realize it we introduce a relation with CustomMethod :
ProductPromoRule --> ProductPromoCond -> CustomMethod
-> ProductPromoAction -> CustomMethod
Each functions's case are converted to service with a related CustomMethod.
With this pattern now you can write your own condition rule and action rule on your plugin and link it on the promo engine
For backward compatibility purpose, current "PPIP" enumeration entries receive in enumCode data the new corresponding customMethodId reference, to ensure that old data works fine with the new engine
on EntityData
<CustomMethod customMethodId="PPC_PRODUCT_AMOUNT" customMethodTypeId="PRODUCT_PROMO_COND" customMethodName="productPromoCondProductAmount" description="Product amount"/>
<Enumeration enumId="PPIP_PRODUCT_AMOUNT" enumCode="PPC_PRODUCT_AMOUNT"/><!--link enumeration with customMethod for backward compatibility-->
on Java
//for backward compatibility resolve customMethodId from enumCode
GenericValue condEnum = EntityQuery.use(delegator).from("Enumeration").where("enumId", inputParamEnumId).cache().queryOne();
if (condEnum != null) {
customMethod = EntityQuery.use(delegator).from("CustomMethod").where("customMethodId", condEnum.get("enumCode")).cache().queryOne();
if (customMethod == null) {
Debug.logWarning("The oldest enumeration " + inputParamEnumId + " for promo " + productPromoCond.getPkShortValueString() + " haven't the new customMethod to use, please check your data or load seed data", module);
return false;
}
serviceName = customMethod.getString("customMethodName");
}
Many thanks to Ziri Khalifa and Leila Mekika for their helping work
|