View | Details | Raw Unified | Return to bug 17047
Collapse All | Expand All

(-)a/C4/Serials.pm (-1 / +1 lines)
Lines 280-286 sub GetSubscription { Link Here
280
    $subscription->{additional_fields} = $additional_field_values->{$subscriptionid};
280
    $subscription->{additional_fields} = $additional_field_values->{$subscriptionid};
281
281
282
    if ( my $mana_id = $subscription->{mana_id} ) {
282
    if ( my $mana_id = $subscription->{mana_id} ) {
283
        my $mana_subscription = Koha::SharedContent::manaGetRequestWithId(
283
        my $mana_subscription = Koha::SharedContent::get_entity_by_id(
284
            'subscription', $mana_id, {usecomments => 1});
284
            'subscription', $mana_id, {usecomments => 1});
285
        $subscription->{comments} = $mana_subscription->{data}->{comments};
285
        $subscription->{comments} = $mana_subscription->{data}->{comments};
286
    }
286
    }
(-)a/Koha/SharedContent.pm (-22 / +22 lines)
Lines 34-44 Package for accessing shared content via Mana Link Here
34
34
35
=cut
35
=cut
36
36
37
=head3 manaRequest
37
=head3 process_request
38
38
39
=cut
39
=cut
40
40
41
sub manaRequest {
41
sub process_request {
42
    my $mana_request = shift;
42
    my $mana_request = shift;
43
    my $result;
43
    my $result;
44
    $mana_request->content_type('application/json');
44
    $mana_request->content_type('application/json');
Lines 63-88 sub manaRequest { Link Here
63
    return $result ;
63
    return $result ;
64
}
64
}
65
65
66
=head3 manaIncrementRequest
66
=head3 increment_entity_value
67
67
68
=cut
68
=cut
69
69
70
sub manaIncrementRequest {
70
sub increment_entity_value {
71
    return manaRequest(buildRequest('increment', @_));
71
    return process_request(build_request('increment', @_));
72
}
72
}
73
73
74
=head3 manaPostRequest
74
=head3 send_entity
75
75
76
=cut
76
=cut
77
77
78
sub manaPostRequest {
78
sub send_entity {
79
    my ($lang, $loggedinuser, $resourceid, $resourcetype, $content) = @_;
79
    my ($lang, $loggedinuser, $resourceid, $resourcetype, $content) = @_;
80
80
81
    unless ( $content ) {
81
    unless ( $content ) {
82
        $content = prepareSharedData($lang, $loggedinuser, $resourceid, $resourcetype);
82
        $content = prepare_entity_data($lang, $loggedinuser, $resourceid, $resourcetype);
83
    }
83
    }
84
84
85
    my $result = manaRequest(buildRequest('post', $resourcetype, $content));
85
    my $result = process_request(build_request('post', $resourcetype, $content));
86
86
87
    if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) {
87
    if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) {
88
        my $packages = "Koha::".ucfirst($resourcetype)."s";
88
        my $packages = "Koha::".ucfirst($resourcetype)."s";
Lines 92-102 sub manaPostRequest { Link Here
92
    return $result;
92
    return $result;
93
}
93
}
94
94
95
=head3 prepareSharedData
95
=head3 prepare_entity_data
96
96
97
=cut
97
=cut
98
98
99
sub prepareSharedData {
99
sub prepare_entity_data {
100
    my ($lang, $loggedinuser, $ressourceid, $ressourcetype) = @_;
100
    my ($lang, $loggedinuser, $ressourceid, $ressourcetype) = @_;
101
    $lang ||= C4::Context->preference('language');
101
    $lang ||= C4::Context->preference('language');
102
102
Lines 126-155 sub prepareSharedData { Link Here
126
    return $ressource_mana_info;
126
    return $ressource_mana_info;
127
}
127
}
128
128
129
=head3 manaGetRequestWithId
129
=head3 get_entity_by_id
130
130
131
=cut
131
=cut
132
132
133
sub manaGetRequestWithId {
133
sub get_entity_by_id {
134
    return manaRequest(buildRequest('getwithid', @_));
134
    return process_request(build_request('getwithid', @_));
135
}
135
}
136
136
137
=head3 manaGetRequest
137
=head3 search_entities
138
138
139
=cut
139
=cut
140
140
141
sub manaGetRequest {
141
sub search_entities {
142
    return manaRequest(buildRequest('get', @_));
142
    return process_request(build_request('get', @_));
143
}
143
}
144
144
145
=head3 buildRequest
145
=head3 build_request
146
146
147
=cut
147
=cut
148
148
149
sub buildRequest {
149
sub build_request {
150
    my $type = shift;
150
    my $type = shift;
151
    my $resource = shift;
151
    my $resource = shift;
152
    my $mana_url = manaUrl();
152
    my $mana_url = get_sharing_url();
153
153
154
    if ( $type eq 'get' ) {
154
    if ( $type eq 'get' ) {
155
        my $params = shift;
155
        my $params = shift;
Lines 201-211 sub buildRequest { Link Here
201
    }
201
    }
202
}
202
}
203
203
204
=head3 manaUrl
204
=head3 get_sharing_url
205
205
206
=cut
206
=cut
207
207
208
sub manaUrl {
208
sub get_sharing_url {
209
    return C4::Context->config('mana_config');
209
    return C4::Context->config('mana_config');
210
}
210
}
211
211
(-)a/reports/guided_reports.pl (-1 / +1 lines)
Lines 678-684 elsif ( $phase eq 'Save Report' ) { Link Here
678
}
678
}
679
679
680
elsif ($phase eq 'Share'){
680
elsif ($phase eq 'Share'){
681
    my $result = Koha::SharedContent::manaPostRequest($input->param('mana_language'), $borrowernumber, scalar $input->param('reportid'), 'report');
681
    my $result = Koha::SharedContent::send_entity($input->param('mana_language'), $borrowernumber, scalar $input->param('reportid'), 'report');
682
    if ( $result ) {
682
    if ( $result ) {
683
        print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg});
683
        print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg});
684
    }else{
684
    }else{
(-)a/serials/serials-search.pl (-1 / +1 lines)
Lines 99-105 my @subscriptions; Link Here
99
my $mana_statuscode;
99
my $mana_statuscode;
100
if ($searched){
100
if ($searched){
101
    if ($mana) {
101
    if ($mana) {
102
        my $result = Koha::SharedContent::manaGetRequest("subscription",{
102
        my $result = Koha::SharedContent::search_entities("subscription",{
103
            title        => $title,
103
            title        => $title,
104
            issn         => $ISSN,
104
            issn         => $ISSN,
105
            ean          => $EAN,
105
            ean          => $EAN,
(-)a/serials/subscription-add.pl (-3 / +3 lines)
Lines 342-348 sub redirect_add_subscription { Link Here
342
    my $mana_id;
342
    my $mana_id;
343
    if ( $query->param('mana_id') ne "" ) {
343
    if ( $query->param('mana_id') ne "" ) {
344
        $mana_id = $query->param('mana_id');
344
        $mana_id = $query->param('mana_id');
345
        Koha::SharedContent::manaIncrementRequest("subscription",$mana_id, "nbofusers");
345
        Koha::SharedContent::increment_entity_value("subscription",$mana_id, "nbofusers");
346
    }
346
    }
347
347
348
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
348
    my $startdate      = output_pref( { str => scalar $query->param('startdate'),      dateonly => 1, dateformat => 'iso' } );
Lines 367-373 sub redirect_add_subscription { Link Here
367
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
367
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id
368
    );
368
    );
369
    if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
369
    if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
370
        my $result = Koha::SharedContent::manaPostRequest( $query->param('mana_language'), $loggedinuser, $subscriptionid, 'subscription');
370
        my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
371
        $template->param( mana_msg => $result->{msg} );
371
        $template->param( mana_msg => $result->{msg} );
372
    }
372
    }
373
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
373
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
Lines 440-446 sub redirect_mod_subscription { Link Here
440
    my $mana_id;
440
    my $mana_id;
441
    if ( defined( $query->param('mana_id') ) ) {
441
    if ( defined( $query->param('mana_id') ) ) {
442
        $mana_id = $query->param('mana_id');
442
        $mana_id = $query->param('mana_id');
443
        Koha::SharedContent::manaIncrementRequest("subscription",$mana_id, "nbofusers");
443
        Koha::SharedContent::increment_entity_value("subscription",$mana_id, "nbofusers");
444
    }
444
    }
445
    else {
445
    else {
446
        $mana_id = undef;
446
        $mana_id = undef;
(-)a/serials/subscription-detail.pl (-1 / +1 lines)
Lines 96-102 if ($op eq 'del') { Link Here
96
}
96
}
97
elsif ( $op and $op eq "share" ) {
97
elsif ( $op and $op eq "share" ) {
98
    my $mana_language = $query->param('mana_language');
98
    my $mana_language = $query->param('mana_language');
99
    my $result = Koha::SharedContent::manaPostRequest($mana_language, $loggedinuser, $subscriptionid, 'subscription');
99
    my $result = Koha::SharedContent::send_entity($mana_language, $loggedinuser, $subscriptionid, 'subscription');
100
    $template->param( mana_code => $result->{msg} );
100
    $template->param( mana_code => $result->{msg} );
101
    $subs->{mana_id} = $result->{id};
101
    $subs->{mana_id} = $result->{id};
102
}
102
}
(-)a/svc/mana/increment (-1 / +1 lines)
Lines 38-44 my ( $auth_status, $sessionID ) = Link Here
38
if ( $auth_status ne "ok" ) {
38
if ( $auth_status ne "ok" ) {
39
    exit 0;
39
    exit 0;
40
}
40
}
41
my $result = Koha::SharedContent::manaIncrementRequest(
41
my $result = Koha::SharedContent::increment_entity_value(
42
    scalar $input->param('resource'),
42
    scalar $input->param('resource'),
43
    scalar $input->param('id'),
43
    scalar $input->param('id'),
44
    scalar $input->param('field'),
44
    scalar $input->param('field'),
(-)a/svc/mana/search (-1 / +1 lines)
Lines 66-72 $sub_mana_info = $package->get_search_info($identifier); Link Here
66
66
67
$sub_mana_info->{ usecomments } = $input->param('usecomments');
67
$sub_mana_info->{ usecomments } = $input->param('usecomments');
68
my $resourcename = $input->param('resource');
68
my $resourcename = $input->param('resource');
69
my $result = Koha::SharedContent::manaGetRequest( $resourcename, $sub_mana_info);
69
my $result = Koha::SharedContent::search_entities( $resourcename, $sub_mana_info);
70
my $nbofcomment;
70
my $nbofcomment;
71
foreach my $resource (@{ $result->{data} }){
71
foreach my $resource (@{ $result->{data} }){
72
    $nbofcomment = 0;
72
    $nbofcomment = 0;
(-)a/svc/mana/share (-2 / +2 lines)
Lines 44-55 my $content; Link Here
44
$content->{resource_id} = $input->param("resource_id");
44
$content->{resource_id} = $input->param("resource_id");
45
$content->{resource_type} = $input->param("resource");
45
$content->{resource_type} = $input->param("resource");
46
$content->{message} = $input->param("message");
46
$content->{message} = $input->param("message");
47
Koha::SharedContent::manaPostRequest('', undef, undef, 'resource_comment', $content);
47
Koha::SharedContent::send_entity('', undef, undef, 'resource_comment', $content);
48
my $package = "Koha::".ucfirst($input->param('resource'));
48
my $package = "Koha::".ucfirst($input->param('resource'));
49
my $resource;
49
my $resource;
50
my $result;
50
my $result;
51
eval{
51
eval{
52
    $result = Koha::SharedContent::manaGetRequestWithId(
52
    $result = Koha::SharedContent::get_entity_by_id(
53
        scalar $input->param('resource'),
53
        scalar $input->param('resource'),
54
        scalar $input->param('id')
54
        scalar $input->param('id')
55
    );
55
    );
(-)a/svc/mana/token (-1 / +1 lines)
Lines 50-55 $content->{ lastname }= $input->param("lastname"); Link Here
50
$content->{ email }= $input->param("email");
50
$content->{ email }= $input->param("email");
51
my $json = to_json( $content, { utf8 => 1 } );
51
my $json = to_json( $content, { utf8 => 1 } );
52
$request->content($json);
52
$request->content($json);
53
my $result = Koha::SharedContent::manaRequest($request);
53
my $result = Koha::SharedContent::process_request($request);
54
54
55
print(to_json($result));
55
print(to_json($result));
(-)a/svc/mana/use (-1 / +1 lines)
Lines 40-46 if ( $auth_status ne "ok" ) { Link Here
40
    exit 0;
40
    exit 0;
41
}
41
}
42
42
43
my $result = Koha::SharedContent::manaGetRequestWithId(
43
my $result = Koha::SharedContent::get_entity_by_id(
44
    scalar $input->param('resource'),
44
    scalar $input->param('resource'),
45
    scalar $input->param('id')
45
    scalar $input->param('id')
46
);
46
);
(-)a/t/db_dependent/Koha/SharedContent.t (-15 / +14 lines)
Lines 43-51 my $query = {}; Link Here
43
43
44
t::lib::Mocks::mock_config( 'mana_config', 'https://foo.bar');
44
t::lib::Mocks::mock_config( 'mana_config', 'https://foo.bar');
45
45
46
is(Koha::SharedContent::manaUrl(), 'https://foo.bar', 'Mana URL');
46
is(Koha::SharedContent::get_sharing_url(), 'https://foo.bar', 'Mana URL');
47
47
48
my $result = Koha::SharedContent::manaGetRequest('report', $query);
48
my $result = Koha::SharedContent::search_entities('report', $query);
49
ok($result->{msg} =~ /Can\'t connect to foo.bar:443$/, 'Unable to connect');
49
ok($result->{msg} =~ /Can\'t connect to foo.bar:443$/, 'Unable to connect');
50
is($result->{code}, 500, 'Code is 500');
50
is($result->{code}, 500, 'Code is 500');
51
51
Lines 56-72 $ua->mock('request', sub { Link Here
56
56
57
$want_error = 1;
57
$want_error = 1;
58
$query = {query => 'foo', usecomments => 1};
58
$query = {query => 'foo', usecomments => 1};
59
$result = Koha::SharedContent::manaGetRequest('report', $query);
59
$result = Koha::SharedContent::search_entities('report', $query);
60
ok($result->{msg} =~ /^Error thrown by decoded_content/, 'Error in decoded_content');
60
ok($result->{msg} =~ /^Error thrown by decoded_content/, 'Error in decoded_content');
61
is($result->{code}, 500, 'Code is 500');
61
is($result->{code}, 500, 'Code is 500');
62
62
63
$want_error = 0;
63
$want_error = 0;
64
$query = {title => 'foo', usecomments => 1};
64
$query = {title => 'foo', usecomments => 1};
65
$result = Koha::SharedContent::manaGetRequest('subscription', $query);
65
$result = Koha::SharedContent::search_entities('subscription', $query);
66
is($result->{code}, 200, 'manaGetRequest success');
66
is($result->{code}, 200, 'search_entities success');
67
67
68
$result = Koha::SharedContent::manaGetRequestWithId('subscription', 23);
68
$result = Koha::SharedContent::get_entity_by_id('subscription', 23);
69
is($result->{code}, 200, 'manaGetRequestWithId success');
69
is($result->{code}, 200, 'get_entity_by_id success');
70
70
71
my $params = {
71
my $params = {
72
    title => 'The English historical review',
72
    title => 'The English historical review',
Lines 76-82 my $params = { Link Here
76
};
76
};
77
77
78
# Search a subscription.
78
# Search a subscription.
79
my $request = Koha::SharedContent::buildRequest('get', 'subscription', $params);
79
my $request = Koha::SharedContent::build_request('get', 'subscription', $params);
80
is($request->method, 'GET', 'Get subscription - Method is get');
80
is($request->method, 'GET', 'Get subscription - Method is get');
81
81
82
my %query = $request->uri->query_form;
82
my %query = $request->uri->query_form;
Lines 88-94 is($query{publishercode}, 'Longman', 'Check publisher'); Link Here
88
is($request->uri->path, '/subscription.json', 'Path is subscription');
88
is($request->uri->path, '/subscription.json', 'Path is subscription');
89
89
90
# Get a report by id.
90
# Get a report by id.
91
$request = Koha::SharedContent::buildRequest('getwithid', 'report', 26);
91
$request = Koha::SharedContent::build_request('getwithid', 'report', 26);
92
is($request->method, 'GET', 'Get with id - Method is get');
92
is($request->method, 'GET', 'Get with id - Method is get');
93
93
94
is($request->uri->path, '/report/26.json', 'Path is report/26.json');
94
is($request->uri->path, '/report/26.json', 'Path is report/26.json');
Lines 105-111 my $content = { Link Here
105
    'type' => undef
105
    'type' => undef
106
};
106
};
107
107
108
$request = Koha::SharedContent::buildRequest('post', 'report', $content);
108
$request = Koha::SharedContent::build_request('post', 'report', $content);
109
is($request->method, 'POST', 'Share report - Method is post');
109
is($request->method, 'POST', 'Share report - Method is post');
110
110
111
is($request->uri->path, '/report.json', 'Path is report.json');
111
is($request->uri->path, '/report.json', 'Path is report.json');
Lines 163-175 C4::Context->set_userenv(0,0,0, Link Here
163
t::lib::Mocks::mock_preference('language', 'en');
163
t::lib::Mocks::mock_preference('language', 'en');
164
164
165
$post_request = 1;
165
$post_request = 1;
166
$result = Koha::SharedContent::manaPostRequest('en', $loggedinuser->{borrowernumber}, $subscription->{subscriptionid}, 'subscription');
166
$result = Koha::SharedContent::send_entity('en', $loggedinuser->{borrowernumber}, $subscription->{subscriptionid}, 'subscription');
167
is($result->{code}, 200, 'manaPostRequest success');
167
is($result->{code}, 200, 'send_entity success');
168
168
169
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
169
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
170
is($s->mana_id, 5, 'Mana id is set');
170
is($s->mana_id, 5, 'Mana id is set');
171
171
172
my $data = Koha::SharedContent::prepareSharedData(
172
my $data = Koha::SharedContent::prepare_entity_data(
173
    '',
173
    '',
174
    $loggedinuser->{borrowernumber},
174
    $loggedinuser->{borrowernumber},
175
    $subscription->{subscriptionid},
175
    $subscription->{subscriptionid},
Lines 235-241 sub mock_response { Link Here
235
}
235
}
236
236
237
# Increment request.
237
# Increment request.
238
$request = Koha::SharedContent::buildRequest('increment',
238
$request = Koha::SharedContent::build_request('increment',
239
                                             'subscription',
239
                                             'subscription',
240
                                             12,
240
                                             12,
241
                                             'foo');
241
                                             'foo');
242
- 

Return to bug 17047