Commit 572902da authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Fix rules

parent bda39443
...@@ -93,6 +93,7 @@ class SimpleRule (ABC): ...@@ -93,6 +93,7 @@ class SimpleRule (ABC):
class LinkRule (SimpleRule): class LinkRule (SimpleRule):
def __init__(self, user_args, wf_instance, src_arg, targets_args, nb_rows): def __init__(self, user_args, wf_instance, src_arg, targets_args, nb_rows):
SimpleRule.__init__(self, user_args, wf_instance, src_arg, nb_rows) SimpleRule.__init__(self, user_args, wf_instance, src_arg, nb_rows)
self.require_src = True
self.targets_args = targets_args self.targets_args = targets_args
@abstractmethod @abstractmethod
...@@ -251,8 +252,12 @@ class AtLeastOneAmong(LinkRule): ...@@ -251,8 +252,12 @@ class AtLeastOneAmong(LinkRule):
At least one parameter among the list must be set At least one parameter among the list must be set
""" """
def __init__(self, user_args, wf_instance, src_arg, targets_args, nb_rows):
LinkRule.__init__(self, user_args, wf_instance, src_arg, targets_args, nb_rows)
self.require_src = False
def check(self): def check(self):
if self.parameter_value is None: if self.parameter_value is None or not self.parameter_value:
has_one = False has_one = False
for grp_param in self.targets_args: for grp_param in self.targets_args:
if not getattr(self.wf_instance, grp_param).is_None: if not getattr(self.wf_instance, grp_param).is_None:
......
...@@ -1360,8 +1360,7 @@ class Workflow(threading.Thread): ...@@ -1360,8 +1360,7 @@ class Workflow(threading.Thread):
validator.check() validator.check()
else: else:
raise Exception("Rule is not a conditional link rule: " + name) raise Exception("Rule is not a conditional link rule: " + name)
elif (src_arg in user_args and user_args[src_arg] is not None and user_args[src_arg]) or \ else:
(isinstance(getattr(self, src_arg), MultiParameterList)):
is_link_rule = re.match(link_rule, rule) # Check the second special rule is_link_rule = re.match(link_rule, rule) # Check the second special rule
if is_link_rule: if is_link_rule:
# Check this special rule: # Check this special rule:
...@@ -1380,12 +1379,15 @@ class Workflow(threading.Thread): ...@@ -1380,12 +1379,15 @@ class Workflow(threading.Thread):
if issubclass(validator_class, j_rules.LinkRule): if issubclass(validator_class, j_rules.LinkRule):
# Check the rule is the same special rule # Check the rule is the same special rule
validator = validator_class(user_args, self, src_arg, targets, nb_rows) validator = validator_class(user_args, self, src_arg, targets, nb_rows)
validator.check()
elif issubclass(validator_class, j_rules.ValueRule): elif issubclass(validator_class, j_rules.ValueRule):
validator = validator_class(user_args, self, src_arg, is_link_rule.group(2), nb_rows) validator = validator_class(user_args, self, src_arg, is_link_rule.group(2), nb_rows)
validator.check()
else: else:
raise Exception("Rule is not a link rule: " + name) raise Exception("Rule is not a link rule: " + name)
if (src_arg in user_args and user_args[src_arg] is not None and user_args[src_arg]) or \
(isinstance(getattr(self, src_arg), MultiParameterList)) or (
not validator.require_src):
validator.check()
else: # It's a simple rule else: # It's a simple rule
name = rule name = rule
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment