I am trying to do below things. Plesse check.
rule "new rule"
salience -101
dialect "mvel"
when
$pricingLineItem : PricingLineItem( $ackId : ackId, $prefix : prefix )
$baseUpChargeConfig : BaseUpChargeConfig( $baseOptionId : baseOptionId,
prefix == $prefix )
$pricingOptionType : PricingOptionType( ackId == $ackId,
$optionId : optionId, $optionValue : optionValue )
$baseOptionConfig : BaseOptionConfig( bOptionValue == $optionValue,
bOptionCode == $optionId ,id == $baseOptionId )
then
$pricingLineItem.increment($baseOptionId);
System.out.println("excuted - "+ $baseOptionId +" "+$baseOptionConfig);
end
There will multiple BaseUpChargeConfig object match for one PricngLineItem. In the BaseUpChargeConfig object, we are getting all related BaseOptionConfig object and then trying to matche with PricingOptionType object of PricingLineItem. I need to take the best BaseUpChargeConfig object having maximum match with the PricingOptionType object of PricngLineItem.
EDIT
Say I have one PricingLineItem object with ackID, prefix value.
Now, I have multiple set of BaseUpChargeConfig object based on prefix value of PricingLineItem.
Now on ackId value, I have certain set of PricingOptionType object in rule engine.
and Also on baseOptionId value, I have multiple BaseOptionConfig object.
In PricingOptionType and BaseOptionConfig object, I need to compare the optioncode and option value.
If both are matching, I need to collect all matched pricing option type for a perticuler BaseUpChrageConfig.
In the same way, this will check for all other BaseUpChrageConfig object BaseOptionConfig and match.
Now the highest matched BaseOptionConfig object ; we will select that BaseUpChargeConfig as best object for our purpose.
I hope it would be clear for you.
Currently I am doing through java method by passing all three and calculating in java.
public void matchOptions(BaseUpChargeConfig config, List pricingOptionList,
List baseOptionList) {
if ((pricingOptionList != null && !pricingOptionList.isEmpty())
&& (baseOptionList != null && !baseOptionList.isEmpty())) {
List<PricingOptionType> matchedOption = null;
matchedOption = new ArrayList<PricingOptionType>();
for (PricingOptionType pOption : pricingOptionList) {
int matchCount = 0;
for (BaseOptionConfig bConfig : baseOptionList) {
boolean optioncodeMatch = pOption.getOptionCode() == bConfig.getBaseOptionCode();
boolean optionValueMatch = pOption.getOptionValue() == bConfig.getBaseOptionValue();
if (optioncodeMatch && optionValueMatch) {
matchedOption.add(pOption);
matchCount++;
}
}
if (matchCount > 0) {
if (bestBaseUpChargeConfig != null) {
optionMatchCount = matchCount;
bestBaseUpChargeConfig = config;
matchedPrcOptionList = matchedOption;
} else if (matchCount == optionMatchCount) {
bestBaseUpChargeConfig = null;
matchedOption = null;
matchedPrcOptionList.clear();
} else if (matchCount > optionMatchCount) {
optionMatchCount = matchCount;
bestBaseUpChargeConfig = config;
matchedPrcOptionList = matchedOption;
} else {
// do nothing
}
}
}
} else {
// do nothing
}
}
Thanks
See Question&Answers more detail:
os