TT#74220 - Upgrade '/api/cfmappings'

* Introduce posibility to provision source sets,
	   time sets, b number sets and destination sets
	   in the same request with defining cf mappings
	   which include advanced cf setting with multiple
	   cf rules.

Change-Id: I9d2865c3fbdac0651a287b926a3fb0e190fca814
changes/66/39966/2
Flaviu Mates 6 years ago
parent d99a48216d
commit 10415a55f6

@ -100,7 +100,7 @@ has_field 'cfo' => (
);
has_field 'cfu.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -111,7 +111,7 @@ has_field 'cfu.destinationset_id' => (
);
has_field 'cfu.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -122,7 +122,7 @@ has_field 'cfu.timeset_id' => (
);
has_field 'cfu.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -133,7 +133,7 @@ has_field 'cfu.sourceset_id' => (
);
has_field 'cfu.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -144,7 +144,7 @@ has_field 'cfu.bnumberset_id' => (
);
has_field 'cfb.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -160,7 +160,7 @@ has_field 'cfu.enabled' => (
);
has_field 'cfb.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -171,7 +171,7 @@ has_field 'cfb.timeset_id' => (
);
has_field 'cfb.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -182,7 +182,7 @@ has_field 'cfb.sourceset_id' => (
);
has_field 'cfb.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -198,7 +198,7 @@ has_field 'cfb.enabled' => (
);
has_field 'cft.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -209,7 +209,7 @@ has_field 'cft.destinationset_id' => (
);
has_field 'cft.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -220,7 +220,7 @@ has_field 'cft.timeset_id' => (
);
has_field 'cft.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -231,7 +231,7 @@ has_field 'cft.sourceset_id' => (
);
has_field 'cft.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -247,7 +247,7 @@ has_field 'cft.enabled' => (
);
has_field 'cfna.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -258,7 +258,7 @@ has_field 'cfna.destinationset_id' => (
);
has_field 'cfna.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -269,7 +269,7 @@ has_field 'cfna.timeset_id' => (
);
has_field 'cfna.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -280,7 +280,7 @@ has_field 'cfna.sourceset_id' => (
);
has_field 'cfna.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -296,7 +296,7 @@ has_field 'cfna.enabled' => (
);
has_field 'cfs.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -307,7 +307,7 @@ has_field 'cfs.destinationset_id' => (
);
has_field 'cfs.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -318,7 +318,7 @@ has_field 'cfs.timeset_id' => (
);
has_field 'cfs.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -329,7 +329,7 @@ has_field 'cfs.sourceset_id' => (
);
has_field 'cfs.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -351,7 +351,7 @@ has_field 'cft_ringtimeout' => (
);
has_field 'cfr.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -362,7 +362,7 @@ has_field 'cfr.destinationset_id' => (
);
has_field 'cfr.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -373,7 +373,7 @@ has_field 'cfr.timeset_id' => (
);
has_field 'cfr.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -384,7 +384,7 @@ has_field 'cfr.sourceset_id' => (
);
has_field 'cfr.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -400,7 +400,7 @@ has_field 'cfr.enabled' => (
);
has_field 'cfo.destinationset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -411,7 +411,7 @@ has_field 'cfo.destinationset_id' => (
);
has_field 'cfo.timeset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -422,7 +422,7 @@ has_field 'cfo.timeset_id' => (
);
has_field 'cfo.sourceset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);
@ -433,7 +433,7 @@ has_field 'cfo.sourceset_id' => (
);
has_field 'cfo.bnumberset' => (
type => 'Text',
type => 'Compound',
do_wrapper => 1,
do_label => 0,
);

