Activiti-Rest-Client
view release on metacpan or search on metacpan
lib/Activiti/Rest/Client.pm view on Meta::CPAN
package Activiti::Rest::Client;
use Activiti::Sane;
use Carp qw(confess);
use Moo;
use Data::Util qw(:check :validate);
use JSON qw(decode_json encode_json);
use URI::Escape qw(uri_escape);
use Activiti::Rest::Response;
our $VERSION = "0.1259";
#see: http://www.activiti.org/userguide
=head1 NAME
Activiti::Rest::Client - Low level client for the Activiti Rest API
=head1 AUTHORS
Nicolas Franck C<< <nicolas.franck at ugent.be> >>
=head1 NOTE
This is a work in progress. More documentation will be added in time
=head1 PROJECT
see http://www.activiti.org/userguide
=head1 SYNOPSIS
my $client = Activiti::Rest::Client->new(
url => 'http://kermit:kermit@localhost:8080/activiti-rest/service'
);
my $res = $client->process_definitions;
die("no parsed content") unless $res->has_parsed_content;
my $pdefs = $res->parsed_content;
my @ids = map { $_->{id} } @{ $pdefs->{data} };
for my $id(@ids){
print Dumper($client->process_definition(processDefinitionId => $id)->parsed_content);
}
=head1 CONSTRUCTOR parameters
=head2 url
base url of the activiti rest api
activiti-rest uses basic http authentication, so username and password should be included in the url
e.g.
http://kermit:kermit@localhost:8080/activiti-rest/service
=cut
has url => (
is => 'ro',
isa => sub { $_[0] =~ /^https?:\/\//o or die("url must be a valid web url\n"); },
required => 1
);
=head2 timeout
timeout in seconds when connecting to the activiti rest api
default value is 180
=cut
has timeout => (
is => 'ro',
isa => sub { is_integer($_[0]) && $_[0] >= 0 || die("timeout should be natural number"); },
lazy => 1,
default => sub { 180; }
);
has ua => (
is => 'ro',
lazy => 1,
builder => '_build_ua'
);
sub _build_ua {
require Activiti::Rest::UserAgent::LWP;
Activiti::Rest::UserAgent::LWP->new(
url => $_[0]->url(),
timeout => $_[0]->timeout()
);
}
=head1 METHODS
=head2 deployments
Retrieve list of Deployments
parameters: see user guide (http://www.activiti.org/userguide/index.html#N13293)
equal to rest call:
GET repository/deployments
lib/Activiti/Rest/Client.pm view on Meta::CPAN
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/deployments/".uri_escape($args{deploymentId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 deployment_resources
List resources in a deployment
parameters:
deploymentId
other parameters: see user guide (http://www.activiti.org/userguide/index.html#N133F1)
equal to rest call:
GET repository/deployments/:deploymentId/resources
=cut
sub deployment_resources {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/deployments/".uri_escape($args{deploymentId})."/resources",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 deployment_resource
Get a deployment resource
parameters:
deploymentId
resourceId
other parameters: see user guide (http://www.activiti.org/userguide/index.html#N1345B)
equal to rest call:
GET repository/deployments/:deploymentId/resources/:resourceId
=cut
sub deployment_resource {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/deployments/".uri_escape($args{deploymentId})."/resources/".uri_escape($args{resourceId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_definitions
List of process definitions
parameters: see user guide (http://www.activiti.org/userguide/index.html#N13520)
equal to rest call:
GET repository/process-definitions
=cut
sub process_definitions {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/process-definitions",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_definition
Get a process definition
parameters:
processDefinitionId
other parameters: see user guide (http://www.activiti.org/userguide/index.html#N13605)
equal to rest call:
GET repository/process-definitions/:processDefinitionId
=cut
sub process_definition {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/process-definitions/".uri_escape($args{processDefinitionId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_definition_resource_data
Get a process definition resource content
parameters:
processDefinitionId
equal to rest call:
GET repository/process-definitions/:processDefinitionId/resourcedata
=cut
sub process_definition_resource_data {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/process-definitions/".uri_escape($args{processDefinitionId})."/resourcedata",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_definition_model
Get a process definition BPMN model
parameters:
processDefinitionId
equal to rest call:
GET repository/process-definitions/:processDefinitionId/model
=cut
sub process_definition_model {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/process-definitions/".uri_escape($args{processDefinitionId})."/model",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_definition_identity_links
Get all candidate starters for a process-definition
parameters:
processDefinitionId
equal to rest call:
GET repository/process-definitions/:processDefinitionId/identitylinks
=cut
sub process_definition_identity_links {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/process-definitions/".uri_escape($args{processDefinitionId})."/identitylinks",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_definition_identity_link
Get a candidate starter from a process definition
parameters: (see http://www.activiti.org/userguide/index.html#N138A9)
processDefinitionId
family
identityId
equal to rest call:
GET repository/process-definitions/:processDefinitionId/identitylinks/:family/:identityId
=cut
sub process_definition_identity_link {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/process-definitions/".uri_escape($args{processDefinitionId})."/identitylinks/".uri_escape($args{family})."/".uri_escape($args{identityId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 models
Get a list of models
Parameters: see user guide (http://www.activiti.org/userguide/index.html#N1390A)
equal to rest call:
GET repository/models
=cut
sub models {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/models",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 models
Get a model
Parameters:
modelId
equal to rest call:
GET repository/models/:modelId
=cut
sub model {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/repository/models/".uri_escape($args{modelId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_instances
List of process instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#restProcessInstancesGet)
equal to rest call:
GET runtime/process-instances
=cut
sub process_instances {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_instance
Get a process instance
Parameters:
processInstanceId
equal to rest call:
GET runtime/process-instances/:processInstanceId
=cut
sub process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
sub delete_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId}),
params => { deleteReason => $args{deleteReason} },
method => "DELETE"
);
Activiti::Rest::Response->from_http_response($res);
}
sub suspend_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId}),
params => {},
headers => {
'Content-Type' => "application/json",
Content => encode_json({ action => "suspend" })
},
method => "PUT"
);
Activiti::Rest::Response->from_http_response($res);
}
sub activate_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId}),
params => {},
headers => {
'Content-Type' => "application/json",
Content => encode_json({ action => "activate" })
},
method => "PUT"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 query_process_instances
Query process instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#N13E2A)
equal to rest call:
POST runtime/process-instances
=cut
sub query_process_instances {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/query/process-instances",
params => {},
method => "POST",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 start_process_instance
Start a process instance
Parameters: see user guide (http://www.activiti.org/userguide/index.html#N13CE6)
equal to rest call:
POST runtime/process-instances
=cut
sub start_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances",
params => {},
method => "POST",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_instance_identitylinks
Get involved people for process instance
Parameters:
processInstanceId
equal to rest call:
GET runtime/process-instances/:processInstanceId/identitylinks
=cut
sub process_instance_identitylinks {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId})."/identitylinks",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_instance_variables
List of variables for a process instance
Parameters:
processInstanceId
equal to rest call:
GET runtime/process-instances/:processInstanceId/variables
=cut
sub process_instance_variables {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId})."/variables",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_instance_variable
Get a variable for a process instance
Parameters:
processInstanceId
variableName
equal to rest call:
GET runtime/process-instances/:processInstanceId/variables/:variableName
=cut
sub process_instance_variable {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId})."/variables/".uri_escape($args{variableName}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
sub update_process_instance_variable {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId})."/variables/".uri_escape($args{variableName}),
params => {},
method => "PUT",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
#DEPRECATED!
sub signal_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/process-instance/".uri_escape($args{processInstanceId})."/signal",
params => {},
method => "POST",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 process_instance_diagram
Get a diagram for a process instance
Parameters:
processInstanceId
equal to rest call:
GET runtime/process-instances/:processInstanceId/diagram
when successfull the "content_type" of the response is "image/png" and "content" is equal to the image data
=cut
#return: png image data
sub process_instance_diagram {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/process-instances/".uri_escape($args{processInstanceId})."/diagram",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 executions
List of executions
Parameters: see user guide (http://www.activiti.org/userguide/index.html#restExecutionsGet)
equal to rest call:
GET repository/executions
=cut
sub executions {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/executions",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
sub query_executions {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/query/executions",
params => {},
method => "POST",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 query_executions
Query executions
Parameters in request body (i.e. 'content' hash)
equal to rest call:
POST query/executions
=cut
sub signal_execution {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/executions/".uri_escape($args{executionId}),
params => {},
method => "PUT",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
lib/Activiti/Rest/Client.pm view on Meta::CPAN
=cut
sub task_attachments {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/tasks/".uri_escape($args{taskId})."/attachments",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 task_attachment
Get an attachment on a task
Parameters:
taskId
attachmentId
equal to rest call:
GET runtime/tasks/:taskId/comments/:attachmentId
=cut
sub task_attachment {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/tasks/".uri_escape($args{taskId})."/attachments/".uri_escape($args{attachmentId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 task_attachment_content
Get the content for an attachment on a task
Parameters:
taskId
attachmentId
equal to rest call:
GET runtime/tasks/:taskId/attachments/:attachmentId/content
=cut
sub task_attachment_content {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/runtime/tasks/".uri_escape($args{taskId})."/attachments/".uri_escape($args{attachmentId})."/content",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_process_instances
List of historic process instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#restHistoricProcessInstancesGet)
equal to rest call:
GET history/historic-process-instances
=cut
sub historic_process_instances {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-process-instances",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 query_historic_process_instances
Query for historic process instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#N153C2)
equal to rest call:
POST history/historic-process-instances
=cut
sub query_historic_process_instances {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/query/historic-process-instances",
params => {},
method => "POST",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_process_instance
Get a historic process instance
Parameters:
processInstanceId
equal to rest call:
GET history/historic-process-instances/:processInstanceId
=cut
sub historic_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-process-instances/".uri_escape($args{processInstanceId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 delete_historic_process_instance
Delete a historic process instance
Parameters:
processInstanceId
equal to rest call:
DELETE history/historic-process-instances/:processInstanceId
=cut
sub delete_historic_process_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-process-instances/".uri_escape($args{processInstanceId}),
params => {},
method => "DELETE"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_process_instance_comments
Get all comments on a historic process instance
Parameters:
processInstanceId
equal to rest call:
GET history/historic-process-instances/:processInstanceId/comments
=cut
sub historic_process_instance_comments {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-process-instances/".uri_escape($args{processInstanceId})."/comments",
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_process_instance_comment
Get a comment on a historic process instance
Parameters:
processInstanceId
commentId
equal to rest call:
GET history/historic-process-instances/:processInstanceId/comments/:commentId
=cut
sub historic_process_instance_comment {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-process-instances/".uri_escape($args{processInstanceId})."/comments/".uri_escape($args{commentId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_task_instances
Get historic task instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#restHistoricTaskInstancesGet)
equal to rest call:
GET history/historic-task-instances
=cut
sub historic_task_instances {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-task-instances",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_variable_instances
Get historic variable instances, either from tasks or process instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#restHistoricVariableInstancesGet)
equal to rest call:
GET history/historic-variable-instances
=cut
sub historic_variable_instances {
my($self,%args) = @_;
my $res = $self->ua->request(
path => "/history/historic-variable-instances",
params => \%args,
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 query_historic_variable_instances
Query historic variable instances, either from tasks or process instances
Parameters: see user guide (http://www.activiti.org/userguide/index.html#N15B00)
equal to rest call:
POST query/historic-variable-instances
=cut
sub query_historic_variable_instances {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/query/historic-variable-instances",
params => {},
method => "POST",
headers => {
'Content-Type' => "application/json",
Content => encode_json($args{content})
}
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_task_instance
Get a historic task instance
Parameters:
taskId
equal to rest call:
GET history/historic-task-instances/:taskId
=cut
sub historic_task_instance {
my($self,%args)=@_;
my $res = $self->ua->request(
path => "/history/historic-task-instances/".uri_escape($args{taskInstanceId}),
params => {},
method => "GET"
);
Activiti::Rest::Response->from_http_response($res);
}
=head2 historic_task_instance_identity_links
Get the identity links of a historic task instance
Parameters:
taskId
equal to rest call:
GET history/historic-task-instances/:taskId/identitylinks
=cut
sub historic_task_instance_identity_links {
( run in 1.015 second using v1.01-cache-2.11-cpan-9581c071862 )