Claudiu Muresan
Claudiu Muresan

Reputation: 411

Drools rule to check that sublist is contained in a list

I want to be able to check if at least one element from a list of string elements (see $el.getTags()) is contained in a list (tagService.getAvailableTags($el.getName()) using a Drools rule. I'm using a helper method for the check: CollectionUtils.containsValuesFromList(subList, targetList, checkAllValues).

For now I'm using below rule definition:

rule "Check at least one tag is set"
when
   $el: Element()
   $tags : tagService.getTags($el.getName())
   $errors : ValidationErrors()
   $condition: CollectionUtils.containsValueFromList($el.getTags(), $tags, true)
then
   $errors.addError( $el, "el", "At least one tag should be set!");
end

Could it be possible to check if at least one sub list element is contained in a list, without using any helper method? Thanks.

Upvotes: 1

Views: 1127

Answers (1)

Vijay Rumao
Vijay Rumao

Reputation: 72

rule "Check at least one tag is set"
when
$el: Element()
$tags : tagService.getTags($el.getName())
$errors : ValidationErrors()
//  $condition: CollectionUtils.containsValueFromList($el.getTags(), $tags, true)
Element( Tags in ($tags) )
then
$errors.addError( $el, "el", "At least one tag should be set!");
end

Upvotes: 1

Related Questions