Lines 491-511
sub add {
Link Here
|
491 |
my $c = shift->openapi->valid_input or return; |
491 |
my $c = shift->openapi->valid_input or return; |
492 |
|
492 |
|
493 |
try { |
493 |
try { |
494 |
my $body = $c->validation->param('Body'); |
494 |
my $headers = $c->req->headers; |
495 |
|
495 |
|
496 |
my $flavour = $c->validation->param('x-marc-schema'); |
496 |
my $flavour = $headers->header('x-marc-schema'); |
497 |
$flavour = C4::Context->preference('marcflavour') unless $flavour; |
497 |
$flavour //= C4::Context->preference('marcflavour'); |
498 |
|
498 |
|
499 |
my $record; |
499 |
my $record; |
500 |
|
500 |
|
501 |
my $frameworkcode = $c->validation->param('x-framework-id'); |
501 |
my $frameworkcode = $headers->header('x-framework-id'); |
502 |
if ( $c->req->headers->content_type =~ m/application\/marcxml\+xml/ ) { |
502 |
my $content_type = $headers->content_type; |
503 |
$record = MARC::Record->new_from_xml( $body, 'UTF-8', $flavour ); |
503 |
|
504 |
} elsif ( $c->req->headers->content_type =~ m/application\/marc-in-json/ ) { |
504 |
if ( $content_type =~ m/application\/marcxml\+xml/ ) { |
505 |
$record = MARC::Record->new_from_mij_structure( $body ); |
505 |
$record = MARC::Record->new_from_xml( $c->req->body, 'UTF-8', $flavour ); |
506 |
} elsif ( $c->req->headers->content_type =~ m/application\/marc/ ) { |
506 |
} |
507 |
$record = MARC::Record->new_from_usmarc( $body ); |
507 |
elsif ( $content_type =~ m/application\/marc-in-json/ ) { |
508 |
} else { |
508 |
$record = MARC::Record->new_from_mij_structure( $c->req->json ); |
|
|
509 |
} |
510 |
elsif ( $content_type =~ m/application\/marc/ ) { |
511 |
$record = MARC::Record->new_from_usmarc( $c->req->body ); |
512 |
} |
513 |
else { |
509 |
return $c->render( |
514 |
return $c->render( |
510 |
status => 406, |
515 |
status => 406, |
511 |
openapi => [ |
516 |
openapi => [ |
Lines 519-530
sub add {
Link Here
|
519 |
my ( $duplicatebiblionumber, $duplicatetitle ); |
524 |
my ( $duplicatebiblionumber, $duplicatetitle ); |
520 |
( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record); |
525 |
( $duplicatebiblionumber, $duplicatetitle ) = FindDuplicate($record); |
521 |
|
526 |
|
522 |
my $confirm_not_duplicate = $c->validation->param('x-confirm-not-duplicate'); |
527 |
my $confirm_not_duplicate = $headers->header('x-confirm-not-duplicate'); |
523 |
|
528 |
|
524 |
return $c->render( |
529 |
return $c->render( |
525 |
status => 400, |
530 |
status => 400, |
526 |
openapi => { |
531 |
openapi => { |
527 |
error => "Duplicate biblio $duplicatebiblionumber" |
532 |
error => "Duplicate biblio $duplicatebiblionumber", |
528 |
} |
533 |
} |
529 |
) unless !$duplicatebiblionumber || $confirm_not_duplicate; |
534 |
) unless !$duplicatebiblionumber || $confirm_not_duplicate; |
530 |
|
535 |
|
Lines 550-559
Controller function that handles modifying an biblio object
Link Here
|
550 |
sub update { |
555 |
sub update { |
551 |
my $c = shift->openapi->valid_input or return; |
556 |
my $c = shift->openapi->valid_input or return; |
552 |
|
557 |
|
553 |
my $biblionumber = $c->validation->param('biblio_id'); |
558 |
my $biblio_id = $c->param('biblio_id'); |
554 |
my $biblio = Koha::Biblios->find( $biblionumber ); |
559 |
my $biblio = Koha::Biblios->find($biblio_id); |
555 |
|
560 |
|
556 |
if ( not defined $biblio ) { |
561 |
if ( ! defined $biblio ) { |
557 |
return $c->render( |
562 |
return $c->render( |
558 |
status => 404, |
563 |
status => 404, |
559 |
openapi => { error => "Object not found" } |
564 |
openapi => { error => "Object not found" } |
Lines 561-580
sub update {
Link Here
|
561 |
} |
566 |
} |
562 |
|
567 |
|
563 |
try { |
568 |
try { |
564 |
my $body = $c->validation->param('Body'); |
569 |
my $headers = $c->req->headers; |
|
|
570 |
|
571 |
my $flavour = $headers->header('x-marc-schema'); |
572 |
$flavour //= C4::Context->preference('marcflavour'); |
565 |
|
573 |
|
566 |
my $flavour = $c->validation->param('x-marc-schema'); |
574 |
my $frameworkcode = $headers->header('x-framework-id') || $biblio->frameworkcode; |
567 |
$flavour = C4::Context->preference('marcflavour') unless $flavour; |
575 |
|
|
|
576 |
my $content_type = $headers->content_type; |
568 |
|
577 |
|
569 |
my $record; |
578 |
my $record; |
570 |
my $frameworkcode = $c->validation->param('x-framework-id') || $biblio->frameworkcode; |
579 |
|
571 |
if ( $c->req->headers->content_type =~ m/application\/marcxml\+xml/ ) { |
580 |
if ( $content_type =~ m/application\/marcxml\+xml/ ) { |
572 |
$record = MARC::Record->new_from_xml( $body, 'UTF-8', $flavour ); |
581 |
$record = MARC::Record->new_from_xml( $c->req->body, 'UTF-8', $flavour ); |
573 |
} elsif ( $c->req->headers->content_type =~ m/application\/marc-in-json/ ) { |
582 |
} |
574 |
$record = MARC::Record->new_from_mij_structure( $body ); |
583 |
elsif ( $content_type =~ m/application\/marc-in-json/ ) { |
575 |
} elsif ( $c->req->headers->content_type =~ m/application\/marc/ ) { |
584 |
$record = MARC::Record->new_from_mij_structure( $c->req->json ); |
576 |
$record = MARC::Record->new_from_usmarc( $body ); |
585 |
} |
577 |
} else { |
586 |
elsif ( $content_type =~ m/application\/marc/ ) { |
|
|
587 |
$record = MARC::Record->new_from_usmarc( $c->req->body ); |
588 |
} |
589 |
else { |
578 |
return $c->render( |
590 |
return $c->render( |
579 |
status => 406, |
591 |
status => 406, |
580 |
openapi => [ |
592 |
openapi => [ |
Lines 586-596
sub update {
Link Here
|
586 |
); |
598 |
); |
587 |
} |
599 |
} |
588 |
|
600 |
|
589 |
ModBiblio( $record, $biblionumber, $frameworkcode ); |
601 |
ModBiblio( $record, $biblio_id, $frameworkcode ); |
590 |
|
602 |
|
591 |
$c->render( |
603 |
$c->render( |
592 |
status => 200, |
604 |
status => 200, |
593 |
openapi => { id => $biblionumber } |
605 |
openapi => { id => $biblio_id } |
594 |
); |
606 |
); |
595 |
} |
607 |
} |
596 |
catch { |
608 |
catch { |