MT#11917 next batch of API resources w. journal

-enhanced test detail: did not detect missing CRUD operations yet
-query param 'operation' didn't work for 'recent' yournal entry of all API resources so far
-fix of several copy paste errors in existing rest api code
-...

Change-Id: I71b54212d8126b0280fcad2e568fad52a673cbf0
changes/63/1663/1
Rene Krenn 11 years ago
parent 0232af69d1
commit b5dca5e6e2

@ -19,6 +19,8 @@ class_has('resource_name', is => 'ro', default => 'billingprofiles');
class_has('dispatch_path', is => 'ro', default => '/api/billingprofiles/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-billingprofiles');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -211,6 +211,7 @@ sub POST :Allow {
});
for my $d ( @{$resource->{destinations}} ) {
delete $d->{destination_set_id};
delete $d->{simple_destination};
$d->{destination} = NGCP::Panel::Utils::Subscriber::field_to_destination(
destination => $d->{destination},
number => $number,
@ -225,6 +226,12 @@ sub POST :Allow {
last;
}
last unless $self->add_create_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
my $_dset = $self->item_by_id($c, $dset->id);
return $self->hal_from_item($c, $_dset, "cfdestinationsets"); });
$guard->commit;
$c->response->status(HTTP_CREATED);

@ -22,16 +22,23 @@ class_has('resource_name', is => 'ro', default => 'cfdestinationsets');
class_has('dispatch_path', is => 'ro', default => '/api/cfdestinationsets/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-cfdestinationsets');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods },
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -110,6 +117,9 @@ sub PATCH :Allow {
$dset = $self->update_item($c, $dset, $old_resource, $resource, $form);
last unless $dset;
my $hal = $self->hal_from_item($c, $dset, "destinationsets");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -117,7 +127,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $dset, "destinationsets");
#my $hal = $self->hal_from_item($c, $dset, "destinationsets");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -149,6 +159,9 @@ sub PUT :Allow {
my $form = $self->get_form($c);
$dset = $self->update_item($c, $dset, $old_resource, $resource, $form);
last unless $dset;
my $hal = $self->hal_from_item($c, $dset, "destinationsets");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -157,7 +170,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $dset, "destinationsets");
#my $hal = $self->hal_from_item($c, $dset, "destinationsets");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -190,6 +203,41 @@ sub DELETE :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -22,6 +22,8 @@ class_has('resource_name', is => 'ro', default => 'contracts');
class_has('dispatch_path', is => 'ro', default => '/api/contracts/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-contracts');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -194,7 +194,7 @@ sub POST :Allow {
last;
}
last unless $self->add_delete_journal_item_hal($c,sub {
last unless $self->add_create_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
my $_contact = $self->contact_by_id($c, $contact->id);

@ -19,6 +19,8 @@ class_has('resource_name', is => 'ro', default => 'customercontacts');
class_has('dispatch_path', is => 'ro', default => '/api/customercontacts/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-customercontacts');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -22,16 +22,23 @@ class_has('resource_name', is => 'ro', default => 'customerpreferences');
class_has('dispatch_path', is => 'ro', default => '/api/customerpreferences/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-customerpreferences');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods },
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -110,6 +117,9 @@ sub PATCH :Allow {
# for proper PATCH behavior
$customer = $self->update_item($c, $customer, $old_resource, $resource, 0, "contracts");
last unless $customer;
my $hal = $self->hal_from_item($c, $customer, "contracts");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -118,7 +128,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $customer, "contracts");
#my $hal = $self->hal_from_item($c, $customer, "contracts");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -151,6 +161,9 @@ sub PUT :Allow {
# for proper PUT behavior
$customer = $self->update_item($c, $customer, $old_resource, $resource, 1, "contracts");
last unless $customer;
my $hal = $self->hal_from_item($c, $customer, "contracts");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -159,7 +172,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $customer, "contracts");
#my $hal = $self->hal_from_item($c, $customer, "contracts");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -171,6 +184,41 @@ sub PUT :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -22,6 +22,8 @@ class_has('resource_name', is => 'ro', default => 'domains');
class_has('dispatch_path', is => 'ro', default => '/api/domains/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-domains');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -22,16 +22,23 @@ class_has('resource_name', is => 'ro', default => 'profilepreferences');
class_has('dispatch_path', is => 'ro', default => '/api/profilepreferences/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-profilepreferences');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -111,6 +118,9 @@ sub PATCH :Allow {
$profile = $self->update_item($c, $profile, $old_resource, $resource, 0, "profiles");
last unless $profile;
my $hal = $self->hal_from_item($c, $profile, "profiles");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -118,7 +128,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $profile, "profiles");
#my $hal = $self->hal_from_item($c, $profile, "profiles");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -153,6 +163,9 @@ sub PUT :Allow {
$profile = $self->update_item($c, $profile, $old_resource, $resource, 1, "profiles");
last unless $profile;
my $hal = $self->hal_from_item($c, $profile, "profiles");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -160,7 +173,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $profile, "profiles");
#my $hal = $self->hal_from_item($c, $profile, "profiles");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -172,6 +185,41 @@ sub PUT :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -19,6 +19,8 @@ class_has('resource_name', is => 'ro', default => 'resellers');
class_has('dispatch_path', is => 'ro', default => '/api/resellers/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-resellers');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -176,12 +176,12 @@ sub POST :Allow {
form => $form,
);
$form //= $self->get_form($c);
return unless $self->validate_form(
c => $c,
form => $form,
resource => $resource,
);
#$form //= $self->get_form($c);
#return unless $self->validate_form(
# c => $c,
# form => $form,
# resource => $resource,
#);
if($c->user->roles eq "admin") {
} elsif($c->user->roles eq "reseller") {
@ -233,6 +233,12 @@ sub POST :Allow {
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create soundset.");
last;
}
last unless $self->add_create_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
my $_item = $self->item_by_id($c, $item->id); #reload is required here, otherwise description field is missing
return $self->hal_from_item($c, $_item); });
$guard->commit;

