From 698c1e930b7069fb6c27fe4331db77b4daf5998a Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 16 Oct 2023 10:45:25 +0000 Subject: [PATCH] Bug 34788: Add a relationship to a package for the imported file Signed-off-by: Clemens Tubach Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- Koha/BackgroundJob/ImportKBARTFile.pm | 4 ++ Koha/REST/V1/ERM/EHoldings/Titles/Local.pm | 8 ++-- .../swagger/paths/erm_eholdings_titles.yaml | 6 +-- .../ERM/EHoldingsLocalTitlesKBARTImport.vue | 46 +++++++++++++++++-- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Koha/BackgroundJob/ImportKBARTFile.pm b/Koha/BackgroundJob/ImportKBARTFile.pm index 73cbae84c4..c243695127 100644 --- a/Koha/BackgroundJob/ImportKBARTFile.pm +++ b/Koha/BackgroundJob/ImportKBARTFile.pm @@ -77,6 +77,7 @@ sub process { try { my $file = $args->{file}; + my $package_id = $args->{package_id}; my ( $column_headers, $lines ) = format_file($file); if ( scalar( @{$lines} ) == 0 ) { @@ -118,6 +119,9 @@ sub process { $failed_imports++; } else { my $imported_title = Koha::ERM::EHoldings::Title->new($formatted_title)->store; + my $title_id = $imported_title->title_id; + Koha::ERM::EHoldings::Resource->new( { title_id => $title_id, package_id => $package_id } ) + ->store; # No need to add a message for a successful import, # files could have 1000s of titles which will lead to lots of messages in background_job->data diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm index 3144bc510d..7587eaa84f 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/Local.pm @@ -271,7 +271,9 @@ sub import_from_list { sub import_from_kbart_file { my $c = shift or return; - my $file = $c->req->json; + my $import_data = $c->req->json; + my $file = $import_data->{file}; + my $package_id = $import_data->{package_id}; return try { my @job_ids; @@ -315,12 +317,12 @@ sub import_from_kbart_file { filename => $file->{filename}, file_content => encode_base64( join( "\r", @{$chunk} ) ) }; - my $params = { file => $chunked_file }; + my $params = { file => $chunked_file, package_id => $package_id }; my $job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue($params); push @job_ids, $job_id; } } else { - my $params = { file => $file }; + my $params = { file => $file, package_id => $package_id }; my $job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue($params); push @job_ids, $job_id; } diff --git a/api/v1/swagger/paths/erm_eholdings_titles.yaml b/api/v1/swagger/paths/erm_eholdings_titles.yaml index a72ef34bd0..6959d39237 100644 --- a/api/v1/swagger/paths/erm_eholdings_titles.yaml +++ b/api/v1/swagger/paths/erm_eholdings_titles.yaml @@ -512,9 +512,9 @@ schema: type: object properties: - filename: - type: string - file_content: + file: + type: object + package_id: type: string additionalProperties: false responses: diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue index 6d2269db54..afc545f132 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue @@ -11,6 +11,7 @@ @change="selectFile($event)" :id="`import_file`" :name="`import_file`" + required />
    @@ -18,11 +19,28 @@ {{ $__("File name") }}: {{ file.filename }} -
  1. - {{ $__("File type") }}: - {{ file.file_type }} -
+
+ {{ $__("To the following local package") }}: + + + + {{ $__("Required") }} +
@@ -46,8 +64,20 @@ export default { filename: null, file_content: null, }, + packages: [], + package_id: null, } }, + beforeCreate() { + const client = APIClient.erm + client.localPackages.getAll().then( + packages => { + this.packages = packages + this.initialized = true + }, + error => {} + ) + }, methods: { selectFile(e) { let files = e.target.files @@ -63,8 +93,13 @@ export default { }, addDocument(e) { e.preventDefault() + const client = APIClient.erm - client.localTitles.import_kbart(this.file).then( + const importData = { + file: this.file, + package_id: this.package_id, + } + client.localTitles.import_kbart(importData).then( success => { let message = "" if (success.job_ids) { @@ -108,6 +143,7 @@ export default { file_type: null, file_content: null, } + this.package_id = null }, }, components: { -- 2.39.5