converted workflow system to use WebGUI::Pluggable
This commit is contained in:
parent
0e55ec42cd
commit
1b4022205a
4 changed files with 43 additions and 68 deletions
|
|
@ -17,6 +17,7 @@ package WebGUI::Workflow::Activity;
|
|||
|
||||
use strict;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Pluggable;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -297,11 +298,11 @@ sub new {
|
|||
my $main = $session->db->getRow("WorkflowActivity","activityId", $activityId);
|
||||
return unless $main->{activityId};
|
||||
$class = $main->{className};
|
||||
(my $module = "$class.pm") =~ s{'|::}{/}g;
|
||||
unless (eval { require $module; 1 }) {
|
||||
$session->errorHandler->error("Couldn't compile workflow activity package: ".$class.". Root cause: ".$@);
|
||||
eval { WebGUI::Pluggable::load($class) };
|
||||
if ($@) {
|
||||
$session->errorHandler->error($@);
|
||||
return;
|
||||
}
|
||||
}
|
||||
my $sub = $session->db->buildHashRef("select name,value from WorkflowActivityData where activityId=?",[$activityId]);
|
||||
my %data = (%{$main}, %{$sub});
|
||||
for my $definition (reverse @{$class->definition($session)}) {
|
||||
|
|
@ -331,19 +332,18 @@ A properties hash reference. The className of the properties hash must be valid.
|
|||
=cut
|
||||
|
||||
sub newByPropertyHashRef {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $properties = shift;
|
||||
return unless defined $properties;
|
||||
return unless exists $properties->{className};
|
||||
my $className = $properties->{className};
|
||||
my $cmd = "use ".$className;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
$session->errorHandler->warn("Couldn't compile activity package: ".$className.". Root cause: ".$@);
|
||||
return;
|
||||
}
|
||||
bless {_session=>$session, _id=>$properties->{activityId}, _data => $properties}, $className;
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $properties = shift;
|
||||
return unless defined $properties;
|
||||
return unless exists $properties->{className};
|
||||
my $className = $properties->{className};
|
||||
eval { WebGUI::Pluggable::load($class) };
|
||||
if ($@) {
|
||||
$session->errorHandler->error($@);
|
||||
return;
|
||||
}
|
||||
bless {_session=>$session, _id=>$properties->{activityId}, _data => $properties}, $className;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package WebGUI::Workflow::Instance;
|
|||
|
||||
use strict;
|
||||
use JSON;
|
||||
use WebGUI::Pluggable;
|
||||
use WebGUI::Workflow::Spectre;
|
||||
use WebGUI::Workflow;
|
||||
|
||||
|
|
@ -311,42 +312,25 @@ sub run {
|
|||
my $method = $self->get("methodName");
|
||||
my $params = $self->get("parameters");
|
||||
my $status = "";
|
||||
my $object = undef;
|
||||
if ($class && $method) {
|
||||
my $cmd = "use $class";
|
||||
eval($cmd);
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Error loading activity class $class: ".$@);
|
||||
$object = eval { WebGUI::Pluggable::instanciate($class, $method, [$self->session, $params]) };
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error($@);
|
||||
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||
return "error";
|
||||
}
|
||||
my $object = eval{ $class->$method($self->session, $params) };
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Error instanciating activity (".$activity->getId.") pass-in object: ".$@);
|
||||
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||
return "error";
|
||||
}
|
||||
unless (defined $object) {
|
||||
$self->session->errorHandler->error("Pass in object came back undefined for activity (".$activity->getId.") using ".$class.", ".$method.", ".$params.".");
|
||||
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||
return "error";
|
||||
}
|
||||
$status = eval{$activity->execute($object, $self)};
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
||||
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||
return "error";
|
||||
}
|
||||
} else {
|
||||
$status = $activity->execute(undef, $self);
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
||||
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
}
|
||||
$status = eval { $activity->execute($object, $self) };
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
||||
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||
return "error";
|
||||
}
|
||||
if ($status eq "complete") {
|
||||
$self->set({lastStatus=>"complete", "currentActivityId"=>$activity->getId, notifySpectre=>0});
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$self->set({lastStatus=>$status, notifySpectre=>0});
|
||||
}
|
||||
return $status;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue