LPXXX Support stacked A/T Validators
authorBill Erickson <berickxx@gmail.com>
Fri, 2 Oct 2020 17:29:19 +0000 (13:29 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 2 Oct 2020 17:29:21 +0000 (13:29 -0400)
Action/Trigger validators can now be configured with comma-separated
strings to support stacked validators.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Event.pm

index 4291eeb..8fd6f18 100644 (file)
@@ -244,17 +244,31 @@ sub validate {
 
     if ($self->build_environment->environment->{complete}) {
         $self->update_state( 'validating') || die 'Unable to update event state';
-        try {
-            $self->valid(
-                OpenILS::Application::Trigger::ModRunner::Validator
-                    ->new( $self->event->event_def->validator, $self->environment )
-                    ->run
-                    ->final_result
-            );
-        } otherwise {
-            $log->error("Event validation failed with ". shift() );
-            $self->update_state( 'error' ) || die 'Unable to update event state';
-        };
+
+        my @validators = split(',', $self->event->event_def->validator);
+
+        my $valid;
+        for my $validator (@validators) {
+
+            eval {
+                $valid =
+                    OpenILS::Application::Trigger::ModRunner::Validator
+                        ->new( $validator, $self->environment )
+                        ->run
+                        ->final_result
+            };
+
+            if ($@) {
+                $log->error("Event validation [$validator] failed with: $@");
+                $self->update_state('error') || die 'Unable to update event state';
+                $valid = undef;
+            };
+
+            # Stop on first failed validator.
+            last unless $valid; # 0 or undef
+        }
+
+        $self->valid($valid);
 
         if (defined $self->valid) {
             if ($self->valid) {