@ -19,16 +19,23 @@ class_has('resource_name', is => 'ro', default => 'soundsets');
class_has('dispatch_path', is => 'ro', default => '/api/soundsets/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-soundsets');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -106,6 +113,9 @@ sub PATCH :Allow {
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
last unless $item;
my $hal = $self->hal_from_item($c, $item, $form);
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -113,7 +123,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $item, $form);
#my $hal = $self->hal_from_item($c, $item, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -145,6 +155,9 @@ sub PUT :Allow {
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
last unless $item;
my $hal = $self->hal_from_item($c, $item, $form);
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -153,7 +166,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $item, $form);
#my $hal = $self->hal_from_item($c, $item, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -188,6 +201,12 @@ sub DELETE :Allow {
join => 'attribute',
})->delete_all; # explicit delete_all, otherwise query fails
}
last unless $self->add_delete_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
return $self->hal_from_item($c, $item); });
$item->delete;
$guard->commit;
@ -198,6 +217,41 @@ sub DELETE :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -22,16 +22,23 @@ class_has('resource_name', is => 'ro', default => 'subscriberpreferences');
class_has('dispatch_path', is => 'ro', default => '/api/subscriberpreferences/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-subscriberpreferences');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods },
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -110,6 +117,9 @@ sub PATCH :Allow {
# for proper PATCH behavior
$subscriber = $self->update_item($c, $subscriber, $old_resource, $resource, 0, "subscribers");
last unless $subscriber;
my $hal = $self->hal_from_item($c, $subscriber, "subscribers");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -118,7 +128,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $subscriber, "subscribers");
#my $hal = $self->hal_from_item($c, $subscriber, "subscribers");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -152,6 +162,9 @@ sub PUT :Allow {
$subscriber = $self->update_item($c, $subscriber, $old_resource, $resource, 1, "subscribers");
last unless $subscriber;
my $hal = $self->hal_from_item($c, $subscriber, "subscribers");
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -159,7 +172,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $subscriber, "subscribers");
#my $hal = $self->hal_from_item($c, $subscriber, "subscribers");
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -171,6 +184,41 @@ sub PUT :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -155,6 +155,7 @@ sub POST :Allow {
return;
}
my $guard = $c->model('DB')->txn_scope_guard;
{
my $resource = $self->get_valid_post_data(
c => $c,
@ -192,6 +193,14 @@ sub POST :Allow {
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create subscriber profile set.");
last;
}
last unless $self->add_create_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
my $_item = $self->item_by_id($c, $item->id);
return $self->hal_from_item($c, $_item); });
$guard->commit;
$c->response->status(HTTP_CREATED);
$c->response->header(Location => sprintf('/%s%d', $c->request->path, $item->id));

@ -19,16 +19,23 @@ class_has('resource_name', is => 'ro', default => 'subscriberprofilesets');
class_has('dispatch_path', is => 'ro', default => '/api/subscriberprofilesets/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-subscriberprofilesets');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -113,6 +120,9 @@ sub PATCH :Allow {
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
last unless $item;
my $hal = $self->hal_from_item($c, $item, $form);
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -120,7 +130,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $item, $form);
#my $hal = $self->hal_from_item($c, $item, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -159,6 +169,9 @@ sub PUT :Allow {
my $form = $self->get_form($c);
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
last unless $item;
my $hal = $self->hal_from_item($c, $item, $form);
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -167,7 +180,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $item, $form);
#my $hal = $self->hal_from_item($c, $item, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -201,6 +214,12 @@ sub DELETE :Allow {
});
$item->voip_subscriber_profiles->delete;
last unless $self->add_delete_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
return $self->hal_from_item($c, $item); });
$item->delete;
$guard->commit;
@ -211,6 +230,41 @@ sub DELETE :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -232,6 +232,12 @@ sub POST :Allow {
last;
}
last unless $self->add_create_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
my $_item = $self->item_by_id($c, $item->id);
return $self->hal_from_item($c, $_item); });
$guard->commit;
$c->response->status(HTTP_CREATED);

