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

(-)a/Koha/BackgroundJob/ImportKBARTFile.pm (-7 / +23 lines)
Lines 24-29 use POSIX qw( floor ); Link Here
24
use C4::Context;
24
use C4::Context;
25
25
26
use Koha::ERM::EHoldings::Titles;
26
use Koha::ERM::EHoldings::Titles;
27
use Koha::SearchEngine::Indexer;
27
28
28
use base 'Koha::BackgroundJob';
29
use base 'Koha::BackgroundJob';
29
30
Lines 94-103 sub process { Link Here
94
        $self->size( scalar( @{$rows} ) )->store;
95
        $self->size( scalar( @{$rows} ) )->store;
95
        $total_rows = scalar( @{$rows} );
96
        $total_rows = scalar( @{$rows} );
96
97
98
        my @biblio_ids;
99
97
        foreach my $row ( @{$rows} ) {
100
        foreach my $row ( @{$rows} ) {
98
            next if !$row;
101
            next if !$row;
99
            my $new_title   = create_title_hash_from_line_data( $row, $column_headers, $invalid_columns );
102
            my $new_title   = create_title_hash_from_line_data( $row, $column_headers, $invalid_columns );
100
            my $title_match = check_for_matching_title($new_title);
103
            my $title_match = check_for_matching_title( $new_title, $package_id );
101
104
102
            if ($title_match) {
105
            if ($title_match) {
103
                $duplicate_titles++;
106
                $duplicate_titles++;
Lines 122-127 sub process { Link Here
122
                    } else {
125
                    } else {
123
                        my $imported_title = Koha::ERM::EHoldings::Title->new($formatted_title)
126
                        my $imported_title = Koha::ERM::EHoldings::Title->new($formatted_title)
124
                            ->store( { create_linked_biblio => $create_linked_biblio } );
127
                            ->store( { create_linked_biblio => $create_linked_biblio } );
128
                        push( @biblio_ids, $imported_title->biblio_id ) if $create_linked_biblio;
125
                        create_linked_resource(
129
                        create_linked_resource(
126
                            {
130
                            {
127
                                title      => $imported_title,
131
                                title      => $imported_title,
Lines 146-155 sub process { Link Here
146
            $self->step;
150
            $self->step;
147
        }
151
        }
148
152
153
        if ( scalar(@biblio_ids) > 0 ) {
154
            my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
155
            $indexer->index_records( \@biblio_ids, "specialUpdate", "biblioserver" );
156
        }
157
149
        $report->{duplicates_found} = $duplicate_titles;
158
        $report->{duplicates_found} = $duplicate_titles;
150
        $report->{titles_imported}  = $titles_imported;
159
        $report->{titles_imported}  = $titles_imported;
151
        $report->{total_rows}       = $total_rows;
160
        $report->{total_rows}       = $total_rows;
152
        $report->{failed_imports}   = $failed_imports;
161
        $report->{failed_imports}   = $failed_imports;
162
        $report->{package_id}       = $package_id;
153
163
154
        my $data = $self->decoded_data;
164
        my $data = $self->decoded_data;
155
        $data->{messages} = \@messages;
165
        $data->{messages} = \@messages;
Lines 266-272 sub create_title_hash_from_line_data { Link Here
266
    }
276
    }
267
277
268
    # Remove any additional columns
278
    # Remove any additional columns
269
    foreach my $invalid_column ( @$invalid_columns ) {
279
    foreach my $invalid_column (@$invalid_columns) {
270
        delete $new_title{$invalid_column};
280
        delete $new_title{$invalid_column};
271
    }
281
    }
272
282
Lines 280-286 Checks whether this title already exists to avoid duplicates Link Here
280
=cut
290
=cut
281
291
282
sub check_for_matching_title {
292
sub check_for_matching_title {
283
    my ($title) = @_;
293
    my ( $title, $package_id ) = @_;
284
294
285
    my $match_parameters = {};
295
    my $match_parameters = {};
286
    $match_parameters->{print_identifier}  = $title->{print_identifier}  if $title->{print_identifier};
296
    $match_parameters->{print_identifier}  = $title->{print_identifier}  if $title->{print_identifier};
Lines 290-303 sub check_for_matching_title { Link Here
290
    $match_parameters->{external_id} = $title->{title_id} if $title->{title_id};
300
    $match_parameters->{external_id} = $title->{title_id} if $title->{title_id};
291
301
292
    # We should also check the date_first_issue_online for serial publications
302
    # We should also check the date_first_issue_online for serial publications
293
    $match_parameters->{date_first_issue_online} = $title->{date_first_issue_online} if $title->{date_first_issue_online};
303
    $match_parameters->{date_first_issue_online} = $title->{date_first_issue_online}
304
        if $title->{date_first_issue_online};
294
305
295
    # If no match parameters are provided in the file we should add the new title
306
    # If no match parameters are provided in the file we should add the new title
296
    return 0 if !%$match_parameters;
307
    return 0 if !%$match_parameters;
297
308
298
    my $title_match = Koha::ERM::EHoldings::Titles->search($match_parameters)->count;
309
    my $matching_title_found;
310
    my @title_matches = Koha::ERM::EHoldings::Titles->search($match_parameters)->as_list;
311
    foreach my $title_match (@title_matches) {
312
        my $resource = Koha::ERM::EHoldings::Resources->find( { title_id => $title_match->title_id } );
313
        $matching_title_found = 1 if $resource->package_id == $package_id;
314
    }
299
315
300
    return $title_match;
316
    return $matching_title_found;
301
}
317
}
302
318
303
=head3 create_linked_resource
319
=head3 create_linked_resource
Lines 437-443 sub is_file_too_large { Link Here
437
453
438
=head3 rescue_EBSCO_files
454
=head3 rescue_EBSCO_files
439
455
440
EBSCO have an incorrect spelling for "preceding_publication_title_id" in all of their KBART files ("preceeding" instead of "preceding").
456
EBSCO have an incorrect spelling for "preceding_publication_title_id" in all of their KBART files (preceding is spelled with a double 'e').
441
This means all of their KBART files fail to import using the current methodology.
457
This means all of their KBART files fail to import using the current methodology.
442
There is no simple way of finding out who the vendor is before importing so all KBART files from any vendor are going to have to be checked for this spelling and corrected.
458
There is no simple way of finding out who the vendor is before importing so all KBART files from any vendor are going to have to be checked for this spelling and corrected.
443
459
(-)a/Koha/ERM/EHoldings/Title.pm (-2 / +2 lines)
Lines 55-61 sub store { Link Here
55
            my $record      = $biblio->metadata->record();
55
            my $record      = $biblio->metadata->record();
56
            my $title_field = $record->field($title_tag);
56
            my $title_field = $record->field($title_tag);
57
            $title_field->update( $title_subfield => $self->publication_title );
57
            $title_field->update( $title_subfield => $self->publication_title );
58
            C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
58
            C4::Biblio::ModBiblio( $record, $self->biblio_id, '', { skip_record_index => 1 } );
59
        } else {
59
        } else {
60
60
61
            # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
61
            # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
Lines 64-70 sub store { Link Here
64
                    'biblio.title' => $self->publication_title,
64
                    'biblio.title' => $self->publication_title,
65
                }
65
                }
66
            );
66
            );
67
            my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' );
67
            my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '', { skip_record_index => 1 } );
68
            $self->biblio_id($biblio_id);
68
            $self->biblio_id($biblio_id);
69
        }
69
        }
70
    }
70
    }
(-)a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm (-10 / +4 lines)
Lines 24-32 use Koha::BackgroundJob::CreateEHoldingsFromBiblios; Link Here
24
use Koha::BackgroundJob::ImportKBARTFile;
24
use Koha::BackgroundJob::ImportKBARTFile;
25
25
26
use Scalar::Util qw( blessed );
26
use Scalar::Util qw( blessed );
27
use Try::Tiny qw( catch try );
27
use Try::Tiny    qw( catch try );
28
use MIME::Base64 qw( decode_base64 encode_base64 );
28
use MIME::Base64 qw( decode_base64 encode_base64 );
29
use POSIX qw( floor );
29
use POSIX        qw( floor );
30
use Text::CSV_XS;
30
use Text::CSV_XS;
31
31
32
=head1 API
32
=head1 API
Lines 294-300 sub import_from_kbart_file { Link Here
294
294
295
        # Check that the column headers in the file match the standardised KBART phase II columns
295
        # Check that the column headers in the file match the standardised KBART phase II columns
296
        # If not, return a warning
296
        # If not, return a warning
297
        my $warnings = {};
297
        my $warnings      = {};
298
        my @valid_headers = Koha::BackgroundJob::ImportKBARTFile::get_valid_headers();
298
        my @valid_headers = Koha::BackgroundJob::ImportKBARTFile::get_valid_headers();
299
        foreach my $header (@$column_headers) {
299
        foreach my $header (@$column_headers) {
300
            if ( !grep { $_ eq $header } @valid_headers ) {
300
            if ( !grep { $_ eq $header } @valid_headers ) {
Lines 324-336 sub import_from_kbart_file { Link Here
324
            my @chunked_files;
324
            my @chunked_files;
325
            push @chunked_files, [ splice @$rows, 0, $max_number_of_rows ] while @$rows;
325
            push @chunked_files, [ splice @$rows, 0, $max_number_of_rows ] while @$rows;
326
            foreach my $chunk (@chunked_files) {
326
            foreach my $chunk (@chunked_files) {
327
                my $params = {
327
                $params->{rows} = $chunk;
328
                    column_headers => $column_headers,
329
                    rows           => $chunk,
330
                    package_id     => $package_id,
331
                    file_name      => $file->{filename}
332
                };
333
334
                my $chunked_job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue($params);
328
                my $chunked_job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue($params);
335
                push @job_ids, $chunked_job_id;
329
                push @job_ids, $chunked_job_id;
336
            }
330
            }
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/import_from_kbart_file.inc (+1 lines)
Lines 28-33 Link Here
28
                        <td>[% report.failed_imports | html %]</td>
28
                        <td>[% report.failed_imports | html %]</td>
29
                    </tr>
29
                    </tr>
30
                </table>
30
                </table>
31
                <a href="/cgi-bin/koha/erm/eholdings/local/packages/[% report.package_id | $raw %]">Click here to see the package</a>
31
            [% ELSIF job.status == 'started' %]
32
            [% ELSIF job.status == 'started' %]
32
                <p id="jobactionlabel"></p>
33
                <p id="jobactionlabel"></p>
33
            [% END %]
34
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue (-4 / +9 lines)
Lines 80-89 Link Here
80
<script>
80
<script>
81
import ButtonSubmit from "../ButtonSubmit.vue"
81
import ButtonSubmit from "../ButtonSubmit.vue"
82
import { APIClient } from "../../fetch/api-client.js"
82
import { APIClient } from "../../fetch/api-client.js"
83
import { setMessage, setWarning } from "../../messages"
83
import { ref, inject } from "vue"
84
import { ref } from "vue"
85
84
86
export default {
85
export default {
86
    setup() {
87
        const { setMessage } = inject("mainStore")
88
        return {
89
            setMessage,
90
        }
91
    },
87
    data() {
92
    data() {
88
        const fileLoader = ref()
93
        const fileLoader = ref()
89
        return {
94
        return {
Lines 143-149 export default { Link Here
143
                                '<li>Job %s for uploaded file has been queued, <a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=%s" target="_blank">click here</a> to check its progress.</li>'
148
                                '<li>Job %s for uploaded file has been queued, <a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=%s" target="_blank">click here</a> to check its progress.</li>'
144
                            ).format(i + 1, job)
149
                            ).format(i + 1, job)
145
                        })
150
                        })
146
                        setMessage(message, true)
151
                        this.setMessage(message, true)
147
                    }
152
                    }
148
                    if (success.warnings.invalid_columns) {
153
                    if (success.warnings.invalid_columns) {
149
                        message += this.$__(
154
                        message += this.$__(
Lines 158-164 export default { Link Here
158
                        message += this.$__(
163
                        message += this.$__(
159
                            "<p style='margin-top: 0.1em;'>The data in these columns will not be imported.</p>"
164
                            "<p style='margin-top: 0.1em;'>The data in these columns will not be imported.</p>"
160
                        )
165
                        )
161
                        setMessage(message)
166
                        this.setMessage(message, true)
162
                    }
167
                    }
163
                    if (success.invalid_filetype) {
168
                    if (success.invalid_filetype) {
164
                        message += this.$__(
169
                        message += this.$__(
(-)a/t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t (-22 / +29 lines)
Lines 79-89 subtest 'read_file' => sub { Link Here
79
    plan tests => 6;
79
    plan tests => 6;
80
80
81
    my $file = {
81
    my $file = {
82
        filename     => 'Test_file.tsv',
82
        filename     => 'Test_file.csv',
83
        file_content => encode_base64(
83
        file_content => encode_base64(
84
            'publication_title	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	first_author	title_id	embargo_info	coverage_depth	coverage_notes	publisher_name	publication_type	date_monograph_published_print	date_monograph_published_online	monograph_volume	monograph_edition	first_editor	parent_publication_title_id	preceding_publication_title_id	access_type
84
            'publication_title,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,first_author,title_id,embargo_info,coverage_depth,coverage_notes,publisher_name,publication_type,date_monograph_published_print,date_monograph_published_online,monograph_volume,monograph_edition,first_editor,parent_publication_title_id,preceding_publication_title_id,access_type
85
Nature Plants		2055-0278	2015-01	1	1				https://www.nature.com/nplants		4aaa7		fulltext	Hybrid (Open Choice)	Nature Publishing Group UK	serial								P
85
Nature Plants,,2055-0278,2015-01,1,1,,,,https://www.nature.com/nplants,,4aaa7,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P
86
Nature Astronomy		2397-3366	2017-01	1	1				https://www.nature.com/natastron		4bbb0		fulltext	Hybrid (Open Choice)	Nature Publishing Group UK	serial								P'
86
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bbb0,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P'
87
        )
87
        )
88
    };
88
    };
89
89
Lines 119-139 subtest 'create_title_hash_from_line_data' => sub { Link Here
119
    plan tests => 2;
119
    plan tests => 2;
120
120
121
    my $file = {
121
    my $file = {
122
        filename     => 'Test_file.tsv',
122
        filename     => 'Test_file.csv',
123
        file_content => encode_base64(
123
        file_content => encode_base64(
124
            'publication_title	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	first_author	title_id	embargo_info	coverage_depth	coverage_notes	publisher_name	publication_type	date_monograph_published_print	date_monograph_published_online	monograph_volume	monograph_edition	first_editor	parent_publication_title_id	preceding_publication_title_id	access_type
124
            'publication_title,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,first_author,title_id,embargo_info,coverage_depth,coverage_notes,publisher_name,publication_type,date_monograph_published_print,date_monograph_published_online,monograph_volume,monograph_edition,first_editor,parent_publication_title_id,preceding_publication_title_id,access_type
125
Nature Plants		2055-0278	2015-01	1	1				https://www.nature.com/nplants		4aaa7		fulltext	Hybrid (Open Choice)	Nature Publishing Group UK	serial								P
125
Nature Plants,,2055-0278,2015-01,1,1,,,,https://www.nature.com/nplants,,4aaa7,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P
126
Nature Astronomy		2397-3366	2017-01	1	1				https://www.nature.com/natastron		4bbb0		fulltext	Hybrid (Open Choice)	Nature Publishing Group UK	serial								P'
126
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bbb0,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P'
127
        )
127
        )
128
    };
128
    };
129
129
130
    my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file);
130
    my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file);
131
    my @invalid_columns;
131
    my @invalid_columns;
132
132
133
    my $title_from_line1 =
133
    my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data(
134
        Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( @{$lines}[0], $column_headers, \@invalid_columns );
134
        @{$lines}[0], $column_headers,
135
    my $title_from_line2 =
135
        \@invalid_columns
136
        Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( @{$lines}[1], $column_headers, \@invalid_columns );
136
    );
137
    my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data(
138
        @{$lines}[1], $column_headers,
139
        \@invalid_columns
140
    );
137
141
138
    my $line1_match = {
142
    my $line1_match = {
139
        'coverage_depth'                  => 'fulltext',
143
        'coverage_depth'                  => 'fulltext',
Lines 210-219 Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb Link Here
210
    my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file);
214
    my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file);
211
    my @invalid_columns = ('invalid_column');
215
    my @invalid_columns = ('invalid_column');
212
216
213
    my $title_from_line1 =
217
    my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data(
214
        Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( @{$lines}[0], $column_headers, \@invalid_columns );
218
        @{$lines}[0], $column_headers,
215
    my $title_from_line2 =
219
        \@invalid_columns
216
        Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( @{$lines}[1], $column_headers, \@invalid_columns );
220
    );
221
    my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data(
222
        @{$lines}[1], $column_headers,
223
        \@invalid_columns
224
    );
217
225
218
    my $line1_match = {
226
    my $line1_match = {
219
        'coverage_depth'                  => 'fulltext',
227
        'coverage_depth'                  => 'fulltext',
Lines 288-298 subtest 'process' => sub { Link Here
288
    );
296
    );
289
297
290
    my $file = {
298
    my $file = {
291
        filename     => 'Test_file.tsv',
299
        filename     => 'Test_file.csv',
292
        file_content => encode_base64(
300
        file_content => encode_base64(
293
            'publication_title	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	first_author	title_id	embargo_info	coverage_depth	coverage_notes	publisher_name	publication_type	date_monograph_published_print	date_monograph_published_online	monograph_volume	monograph_edition	first_editor	parent_publication_title_id	preceding_publication_title_id	access_type
301
            'publication_title,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,first_author,title_id,embargo_info,coverage_depth,coverage_notes,publisher_name,publication_type,date_monograph_published_print,date_monograph_published_online,monograph_volume,monograph_edition,first_editor,parent_publication_title_id,preceding_publication_title_id,access_type
294
Nature Plants		2055-0278	2015-01	1	1				https://www.nature.com/nplants		4aaa7		fulltext	Hybrid (Open Choice)	Nature Publishing Group UK	serial								P
302
Nature Plants,,2055-0278,2015-01,1,1,,,,https://www.nature.com/nplants,,4aaa7,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P
295
Nature Astronomy		2397-3366	2017-01	1	1				https://www.nature.com/natastron		4bbb0		fulltext	Hybrid (Open Choice)	Nature Publishing Group UK	serial								P'
303
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bbb0,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P'
296
        )
304
        )
297
    };
305
    };
298
306
Lines 453-456 Nature Astronomy 2397-3366 2017-01 1 1 https://www.nature.com/natastron 4bb Link Here
453
    is( @{ $job4->messages }[1]->{code}, 'title_already_exists', 'Error message for a duplicate title' );
461
    is( @{ $job4->messages }[1]->{code}, 'title_already_exists', 'Error message for a duplicate title' );
454
462
455
    $schema->storage->txn_rollback;
463
    $schema->storage->txn_rollback;
456
}
464
    }
457
- 

Return to bug 34788