* New column on action_trigger.event and fieldmapper field (user_data) to hold json-encoded data blob
* New optional param to event creation calls to pass said data blob
(related, added a granularity param to targeted event creator -- pass undef in that position to ignore def granularity, as before)
* New grouped event environment array, called user_data, carrying the peer user_data fields to target and event
* New grouped event method, environment.EventProcessor.findEvent(), for grabbing a specific Event instance (fully fleshed)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15026
dcc99617-32d9-48b4-a31d-
7c20da2025e4
<field reporter:label="Update Time" name="update_time" reporter:datatype="timestamp"/>
<field reporter:label="Complete Time" name="complete_time" reporter:datatype="timestamp"/>
<field reporter:label="State" name="state" reporter:datatype="text"/>
+ <field reporter:label="User Data" name="user_data" reporter:datatype="text"/>
<field reporter:label="Template Output" name="template_output" reporter:datatype="link"/>
<field reporter:label="Error Output" name="error_output" reporter:datatype="text"/>
<field reporter:label="Asynchronous Output" name="async_output" reporter:datatype="link"/>
use base qw/OpenILS::Application/;
use OpenSRF::EX qw/:try/;
+use OpenSRF::Utils::JSON;
use OpenSRF::AppSession;
use OpenSRF::Utils::SettingsClient;
my $key = shift;
my $target = shift;
my $location = shift;
+ my $granularity = shift;
+ my $user_data = shift;
my $ident = $target->Identity;
my $ident_value = $target->$ident();
);
for my $def ( @$defs ) {
+ next if ($granularity && $def->granularity ne $granularity );
if ($def->usr_field && $def->opt_in_setting) {
my $ufield = $def->usr_field;
$event->target( $ident_value );
$event->event_def( $def->id );
$event->run_time( $date->strftime( '%F %T%z' ) );
+ $event->user_data( OpenSRF::Utils::JSON->perl2JSON($user_data) ) if (defined($user_data));
$editor->create_action_trigger_event( $event );
my $definitions = shift;
my $target = shift;
my $location = shift;
+ my $user_data = shift;
my $ident = $target->Identity;
my $ident_value = $target->$ident();
$event->target( $ident_value );
$event->event_def( $def->id );
$event->run_time( $date->strftime( '%F %T%z' ) );
+ $event->user_data( OpenSRF::Utils::JSON->perl2JSON($user_data) ) if (defined($user_data));
$editor->create_action_trigger_event( $event );
my $location_field = shift; # where to look for event_def.owner filtering ... circ_lib, for instance, where hook.core_type = circ
my $filter = shift || {};
my $granularity = shift;
+ my $user_data = shift;
my $active = ($self->api_name =~ /active/o) ? 1 : 0;
if ($active && !keys(%$filter)) {
$event->target( $o_id );
$event->event_def( $def->id );
$event->run_time( $run_time );
+ $event->user_data( OpenSRF::Utils::JSON->perl2JSON($user_data) ) if (defined($user_data));
$editor->create_action_trigger_event( $event );
package OpenILS::Application::Trigger::Event;
use strict; use warnings;
use OpenSRF::EX qw/:try/;
+use OpenSRF::Utils::JSON;
use OpenSRF::Utils::Logger qw/$logger/;
])
);
+ $self->user_data(OpenSRF::Utils::JSON->JSON2perl( $self->event->user_data ))
+ if (defined( $self->event->user_data ));
+
if ($self->event->state eq 'valid') {
$self->valid(1);
} elsif ($self->event->state eq 'invalid') {
return $self->{cleanedup};
}
+sub user_data {
+ my $self = shift;
+ return undef unless (ref $self);
+
+ my $r = shift;
+ $self->{user_data} = $r if (defined $r);
+ return $self->{user_data};
+}
+
sub reacted {
my $self = shift;
return undef unless (ref $self);
$self->environment->{target} = $self->target;
$self->environment->{event} = $self->event;
$self->environment->{template} = $self->event->event_def->template;
+ $self->environment->{user_data} = $self->user_data;
- $current_environment = $self->environment;
+ $current_environment = $self->environment;
$self->environment->{params}{ $_->param } = $compartment->reval($_->value) for ( @{$self->event->event_def->params} );
return $ok || undef;
}
+sub findEvent {
+ my $self = shift;
+ my $member = shift;
+
+ $member = $member->id if (ref($member));
+
+ my @list = grep { $member == $_->id } @{ $self->events };
+
+ return shift(@list);
+}
+
sub build_environment {
my $self = shift;
my $env = $self->environment;
$$env{EventProcessor} = $self;
$$env{target} = [];
$$env{event} = [];
+ $$env{user_data} = [];
for my $e ( @{ $self->events } ) {
for my $env_part ( keys %{ $e->environment } ) {
next if ($env_part eq 'EventProcessor');
push @{ $$env{target} }, $e->environment->{target};
} elsif ($env_part eq 'event') {
push @{ $$env{event} }, $e->environment->{event};
+ } elsif ($env_part eq 'user_data') {
+ push @{ $$env{user_data} }, $e->environment->{user_data};
} else {
$$env{$env_part} = $e->environment->{$env_part};
}
SELECT $2;
$$ LANGUAGE SQL;
+CREATE OR REPLACE FUNCTION is_json (TEXT) RETURNS BOOL AS $func$
+ use JSON::XS;
+ my $json = shift();
+ eval { decode_json( $json ) };
+ return $@ ? 0 : 1;
+$func$ LANGUAGE PLPERLU;
+
COMMIT;
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0091'); -- berick
+INSERT INTO config.upgrade_log (version) VALUES ('0092'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
complete_time TIMESTAMPTZ,
update_process INT,
state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending','invalid','found','collecting','collected','validating','valid','reacting','reacted','cleaning','complete','error')),
+ user_data TEXT CHECK (user_data IS NULL OR is_json( user_data )),
template_output BIGINT REFERENCES action_trigger.event_output (id),
error_output BIGINT REFERENCES action_trigger.event_output (id),
async_output BIGINT REFERENCES action_trigger.event_output (id)
--- /dev/null
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0092'); -- miker
+
+ALTER TABLE action_trigger.event ADD COLUMN user_data TEXT CHECK (user_data IS NULL OR is_json( user_data ));
+
+COMMIT;
+