@ -19,16 +19,23 @@ class_has('resource_name', is => 'ro', default => 'subscriberprofiles');
class_has('dispatch_path', is => 'ro', default => '/api/subscriberprofiles/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-subscriberprofiles');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
map { $_ => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller/],
Does => [qw(ACL RequireSSL)],
}) }
},
action_roles => [qw(HTTPMethods)],
);
@ -108,6 +115,9 @@ sub PATCH :Allow {
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
last unless $item;
my $hal = $self->hal_from_item($c, $item, $form);
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
if ('minimal' eq $preference) {
@ -115,7 +125,7 @@ sub PATCH :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $item, $form);
#my $hal = $self->hal_from_item($c, $item, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -146,6 +156,9 @@ sub PUT :Allow {
my $old_resource = $self->resource_from_item($c, $item, $form);
$item = $self->update_item($c, $item, $old_resource, $resource, $form);
last unless $item;
my $hal = $self->hal_from_item($c, $item, $form);
last unless $self->add_update_journal_item_hal($c,$hal);
$guard->commit;
@ -154,7 +167,7 @@ sub PUT :Allow {
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $hal = $self->hal_from_item($c, $item, $form);
#my $hal = $self->hal_from_item($c, $item, $form);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
@ -195,6 +208,12 @@ sub DELETE :Allow {
}
$item->voip_prof_preferences->delete;
last unless $self->add_delete_journal_item_hal($c,sub {
my $self = shift;
my ($c) = @_;
return $self->hal_from_item($c, $item); });
$item->delete;
$guard->commit;
@ -205,6 +224,41 @@ sub DELETE :Allow {
return;
}
sub item_base_journal :Journal {
my $self = shift @_;
return $self->handle_item_base_journal(@_);
}
sub journals_get :Journal {
my $self = shift @_;
return $self->handle_journals_get(@_);
}
sub journalsitem_get :Journal {
my $self = shift @_;
return $self->handle_journalsitem_get(@_);
}
sub journals_options :Journal {
my $self = shift @_;
return $self->handle_journals_options(@_);
}
sub journalsitem_options :Journal {
my $self = shift @_;
return $self->handle_journalsitem_options(@_);
}
sub journals_head :Journal {
my $self = shift @_;
return $self->handle_journals_head(@_);
}
sub journalsitem_head :Journal {
my $self = shift @_;
return $self->handle_journalsitem_head(@_);
}
sub end : Private {
my ($self, $c) = @_;

@ -22,6 +22,8 @@ class_has('resource_name', is => 'ro', default => 'subscribers');
class_has('dispatch_path', is => 'ro', default => '/api/subscribers/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-subscribers');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -19,6 +19,8 @@ class_has('resource_name', is => 'ro', default => 'systemcontacts');
class_has('dispatch_path', is => 'ro', default => '/api/systemcontacts/');
class_has('relation', is => 'ro', default => 'http://purl.org/sipwise/ngcp-api/#rel-systemcontacts');
class_has(@{ __PACKAGE__->get_journal_query_params() });
__PACKAGE__->config(
action => {
(map { $_ => {

@ -58,6 +58,7 @@ sub hal_from_item {
Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
Data::HAL::Link->new(relation => "ngcp:$type", href => sprintf("/api/%s/%d", $type, $item->id)),
Data::HAL::Link->new(relation => "ngcp:subscribers", href => sprintf("/api/subscribers/%d", $b_subs_id)),
$self->get_journal_relation_link($item->id),
],
relation => 'ngcp:'.$self->resource_name,
);

@ -39,6 +39,7 @@ sub hal_from_item {
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
Data::HAL::Link->new(relation => "ngcp:$print_type", href => sprintf("/api/%s/%d", $print_type, $item->id)),
$self->get_journal_relation_link($item->id),
],
relation => 'ngcp:'.$self->resource_name,
);
@ -558,7 +559,7 @@ sub update_item {
});
unless($set) {
$c->log->error("no $pref '".$resource->{$pref}."' for reseller id $reseller_id found");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Unknown $pref'".$resource->{$pref}."'");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Unknown $pref '".$resource->{$pref}."'");
return;
}
my $rs = $self->get_preference_rs($c, $type, $elem, $pref);

@ -56,6 +56,7 @@ sub hal_from_item {
Data::HAL::Link->new(relation => 'ngcp:resellers', href => sprintf("/api/resellers/%d", $item->reseller_id)),
$item->contract_id ? Data::HAL::Link->new(relation => 'ngcp:customers', href => sprintf("/api/customers/%d", $item->contract_id)) : (),
Data::HAL::Link->new(relation => 'ngcp:soundfiles', href => sprintf("/api/soundfiles/?set_id=%d", $item->id)),
$self->get_journal_relation_link($item->id),
],
relation => 'ngcp:'.$self->resource_name,
);

@ -50,6 +50,7 @@ sub hal_from_item {
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
Data::HAL::Link->new(relation => 'ngcp:resellers', href => sprintf("/api/resellers/%d", $item->reseller_id)),
$self->get_journal_relation_link($item->id),
],
relation => 'ngcp:'.$self->resource_name,
);

@ -47,6 +47,7 @@ sub hal_from_item {
Data::HAL::Link->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
Data::HAL::Link->new(relation => 'self', href => sprintf("%s%d", $self->dispatch_path, $item->id)),
Data::HAL::Link->new(relation => 'ngcp:subscriberprofilesets', href => sprintf("/api/subscriberprofilesets/%d", $item->set_id)),
$self->get_journal_relation_link($item->id),
],
relation => 'ngcp:'.$self->resource_name,
);

@ -201,7 +201,57 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{
operations delete
format sereal
enabled 1
</subscribers>
</subscribers>
<customerpreferences>
operations create
operations update
operations delete
format sereal
enabled 1
</customerpreferences>
<soundsets>
operations create
operations update
operations delete
format sereal
enabled 1
</soundsets>
<subscriberpreferences>
operations create
operations update
operations delete
format sereal
enabled 1
</subscriberpreferences>
<subscriberprofilesets>
operations create
operations update
operations delete
format sereal
enabled 1
</subscriberprofilesets>
<subscriberprofiles>
operations create
operations update
operations delete
format sereal
enabled 1
</subscriberprofiles>
<profilepreferences>
operations create
operations update
operations delete
format sereal
enabled 1
</profilepreferences>
<cfdestinationsets>
operations create
operations update
operations delete
format sereal
enabled 1
</cfdestinationsets>
</api_journal>

@ -60,34 +60,590 @@ my $contract = test_contract($billingprofile,$systemcontact);
my $domain = test_domain($t,$reseller);
my $customercontact = test_customercontact($t,$reseller);
my $customer = test_customer($customercontact,$billingprofile);
my $customerpreferences = test_customerpreferences($customer);
my $subscriberprofileset = test_subscriberprofileset($t,$reseller);
my $subscriberprofile = test_subscriberprofile($t,$subscriberprofileset);
my $profilepreferences = test_profilepreferences($subscriberprofile);
my $subscriber = test_subscriber($t,$customer,$domain);
my $cfdestinationset = test_cfdestinationset($t,$subscriber);
my $systemsoundset = test_soundset($t,$reseller);
my $customersoundset = test_soundset($t,$reseller,$customer);
my $subscriberpreferences = test_subscriberpreferences($subscriber,$customersoundset,$systemsoundset);
#test_customerpreferences();
done_testing;
#sub test_customerpreferences {
#
# $req = HTTP::Request->new('PUT', $uri.'/api/customerpreferences/'.$customer->{id});
# $req->header('Content-Type' => 'application/json');
# $req->header('Prefer' => 'return=representation');
# $req->content(JSON::to_json({
# name => "test profile $t PUT",
# handle => "testprofile$t",
# reseller_id => $reseller_id,
# }));
# $res = $ua->request($req);
# is($res->code, 200, "PUT test billingprofile");
# $req = HTTP::Request->new('GET', $billingprofile_uri);
# $res = $ua->request($req);
# is($res->code, 200, "fetch PUT test billingprofile");
# $billingprofile = JSON::from_json($res->decoded_content);
#
# $req = HTTP::Request->new('GET', $uri.'/api/customerpreferences/136');
# $res = $ua->request($req);
# is($res->code, 200, "fetch blah");
#
#}
sub test_cfdestinationset {
my ($t,$subscriber) = @_;
my @destinations = map { { destination => $_,
timeout => '10',
priority => '1',
simple_destination => undef }; } (
'voicebox',
'fax2mail',
'conference',
'callingcard',
'callthrough',
'localuser',
'autoattendant',
'officehours',
'test_destination@example.com');
$req = HTTP::Request->new('POST', $uri.'/api/cfdestinationsets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "cf_destination_set_".($t-1),
subscriber_id => $subscriber->{id},
destinations => \@destinations,
}));
$res = $ua->request($req);
is($res->code, 201, "POST test cfdestinationset");
my $cfdestinationset_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $cfdestinationset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test cfdestinationset");
my $cfdestinationset = JSON::from_json($res->decoded_content);
_test_item_journal_link('cfdestinationsets',$cfdestinationset);
_test_journal_options_head('cfdestinationsets',$cfdestinationset->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'create',$journals);
_test_journal_options_head('cfdestinationsets',$cfdestinationset->{id},$journal->{id});
$req = HTTP::Request->new('PUT', $cfdestinationset_uri);
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json({
name => "cf_destination_set_".($t-1).'_put',
subscriber_id => $subscriber->{id},
destinations => \@destinations,
}));
$res = $ua->request($req);
is($res->code, 200, "PUT test cfdestinationset");
$req = HTTP::Request->new('GET', $cfdestinationset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test cfdestinationset");
$cfdestinationset = JSON::from_json($res->decoded_content);
_test_item_journal_link('cfdestinationsets',$cfdestinationset);
$journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'update',$journals,$journal);
$req = HTTP::Request->new('PATCH', $cfdestinationset_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json(
[ { op => 'replace', path => '/name', value => "cf_destination_set_".($t-1).'_patch' } ]
));
$res = $ua->request($req);
is($res->code, 200, "PATCH test cfdestinationset");
$req = HTTP::Request->new('GET', $cfdestinationset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHed test cfdestinationset");
$cfdestinationset = JSON::from_json($res->decoded_content);
_test_item_journal_link('cfdestinationsets',$cfdestinationset);
$journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'update',$journals,$journal);
$req = HTTP::Request->new('DELETE', $cfdestinationset_uri);
$res = $ua->request($req);
is($res->code, 204, "delete POSTed test cfdestinationset");
#$domain = JSON::from_json($res->decoded_content);
$journal = _test_journal_top_journalitem('cfdestinationsets',$cfdestinationset->{id},$cfdestinationset,'delete',$journals,$journal);
_test_journal_collection('cfdestinationsets',$cfdestinationset->{id},$journals);
$req = HTTP::Request->new('POST', $uri.'/api/cfdestinationsets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "cf_destination_set_".$t,
subscriber_id => $subscriber->{id},
destinations => \@destinations,
}));
$res = $ua->request($req);
is($res->code, 201, "POST another test cfdestinationset");
$cfdestinationset_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $cfdestinationset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test cfdestinationset");
$cfdestinationset = JSON::from_json($res->decoded_content);
return $cfdestinationset;
}
sub test_profilepreferences {
my ($subscriberprofile) = @_;
$req = HTTP::Request->new('GET', $uri.'/api/profilepreferencedefs/');
$res = $ua->request($req);
is($res->code, 200, "fetch profilepreferencedefs");
my $profilepreferencedefs = JSON::from_json($res->decoded_content);
my $profilepreferences_uri = $uri.'/api/profilepreferences/'.$subscriberprofile->{id};
$req = HTTP::Request->new('PUT', $profilepreferences_uri); #$customer->{id});
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
my $put_data = {};
foreach my $attr (keys %$profilepreferencedefs) {
my $def = $profilepreferencedefs->{$attr};
my $val = _get_preference_value($attr,$def);
if (defined $val) {
$put_data->{$attr} = $val;
}
}
$req->content(JSON::to_json($put_data));
$res = $ua->request($req);
is($res->code, 200, "PUT test profilepreferences");
$req = HTTP::Request->new('GET', $profilepreferences_uri); # . '?page=1&rows=' . (scalar keys %$put_data));
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test profilepreferences");
my $profilepreferences = JSON::from_json($res->decoded_content);
_test_item_journal_link('profilepreferences',$profilepreferences);
_test_journal_options_head('profilepreferences',$profilepreferences->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('profilepreferences',$profilepreferences->{id},$profilepreferences,'update',$journals);
_test_journal_options_head('profilepreferences',$profilepreferences->{id},$journal->{id});
$req = HTTP::Request->new('PATCH', $profilepreferences_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
my @patch_data = ();
foreach my $attr (keys %$profilepreferencedefs) {
my $def = $profilepreferencedefs->{$attr};
my $val = _get_preference_value($attr,$def);
if (defined $val) {
push(@patch_data,{ op => 'replace', path => '/'.$attr, value => $val });
}
}
$req->content(JSON::to_json(\@patch_data));
$res = $ua->request($req);
is($res->code, 200, "PATCH test profilepreferences");
$req = HTTP::Request->new('GET', $profilepreferences_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHED test profilepreferences");
$profilepreferences = JSON::from_json($res->decoded_content);
_test_item_journal_link('profilepreferences',$profilepreferences);
$journal = _test_journal_top_journalitem('profilepreferences',$profilepreferences->{id},$profilepreferences,'update',$journals,$journal);
_test_journal_collection('profilepreferences',$profilepreferences->{id},$journals);
return $profilepreferences;
}
sub test_subscriberprofile {
my ($t,$profileset) = @_;
$req = HTTP::Request->new('GET', $uri.'/api/subscriberpreferencedefs/');
$res = $ua->request($req);
is($res->code, 200, "fetch profilepreferencedefs");
my $subscriberpreferencedefs = JSON::from_json($res->decoded_content);
my @attributes = ();
foreach my $attr (keys %$subscriberpreferencedefs) {
push(@attributes,$attr);
#my $def = $profilepreferencedefs->{$attr};
#my $val = _get_preference_value($attr,$def);
#if (defined $val) {
# push(@attributes,$attr);
#}
}
$req = HTTP::Request->new('POST', $uri.'/api/subscriberprofiles/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "subscriber_profile_".($t-1),
profile_set_id => $profileset->{id},
attributes => \@attributes,
}));
$res = $ua->request($req);
is($res->code, 201, "POST test subscriberprofile");
my $subscriberprofile_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $subscriberprofile_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofile");
my $subscriberprofile = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberprofiles',$subscriberprofile);
_test_journal_options_head('subscriberprofiles',$subscriberprofile->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('subscriberprofiles',$subscriberprofile->{id},$subscriberprofile,'create',$journals);
_test_journal_options_head('subscriberprofiles',$subscriberprofile->{id},$journal->{id});
$req = HTTP::Request->new('PUT', $subscriberprofile_uri);
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json({
name => "subscriber_profile_".($t-1).'_put',
profile_set_id => $profileset->{id},
attributes => \@attributes,
}));
$res = $ua->request($req);
is($res->code, 200, "PUT test subscriberprofile");
$req = HTTP::Request->new('GET', $subscriberprofile_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test subscriberprofile");
$subscriberprofile = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberprofiles',$subscriberprofile);
$journal = _test_journal_top_journalitem('subscriberprofiles',$subscriberprofile->{id},$subscriberprofile,'update',$journals,$journal);
$req = HTTP::Request->new('PATCH', $subscriberprofile_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json(
[ { op => 'replace', path => '/name', value => "subscriber_profile_".($t-1).'_patch' } ]
));
$res = $ua->request($req);
is($res->code, 200, "PATCH test subscriberprofile");
$req = HTTP::Request->new('GET', $subscriberprofile_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHed test subscriberprofile");
$subscriberprofile = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberprofiles',$subscriberprofile);
$journal = _test_journal_top_journalitem('subscriberprofiles',$subscriberprofile->{id},$subscriberprofile,'update',$journals,$journal);
$req = HTTP::Request->new('DELETE', $subscriberprofile_uri);
$res = $ua->request($req);
is($res->code, 204, "delete POSTed test subscriberprofile");
#$domain = JSON::from_json($res->decoded_content);
$journal = _test_journal_top_journalitem('subscriberprofiles',$subscriberprofile->{id},$subscriberprofile,'delete',$journals,$journal);
_test_journal_collection('subscriberprofiles',$subscriberprofile->{id},$journals);
$req = HTTP::Request->new('POST', $uri.'/api/subscriberprofiles/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "subscriber_profile_".$t,
profile_set_id => $profileset->{id},
attributes => \@attributes,
}));
$res = $ua->request($req);
is($res->code, 201, "POST another test subscriberprofile");
$subscriberprofile_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $subscriberprofile_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofile");
$subscriberprofile = JSON::from_json($res->decoded_content);
return $subscriberprofile;
}
sub test_subscriberprofileset {
my ($t,$reseller) = @_;
$req = HTTP::Request->new('POST', $uri.'/api/subscriberprofilesets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "subscriber_profile_set_".($t-1),
reseller_id => $reseller->{id},
}));
$res = $ua->request($req);
is($res->code, 201, "POST test subscriberprofileset");
my $subscriberprofileset_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $subscriberprofileset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofileset");
my $subscriberprofileset = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberprofilesets',$subscriberprofileset);
_test_journal_options_head('subscriberprofilesets',$subscriberprofileset->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('subscriberprofilesets',$subscriberprofileset->{id},$subscriberprofileset,'create',$journals);
_test_journal_options_head('subscriberprofilesets',$subscriberprofileset->{id},$journal->{id});
$req = HTTP::Request->new('PUT', $subscriberprofileset_uri);
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json({
name => "subscriber_profile_set_".($t-1).'_put',
reseller_id => $reseller->{id},
}));
$res = $ua->request($req);
is($res->code, 200, "PUT test subscriberprofileset");
$req = HTTP::Request->new('GET', $subscriberprofileset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test subscriberprofileset");
$subscriberprofileset = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberprofilesets',$subscriberprofileset);
$journal = _test_journal_top_journalitem('subscriberprofilesets',$subscriberprofileset->{id},$subscriberprofileset,'update',$journals,$journal);
$req = HTTP::Request->new('PATCH', $subscriberprofileset_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json(
[ { op => 'replace', path => '/name', value => "subscriber_profile_set_".($t-1).'_patch' } ]
));
$res = $ua->request($req);
is($res->code, 200, "PATCH test subscriberprofileset");
$req = HTTP::Request->new('GET', $subscriberprofileset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHed test subscriberprofileset");
$subscriberprofileset = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberprofilesets',$subscriberprofileset);
$journal = _test_journal_top_journalitem('subscriberprofilesets',$subscriberprofileset->{id},$subscriberprofileset,'update',$journals,$journal);
$req = HTTP::Request->new('DELETE', $subscriberprofileset_uri);
$res = $ua->request($req);
is($res->code, 204, "delete POSTed test subscriberprofileset");
#$domain = JSON::from_json($res->decoded_content);
$journal = _test_journal_top_journalitem('subscriberprofilesets',$subscriberprofileset->{id},$subscriberprofileset,'delete',$journals,$journal);
_test_journal_collection('subscriberprofilesets',$subscriberprofileset->{id},$journals);
$req = HTTP::Request->new('POST', $uri.'/api/subscriberprofilesets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "subscriber_profile_set_".$t,
reseller_id => $reseller->{id},
}));
$res = $ua->request($req);
is($res->code, 201, "POST another test subscriberprofileset");
$subscriberprofileset_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $subscriberprofileset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofileset");
$subscriberprofileset = JSON::from_json($res->decoded_content);
return $subscriberprofileset;
}
sub test_soundset {
my ($t,$reseller,$customer) = @_;
my $test_label = (defined $customer ? '' : 'system ') . "soundset";
$req = HTTP::Request->new('POST', $uri.'/api/soundsets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => $test_label."_".($t-1),
reseller_id => $reseller->{id},
(defined $customer ? (customer_id => $customer->{id}) : ()), #contract_id is overwritten
}));
$res = $ua->request($req);
is($res->code, 201, "POST test " . $test_label);
my $soundset_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $soundset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test " . $test_label);
my $soundset = JSON::from_json($res->decoded_content);
_test_item_journal_link('soundsets',$soundset);
_test_journal_options_head('soundsets',$soundset->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('soundsets',$soundset->{id},$soundset,'create',$journals);
_test_journal_options_head('soundsets',$soundset->{id},$journal->{id});
$req = HTTP::Request->new('PUT', $soundset_uri);
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json({
name => $test_label."_".($t-1).'_put',
reseller_id => $reseller->{id},
#description => 'put'
(defined $customer ? (customer_id => $customer->{id}) : ()),
}));
$res = $ua->request($req);
is($res->code, 200, "PUT test " . $test_label);
$req = HTTP::Request->new('GET', $soundset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test " . $test_label);
$soundset = JSON::from_json($res->decoded_content);
_test_item_journal_link('soundsets',$soundset);
$journal = _test_journal_top_journalitem('soundsets',$soundset->{id},$soundset,'update',$journals,$journal);
$req = HTTP::Request->new('PATCH', $soundset_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
$req->content(JSON::to_json(
[ { op => 'replace', path => '/name', value => $test_label."_".($t-1)."_patch" } ]
));
$res = $ua->request($req);
is($res->code, 200, "PATCH test " . $test_label);
$req = HTTP::Request->new('GET', $soundset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHed test " . $test_label);
$soundset = JSON::from_json($res->decoded_content);
_test_item_journal_link('soundsets',$soundset);
$journal = _test_journal_top_journalitem('soundsets',$soundset->{id},$soundset,'update',$journals,$journal);
$req = HTTP::Request->new('DELETE', $soundset_uri);
$res = $ua->request($req);
is($res->code, 204, "delete POSTed test " . $test_label);
#$domain = JSON::from_json($res->decoded_content);
$journal = _test_journal_top_journalitem('soundsets',$soundset->{id},$soundset,'delete',$journals,$journal);
_test_journal_collection('soundsets',$soundset->{id},$journals);
$req = HTTP::Request->new('POST', $uri.'/api/soundsets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => $test_label."_".$t,
reseller_id => $reseller->{id},
(defined $customer ? (customer_id => $customer->{id}) : ()),
}));
$res = $ua->request($req);
is($res->code, 201, "POST another test " . $test_label);
$soundset_uri = $uri.'/'.$res->header('Location');
$req = HTTP::Request->new('GET', $soundset_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test " . $test_label);
$soundset = JSON::from_json($res->decoded_content);
return $soundset;
}
sub test_subscriberpreferences {
my ($subscriber,$soundset,$contract_soundset) = @_;
$req = HTTP::Request->new('GET', $uri.'/api/subscriberpreferencedefs/');
$res = $ua->request($req);
is($res->code, 200, "fetch subscriberpreferencedefs");
my $subscriberpreferencedefs = JSON::from_json($res->decoded_content);
my $subscriberpreferences_uri = $uri.'/api/subscriberpreferences/'.$subscriber->{id};
$req = HTTP::Request->new('PUT', $subscriberpreferences_uri); #$customer->{id});
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
my $put_data = {};
foreach my $attr (keys %$subscriberpreferencedefs) {
my $def = $subscriberpreferencedefs->{$attr};
my $val = _get_preference_value($attr,$def,$soundset,$contract_soundset);
if (defined $val) {
$put_data->{$attr} = $val;
}
}
$req->content(JSON::to_json($put_data));
$res = $ua->request($req);
is($res->code, 200, "PUT test subscriberpreferences");
$req = HTTP::Request->new('GET', $subscriberpreferences_uri); # . '?page=1&rows=' . (scalar keys %$put_data));
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test subscriberpreferences");
my $subscriberpreferences = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberpreferences',$subscriberpreferences);
_test_journal_options_head('subscriberpreferences',$subscriberpreferences->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('subscriberpreferences',$subscriberpreferences->{id},$subscriberpreferences,'update',$journals);
_test_journal_options_head('subscriberpreferences',$subscriberpreferences->{id},$journal->{id});
$req = HTTP::Request->new('PATCH', $subscriberpreferences_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
my @patch_data = ();
foreach my $attr (keys %$subscriberpreferencedefs) {
my $def = $subscriberpreferencedefs->{$attr};
my $val = _get_preference_value($attr,$def,$soundset,$contract_soundset);
if (defined $val) {
push(@patch_data,{ op => 'replace', path => '/'.$attr, value => $val });
}
}
$req->content(JSON::to_json(\@patch_data));
$res = $ua->request($req);
is($res->code, 200, "PATCH test subscriberpreferences");
$req = HTTP::Request->new('GET', $subscriberpreferences_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHED test subscriberpreferences");
$subscriberpreferences = JSON::from_json($res->decoded_content);
_test_item_journal_link('subscriberpreferences',$subscriberpreferences);
$journal = _test_journal_top_journalitem('subscriberpreferences',$subscriberpreferences->{id},$subscriberpreferences,'update',$journals,$journal);
_test_journal_collection('subscriberpreferences',$subscriberpreferences->{id},$journals);
return $subscriberpreferences;
}
sub test_customerpreferences {
my ($customer) = @_;
$req = HTTP::Request->new('GET', $uri.'/api/customerpreferencedefs/');
$res = $ua->request($req);
is($res->code, 200, "fetch customerpreferencedefs");
my $customerpreferencedefs = JSON::from_json($res->decoded_content);
my $customerpreferences_uri = $uri.'/api/customerpreferences/'.$customer->{id};
$req = HTTP::Request->new('PUT', $customerpreferences_uri); #$customer->{id});
$req->header('Content-Type' => 'application/json');
$req->header('Prefer' => 'return=representation');
my $put_data = {};
foreach my $attr (keys %$customerpreferencedefs) {
my $def = $customerpreferencedefs->{$attr};
my $val = _get_preference_value($attr,$def);
if (defined $val) {
$put_data->{$attr} = $val;
}
}
$req->content(JSON::to_json($put_data));
$res = $ua->request($req);
is($res->code, 200, "PUT test customerpreferences");
$req = HTTP::Request->new('GET', $customerpreferences_uri); # . '?page=1&rows=' . (scalar keys %$put_data));
$res = $ua->request($req);
is($res->code, 200, "fetch PUT test customerpreferences");
my $customerpreferences = JSON::from_json($res->decoded_content);
_test_item_journal_link('customerpreferences',$customerpreferences);
_test_journal_options_head('customerpreferences',$customerpreferences->{id});
my $journals = {};
my $journal = _test_journal_top_journalitem('customerpreferences',$customerpreferences->{id},$customerpreferences,'update',$journals);
_test_journal_options_head('customerpreferences',$customerpreferences->{id},$journal->{id});
$req = HTTP::Request->new('PATCH', $customerpreferences_uri);
$req->header('Content-Type' => 'application/json-patch+json');
$req->header('Prefer' => 'return=representation');
my @patch_data = ();
foreach my $attr (keys %$customerpreferencedefs) {
my $def = $customerpreferencedefs->{$attr};
my $val = _get_preference_value($attr,$def);
if (defined $val) {
push(@patch_data,{ op => 'replace', path => '/'.$attr, value => $val });
}
}
$req->content(JSON::to_json(\@patch_data));
$res = $ua->request($req);
is($res->code, 200, "PATCH test customerpreferences");
$req = HTTP::Request->new('GET', $customerpreferences_uri);
$res = $ua->request($req);
is($res->code, 200, "fetch PATCHED test customerpreferences");
$customerpreferences = JSON::from_json($res->decoded_content);
_test_item_journal_link('customerpreferences',$customerpreferences);
$journal = _test_journal_top_journalitem('customerpreferences',$customerpreferences->{id},$customerpreferences,'update',$journals,$journal);
_test_journal_collection('customerpreferences',$customerpreferences->{id},$journals);
return $customerpreferences;
}
sub test_billingprofile {
my ($t,$reseller_id) = @_;
@ -743,34 +1299,37 @@ sub _test_journal_top_journalitem {
}
$req = HTTP::Request->new('GET',$url);
$res = $ua->request($req);
is($res->code, 200, "check recent '$op' journalitem request");
my $journal = JSON::from_json($res->decoded_content);
ok(exists $journal->{id}, "check existence of id");
ok(exists $journal->{operation}, "check existence of operation");
ok(exists $journal->{username}, "check existence of username");
ok(exists $journal->{timestamp}, "check existence of timestamp");
ok(exists $journal->{content}, "check existence of content");
if (is($res->code, 200, "check recent '$op' journalitem request")) {
my $journal = JSON::from_json($res->decoded_content);
ok(exists $journal->{id}, "check existence of id");
ok(exists $journal->{operation}, "check existence of operation");
ok($journal->{operation} eq $op, "check expected journal operation");
ok(exists $journal->{username}, "check existence of username");
ok(exists $journal->{timestamp}, "check existence of timestamp");
ok(exists $journal->{content}, "check existence of content");
ok(exists $journal->{_links}, "check existence of _links");
#ok(exists $journal->{_embedded}, "check existence of _embedded");
ok($journal->{_links}->{self}, "check existence of self link");
ok($journal->{_links}->{collection}, "check existence of collection link");
ok($journal->{_links}->{'ngcp:'.$resource}, "check existence of ngcp:$resource link");
ok($journal->{_links}->{'ngcp:'.$resource}->{href} eq '/api/'.$resource . '/' . $item_id, "check if ngcp:$resource link equals '/api/$resource/$item_id'");
ok(exists $journal->{_links}, "check existence of _links");
#ok(exists $journal->{_embedded}, "check existence of _embedded");
ok($journal->{_links}->{self}, "check existence of self link");
ok($journal->{_links}->{collection}, "check existence of collection link");
ok($journal->{_links}->{'ngcp:'.$resource}, "check existence of ngcp:$resource link");
ok($journal->{_links}->{'ngcp:'.$resource}->{href} eq '/api/'.$resource . '/' . $item_id, "check if ngcp:$resource link equals '/api/$resource/$item_id'");
if (defined $old_journal) {
ok($journal->{timestamp} ge $old_journal->{timestamp},"check incremented timestamp");
}
if (defined $content) {
my $original = Storable::dclone($content);
delete $original->{_links};
#delete $original->{_embedded};
is_deeply($journal->{content}, $original, "check resource '/api/$resource/$item_id' content deeply");
}
if (defined $journals) {
$journals->{$journal->{_links}->{self}->{href}} = $journal;
if (defined $old_journal) {
ok($journal->{timestamp} ge $old_journal->{timestamp},"check incremented timestamp");
ok($journal->{id} > $old_journal->{id},"check incremented journal item id");
}
if (defined $content) {
my $original = Storable::dclone($content);
delete $original->{_links};
#delete $original->{_embedded};
is_deeply($journal->{content}, $original, "check resource '/api/$resource/$item_id' content deeply");
}
if (defined $journals) {
$journals->{$journal->{_links}->{self}->{href}} = $journal;
}
return $journal;
}
return $journal;
}
return undef;
}
@ -870,9 +1429,36 @@ sub _is_journal_resource_enabled {
my ($resource) = @_;
my $cfg = NGCP::Panel::Utils::Journal::get_journal_resource_config(\%config,$resource);
if (not $cfg->{journal_resource_enabled}) {
diag("'api/$resource' journal disabled, skipping tests");
diag("'api/$resource' journal resource disabled, skipping tests");
}
return ($enable_journal_tests && $cfg->{journal_resource_enabled});
}
sub _get_preference_value {
my ($attr,$def,$soundset,$contract_soundset) = @_;
if (exists $def->{data_type} and not $def->{read_only} and $def->{max_occur} > 0) {
my $val_code = undef;
if ($attr eq 'sound_set') {
$val_code = sub { return $soundset->{name}; };
} elsif ($attr eq 'contract_sound_set') {
$val_code = sub { return $contract_soundset->{name}; };
} else {
if ($def->{data_type} eq 'int') {
$val_code = sub { return 1; };
} elsif ($def->{data_type} eq 'string') {
$val_code = sub { return 'test'; };
}
}
if (defined $val_code) {
if ($def->{max_occur} > 1) {
my @ary = map { &$_(); } (($val_code) x $def->{max_occur});
return \@ary;
} else {
return &$val_code;
}
}
}
return undef;
}
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save