Drools collect list from object property

旧巷老猫 提交于 2020-06-17 15:51:03

问题


I have a student, who have list of courses. Also I have a lectures and I need to check that student courses list and list of courses of lectures that he visits are same

I added rule for case, when student visits lecture, that he doesn't have in courses list:

    when
        $student:Student ($courses:courses) 
        LectureAssignment(student == $student, course not memberOf $courses)
    then
        scoreHolder.addHardConstraintMatch(kcontext, -1);

But I also need to check, that student visits all lecture, that he have in courses list

    $student:Student ($courses:courses)
    $rightCourses: collect (LectureAssignment(student == $student)) // and get courses list

here I get lectures, that assigned to current student , all lectures have property course and I need to collect them into list $rightCourses and after this compare $courses and $rightCourses (in this case I think I don't need first rule)


回答1:


You could use forall operator. See documentation here [1]. If that doesn't work for you, you could use accumulate [2], checking that the lecture count a student has assigned is correct, with a combination of your first rule that checks that a student has not assigned a course that is not part of the courses list.

[1] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_forall
[2] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_accumulate



来源:https://stackoverflow.com/questions/54182500/drools-collect-list-from-object-property

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