Skip to content

Commit

Permalink
Adds GenericObject to Workflow - for use by Flux workflows
Browse files Browse the repository at this point in the history
To be fully flexible, Flux needs to be able to pass any data it likes
into workflow activities, whereas WebGUI's workflow system requires that
you specify what object the workflow instance will work with (User, etc..)

To work around this, I added a new object that can take arbitrary data.

This was motivated by the "email user about flux rule" workflow activity,
which needed to know which flux rule had just become true. Previously, all
flux workflows expected a User object, whereas now you can use the GenericObject
and pass in a userId, fluxRuleId, and anything else you need.
  • Loading branch information
patspam committed Jun 17, 2010
1 parent 9f87e58 commit c27a9e5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions etc/.gitignore
@@ -0,0 +1 @@
/*.conf
4 changes: 2 additions & 2 deletions lib/WebGUI/Flux/Rule.pm
Expand Up @@ -844,8 +844,8 @@ sub _updateDataAndTriggerWorkflows {
$self->session,
{ workflowId => $workflowId,
methodName => "new",
className => "WebGUI::User",
parameters => $user_id,
className => "WebGUI::Workflow::Instance::GenericObject",
parameters => { userId => $user_id, fluxRuleId => $self->getId() },
}
)->start( !$ENV{FLUX_REALTIME_WORKFLOWS} );

Expand Down
8 changes: 8 additions & 0 deletions lib/WebGUI/Workflow/Instance/GenericObject.pm
@@ -0,0 +1,8 @@
package WebGUI::Workflow::Instance::GenericObject;

sub new {
my ($class, $session, $properties) = @_;
bless { session => $session, %$properties }, $class;
}

1;
47 changes: 47 additions & 0 deletions t/Workflow/GenericObject.t
@@ -0,0 +1,47 @@
# Tests WebGUI::Workflow::Instance::GenericObject

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;

#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;

#----------------------------------------------------------------------------
# Tests
plan tests => 5;

#----------------------------------------------------------------------------
# put your tests here

use_ok('WebGUI::Workflow::Instance::GenericObject');

my %props = ( a => 1, b => 2, c => 3 );
my $d = WebGUI::Workflow::Instance::GenericObject->new( $session, {%props} );
is( $d->{$_}, $props{$_}, qq{Property "$_" matches} ) for qw(a b);

my $wf = WebGUI::Workflow->create(
$session,
{ title => 'WebGUI::Workflow::Instance Test',
description => 'Description',
type => 'None',
mode => 'singleton',
}
);
WebGUI::Test->workflowsToDelete($wf);
my $instance = WebGUI::Workflow::Instance->create(
$session,
{ workflowId => $wf->getId,
methodName => "new",
className => "WebGUI::Workflow::Instance::GenericObject",
parameters => {%props},
}
);

my $obj = $instance->getObject;
is( $obj->{$_}, $props{$_}, qq{Property "$_" matches} ) for qw(a b);

0 comments on commit c27a9e5

Please sign in to comment.