TT#2651 add /partycallcontrols API

Used to notify NGCP about pending calls and sms.

    * /partycallcontrols is for handling incoming
      call control requests from external API sources

Change-Id: I4d886f941f19f659017e32504fdb10e8ae02ba8b
changes/81/10381/10
Kirill Solomko 8 years ago committed by Andreas Granig
parent dfa4a884b9
commit 1bbad6aaf2

@ -0,0 +1,129 @@
package NGCP::Panel::Controller::API::PartyCallControls;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use boolean qw(true);
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::DateTime;
use Path::Tiny qw(path);
use Safe::Isa qw($_isa);
use NGCP::Panel::Utils::Sems;
require Catalyst::ActionRole::ACL;
require Catalyst::ActionRole::CheckTrailingSlash;
require NGCP::Panel::Role::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
sub allowed_methods{
return [qw/POST OPTIONS/];
}
sub api_description {
return 'Allows to place calls via the API.';
};
sub query_params {
return [
];
}
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::PartyCallControls/;
sub resource_name{
return 'partycallcontrols';
}
sub dispatch_path{
return '/api/partycallcontrols/';
}
sub relation{
return 'http://purl.org/sipwise/ngcp-api/#rel-callcontrols';
}
__PACKAGE__->config(
action => {
map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 0,
Does => [qw(ACL CheckTrailingSlash RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }
},
action_roles => [qw(+NGCP::Panel::Role::HTTPMethods)],
);
sub auto :Private {
my ($self, $c) = @_;
$self->set_body($c);
$self->log_request($c);
}
sub OPTIONS :Allow {
my ($self, $c) = @_;
my $allowed_methods = $self->allowed_methods_filtered($c);
$c->response->headers(HTTP::Headers->new(
Allow => join(', ', @{ $allowed_methods }),
Accept_Post => 'application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-'.$self->resource_name,
));
$c->response->content_type('application/json');
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
return;
}
sub POST :Allow {
my ($self, $c) = @_;
my $guard = $c->model('DB')->txn_scope_guard;
{
my $resource = $self->get_valid_post_data(
c => $c,
media_type => 'application/json',
);
last unless $resource;
my $form = $self->get_form($c);
last unless $self->validate_form(
c => $c,
resource => $resource,
form => $form,
);
if ($resource->{type} eq "pcc") {
try {
NGCP::Panel::Utils::Sems::party_call_control($c, $resource);
} catch($e) {
$c->log->error("failed to handle a party call control request: $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR,
"Failed to handle a party call control request.");
last;
}
} else {
$self->error($c, HTTP_INTERNAL_SERVER_ERROR,
"Failed to handle a party call control request of unknown type.");
last;
}
$guard->commit;
$c->response->status(HTTP_OK);
$c->response->body(q());
}
return;
}
sub end : Private {
my ($self, $c) = @_;
$self->log_response($c);
}
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,81 @@
package NGCP::Panel::Form::PartyCallControl::API;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
sub build_form_element_class {[qw(form-horizontal)]}
has_field 'callid' => (
type => 'Text',
label => 'Call id',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['Call id']
},
);
has_field 'type' => (
type => 'Text',
label => 'Type',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['External call control request type']
},
);
has_field 'caller' => (
type => 'Text',
label => 'Caller number',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['Caller number']
},
);
has_field 'callee' => (
type => 'Text',
label => 'Callee number',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['Callee number']
},
);
has_field 'status' => (
type => 'Text',
label => 'Call status',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['Call status']
},
);
has_field 'token' => (
type => 'Text',
label => 'Token',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['Session related token']
},
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/subscriber_id destination/],
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,25 @@
package NGCP::Panel::Role::API::PartyCallControls;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use parent 'NGCP::Panel::Role::API';
use boolean qw(true);
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Form::PartyCallControl::API;
sub _item_rs {
}
sub get_form {
my ($self, $c) = @_;
return NGCP::Panel::Form::PartyCallControl::API->new;
}
1;
# vim: set tabstop=4 expandtab:

@ -303,6 +303,62 @@ EOF
return 1;
}
sub party_call_control {
my ($c, $data) = @_;
foreach my $param (qw(caller callee call_id status)) {
die "missing '$param' parameter'" unless $data->{$param};
}
my ($caller, $callee, $callid, $status) =
@{$data}{qw(caller callee callid status)};
my $service = 'appserver';
my $dispatcher = NGCP::Panel::Utils::XMLDispatcher->new;
my @ret = $dispatcher->dispatch($c, $service, 1, 1, <<EOF );
<?xml version="1.0"?>
<methodCall>
<methodName>postDSMEvent</methodName>
<params>
<param>
<value><string>pcc_$call_id</string></value>
</param>
<param>
<value><array><data>
<value><array><data>
<value><string>cmd</string></value>
<value><string>handleCall</string></value>
</data></array></value>
<value><array><data>
<value><string>callid</string></value>
<value><string>$callid</string></value>
</data></array></value>
<value><array><data>
<value><string>caller</string></value>
<value><string>$caller</string></value>
</data></array></value>
<value><array><data>
<value><string>callee</string></value>
<value><string>$callee</string></value>
</data></array></value>
<value><array><data>
<value><string>status</string></value>
<value><string>$status</string></value>
</data></array></value>
</data></array></value>
</param>
</params>
</methodCall>
EOF
if(grep { $$_[1] != 1 or $$_[2] !~ m#<value>OK</value># } @ret) {
die "failed to handle party call control request";
}
return 1;
}
1;
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save