From ff64b6c1334b059da3d31c7f02e5c7a2f04bf192 Mon Sep 17 00:00:00 2001 From: morgane alonso Date: Thu, 25 Aug 2016 08:22:50 +0000 Subject: [PATCH] Bug 17047 subscriptions management with Mana-KB - add a class SharedContent.pm to communicate with Mana-KB server - add a link in serials-menu.inc to serials_search.pl to open a mana-subscription research form - modify the research form in serials-search.tt to show the right fields for Mana-KB - create datatable in mana-subscription-search-result.inc to show results from a research on Mana-KB - modify serials-search.pl to manage research on Mana-KB - add a mana_id to subscription table - add a share button on serials-toolbar.inc and a modal to ask the language of the share and to alert if the subscription is already link to a Mana-KB subscription model - add function in C4/Serials to get all the info for a subscription sharing - modify subscription-detail.pl to manage sharing to Mana-KB - modify subscription-add.tt and subscription.pl to manage a import from Mana-KB during a subscription creation - add 2 script in svc for ajax calling from subscription-add.tt to communicate with Mana-KB server during a asubscription creation - add a function in Subscription.pm to have all the info for a Mana-KB research from a biblionumber - modify functions used by subscription-add.pl in C4/Serials to manage a frequency which came from Mana-KB server and not already created on the koha database, and modify the tests of the said functions --- Koha/SharedContent.pm | 90 ++++++++++++++++++++++ Koha/Subscription/Frequencies.pm | 57 ++++++++++++++ Koha/Subscription/Frequency.pm | 48 ++++++++++++ Koha/Subscription/Numberpattern.pm | 48 ++++++++++++ Koha/Subscription/Numberpatterns.pm | 77 ++++++++++++++++++ .../mana_01-add_mana_id_in_subscription.sql | 1 + .../includes/mana-subscription-search-result.inc | 46 +++++++++++ .../serials/mana-subscription-search-result.tt | 1 + svc/mana/search | 62 +++++++++++++++ svc/mana/use | 48 ++++++++++++ t/db_dependent/Serials/GetFictiveIssueNumber.t | 1 - 11 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 Koha/SharedContent.pm create mode 100644 Koha/Subscription/Frequencies.pm create mode 100644 Koha/Subscription/Frequency.pm create mode 100644 Koha/Subscription/Numberpattern.pm create mode 100644 Koha/Subscription/Numberpatterns.pm create mode 100644 installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt create mode 100755 svc/mana/search create mode 100755 svc/mana/use diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm new file mode 100644 index 0000000..e0c512b --- /dev/null +++ b/Koha/SharedContent.pm @@ -0,0 +1,90 @@ +package Koha::SharedContent; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use JSON; +use HTTP::Request; +use LWP::UserAgent; + +our $MANA_IP = "http://10.25.159.107:5000"; + +sub manaRequest { + my $mana_request = shift; + my $result; + + $mana_request->content_type('application/json'); + my $userAgent = LWP::UserAgent->new; + my $response = $userAgent->request($mana_request); + + if ( $response->code ne "204" ) { + $result = from_json( $response->decoded_content ); + } + $result->{code} = $response->code; + + return $result if ( $response->code =~ /^2..$/ ); +} + +sub manaNewUserPatchRequest { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json/newUser"; + my $request = HTTP::Request->new( PATCH => $url ); + + return manaRequest($request); +} + +sub manaPostRequest { + my $resource = shift; + my $content = shift; + + my $url = "$MANA_IP/$resource.json"; + my $request = HTTP::Request->new( POST => $url ); + + $content->{bulk_import} = 0; + my $json = to_json( $content, { utf8 => 1 } ); + $request->content($json); + + return manaRequest($request); +} + +sub manaGetRequestWithId { + my $resource = shift; + my $id = shift; + + my $url = "$MANA_IP/$resource/$id.json"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + +sub manaGetRequest { + my $resource = shift; + my $parameters = shift; + + $parameters = join '&', + map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () } + keys %$parameters; + my $url = "$MANA_IP/$resource.json?$parameters"; + my $request = HTTP::Request->new( GET => $url ); + + return manaRequest($request); +} + +1; diff --git a/Koha/Subscription/Frequencies.pm b/Koha/Subscription/Frequencies.pm new file mode 100644 index 0000000..0742a67 --- /dev/null +++ b/Koha/Subscription/Frequencies.pm @@ -0,0 +1,57 @@ +package Koha::Subscription::Frequencies; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use Koha::Subscription::Frequency; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Subscription::Frequencies - Koha Subscription::Frequency object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Frequency'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/Koha/Subscription/Frequency.pm b/Koha/Subscription/Frequency.pm new file mode 100644 index 0000000..a0b7834 --- /dev/null +++ b/Koha/Subscription/Frequency.pm @@ -0,0 +1,48 @@ +package Koha::Subscription::Frequency; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::Subscription::Frequency - Koha Subscription::Frequency Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionFrequency'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/Koha/Subscription/Numberpattern.pm b/Koha/Subscription/Numberpattern.pm new file mode 100644 index 0000000..049fbfe --- /dev/null +++ b/Koha/Subscription/Numberpattern.pm @@ -0,0 +1,48 @@ +package Koha::Subscription::Numberpattern; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::SubscriptionNumberpattern - Koha SubscriptionNumberpattern Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SubscriptionNumberpattern'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/Koha/Subscription/Numberpatterns.pm b/Koha/Subscription/Numberpatterns.pm new file mode 100644 index 0000000..638e028 --- /dev/null +++ b/Koha/Subscription/Numberpatterns.pm @@ -0,0 +1,77 @@ +package Koha::Subscription::Numberpatterns; + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use Koha::Subscription::Numberpattern; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 uniqeLabel + +=cut + +sub uniqueLabel { + my ($self, $label) = @_; + + my $samelabel = Koha::Subscription::Numberpatterns->search({label => $label})->next(); + if ($samelabel) { + my $i = 2; + my $newlabel = $samelabel->label . " ($i)"; + while (my $othersamelabel = $self->search({label => $newlabel})->next()) { + $i++; + $newlabel = $samelabel->label . " ($i)"; + } + $label = $newlabel; + } + return $label; +} + +=head3 type + +=cut + +sub _type { + return 'SubscriptionNumberpattern'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription::Numberpattern'; +} + +=head1 AUTHOR + +Morgane Alonso + +=cut + +1; diff --git a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql new file mode 100644 index 0000000..5c590d1 --- /dev/null +++ b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql @@ -0,0 +1 @@ +ALTER TABLE subscription ADD mana_id int(11); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc new file mode 100644 index 0000000..4ce9b9b --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc @@ -0,0 +1,46 @@ +[% USE KohaDates %] + + + + + + + + + + [% UNLESS search_only %] + + [% END %] + + + + + + + + + + + [% UNLESS search_only %] + + [% END %] + + + + [% FOREACH subscription IN subscriptions %] + [% UNLESS subscription.cannotdisplay %] + + + + + + + + [% UNLESS search_only %] + + [% END %] + + [% END %] + [% END %] + +
ISSNTitleFrequencyNumbering patternNumber of usersLast ImportActions
[% IF ( subscription.issn ) %][% subscription.issn %][% END %][% subscription.title %][% IF ( subscription.sfdescription ) %][% subscription.sfdescription %][% END %][% IF ( subscription.numberingmethod ) %][% subscription.numberingmethod %][% END %][% IF ( subscription.nbofusers ) %][% subscription.nbofusers %][% END %][% subscription.lastimport | $KohaDates %] Use
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt new file mode 100644 index 0000000..0afe02c --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt @@ -0,0 +1 @@ +[% INCLUDE 'mana-subscription-search-result.inc' %] diff --git a/svc/mana/search b/svc/mana/search new file mode 100755 index 0000000..0f58c84 --- /dev/null +++ b/svc/mana/search @@ -0,0 +1,62 @@ +#!/usr/bin/perl + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . +# + +use strict; +use warnings; + +use Koha::SharedContent; +use Koha::Subscription; +use C4::Auth qw(check_cookie_auth), qw(get_template_and_user); +use C4::Output qw( output_with_http_headers ); + +use CGI; +use JSON; + +my $input = new CGI; + +my ( $auth_status, $sessionID ) = + check_cookie_auth( $input->cookie('CGISESSID'), + { serials => 'create_subscription' } ); + +if ( $auth_status ne "ok" ) { + exit 0; +} + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "serials/mana-subscription-search-result.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + + # flagsrequired => { serials => $permission }, + flagsrequired => { serials => 'create_subscription' }, + debug => 1, + } +); + +my $biblionumber = $input->param('biblionumber'); + +my $sub_mana_info = Koha::Subscription::get_search_info($biblionumber); +my $result = + Koha::SharedContent::manaGetRequest( "subscription", $sub_mana_info ); +$template->param( subscriptions => $result->{data} ); + +output_with_http_headers $input, $cookie, $template->output, 'json'; diff --git a/svc/mana/use b/svc/mana/use new file mode 100755 index 0000000..a2f2e44 --- /dev/null +++ b/svc/mana/use @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# Copyright 2016 BibLibre Morgane Alonso +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . +# + +use strict; +use warnings; + +use Koha::SharedContent; +use C4::Auth qw(check_cookie_auth); + +use CGI; +use JSON; + + +my $input = new CGI; +binmode STDOUT, ":encoding(UTF-8)"; +print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); + +my ( $auth_status, $sessionID ) = + check_cookie_auth( $input->cookie('CGISESSID'), + { serials => 'create_subscription' } ); + +if ( $auth_status ne "ok" ) { + exit 0; +} + +my $result = Koha::SharedContent::manaGetRequestWithId("subscription", $input->param('id') ); + +my $subscription; +$subscription = $result->{data}; + +print(to_json($subscription)); diff --git a/t/db_dependent/Serials/GetFictiveIssueNumber.t b/t/db_dependent/Serials/GetFictiveIssueNumber.t index 33e9a69..e944de9 100644 --- a/t/db_dependent/Serials/GetFictiveIssueNumber.t +++ b/t/db_dependent/Serials/GetFictiveIssueNumber.t @@ -1,6 +1,5 @@ #!/usr/bin/perl - use C4::Context; use Test::More tests => 18; use Modern::Perl; -- 2.7.4