From 487470b411e6027a7a0cb0b175b2fbd95c0b15e1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 30 May 2022 14:46:25 +0200 Subject: [PATCH] Bug 32030: maintenance holdingsIQ Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../erm/ebsco/populate_from_holdingsiq.pl | 232 +++++++++++++++++- 1 file changed, 220 insertions(+), 12 deletions(-) diff --git a/misc/maintenance/erm/ebsco/populate_from_holdingsiq.pl b/misc/maintenance/erm/ebsco/populate_from_holdingsiq.pl index 03e7b04bec..c8241b5d9d 100644 --- a/misc/maintenance/erm/ebsco/populate_from_holdingsiq.pl +++ b/misc/maintenance/erm/ebsco/populate_from_holdingsiq.pl @@ -7,6 +7,11 @@ use JSON qw( from_json to_json ); use HTTP::Request; use LWP::UserAgent; +use Koha::Acquisition::Booksellers; +use Koha::ERM::EHoldings::Packages; +use Koha::ERM::EHoldings::Titles; +use Koha::ERM::EHoldings::Resources; + our ( $custid, $api_key ); my( $help, $verbose ); GetOptions( @@ -19,18 +24,18 @@ GetOptions( pod2usage(1) if $help; pod2usage("Parameters 'custid' and 'api-key' are mandatory") unless $custid && $api_key; -my $status = get_status(); -say "Status of the snapshot: $status"; -if ( $status ne 'Completed' && $status ne 'In Progress' ) { - say "Populate holdings..."; - populate_holdings(); -} - -while ($status ne 'Completed') { - sleep(60); - $status = get_status(); - say "Status: " . $status; -} +#my $status = get_status(); +#say "Status of the snapshot: $status"; +#if ( $status ne 'Completed' && $status ne 'In Progress' ) { +# say "Populate holdings..."; +# populate_holdings(); +#} +# +#while ($status ne 'Completed') { +# sleep(60); +# $status = get_status(); +# say "Status: " . $status; +#} sub get_status { my $response= request(GET => '/holdings/status'); @@ -56,3 +61,206 @@ sub request { my $ua = LWP::UserAgent->new; return $ua->simple_request($request); } + +my @lines; +while(my $line = ){chomp $line;push @lines, $line} +my $json = join "", @lines; +my $result = from_json($json); +for my $h ( @{$result->{holdings}} ) { + say $h->{publication_title}; + my $vendor = Koha::Acquisition::Booksellers->search({name => $h->{vendor_name}}); + if ($vendor->count) { + $vendor = $vendor->next; + if ( !$vendor->external_id ) { + $vendor->external_id( $h->{vendor_id} )->store; + } + elsif ( $vendor->external_id != $h->{vendor_id} ) { + die "Cannot update external vendor id for " . $h->{vendor_name}; + } + } + else { + $vendor = Koha::Acquisition::Bookseller->new( + { name => $h->{vendor_name}, external_id => $h->{vendor_id} } ) + ->store; + } + + my $package = + Koha::ERM::EHoldings::Packages->search( { name => $h->{package_name} } ); + if ($package->count) { + $package = $package->next; + if ( !$package->external_id ) { + $package->external_id( $h->{package_id} ); + } + elsif ( $package->external_id != $h->{package_id} ) { + die "Cannot update external package id for " . $h->{package_name}; + } + + } + else { + $package = Koha::ERM::EHoldings::Package->new( + { name => $h->{package_name}, external_id => $h->{package_id} } ); + } + $package->vendor_id($vendor->id); + $package->store; + + my $title = Koha::ERM::EHoldings::Titles->search( + { publication_title => $h->{publication_title} } ); + if ($title->count) { + $title = $title->next; + if ( !$title->external_id ) { + $title->external_id( $h->{title_id} )->store; + } + elsif ( $title->external_id != $h->{title_id} ) { + die "Cannot update external title id for " + . $h->{publication_title}; + } + } + else { + $title = Koha::ERM::EHoldings::Title->new( + { + publication_title => $h->{publication_title}, + external_id => $h->{title_id} + } + )->store; + } + + $title->update( + { + print_identifier => $h->{print_identifier}, + online_identifier => $h->{online_identifier}, + date_first_issue_online => $h->{date_first_issue_online}, + num_first_vol_online => $h->{num_first_vol_online}, + num_first_issue_online => $h->{num_first_issue_online}, + date_last_issue_online => $h->{date_last_issue_online}, + num_last_vol_online => $h->{num_last_vol_online}, + num_last_issue_online => $h->{num_last_issue_online}, + title_url => $h->{title_url}, + first_author => $h->{first_author}, + title_id => $h->{title_id}, + embargo_info => $h->{embargo_info}, + coverage_depth => $h->{coverage_depth}, + notes => $h->{notes}, + publisher_name => $h->{publisher_name}, + publication_type => $h->{publication_type}, + date_monograph_published_print => + $h->{date_monograph_published_print}, + date_monograph_published_online => + $h->{date_monograph_published_online}, + monograph_volume => $h->{monograph_volume}, + monograph_edition => $h->{monograph_edition}, + first_editor => $h->{first_editor}, + parent_publication_title_id => $h->{parent_publication_title_id}, + preceeding_publication_title_id => + $h->{preceeding_publication_title_id}, + access_type => $h->{access_type}, + + # "resource_type": "Database" ? + } + ); + + Koha::ERM::EHoldings::Resource->new({title_id => $title->title_id, package_id => $package->package_id})->store; +} + +__DATA__ +{ + "offset": 1, + "format": "kbart2", + "holdings": [ + { + "publication_title": "PsycFIRST", + "print_identifier": "", + "online_identifier": "", + "date_first_issue_online": "", + "num_first_vol_online": "", + "num_first_issue_online": "", + "date_last_issue_online": "", + "num_last_vol_online": "", + "num_last_issue_online": "", + "title_url": "http://firstsearch.oclc.org/FSIP?db=PsycFIRST", + "first_author": "", + "title_id": "482857", + "embargo_info": "", + "coverage_depth": "abstract", + "notes": "", + "publisher_name": "Unspecified", + "publication_type": "monograph", + "date_monograph_published_print": "2000", + "date_monograph_published_online": "2000", + "monograph_volume": "", + "monograph_edition": "", + "first_editor": "", + "parent_publication_title_id": "", + "preceeding_publication_title_id": "", + "access_type": "P", + "package_name": "PsycFIRST", + "package_id": "2976", + "vendor_name": "OCLC", + "vendor_id": "21", + "resource_type": "Database" + }, + { + "publication_title": "PsycFIRST", + "print_identifier": "", + "online_identifier": "", + "date_first_issue_online": "", + "num_first_vol_online": "", + "num_first_issue_online": "", + "date_last_issue_online": "", + "num_last_vol_online": "", + "num_last_issue_online": "", + "title_url": "http://firstsearch.oclc.org/FSIP?db=PsycFIRST", + "first_author": "", + "title_id": "482857", + "embargo_info": "", + "coverage_depth": "abstract", + "notes": "", + "publisher_name": "Unspecified", + "publication_type": "monograph", + "date_monograph_published_print": "2001", + "date_monograph_published_online": "2001", + "monograph_volume": "", + "monograph_edition": "", + "first_editor": "", + "parent_publication_title_id": "", + "preceeding_publication_title_id": "", + "access_type": "P", + "package_name": "PsycFIRST", + "package_id": "2976", + "vendor_name": "OCLC", + "vendor_id": "21", + "resource_type": "Database" + }, + { + "publication_title": "Idea Engineering: Creative Thinking and Innovation", + "print_identifier": "978-1-60650-472-7", + "online_identifier": "978-1-60650-473-4", + "date_first_issue_online": "", + "num_first_vol_online": "", + "num_first_issue_online": "", + "date_last_issue_online": "", + "num_last_vol_online": "", + "num_last_issue_online": "", + "title_url": "", + "first_author": "Harris, La Verne Abe.", + "title_id": "2461469", + "embargo_info": "", + "coverage_depth": "fulltext", + "notes": "", + "publisher_name": "Momentum Press, LLC", + "publication_type": "monograph", + "date_monograph_published_print": "2014", + "date_monograph_published_online": "2014", + "monograph_volume": "", + "monograph_edition": "", + "first_editor": "", + "parent_publication_title_id": "", + "preceeding_publication_title_id": "", + "access_type": "P", + "package_name": "Ebrary Business Expert Press Digital Library 2014", + "package_id": "22589", + "vendor_name": "Ebrary", + "vendor_id": "269", + "resource_type": "Book" + } + ] +} -- 2.39.5