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

(-)a/Koha/REST/V1/Biblios.pm (-29 / +41 lines)
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 {
(-)a/api/v1/swagger/paths/biblios.yaml (-16 lines)
Lines 7-20 Link Here
7
      - biblios
7
      - biblios
8
    summary: Add biblio
8
    summary: Add biblio
9
    parameters:
9
    parameters:
10
      - name: Body
11
        in: body
12
        description: A JSON object or the Marc string describing a biblio
13
        required: true
14
        schema:
15
          type:
16
            - string
17
            - object
18
      - $ref: "../swagger.yaml#/parameters/framework_id_header"
10
      - $ref: "../swagger.yaml#/parameters/framework_id_header"
19
      - $ref: "../swagger.yaml#/parameters/marc_schema_header"
11
      - $ref: "../swagger.yaml#/parameters/marc_schema_header"
20
      - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header"
12
      - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header"
Lines 214-227 Link Here
214
    summary: Update biblio
206
    summary: Update biblio
215
    parameters:
207
    parameters:
216
      - $ref: "../swagger.yaml#/parameters/biblio_id_pp"
208
      - $ref: "../swagger.yaml#/parameters/biblio_id_pp"
217
      - name: Body
218
        in: body
219
        description: A JSON object or the Marc string describing a biblio
220
        required: true
221
        schema:
222
          type:
223
            - string
224
            - object
225
      - $ref: "../swagger.yaml#/parameters/framework_id_header"
209
      - $ref: "../swagger.yaml#/parameters/framework_id_header"
226
      - $ref: "../swagger.yaml#/parameters/marc_schema_header"
210
      - $ref: "../swagger.yaml#/parameters/marc_schema_header"
227
      - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header"
211
      - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header"
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +1 lines)
Lines 1125-1131 subtest 'post() tests' => sub { Link Here
1125
        }
1125
        }
1126
    );
1126
    );
1127
1127
1128
    $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode, "x-march-schema" => 'INVALID'})
1128
    $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode, "x-marc-schema" => 'INVALID'})
1129
      ->status_is(400, 'Invalid header x-marc-schema');
1129
      ->status_is(400, 'Invalid header x-marc-schema');
1130
1130
1131
    $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode} => $marcxml)
1131
    $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode} => $marcxml)
1132
- 

Return to bug 33227