started adding new workflow based approval process

This commit is contained in:
JT Smith 2006-03-15 20:15:55 +00:00
parent 9ff3308126
commit eb6a7a9416
14 changed files with 676 additions and 89 deletions

View file

@ -151,19 +151,25 @@ sub DESTROY {
#-------------------------------------------------------------------
=head2 execute ( object )
=head2 execute ( object, instance )
This method will be called during workflow operation. It needs to be overridden by the base classes.
This method will be called during workflow operation. It needs to be mutated by the sub classes.
=head2 object
A reference to some object that will be passed in to this activity for an action to be taken on it.
=head2 instance
A reference to the workflow instance object.
=cut
sub execute {
my $self = shift;
my $object = shift;
my $instance = shift;
return 1;
}

View file

@ -0,0 +1,119 @@
package WebGUI::Workflow::Activity::NotifyAboutVersionTag;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2006 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::VersionTag;
use WebGUI::Inbox;
=head1 NAME
Package WebGUI::Workflow::Activity::NotifyAboutVersionTag
=head1 DESCRIPTION
Ask someone for approval of a version tag. If they approve then the workflow continues. If not, it is cancelled.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "VersionTag");
push(@{$definition}, {
name=>$i18n->get("notify about version tag"),
properties=> {
who => {
fieldType=>"selectBox",
defaultValue=>"committer",
options => {
"committer" => $i18n->get("tag committer"),
"creator" => $i18n->get("tag creator"),
"groupToUse" => $i18n->get("group to use")
},
label=>$i18n->get("who to notify"),
hoverHelp=>$i18n->get("who to notify help")
},
subject => {
fieldType=>"text",
defaultValue=>"",
label=>$i18n->get("notify subject"),
hoverHelp => $i18n->get("notify subject help")
},
message => {
fieldType=>"textarea",
defaultValue => "",
label=> $i18n->get("notify message"),
hoverHelp => $i18n->get("notify message help")
},
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $versionTag = shift;
my $inbox = WebGUI::Inbox->new($self->session);
my $properties = {
status=>"completed",
subject=>$self->get("subject"),
message=>$self->get("message")."\n\n".$versionTag->get("name")."\n\n".$versionTag->get("comments"),
};
if ($self->get("who") eq "committer") {
$properties->{userId} = $versionTag->get("committedBy");
} elsif ($self->get("who") eq "creator") {
$properties->{userId} = $versionTag->get("createdBy");
} else {
$properties->{groupId} = $versionTag->get("groupToUse");
}
$inbox->addMessage($properties);
return 1;
}
1;

View file

@ -0,0 +1,133 @@
package WebGUI::Workflow::Activity::RequestApprovalForVersionTag;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2006 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::VersionTag;
use WebGUI::Inbox;
=head1 NAME
Package WebGUI::Workflow::Activity::RequestApprovalForVersionTag
=head1 DESCRIPTION
Ask someone for approval of a version tag. If they approve then the workflow continues. If not, it is cancelled.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "VersionTag");
push(@{$definition}, {
name=>$i18n->get("request approval for version tag"),
properties=> {
groupToApprove => {
fieldType=>"group",
defaultValue=>["4"],
label=>$i18n->get("group to approve"),
hoverHelp=>$i18n->get("group to approve help")
},
subject => {
fieldType=>"text",
defaultValue=>"",
label=>$i18n->get("approval subject"),
hoverHelp => $i18n->get("approval subject help")
},
message => {
fieldType=>"textarea",
defaultValue => "",
label=> $i18n->get("approval message"),
hoverHelp => $i18n->get("approval message help")
},
doOnDeny => {
fieldType=>"workflow",
defaultValue=>"pbwf",
label=>$i18n->get("do on deny"),
hoverHelp => $i18n->get("do on deny help")
}
}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $versionTag = shift;
my $instance = shift;
my $inbox = WebGUI::Inbox->new($self->session);
if ($instance->getScratch("status") eq "") {
my $message = $inbox->addMessage({
subject=>$self->get("subject"),
message=>join("\n\n",$self->get("message"),
$self->session->url->page("op=manageRevisionsInTag;workflowInstanceId=".$instance->getId.";tagId=".$versionTag->getId),
$versionTag->get('name'), $versionTag->get("comments")),
groupId=>$self->get("groupToApprove")
});
$instance->setScratch("messageId",$message->getId);
$instance->setScratch("status","notified");
} elsif ($instance->getScratch("status") eq "denied") {
my $newInstance = WebGUI::Workflow::Instance->create($self->session, {
workflowId=>$self->get("doOnDeny"),
methodName=>$instance->get("methodName"),
className=>$instance->get("className"),
parameters=>$instance->get("parameters"),
priority=>$instance->get("priority")
});
$instance->delete;
} elsif ($instance->getScratch("status") eq "approved") {
my $message = $inbox->getMessage($instance->getScratch("messageId"));
$message->setCompleted;
$instance->deleteScratch("messageId");
$instance->deleteScratch("status");
return 1;
}
}
1;

View file

@ -0,0 +1,81 @@
package WebGUI::Workflow::Activity::UnlockVersionTag;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2006 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use base 'WebGUI::Workflow::Activity';
use WebGUI::VersionTag;
=head1 NAME
Package WebGUI::Workflow::Activity::UnlockVersionTag
=head1 DESCRIPTION
This activity commits an open version tag.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "VersionTag");
push(@{$definition}, {
name=>$i18n->get("unlock version tag"),
properties=> { }
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $versionTag = shift;
$versionTag->unlock;
}
1;

View file

@ -81,6 +81,7 @@ Removes this instance.
sub delete {
my $self = shift;
$self->session->db->write("delete from WorkflowInstanceScratch where instanceId=?",[$self->getId]);
$self->session->db->deleteRow("WorkflowInstance","instanceId",$self->getId);
WebGUI::Workflow::Spectre->new($self->session)->notify("workflow/deleteJob",$self->getId);
undef $self;
@ -88,6 +89,25 @@ sub delete {
#-------------------------------------------------------------------
=head2 deleteScratch ( name )
Removes a scratch variable that's assigned to this instance.
=head3 name
The name of the variable to remove.
=cut
sub deleteScratch {
my $self = shift;
my $name = shift;
delete $self->{_scratch}{$name};
$self->session->db->write("delete from WorkflowInstanceScratch where instanceId=?", [$self->getId]);
}
#-------------------------------------------------------------------
=head2 DESTROY ( )
Deconstructor.
@ -116,6 +136,23 @@ sub get {
#-------------------------------------------------------------------
=head2 getScratch ( name )
Returns the value for a given scratch variable.
=cut
sub get {
my $self = shift;
my $name = shift;
unless (exists $self->{_scratch}) {
$self->{_scratch} = $self->session->db->buildHashRef("select name,value from WorkflowInstanceScratch where instanceId=?", [ $self->getId ]);
}
return $self->{_scratch}{$name};
}
#-------------------------------------------------------------------
=head2 getId ( )
Returns the ID of this instance.
@ -188,7 +225,7 @@ sub run {
return "error";
}
}
$activity->execute($object);
$activity->execute($object, $self);
}
@ -257,6 +294,30 @@ sub set {
$spectre->notify("workflow/addJob",$self->session->config->getFilename, $self->{_data});
}
#-------------------------------------------------------------------
=head2 setScratch (name, value)
Attaches a scratch variable to this workflow instance.
=head3 name
A scalar representing the name of the variable.
=head3 value
A scalar value to assign to the variable.
=cut
sub setScratch {
my $self = shift;
my $name = shift;
my $value = shift;
delete $self->{_scratch};
$self->session->write("replace into WorkflowInstanceScratch (instanceId, name, value) values (?,?,?)", [$self->getId, $name, $value]);
}
1;