Domanda

I use a Map to put the conditions. My Object To:

public class TestTO implements Serializable {

private String resultStr;

private List resultList;

private Map resultMap;

private Map parameterMap;
... ...
}

Execute Drools Rule:

public static Map getMapResult(TestTO rulesTo) throws Exception {
    StatelessKnowledgeSession kSession = getKnowledgeSession();
    AgendaEventListener ael = mock( AgendaEventListener.class );
    kSession.addEventListener(ael);
    kSession.execute(rulesTo);
    Map resultMap = rulesTo.getResultMap();
    if (resultMap != null && !resultMap.isEmpty())
        return resultMap;
    else throw new RuntimeException("EMPTY");
}

My test method:

public void TestA() throws Exception{
Map<String, Object> test= new HashMap<String, Object>();
test.put("str1", "0");//string
test.put("str2", "SC");//string
test.put("dec1", new BigDecimal(372));//bigdecimal
TestTO m = new TestTo();
m.setParameterMap(test);
for(int i=0;i<22;i++){
    m.setResultMap(new HashMap<String, Object>());
    Map result=RuleTest.getMapResult(m);
  }
}

now I have a problem about the rules file, how to get "dec1" from the parameterMap,because this map's value are Object ,if we get the value from this map by key. it's ok. but how to convert the value fromobjecttobigdecimal`? I try to get value in drl file using two ways:

1.to.getParameterMap()["gt"]>=300. but it has some problems.

2.to.getParameterMap()["gt"]>=300B. maybe it is ok.

why the second is ok (I think)?.

I do not have to specify a default value for drools dialect. So I think default is "java".

Does java dialect support 300B?

Many thanks!

È stato utile?

Soluzione

Assuming that the Entry with key "dec1" is always a BigDecimal:

Entry(key == "dec1", $val : value) from myMap.entrySet()
$bigD : BigDecimal() from $val

I think that's right ... it compiles for me, but I'm feeling lazy, so I haven't written a test to prove it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top