Skip to content

Instantly share code, notes, and snippets.

@bmatthews68
Created November 15, 2011 11:59
Show Gist options
  • Select an option

  • Save bmatthews68/1366907 to your computer and use it in GitHub Desktop.

Select an option

Save bmatthews68/1366907 to your computer and use it in GitHub Desktop.
Drools Example
package com.leaseplanis.iq.model.bo.options.validation
import com.leaseplanis.iq.model.bo.options.OptionDetail;
import com.leaseplanis.iq.model.bo.options.validation.translatableProviders.DuplicateOptionGroups;
import com.leaseplanis.iq.model.bo.options.validation.translatableProviders.DuplicateOptions;
import com.leaseplanis.iq.model.bo.options.validation.translatableProviders.Exclusion;
import com.leaseplanis.iq.model.bo.options.validation.translatableProviders.Inclusion;
import com.leaseplanis.iq.model.bo.options.validation.translatableProviders.InvalidSupplement;
# Find supplements whose corresponding pack has not been selected
rule "Supplement has parent"
when
$option: OptionDetail(optionType == "S")
not OptionDetail(optionId == $option.parentId)
then
error = new InvalidSupplement($option, null);
insert(error);
end
# Find options that have the same option identifier
rule "Duplicate options"
when
$option: OptionDetail()
OptionDetail(optionId == $option.optionId)
then
error = new DuplicateOptions($option);
insert(error);
end
# Find options that have the same group id
rule "Duplicate option groups"
when
$child: OptionDetail(groupId != null)
$parent: OptionDetail(groupId == $child.groupId)
then
error = new DuplicateOptionGroups(parent, child);
insert(error);
end
rule "Find missing dependencies"
when
$parent: OptionDetail()
$child: OptionDetail()
not OptionInclusion(parentId == $parent.optionId, childId == $child.optionId)
then
error = new Exclusion(parent, child);
insert(error);
end
rule "Find conflicting options"
when
$parent: OptionDetail()
$child: OptionDetail()
not OptionExclusion(parentId == $parent.optionId, childId == $child.optionId)
then
error = new Exclusion(parent, child);
insert(error);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment