Permalink
Browse files

Adds GenericObject to Workflow - for use by Flux workflows

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...
1 parent 9f87e58 commit c27a9e5e77f8f8e413f2bf04ca9cf6d537f806ff @patspam patspam committed Jun 17, 2010
Showing with 58 additions and 2 deletions.
  1. +1 −0 etc/.gitignore
  2. +2 −2 lib/WebGUI/Flux/Rule.pm
  3. +8 −0 lib/WebGUI/Workflow/Instance/GenericObject.pm
  4. +47 −0 t/Workflow/GenericObject.t
View
@@ -0,0 +1 @@
+/*.conf
View
@@ -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} );
@@ -0,0 +1,8 @@
+package WebGUI::Workflow::Instance::GenericObject;
+
+sub new {
+ my ($class, $session, $properties) = @_;
+ bless { session => $session, %$properties }, $class;
+}
+
+1;
View
@@ -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.