MT#16323 Add rating_status field into item response and filter for collection

Change-Id: Idc82840fd20cfa74ed0e6abe041125e8bb105f8f
changes/99/3299/3
Irina Peshinskaya 11 years ago
parent 1297bdf972
commit 755ca9312a

@ -76,7 +76,7 @@ class_has 'query_params' => (
first => sub {
my $q = shift;
{
call_status => $q,
'me.call_status' => $q,
};
},
second => sub {},
@ -89,12 +89,36 @@ class_has 'query_params' => (
first => sub {
my $q = shift;
{
call_status => { '!=' => $q },
'me.call_status' => { '!=' => $q },
};
},
second => sub {},
},
},
{
param => 'rating_status',
description => 'Filter for calls having a specific rating status. Comma separated list of "ok", "unrated", "failed".',
query => {
first => sub {
my $q = shift;
my @l = split /,/, $q;
{ 'me.rating_status' => { -in => \@l }};
},
second => sub {},
},
},
{
param => 'rating_status_ne',
description => 'Filter for calls not having a specific rating status. Comma separated list of "ok", "unrated", "failed".',
query => {
first => sub {
my $q = shift;
my @l = split /,/, $q;
{ 'me.rating_status' => { -not_in => \@l }};
},
second => sub {},
},
},
{
param => 'type',
description => 'Filter for calls with a specific type. One of "call", "cfu", "cfb", "cft", "cfna".',
@ -156,7 +180,7 @@ class_has 'query_params' => (
first => sub {
my $q = shift;
my $dt = NGCP::Panel::Utils::DateTime::from_string($q);
{ start_time => { '>=' => $dt->epoch } };
{ 'me.start_time' => { '>=' => $dt->epoch } };
},
second => sub {},
},

@ -41,7 +41,7 @@ class_has 'query_params' => (
default => sub {[
{
param => 'status',
description => 'Filter for customers with a specific status (comma-separated list of stati to include possible)',
description => 'Filter for customers with a specific status (comma-separated list of statuses to include possible)',
query => {
first => sub {
my $q = shift;
@ -53,7 +53,7 @@ class_has 'query_params' => (
},
{
param => 'not_status',
description => 'Filter for customers not having a specific status (comma-separated list of stati to exclude possible)',
description => 'Filter for customers not having a specific status (comma-separated list of statuses to exclude possible)',
query => {
first => sub {
my $q = shift;

@ -59,7 +59,19 @@ has_field 'status' => (
title => ['The status of the call, one of ok, busy, noanswer, cancel, offline, timeout, other.']
},
);
has_field 'rating_status' => (
type => 'Select',
required => 1,
options => [
{ label => 'ok', value => 'ok' },
{ label => 'unrated', value => 'unrated' },
{ label => 'failed', value => 'failed' },
],
element_attr => {
rel => ['tooltip'],
title => ['The status of the call rating, one of ok, unrated, failed.']
},
);
has_field 'type' => (
type => 'Select',
required => 1,

@ -54,13 +54,7 @@ sub item_rs {
sub get_form {
my ($self, $c) = @_;
if($c->user->roles eq "admin") {
return NGCP::Panel::Form::CallList::Subscriber->new;
} elsif($c->user->roles eq "reseller") {
return NGCP::Panel::Form::CallList::Subscriber->new;
} else {
return NGCP::Panel::Form::CallList::Subscriber->new;
}
return NGCP::Panel::Form::CallList::Subscriber->new;
}
sub hal_from_item {

@ -180,6 +180,7 @@ sub process_cdr_item {
$resource->{own_cli} .= " (terminated)";
}
$resource->{status} = $item->call_status;
$resource->{rating_status} = $item->rating_status;
$resource->{type} = $item->call_type;
$resource->{start_time} = $item->start_time;

@ -3,6 +3,7 @@ use warnings;
use Test::More;
use Test::Collection;
use Data::Dumper;
my $test_machine = Test::Collection->new(
name => 'calllists',
@ -13,7 +14,7 @@ diag('Note that the next tests require at least one subscriber to be present');
# test with a subscriber
SKIP:
{
my ($res,$sub1,$sub1_id,$cl_collection, $cl_collection_in, $cl_collection_out);
my ($res,$sub1,$sub1_id,$cl_collection);
if($ENV{API_FORCE_SUBSCRIBER_ID}) {
$sub1_id = $ENV{API_FORCE_SUBSCRIBER_ID};
@ -25,7 +26,9 @@ SKIP:
($sub1_id) = $sub1->{_embedded}->{'ngcp:subscribers'}->{_links}{self}{href} =~ m!subscribers/([0-9]*)$!;
}
cmp_ok ($sub1_id, '>', 0, "should be positive integer");
#----
my ($cl_collection_in, $cl_collection_out);
($res, $cl_collection) = $test_machine->check_item_get('/api/calllists/?page=1&rows=10&subscriber_id='.$sub1_id,"fetch calllists collection of subscriber ($sub1_id)");
($res, $cl_collection_in) = $test_machine->check_item_get('/api/calllists/?page=1&rows=10&direction=in&subscriber_id='.$sub1_id,"fetch calllists collection of subscriber ($sub1_id) with direction filter in");
@ -34,6 +37,20 @@ SKIP:
ok($cl_collection_in->{total_count} + $cl_collection_out->{total_count} >= $cl_collection->{total_count},
"Incoming and outgoing calls should be greater than or equal to total number of calls");
#/---
#----16323
my ($cl_collection_ok, $cl_collection_nok);
($res, $cl_collection_ok) = $test_machine->check_item_get('/api/calllists/?page=1&rows=10&rating_status=ok&subscriber_id='.$sub1_id,"fetch calllists collection of subscriber ($sub1_id) with rating_status filter ok");
($res, $cl_collection_nok) = $test_machine->check_item_get('/api/calllists/?page=1&rows=10&rating_status=unrated,failed&subscriber_id='.$sub1_id, "fetch calllists collection of subscriber ($sub1_id) with rating_status filter unrated,failed");
ok( ($cl_collection_ok->{total_count} + $cl_collection_nok->{total_count} ) == $cl_collection->{total_count},
"Rated and not rated calls should be equal to total number of calls");
my($call_hal) = $test_machine->get_hal_from_collection($cl_collection);
ok(exists $call_hal->{rating_status},
"Check existence of rating_status field");
#/---
diag("Total number of calls: " . $cl_collection->{total_count});
}
@ -101,4 +118,5 @@ SKIP:
done_testing;
# vim: set tabstop=4 expandtab:

@ -242,6 +242,7 @@ sub get_role_credentials{
$pass //= $ENV{API_PASS_RESELLER} // 'api_test';
$realm = 'api_admin_http';
#}elsif($role eq 'subscriber'){
## I suggest here the same way as for admin and reseller - trough ENV variables
# $user //= $self->subscriber_user;
# $pass //= $self->subscriber_pass;
# $realm = 'subscriber';
@ -302,7 +303,7 @@ sub get_uri_item{
return $resuri;
}
sub get_item_hal{
my($self,$name) = @_;
my($self,$name,$uri) = @_;
$name ||= $self->name;
my $resitem ;
if(( $name eq $self->name ) && $self->DATA_CREATED->{FIRST}){
@ -313,21 +314,29 @@ sub get_item_hal{
}
if(!$resitem){
my ($reshal, $location);
my($res,$list_collection,$req) = $self->check_item_get($self->get_uri_collection($name)."?page=1&rows=1");
my $hal_name = $self->get_hal_name($name);
if(ref $list_collection->{_links}->{$hal_name} eq "HASH") {
$reshal = $list_collection;
$location = $reshal->{_links}->{$hal_name}->{href};
} else {
$reshal = $list_collection->{_embedded}->{$hal_name}->[0];
$location = $reshal->{_links}->{self}->{href};
}
$uri //= $self->get_uri_collection($name)."?page=1&rows=1";
my($res,$list_collection,$req) = $self->check_item_get($self->normalize_uri($uri));
($reshal,$location) = $self->get_hal_from_collection($list_collection,$name);
$resitem = { num => 1, content => $reshal, res => $res, req => $req, location => $location };
$self->DATA_LOADED->{$name} ||= [];
push @{$self->DATA_LOADED->{$name}}, $resitem;
}
return $resitem;
}
sub get_hal_from_collection{
my($self,$list_collection,$name) = @_;
$name ||= $self->name;
my $hal_name = $self->get_hal_name($name);
my($reshal,$location);
if(ref $list_collection->{_links}->{$hal_name} eq "HASH") {
$reshal = $list_collection;
$location = $reshal->{_links}->{$hal_name}->{href};
} else {
$reshal = $list_collection->{_embedded}->{$hal_name}->[0];
$location = $reshal->{_links}->{self}->{href};
}
return ($reshal,$location);
}
sub get_created_first{
my($self) = @_;
return $self->DATA_CREATED->{ALL}->{$self->DATA_CREATED->{FIRST}};

Loading…
Cancel
Save