Allows you to see/delete recorded calls and download the streams. Change-Id: Ibf3c77c3984154db5877fdaf8b47c4104d554a7echanges/45/12645/4
parent
bb1b419c6d
commit
d8c818ca86
@ -0,0 +1,87 @@
|
||||
package NGCP::Panel::Controller::API::CallRecordingFiles;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use boolean qw(true);
|
||||
use NGCP::Panel::Utils::DataHal qw();
|
||||
use NGCP::Panel::Utils::DataHalLink 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);
|
||||
require Catalyst::ActionRole::ACL;
|
||||
require Catalyst::ActionRole::CheckTrailingSlash;
|
||||
require NGCP::Panel::Role::HTTPMethods;
|
||||
require Catalyst::ActionRole::RequireSSL;
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/OPTIONS/];
|
||||
}
|
||||
|
||||
sub api_description {
|
||||
return 'Defines the actual recording of a recorded call stream. It is referred to by the <a href="#callrecordingstreams">CallRecordingStreams</a> relation. A GET on an item returns the binary blob of the recording with the content type depending on the output format given in the related stream.';
|
||||
};
|
||||
|
||||
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::CallRecordingStreams/;
|
||||
|
||||
sub resource_name{
|
||||
return 'callrecordingfiles';
|
||||
}
|
||||
sub dispatch_path{
|
||||
return '/api/callrecordingfiles/';
|
||||
}
|
||||
sub relation{
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-callrecordingfiles';
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
action => {
|
||||
map { $_ => {
|
||||
ACLDetachTo => '/api/root/invalid_user',
|
||||
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
|
||||
Args => 0,
|
||||
Does => [qw(ACL CheckTrailingSlash RequireSSL)],
|
||||
Method => $_,
|
||||
Path => __PACKAGE__->dispatch_path,
|
||||
} } @{ __PACKAGE__->allowed_methods },
|
||||
},
|
||||
);
|
||||
|
||||
sub gather_default_action_roles {
|
||||
my ($self, %args) = @_; my @roles = ();
|
||||
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
|
||||
return @roles;
|
||||
}
|
||||
|
||||
sub auto :Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->set_body($c);
|
||||
$self->log_request($c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub OPTIONS :Allow {
|
||||
my ($self, $c) = @_;
|
||||
my $allowed_methods = $self->allowed_methods_filtered($c);
|
||||
$c->response->headers(HTTP::Headers->new(
|
||||
Allow => join(', ', @{ $allowed_methods }),
|
||||
));
|
||||
$c->response->content_type('application/json');
|
||||
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sub end : Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->log_response($c);
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,117 @@
|
||||
package NGCP::Panel::Controller::API::CallRecordingFilesItem;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use boolean qw(true);
|
||||
use HTTP::Headers qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
use File::Slurp qw/read_file/;
|
||||
|
||||
use Path::Tiny qw(path);
|
||||
use Safe::Isa qw($_isa);
|
||||
require Catalyst::ActionRole::ACL;
|
||||
require Catalyst::ActionRole::CheckTrailingSlash;
|
||||
require NGCP::Panel::Role::HTTPMethods;
|
||||
require Catalyst::ActionRole::RequireSSL;
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/GET OPTIONS HEAD/];
|
||||
}
|
||||
|
||||
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::CallRecordingStreams/;
|
||||
|
||||
sub resource_name{
|
||||
return 'callrecordingfiles';
|
||||
}
|
||||
sub dispatch_path{
|
||||
return '/api/callrecordingfiles/';
|
||||
}
|
||||
sub relation{
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-callrecordingfiles';
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
action => {
|
||||
map { $_ => {
|
||||
ACLDetachTo => '/api/root/invalid_user',
|
||||
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
|
||||
Args => 1,
|
||||
Does => [qw(ACL RequireSSL)],
|
||||
Method => $_,
|
||||
Path => __PACKAGE__->dispatch_path,
|
||||
} } @{ __PACKAGE__->allowed_methods }
|
||||
},
|
||||
);
|
||||
|
||||
sub gather_default_action_roles {
|
||||
my ($self, %args) = @_; my @roles = ();
|
||||
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
|
||||
return @roles;
|
||||
}
|
||||
|
||||
sub auto :Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->set_body($c);
|
||||
$self->log_request($c);
|
||||
}
|
||||
|
||||
sub GET :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
{
|
||||
last unless $self->valid_id($c, $id);
|
||||
my $item = $self->item_by_id($c, $id);
|
||||
last unless $self->resource_exists($c, callrecordingfile => $item);
|
||||
|
||||
$c->response->header ('Content-Disposition' => 'attachment; filename="' . $self->resource_name . '-' . $item->id . '.' . lc($item->file_format));
|
||||
|
||||
my $data;
|
||||
try {
|
||||
$data = read_file($item->full_filename);
|
||||
} catch($e) {
|
||||
$c->log->error("Failed to read stream file: $e");
|
||||
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to read stream file.");
|
||||
last;
|
||||
}
|
||||
my $mime_type;
|
||||
if($item->file_format eq "wav") {
|
||||
$mime_type = 'audio/x-wav';
|
||||
} elsif($item->file_format eq "mp3") {
|
||||
$mime_type = 'audio/mpeg';
|
||||
} else {
|
||||
$mime_type = 'application/octet-stream';
|
||||
}
|
||||
|
||||
$c->response->content_type($mime_type);
|
||||
$c->response->body($data);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub HEAD :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
$c->forward(qw(GET));
|
||||
$c->response->body(q());
|
||||
return;
|
||||
}
|
||||
|
||||
sub OPTIONS :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
my $allowed_methods = $self->allowed_methods_filtered($c);
|
||||
$c->response->headers(HTTP::Headers->new(
|
||||
Allow => join(', ', @{ $allowed_methods }),
|
||||
));
|
||||
$c->response->content_type('application/json');
|
||||
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sub end : Private {
|
||||
my ($self, $c) = @_;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,182 @@
|
||||
package NGCP::Panel::Controller::API::CallRecordingStreams;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use boolean qw(true);
|
||||
use NGCP::Panel::Utils::DataHal qw();
|
||||
use NGCP::Panel::Utils::DataHalLink qw();
|
||||
use HTTP::Headers qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
use NGCP::Panel::Utils::DateTime;
|
||||
use DateTime::TimeZone;
|
||||
use Path::Tiny qw(path);
|
||||
use Safe::Isa qw($_isa);
|
||||
require Catalyst::ActionRole::ACL;
|
||||
require Catalyst::ActionRole::CheckTrailingSlash;
|
||||
require NGCP::Panel::Role::HTTPMethods;
|
||||
require Catalyst::ActionRole::RequireSSL;
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/GET OPTIONS HEAD/];
|
||||
}
|
||||
|
||||
sub api_description {
|
||||
return 'Defines recording streams of a call recorded in <a href="#callrecordings">CallRecordings</a>. The file content can be fetched via in <a href="#callrecordingfiles">CallRecordingFiles</a>.';
|
||||
};
|
||||
|
||||
sub query_params {
|
||||
return [
|
||||
{
|
||||
param => 'recording_id',
|
||||
description => 'Filter for callrecording streams belonging to a specific recording session.',
|
||||
query => {
|
||||
first => sub {
|
||||
my $q = shift;
|
||||
{ 'call' => $q };
|
||||
},
|
||||
second => sub {}
|
||||
},
|
||||
},
|
||||
{
|
||||
param => 'type',
|
||||
description => 'Filter for callrecording streams with a specific type ("single" or "mixed")',
|
||||
query => {
|
||||
first => sub {
|
||||
my $q = shift;
|
||||
{ 'output_type' => $q };
|
||||
},
|
||||
second => sub {},
|
||||
},
|
||||
},
|
||||
{
|
||||
# we handle that separately/manually in the role
|
||||
param => 'tz',
|
||||
description => 'Format start_time according to the optional time zone provided here, e.g. Europe/Berlin.',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::CallRecordingStreams/;
|
||||
|
||||
sub resource_name{
|
||||
return 'callrecordingstreams';
|
||||
}
|
||||
sub dispatch_path{
|
||||
return '/api/callrecordingstreams/';
|
||||
}
|
||||
sub relation{
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-callrecordingstreams';
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
action => {
|
||||
map { $_ => {
|
||||
ACLDetachTo => '/api/root/invalid_user',
|
||||
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
|
||||
Args => 0,
|
||||
Does => [qw(ACL CheckTrailingSlash RequireSSL)],
|
||||
Method => $_,
|
||||
Path => __PACKAGE__->dispatch_path,
|
||||
} } @{ __PACKAGE__->allowed_methods },
|
||||
},
|
||||
);
|
||||
|
||||
sub gather_default_action_roles {
|
||||
my ($self, %args) = @_; my @roles = ();
|
||||
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
|
||||
return @roles;
|
||||
}
|
||||
|
||||
sub auto :Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->set_body($c);
|
||||
$self->log_request($c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub GET :Allow {
|
||||
my ($self, $c) = @_;
|
||||
my $page = $c->request->params->{page} // 1;
|
||||
my $rows = $c->request->params->{rows} // 10;
|
||||
{
|
||||
if($c->req->param('tz') && !DateTime::TimeZone->is_valid_name($c->req->param('tz'))) {
|
||||
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Query parameter 'tz' value is not a valid time zone");
|
||||
return;
|
||||
}
|
||||
my $callrecordingstreams = $self->item_rs($c);
|
||||
(my $total_count, $callrecordingstreams) = $self->paginate_order_collection($c, $callrecordingstreams);
|
||||
my (@embedded, @links);
|
||||
my $form = $self->get_form($c);
|
||||
for my $domain ($callrecordingstreams->all) {
|
||||
push @embedded, $self->hal_from_item($c, $domain, $form);
|
||||
push @links, NGCP::Panel::Utils::DataHalLink->new(
|
||||
relation => 'ngcp:'.$self->resource_name,
|
||||
href => sprintf('/%s%d', $c->request->path, $domain->id),
|
||||
);
|
||||
}
|
||||
push @links,
|
||||
NGCP::Panel::Utils::DataHalLink->new(
|
||||
relation => 'curies',
|
||||
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
|
||||
name => 'ngcp',
|
||||
templated => true,
|
||||
),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows));
|
||||
if(($total_count / $rows) > $page ) {
|
||||
push @links, NGCP::Panel::Utils::DataHalLink->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows));
|
||||
}
|
||||
if($page > 1) {
|
||||
push @links, NGCP::Panel::Utils::DataHalLink->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows));
|
||||
}
|
||||
|
||||
my $hal = NGCP::Panel::Utils::DataHal->new(
|
||||
embedded => [@embedded],
|
||||
links => [@links],
|
||||
);
|
||||
$hal->resource({
|
||||
total_count => $total_count,
|
||||
});
|
||||
my $rname = $self->resource_name;
|
||||
|
||||
my $response = HTTP::Response->new(HTTP_OK, undef,
|
||||
HTTP::Headers->new($hal->http_headers(skip_links => 1)), $hal->as_json);
|
||||
$c->response->headers($response->headers);
|
||||
$c->response->body($response->content);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub HEAD :Allow {
|
||||
my ($self, $c) = @_;
|
||||
$c->forward(qw(GET));
|
||||
$c->response->body(q());
|
||||
return;
|
||||
}
|
||||
|
||||
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 end : Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->log_response($c);
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,133 @@
|
||||
package NGCP::Panel::Controller::API::CallRecordingStreamsItem;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use boolean qw(true);
|
||||
use NGCP::Panel::Utils::DataHal qw();
|
||||
use NGCP::Panel::Utils::DataHalLink qw();
|
||||
use HTTP::Headers qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
use NGCP::Panel::Utils::DateTime;
|
||||
use DateTime::TimeZone;
|
||||
use Path::Tiny qw(path);
|
||||
use Safe::Isa qw($_isa);
|
||||
require Catalyst::ActionRole::ACL;
|
||||
require Catalyst::ActionRole::CheckTrailingSlash;
|
||||
require NGCP::Panel::Role::HTTPMethods;
|
||||
require Catalyst::ActionRole::RequireSSL;
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/GET OPTIONS HEAD DELETE/];
|
||||
}
|
||||
|
||||
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::CallRecordingStreams/;
|
||||
|
||||
sub resource_name{
|
||||
return 'callrecordingstreams';
|
||||
}
|
||||
sub dispatch_path{
|
||||
return '/api/callrecordingstreams/';
|
||||
}
|
||||
sub relation{
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-callrecordingstreams';
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
action => {
|
||||
map { $_ => {
|
||||
ACLDetachTo => '/api/root/invalid_user',
|
||||
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
|
||||
Args => 1,
|
||||
Does => [qw(ACL RequireSSL)],
|
||||
Method => $_,
|
||||
Path => __PACKAGE__->dispatch_path,
|
||||
} } @{ __PACKAGE__->allowed_methods }
|
||||
},
|
||||
);
|
||||
|
||||
sub gather_default_action_roles {
|
||||
my ($self, %args) = @_; my @roles = ();
|
||||
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
|
||||
return @roles;
|
||||
}
|
||||
|
||||
sub auto :Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->set_body($c);
|
||||
$self->log_request($c);
|
||||
}
|
||||
|
||||
sub GET :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
{
|
||||
last unless $self->valid_id($c, $id);
|
||||
my $item = $self->item_by_id($c, $id);
|
||||
last unless $self->resource_exists($c, callrecordingstream => $item);
|
||||
|
||||
my $hal = $self->hal_from_item($c, $item);
|
||||
|
||||
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
|
||||
(map { # XXX Data::HAL must be able to generate links with multiple relations
|
||||
s|rel="(http://purl.org/sipwise/ngcp-api/#rel-\w+)"|rel="item $1"|r =~
|
||||
s/rel=self/rel="item self"/r;
|
||||
} $hal->http_headers),
|
||||
), $hal->as_json);
|
||||
$c->response->headers($response->headers);
|
||||
$c->response->body($response->content);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub HEAD :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
$c->forward(qw(GET));
|
||||
$c->response->body(q());
|
||||
return;
|
||||
}
|
||||
|
||||
sub OPTIONS :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
my $allowed_methods = $self->allowed_methods_filtered($c);
|
||||
$c->response->headers(HTTP::Headers->new(
|
||||
Allow => join(', ', @{ $allowed_methods }),
|
||||
));
|
||||
$c->response->content_type('application/json');
|
||||
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sub DELETE :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
|
||||
my $guard = $c->model('DB')->txn_scope_guard;
|
||||
{
|
||||
my $item = $self->item_by_id($c, $id);
|
||||
last unless $self->resource_exists($c, callrecordingstream => $item);
|
||||
try {
|
||||
unlink($item->full_filename);
|
||||
$item->delete;
|
||||
} catch($e) {
|
||||
$c->log->error("Failed to delete stream: $e");
|
||||
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to delete stream.");
|
||||
last;
|
||||
}
|
||||
$guard->commit;
|
||||
$c->response->status(HTTP_NO_CONTENT);
|
||||
$c->response->body(q());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub end : Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->log_response($c);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,190 @@
|
||||
package NGCP::Panel::Controller::API::CallRecordings;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use boolean qw(true);
|
||||
use NGCP::Panel::Utils::DataHal qw();
|
||||
use NGCP::Panel::Utils::DataHalLink qw();
|
||||
use HTTP::Headers qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
use NGCP::Panel::Utils::DateTime;
|
||||
use DateTime::TimeZone;
|
||||
use Path::Tiny qw(path);
|
||||
use Safe::Isa qw($_isa);
|
||||
require Catalyst::ActionRole::ACL;
|
||||
require Catalyst::ActionRole::CheckTrailingSlash;
|
||||
require NGCP::Panel::Role::HTTPMethods;
|
||||
require Catalyst::ActionRole::RequireSSL;
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/GET OPTIONS HEAD/];
|
||||
}
|
||||
|
||||
sub api_description {
|
||||
return 'Defines calls being recorded on the system. The recorded streams belonging to a recorded call can be found in <a href="#callrecordingstreams">CallRecordingStreams</a>.';
|
||||
};
|
||||
|
||||
sub query_params {
|
||||
return [
|
||||
{
|
||||
param => 'reseller_id',
|
||||
description => 'Filter for callrecordings belonging to a specific reseller',
|
||||
query => {
|
||||
first => sub {
|
||||
my $q = shift;
|
||||
{ 'domain_resellers.reseller_id' => $q };
|
||||
},
|
||||
second => sub {
|
||||
{ join => 'domain_resellers' };
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
param => 'status',
|
||||
description => 'Filter for callrecordings with a specific status',
|
||||
query => {
|
||||
first => sub {
|
||||
my $q = shift;
|
||||
{ 'status' => $q };
|
||||
},
|
||||
second => sub {},
|
||||
},
|
||||
},
|
||||
{
|
||||
# we handle that separately/manually in the role
|
||||
param => 'subscriber_id',
|
||||
description => 'Filter for callrecordings where the subscriber with the given id is involved.',
|
||||
},
|
||||
{
|
||||
# we handle that separately/manually in the role
|
||||
param => 'tz',
|
||||
description => 'Format start_time according to the optional time zone provided here, e.g. Europe/Berlin.',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::CallRecordings/;
|
||||
|
||||
sub resource_name{
|
||||
return 'callrecordings';
|
||||
}
|
||||
sub dispatch_path{
|
||||
return '/api/callrecordings/';
|
||||
}
|
||||
sub relation{
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-callrecordings';
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
action => {
|
||||
map { $_ => {
|
||||
ACLDetachTo => '/api/root/invalid_user',
|
||||
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
|
||||
Args => 0,
|
||||
Does => [qw(ACL CheckTrailingSlash RequireSSL)],
|
||||
Method => $_,
|
||||
Path => __PACKAGE__->dispatch_path,
|
||||
} } @{ __PACKAGE__->allowed_methods },
|
||||
},
|
||||
);
|
||||
|
||||
sub gather_default_action_roles {
|
||||
my ($self, %args) = @_; my @roles = ();
|
||||
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
|
||||
return @roles;
|
||||
}
|
||||
|
||||
|
||||
sub auto :Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->set_body($c);
|
||||
$self->log_request($c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub GET :Allow {
|
||||
my ($self, $c) = @_;
|
||||
my $page = $c->request->params->{page} // 1;
|
||||
my $rows = $c->request->params->{rows} // 10;
|
||||
{
|
||||
if($c->req->param('tz') && !DateTime::TimeZone->is_valid_name($c->req->param('tz'))) {
|
||||
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Query parameter 'tz' value is not a valid time zone");
|
||||
return;
|
||||
}
|
||||
my $callrecordings = $self->item_rs($c);
|
||||
(my $total_count, $callrecordings) = $self->paginate_order_collection($c, $callrecordings);
|
||||
my (@embedded, @links);
|
||||
my $form = $self->get_form($c);
|
||||
for my $domain ($callrecordings->all) {
|
||||
push @embedded, $self->hal_from_item($c, $domain, $form);
|
||||
push @links, NGCP::Panel::Utils::DataHalLink->new(
|
||||
relation => 'ngcp:'.$self->resource_name,
|
||||
href => sprintf('/%s%d', $c->request->path, $domain->id),
|
||||
);
|
||||
}
|
||||
push @links,
|
||||
NGCP::Panel::Utils::DataHalLink->new(
|
||||
relation => 'curies',
|
||||
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
|
||||
name => 'ngcp',
|
||||
templated => true,
|
||||
),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'self', href => sprintf('/%s?page=%s&rows=%s', $c->request->path, $page, $rows));
|
||||
if(($total_count / $rows) > $page ) {
|
||||
push @links, NGCP::Panel::Utils::DataHalLink->new(relation => 'next', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page + 1, $rows));
|
||||
}
|
||||
if($page > 1) {
|
||||
push @links, NGCP::Panel::Utils::DataHalLink->new(relation => 'prev', href => sprintf('/%s?page=%d&rows=%d', $c->request->path, $page - 1, $rows));
|
||||
}
|
||||
|
||||
my $hal = NGCP::Panel::Utils::DataHal->new(
|
||||
embedded => [@embedded],
|
||||
links => [@links],
|
||||
);
|
||||
$hal->resource({
|
||||
total_count => $total_count,
|
||||
});
|
||||
my $rname = $self->resource_name;
|
||||
|
||||
my $response = HTTP::Response->new(HTTP_OK, undef,
|
||||
HTTP::Headers->new($hal->http_headers(skip_links => 1)), $hal->as_json);
|
||||
$c->response->headers($response->headers);
|
||||
$c->response->body($response->content);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub HEAD :Allow {
|
||||
my ($self, $c) = @_;
|
||||
$c->forward(qw(GET));
|
||||
$c->response->body(q());
|
||||
return;
|
||||
}
|
||||
|
||||
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 end : Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->log_response($c);
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,139 @@
|
||||
package NGCP::Panel::Controller::API::CallRecordingsItem;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use HTTP::Headers qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
use NGCP::Panel::Utils::DateTime;
|
||||
use NGCP::Panel::Utils::ValidateJSON qw();
|
||||
use NGCP::Panel::Utils::Subscriber;
|
||||
use Path::Tiny qw(path);
|
||||
use Safe::Isa qw($_isa);
|
||||
require Catalyst::ActionRole::ACL;
|
||||
require NGCP::Panel::Role::HTTPMethods;
|
||||
require Catalyst::ActionRole::RequireSSL;
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/GET OPTIONS HEAD DELETE/];
|
||||
}
|
||||
|
||||
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::CallRecordings/;
|
||||
|
||||
sub resource_name{
|
||||
return 'callrecordings';
|
||||
}
|
||||
sub dispatch_path{
|
||||
return '/api/callrecordings/';
|
||||
}
|
||||
sub relation{
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-callrecordings';
|
||||
}
|
||||
|
||||
__PACKAGE__->config(
|
||||
action => {
|
||||
map { $_ => {
|
||||
ACLDetachTo => '/api/root/invalid_user',
|
||||
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
|
||||
Args => 1,
|
||||
Does => [qw(ACL RequireSSL)],
|
||||
Method => $_,
|
||||
Path => __PACKAGE__->dispatch_path,
|
||||
} } @{ __PACKAGE__->allowed_methods }
|
||||
},
|
||||
);
|
||||
|
||||
sub gather_default_action_roles {
|
||||
my ($self, %args) = @_; my @roles = ();
|
||||
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
|
||||
return @roles;
|
||||
}
|
||||
|
||||
sub auto :Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->set_body($c);
|
||||
$self->log_request($c);
|
||||
}
|
||||
|
||||
sub GET :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
{
|
||||
last unless $self->valid_id($c, $id);
|
||||
my $item = $self->item_by_id($c, $id);
|
||||
last unless $self->resource_exists($c, callrecording => $item);
|
||||
|
||||
my $hal = $self->hal_from_item($c, $item);
|
||||
|
||||
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
|
||||
(map { # XXX Data::HAL must be able to generate links with multiple relations
|
||||
s|rel="(http://purl.org/sipwise/ngcp-api/#rel-\w+)"|rel="item $1"|r =~
|
||||
s/rel=self/rel="item self"/r;
|
||||
} $hal->http_headers),
|
||||
), $hal->as_json);
|
||||
$c->response->headers($response->headers);
|
||||
$c->response->body($response->content);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub HEAD :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
$c->forward(qw(GET));
|
||||
$c->response->body(q());
|
||||
return;
|
||||
}
|
||||
|
||||
sub OPTIONS :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
my $allowed_methods = $self->allowed_methods_filtered($c);
|
||||
$c->response->headers(HTTP::Headers->new(
|
||||
Allow => join(', ', @{ $allowed_methods }),
|
||||
));
|
||||
$c->response->content_type('application/json');
|
||||
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
|
||||
return;
|
||||
}
|
||||
|
||||
sub DELETE :Allow {
|
||||
my ($self, $c, $id) = @_;
|
||||
|
||||
my $guard = $c->model('DB')->txn_scope_guard;
|
||||
{
|
||||
my $item = $self->item_by_id($c, $id);
|
||||
last unless $self->resource_exists($c, callrecording => $item);
|
||||
|
||||
try {
|
||||
foreach my $stream($item->recording_streams->all) {
|
||||
unlink($stream->full_filename);
|
||||
}
|
||||
$item->recording_streams->delete;
|
||||
$item->recording_metakeys->delete;
|
||||
$item->delete;
|
||||
} catch($e) {
|
||||
$c->log->error("Failed to delete recording: $e");
|
||||
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to delete recording.");
|
||||
last;
|
||||
}
|
||||
|
||||
|
||||
$item->delete;
|
||||
$guard->commit;
|
||||
|
||||
$c->response->status(HTTP_NO_CONTENT);
|
||||
$c->response->body(q());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub end : Private {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
$self->log_response($c);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,51 @@
|
||||
package NGCP::Panel::Form::CallRecording::Recording;
|
||||
|
||||
use HTML::FormHandler::Moose;
|
||||
extends 'HTML::FormHandler';
|
||||
|
||||
has_field 'submitid' => ( type => 'Hidden' );
|
||||
|
||||
has_field 'callid' => (
|
||||
type => 'Text',
|
||||
required => 1,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The SIP call-id of the recorded call.'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'status' => (
|
||||
type => 'Select',
|
||||
required => 1,
|
||||
options => [
|
||||
{ name => 'recording', value => 'recording' },
|
||||
{ name => 'completed', value => 'completed' },
|
||||
{ name => 'confirmed', value => 'confirmed' },
|
||||
],
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The status of the recording (one of "recording", "completed", "confirmed").'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'start_time' => (
|
||||
type => 'Text',
|
||||
required => 0,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The start timestamp of the recording.'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'end_time' => (
|
||||
type => 'Text',
|
||||
required => 0,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The end timestamp of the recording.'],
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,81 @@
|
||||
package NGCP::Panel::Form::CallRecording::Stream;
|
||||
|
||||
use HTML::FormHandler::Moose;
|
||||
extends 'HTML::FormHandler';
|
||||
|
||||
has_field 'submitid' => ( type => 'Hidden' );
|
||||
|
||||
has_field 'recording_id' => (
|
||||
type => 'PosInteger',
|
||||
required => 1,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The id of the recording session.'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'type' => (
|
||||
type => 'Select',
|
||||
required => 1,
|
||||
options => [
|
||||
{ name => 'mixed', value => 'mixed' },
|
||||
{ name => 'single', value => 'single' },
|
||||
],
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The mixing type of the stream (one of "single", "mixed").'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'format' => (
|
||||
type => 'Select',
|
||||
required => 1,
|
||||
options => [
|
||||
{ name => 'wav', value => 'wav' },
|
||||
{ name => 'mp3', value => 'mp3' },
|
||||
],
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The encoding format of the stream (one of "wav", "mp3").'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'sample_rate' => (
|
||||
type => 'PosInteger',
|
||||
required => 0,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The sample rate of the stream (e.g. "8000" for 8000Hz).'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'channels' => (
|
||||
type => 'PosInteger',
|
||||
required => 0,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The number of channels in the stream (e.g. 1 for mono, 2 for stereo).'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'start_time' => (
|
||||
type => 'Text',
|
||||
required => 0,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The start timestamp of the recording stream.'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'end_time' => (
|
||||
type => 'Text',
|
||||
required => 0,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The end timestamp of the recording stream.'],
|
||||
},
|
||||
);
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,152 @@
|
||||
package NGCP::Panel::Role::API::CallRecordingStreams;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use parent 'NGCP::Panel::Role::API';
|
||||
|
||||
use boolean qw(true);
|
||||
use NGCP::Panel::Utils::DataHal qw();
|
||||
use NGCP::Panel::Utils::DataHalLink qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
use NGCP::Panel::Form::CallRecording::Stream;
|
||||
use NGCP::Panel::Utils::Subscriber;
|
||||
|
||||
sub _item_rs {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $item_rs = $c->model('DB')->resultset('recording_streams');
|
||||
if($c->user->roles eq "admin") {
|
||||
} elsif($c->user->roles eq "reseller") {
|
||||
|
||||
my $res_rs = $c->model('DB')->resultset('voip_subscribers')->search({
|
||||
'contact.reseller_id' => $c->user->reseller_id
|
||||
}, {
|
||||
join => { 'contract' => 'contact' }
|
||||
});
|
||||
|
||||
$item_rs = $item_rs->search({
|
||||
status => { -in => [qw/completed confirmed/] },
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => { -in => $res_rs->get_column('uuid')->as_query }
|
||||
},{
|
||||
join => { 'recording_call' => 'recording_metakeys' },
|
||||
});
|
||||
} elsif ($c->user->roles eq "subscriberadmin") {
|
||||
|
||||
my $res_rs = $c->model('DB')->resultset('provisioning_voip_subscribers')->search({
|
||||
'account_id' => $c->user->account_id
|
||||
});
|
||||
|
||||
$item_rs = $item_rs->search({
|
||||
status => { -in => [qw/completed confirmed/] },
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => { -in => $res_rs->get_column('uuid')->as_query }
|
||||
},{
|
||||
join => { 'recording_call' => 'recording_metakeys' },
|
||||
});
|
||||
} elsif ($c->user->roles eq "subscriber") {
|
||||
$item_rs = $item_rs->search({
|
||||
status => { -in => [qw/completed confirmed/] },
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => $c->user->uuid,
|
||||
},{
|
||||
join => { 'recording_call' => 'recording_metakeys' },
|
||||
});
|
||||
}
|
||||
|
||||
if($c->req->params->{subscriber_id}) {
|
||||
my $res_rs = $c->model('DB')->resultset('voip_subscribers')->search({
|
||||
id => $c->req->params->{subscriber_id}
|
||||
});
|
||||
$item_rs = $item_rs->search({
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => { -in => $res_rs->get_column('uuid')->as_query }
|
||||
},{
|
||||
join => { 'recording_call' => 'recording_metakeys' },
|
||||
});
|
||||
}
|
||||
return $item_rs;
|
||||
}
|
||||
|
||||
sub get_form {
|
||||
my ($self, $c) = @_;
|
||||
return NGCP::Panel::Form::CallRecording::Stream->new;
|
||||
}
|
||||
|
||||
sub hal_from_item {
|
||||
my ($self, $c, $item, $form) = @_;
|
||||
|
||||
my $hal = NGCP::Panel::Utils::DataHal->new(
|
||||
links => [
|
||||
NGCP::Panel::Utils::DataHalLink->new(
|
||||
relation => 'curies',
|
||||
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
|
||||
name => 'ngcp',
|
||||
templated => true,
|
||||
),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'collection', href => sprintf("/api/%s/", $self->resource_name)),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'ngcp:callrecordings', href => sprintf("/api/callrecordings/%d", $item->call)),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'ngcp:callrecordingfiles', href => sprintf("/api/callrecordingfiles/%d", $item->id)),
|
||||
],
|
||||
relation => 'ngcp:'.$self->resource_name,
|
||||
);
|
||||
|
||||
my $resource = $self->resource_from_item($c, $item, $form);
|
||||
$hal->resource($resource);
|
||||
return $hal;
|
||||
}
|
||||
|
||||
sub resource_from_item {
|
||||
my ($self, $c, $item, $form) = @_;
|
||||
|
||||
my %resource = ();
|
||||
$resource{id} = int($item->id);
|
||||
$resource{type} = $item->output_type;
|
||||
$resource{recording_id} = $item->call;
|
||||
$resource{format} = lc($item->file_format);
|
||||
$resource{sample_rate} = $item->sample_rate;
|
||||
$resource{channels} = $item->channels;
|
||||
|
||||
my $datetime_fmt = DateTime::Format::Strptime->new(
|
||||
pattern => '%F %T',
|
||||
);
|
||||
my $tz = $c->req->param('tz');
|
||||
unless($tz && DateTime::TimeZone->is_valid_name($tz)) {
|
||||
$tz = undef;
|
||||
}
|
||||
if($item->start_timestamp) {
|
||||
if($tz) {
|
||||
$item->start_timestamp->set_time_zone($tz);
|
||||
}
|
||||
$resource{start_time} = $datetime_fmt->format_datetime($item->start_timestamp);
|
||||
# no need to show millisec precision here, I guess...
|
||||
#$resource{start_time} .= '.'.$item->start_timestamp->millisecond
|
||||
# if $item->start_timestamp->millisecond > 0.0;
|
||||
} else {
|
||||
$resource{start_time} = undef;
|
||||
}
|
||||
if($item->end_timestamp) {
|
||||
if($tz) {
|
||||
$item->end_timestamp->set_time_zone($tz);
|
||||
}
|
||||
$resource{end_time} = $datetime_fmt->format_datetime($item->end_timestamp);
|
||||
#$resource{end_time} .= '.'.$item->end_timestamp->millisecond
|
||||
# if $item->end_timestamp->millisecond > 0.0;
|
||||
} else {
|
||||
$resource{end_time} = undef;
|
||||
}
|
||||
|
||||
return \%resource;
|
||||
}
|
||||
|
||||
sub item_by_id {
|
||||
my ($self, $c, $id) = @_;
|
||||
my $item_rs = $self->item_rs($c);
|
||||
return $item_rs->find($id);
|
||||
}
|
||||
|
||||
1;
|
||||
# vim: set tabstop=4 expandtab:
|
||||
@ -0,0 +1,156 @@
|
||||
package NGCP::Panel::Role::API::CallRecordings;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
|
||||
use Sipwise::Base;
|
||||
|
||||
use parent 'NGCP::Panel::Role::API';
|
||||
|
||||
use boolean qw(true);
|
||||
use NGCP::Panel::Utils::DataHal qw();
|
||||
use NGCP::Panel::Utils::DataHalLink qw();
|
||||
use HTTP::Status qw(:constants);
|
||||
use NGCP::Panel::Form::CallRecording::Recording;
|
||||
use NGCP::Panel::Utils::Subscriber;
|
||||
|
||||
sub _item_rs {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $item_rs = $c->model('DB')->resultset('recording_calls');
|
||||
if($c->user->roles eq "admin") {
|
||||
} elsif($c->user->roles eq "reseller") {
|
||||
|
||||
my $res_rs = $c->model('DB')->resultset('voip_subscribers')->search({
|
||||
'contact.reseller_id' => $c->user->reseller_id
|
||||
}, {
|
||||
join => { 'contract' => 'contact' }
|
||||
});
|
||||
|
||||
$item_rs = $item_rs->search({
|
||||
status => { -in => [qw/completed confirmed/] },
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => { -in => $res_rs->get_column('uuid')->as_query }
|
||||
},{
|
||||
join => 'recording_metakeys',
|
||||
});
|
||||
} elsif ($c->user->roles eq "subscriberadmin") {
|
||||
|
||||
my $res_rs = $c->model('DB')->resultset('provisioning_voip_subscribers')->search({
|
||||
'account_id' => $c->user->account_id
|
||||
});
|
||||
|
||||
$item_rs = $item_rs->search({
|
||||
status => { -in => [qw/completed confirmed/] },
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => { -in => $res_rs->get_column('uuid')->as_query }
|
||||
},{
|
||||
join => 'recording_metakeys',
|
||||
});
|
||||
} elsif ($c->user->roles eq "subscriber") {
|
||||
$item_rs = $item_rs->search({
|
||||
status => { -in => [qw/completed confirmed/] },
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => $c->user->uuid,
|
||||
},{
|
||||
join => 'recording_metakeys',
|
||||
});
|
||||
}
|
||||
|
||||
if($c->req->params->{subscriber_id}) {
|
||||
my $res_rs = $c->model('DB')->resultset('voip_subscribers')->search({
|
||||
id => $c->req->params->{subscriber_id}
|
||||
});
|
||||
$item_rs = $item_rs->search({
|
||||
'recording_metakeys.key' => 'uuid',
|
||||
'recording_metakeys.value' => { -in => $res_rs->get_column('uuid')->as_query }
|
||||
},{
|
||||
join => 'recording_metakeys',
|
||||
});
|
||||
}
|
||||
return $item_rs;
|
||||
}
|
||||
|
||||
sub get_form {
|
||||
my ($self, $c) = @_;
|
||||
return NGCP::Panel::Form::CallRecording::Recording->new;
|
||||
}
|
||||
|
||||
sub hal_from_item {
|
||||
my ($self, $c, $item, $form) = @_;
|
||||
|
||||
my $res_rs = $item->recording_metakeys->search({
|
||||
key => 'uuid'
|
||||
});
|
||||
my @sub_ids = $c->model('DB')->resultset('voip_subscribers')->search({
|
||||
uuid => { -in => $res_rs->get_column('value')->as_query }
|
||||
})->get_column('id')->all;
|
||||
|
||||
my $hal = NGCP::Panel::Utils::DataHal->new(
|
||||
links => [
|
||||
NGCP::Panel::Utils::DataHalLink->new(
|
||||
relation => 'curies',
|
||||
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
|
||||
name => 'ngcp',
|
||||
templated => true,
|
||||
),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'collection', href => sprintf("/api/%s/", $self->resource_name)),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
|
||||
(map { NGCP::Panel::Utils::DataHalLink->new(relation => 'ngcp:subscribers', href => sprintf("/api/subscribers/%d", $_)) } @sub_ids),
|
||||
NGCP::Panel::Utils::DataHalLink->new(relation => 'ngcp:callrecordingstreams', href => sprintf("/api/callrecordingstreams/?recording_id=%d", $item->id)),
|
||||
],
|
||||
relation => 'ngcp:'.$self->resource_name,
|
||||
);
|
||||
|
||||
my $resource = $self->resource_from_item($c, $item, $form);
|
||||
$hal->resource($resource);
|
||||
return $hal;
|
||||
}
|
||||
|
||||
sub resource_from_item {
|
||||
my ($self, $c, $item, $form) = @_;
|
||||
|
||||
my %resource = ();
|
||||
$resource{id} = int($item->id);
|
||||
$resource{status} = $item->status;
|
||||
$resource{callid} = $item->call_id;
|
||||
|
||||
my $datetime_fmt = DateTime::Format::Strptime->new(
|
||||
pattern => '%F %T',
|
||||
);
|
||||
my $tz = $c->req->param('tz');
|
||||
unless($tz && DateTime::TimeZone->is_valid_name($tz)) {
|
||||
$tz = undef;
|
||||
}
|
||||
if($item->start_timestamp) {
|
||||
if($tz) {
|
||||
$item->start_timestamp->set_time_zone($tz);
|
||||
}
|
||||
$resource{start_time} = $datetime_fmt->format_datetime($item->start_timestamp);
|
||||
# no need to show millisec precision here, I guess...
|
||||
#$resource{start_time} .= '.'.$item->start_timestamp->millisecond
|
||||
# if $item->start_timestamp->millisecond > 0.0;
|
||||
} else {
|
||||
$resource{start_time} = undef;
|
||||
}
|
||||
if($item->end_timestamp) {
|
||||
if($tz) {
|
||||
$item->end_timestamp->set_time_zone($tz);
|
||||
}
|
||||
$resource{end_time} = $datetime_fmt->format_datetime($item->end_timestamp);
|
||||
#$resource{end_time} .= '.'.$item->end_timestamp->millisecond
|
||||
# if $item->end_timestamp->millisecond > 0.0;
|
||||
} else {
|
||||
$resource{end_time} = undef;
|
||||
}
|
||||
|
||||
return \%resource;
|
||||
}
|
||||
|
||||
sub item_by_id {
|
||||
my ($self, $c, $id) = @_;
|
||||
my $item_rs = $self->item_rs($c);
|
||||
return $item_rs->find($id);
|
||||
}
|
||||
|
||||
1;
|
||||
# vim: set tabstop=4 expandtab:
|
||||
Loading…
Reference in new issue