Jroosterman
Jroosterman

Reputation: 418

In Drools, how do I check if a list does NOT contain an object with a specific value?

I am making a rule that looks at a list of given objects and checks if one of the string fields does not contain a certain value. If any object in the list contain said value then I want the rule to fail.

    when
        $vr: RequestDTO($activeObjects: activeObjects);
        eval(!$activeObjects contains ObjectDTO(this.name == "TEST NAME")); 
    then
        displayModalAction.setMessage("Message to Show");
    end

Is there a way to do this sort of action in the when statement of the rule?

Upvotes: 2

Views: 2162

Answers (1)

Jeff
Jeff

Reputation: 953

Seems you are looking for RequestDTOs that don't have an ObjectDTO with a name of "TEST NAME". If that's correct, then try this:

when
    RequestDTO($activeObjects: activeObjects)
    not exists(ObjectDTO(name == "TEST NAME") from $activeObjects)
then
    ...

Upvotes: 4

Related Questions