Validation in drools

笑着哭i 提交于 2019-12-20 05:45:10

问题


This is the second part of my drools validation question. First part has been already answered and proposed solutions has been implemented in my code. First Part

This is my java class structure

public class Person {
 List<PersonAddress> personAddress;
 List<FinanceDetails> financeDetails;
}
public enum AddressStatus {
 CURRENT, PREVIOUS;
}
public enum AddressType {
 PHYSICAL, POSTAL;
}
public enum AddressUseType {
 HOME, OFFICE;
}
public class PersonAddress{    
  Address address;
  AddressType type
  AddressStatus status
  AddressUseType useType
  String ownerShipType
  Integer timeAtAddress;        
}
public class Address {
  String city;
  String country;
  String street;
}
public class FinanceDetails {
  String financeItemName;
  BigDecimal itemValue;
}

Ok my problem is, i need to validate itemValue of the FinanceDetails instance if financeItemName is "Land or Building", and if this user has an address which matches following criteria,

AddressStatus == CURRENT

AddressType == PHYSICAL

AddressUseType == HOME

ownerShipType == "Own"

Drools version 5.5.0.Final

Java 1.7

functions can be used

A sample drool rule syntax is needed. Thank you


回答1:


Added itemValue tests as seen in some comment

rule "land-orbuilding..."
when
  Peson( $financeDetails: financeDetails, $personAddress: personAddress )
  FinanceDetails( financeItemName == "Land or Building", itemValue == null || itemValue == 0 ) from $financeDetails
  PersonAddress( status == AddressStatus.CURRENT,
                 type == AddressType.PHYSICAL,
                 useType == AddressUseType.HOME,
                 ownerShipType == "Own" ) from $personAddress
then
  //...
end

How about reading some of that documentation? This is very much like the "first part", and only a minor variation.




回答2:


rule "Check Details"
when
  details:FinanceDetails  (itemValue == 'LAND' || == 'Building')
  address:PersonAddress(status == AddressStatus.CURRENT,
                 type == AddressType.PHYSICAL,
                 useType == AddressUseType.HOME,
                 ownerShipType == "Own" )
then
  modify(details){itemValue=//set your value};
end


来源:https://stackoverflow.com/questions/25735964/validation-in-drools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!