@ -171,11 +171,49 @@ sub update_item {
subscriber_id => $p_subs_id,
id => $mapping->{destinationset_id},
});
} elsif($mapping->{destinationset}) {
} elsif ($mapping->{destinationset} && !ref $mapping->{destinationset}) {
$dset = $dsets_rs->find({
subscriber_id => $p_subs_id,
name => $mapping->{destinationset},
});
} elsif ($mapping->{destinationset} && ref $mapping->{destinationset} eq 'HASH') {
$mapping->{destinationset}->{subscriber_id} = $p_subs_id;
$form = NGCP::Panel::Role::API::CFDestinationSets->get_form($c);
return unless $self->validate_form(
c => $c,
resource => $mapping->{destinationset},
form => $form,
);
if (! exists $mapping->{destinationset}->{destinations} ) {
$mapping->{destinationset}->{destinations} = [];
}
if (!NGCP::Panel::Role::API::CFDestinationSets->check_destinations($c, $mapping->{destinationset})) {
return;
}
my $primary_nr_rs = $item->primary_number;
my $number;
if ($primary_nr_rs) {
$number = $primary_nr_rs->cc . ($primary_nr_rs->ac //'') . $primary_nr_rs->sn;
} else {
$number = ''
}
my $domain = $item->provisioning_voip_subscriber->domain->domain // '';
$dset = $dsets_rs->create({
name => $mapping->{destinationset}->{name},
subscriber_id => $p_subs_id,
});
for my $d ( @{$mapping->{destinationset}->{destinations}} ) {
delete $d->{destination_set_id};
delete $d->{simple_destination};
$d->{destination} = NGCP::Panel::Utils::Subscriber::field_to_destination(
destination => $d->{destination},
number => $number,
domain => $domain,
uri => $d->{destination},
);
$dset->create_related("voip_cf_destinations", $d);
}
} else {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing field 'destinationset' or 'destinationset_id' in '$type'.");
return;
@ -192,12 +230,35 @@ sub update_item {
id => $mapping->{timeset_id},
});
$has_tset = 1;
} elsif (defined $mapping->{timeset}) {
} elsif (defined $mapping->{timeset} && !ref $mapping->{timeset}) {
$tset = $tsets_rs->find({
subscriber_id => $p_subs_id,
name => $mapping->{timeset},
});
$has_tset = 1;
} elsif ($mapping->{timeset} && ref $mapping->{timeset} eq 'HASH') {
$mapping->{timeset}->{subscriber_id} = $p_subs_id;
$form = NGCP::Panel::Role::API::CFTimeSets->get_form($c);
return unless $self->validate_form(
c => $c,
resource => $mapping->{timeset},
form => $form,
);
if (! exists $mapping->{timeset}->{times} ) {
$mapping->{timeset}->{times} = [];
}
if (ref $mapping->{timeset}->{times} ne "ARRAY") {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid field 'times'. Must be an array.");
return;
}
$tset = $tsets_rs->create({
name => $mapping->{timeset}->{name},
subscriber_id => $p_subs_id,
});
for my $t ( @{$mapping->{timeset}->{times}} ) {
delete $t->{time_set_id};
$tset->create_related("voip_cf_periods", $t);
}
}
if($has_tset && !$tset) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'timeset'. Could not be found.");
@ -211,12 +272,40 @@ sub update_item {
id => $mapping->{sourceset_id},
});
$has_sset = 1;
} elsif (defined $mapping->{sourceset}) {
} elsif (defined $mapping->{sourceset} && !ref $mapping->{sourceset}) {
$sset = $ssets_rs->find({
subscriber_id => $p_subs_id,
name => $mapping->{sourceset},
});
$has_sset = 1;
} elsif ($mapping->{sourceset} && ref $mapping->{sourceset} eq 'HASH') {
$mapping->{sourceset}->{subscriber_id} = $p_subs_id;
$form = NGCP::Panel::Role::API::CFSourceSets->get_form($c);
return unless $self->validate_form(
c => $c,
resource => $mapping->{sourceset},
form => $form,
);
if (! exists $mapping->{sourceset}->{sources} ) {
$mapping->{sourceset}->{sources} = [];
}
if (ref $mapping->{sourceset}->{sources} ne "ARRAY") {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid field 'sources'. Must be an array.");
return;
}
my $domain = $item->provisioning_voip_subscriber->domain->domain // '';
$sset = $ssets_rs->create({
name => $mapping->{sourceset}->{name},
mode => $mapping->{sourceset}->{mode},
is_regex => $mapping->{sourceset}->{is_regex} // 0,
subscriber_id => $p_subs_id,
});
for my $s ( @{$mapping->{sourceset}->{sources}} ) {
$sset->create_related("voip_cf_sources", {
source => $s->{source},
});
}
}
if($has_sset && !$sset) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'sourceset'. Could not be found.");
@ -230,12 +319,39 @@ sub update_item {
id => $mapping->{bnumberset_id},
});
$has_bset = 1;
} elsif (defined $mapping->{bnumberset}) {
} elsif (defined $mapping->{bnumberset} && !ref $mapping->{bnumberset}) {
$bset = $bsets_rs->find({
subscriber_id => $p_subs_id,
name => $mapping->{bnumberset},
});
$has_bset = 1;
} elsif ($mapping->{bnumberset} && ref $mapping->{bnumberset} eq 'HASH') {
$mapping->{bnumberset}->{subscriber_id} = $p_subs_id;
$form = NGCP::Panel::Role::API::CFBNumberSets->get_form($c);
return unless $self->validate_form(
c => $c,
resource => $mapping->{bnumberset},
form => $form,
);
if (! exists $mapping->{bnumberset}->{bnumbers} ) {
$mapping->{bnumberset}->{bnumbers} = [];
}
if (ref $mapping->{bnumberset}->{bnumbers} ne "ARRAY") {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid field 'bnumbers'. Must be an array.");
return;
}
$bset = $bsets_rs->create({
name => $mapping->{bnumberset}->{name},
mode => $mapping->{bnumberset}->{mode},
is_regex => $mapping->{bnumberset}->{is_regex} // 0,
subscriber_id => $p_subs_id,
});
for my $b ( @{$mapping->{bnumberset}->{bnumbers}} ) {
$bset->create_related("voip_cf_bnumbers", {
bnumber => $b->{bnumber},
});
}
}
if($has_bset && !$bset) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'bnumberset'. Could not be found.");

Loading…
Cancel
Save