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

(-)a/Koha/Illrequest.pm (+27 lines)
Lines 35-40 use Koha::Illrequestattributes; Link Here
35
use Koha::AuthorisedValue;
35
use Koha::AuthorisedValue;
36
use Koha::Illrequest::Logger;
36
use Koha::Illrequest::Logger;
37
use Koha::Patron;
37
use Koha::Patron;
38
use Koha::Illbatches;
38
use Koha::AuthorisedValues;
39
use Koha::AuthorisedValues;
39
use Koha::Biblios;
40
use Koha::Biblios;
40
use Koha::Items;
41
use Koha::Items;
Lines 146-151 sub push_processor { Link Here
146
    push @{$self->{processors}}, $processor;
147
    push @{$self->{processors}}, $processor;
147
}
148
}
148
149
150
=head3 batch
151
152
    my $batch = $request->batch;
153
154
Returns the batch associated with a request
155
156
=cut
157
158
sub batch {
159
    my ( $self ) = @_;
160
161
    return Koha::Illbatches->find($self->_result->batch_id);
162
}
163
149
=head3 statusalias
164
=head3 statusalias
150
165
151
    my $statusalias = $request->statusalias;
166
    my $statusalias = $request->statusalias;
Lines 1980-1985 sub strings_map { Link Here
1980
        };
1995
        };
1981
    }
1996
    }
1982
1997
1998
    my $batch = $self->batch;
1999
    if ($batch) {
2000
        $strings->{"batch"} = {
2001
            id => $batch->id,
2002
            name => $batch->name,
2003
            backend => $batch->backend,
2004
            borrowernumber => $batch->borrowernumber,
2005
            branchcode => $batch->branchcode,
2006
            statuscode => $batch->statuscode
2007
        };
2008
    }
2009
1983
    return $strings;
2010
    return $strings;
1984
}
2011
}
1985
2012
(-)a/Koha/REST/V1/Illrequests.pm (+87 lines)
Lines 27-32 use Koha::Patrons; Link Here
27
use Koha::Libraries;
27
use Koha::Libraries;
28
use Koha::DateUtils qw( format_sqldatetime );
28
use Koha::DateUtils qw( format_sqldatetime );
29
29
30
use Scalar::Util qw( blessed );
31
use Try::Tiny qw( catch try );
32
30
=head1 NAME
33
=head1 NAME
31
34
32
Koha::REST::V1::Illrequests
35
Koha::REST::V1::Illrequests
Lines 55-58 sub list { Link Here
55
    };
58
    };
56
}
59
}
57
60
61
=head3 add
62
63
Adds a new ILL request
64
65
=cut
66
67
sub add {
68
    my $c = shift->openapi->valid_input or return;
69
70
    return try {
71
72
        Koha::Database->new->schema->txn_do(
73
            sub {
74
75
                my $body = $c->validation->param('body');
76
                $body->{backend} = delete $body->{ill_backend_id};
77
                $body->{borrowernumber} = delete $body->{patron_id};
78
                $body->{branchcode} = delete $body->{library_id};
79
80
                my $request = Koha::Illrequest->new->load_backend( $body->{backend} );
81
82
                my $create_api = $request->_backend->capabilities('create_api');
83
84
                if (!$create_api) {
85
                    return $c->render(
86
                        status  => 405,
87
                        openapi => {
88
                            errors => [ 'This backend does not allow request creation via API' ]
89
                        }
90
                    );
91
                }
92
93
                my $create_result = &{$create_api}($body, $request);
94
                my $new_id = $create_result->illrequest_id;
95
96
                my @new_req = Koha::Illrequests->search({
97
                    illrequest_id => $new_id
98
                })->as_list;
99
100
                $c->res->headers->location($c->req->url->to_string . '/' . $new_req[0]->illrequest_id);
101
                return $c->render(
102
                    status  => 201,
103
                    openapi => $new_req[0]->to_api
104
                );
105
            }
106
        );
107
    }
108
    catch {
109
110
        my $to_api_mapping = Koha::Illrequest->new->to_api_mapping;
111
112
        if ( blessed $_ ) {
113
            if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
114
                return $c->render(
115
                    status  => 409,
116
                    openapi => { error => $_->error, conflict => $_->duplicate_id }
117
                );
118
            }
119
            elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
120
                return $c->render(
121
                    status  => 400,
122
                    openapi => {
123
                            error => "Given "
124
                            . $to_api_mapping->{ $_->broken_fk }
125
                            . " does not exist"
126
                    }
127
                );
128
            }
129
            elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
130
                return $c->render(
131
                    status  => 400,
132
                    openapi => {
133
                            error => "Given "
134
                            . $to_api_mapping->{ $_->parameter }
135
                            . " does not exist"
136
                    }
137
                );
138
            }
139
        }
140
141
        $c->unhandled_exception($_);
142
    };
143
}
144
58
1;
145
1;
(-)a/api/v1/swagger/definitions/ill_request.yaml (+5 lines)
Lines 9-14 properties: Link Here
9
      - integer
9
      - integer
10
      - "null"
10
      - "null"
11
    description: Internal bibliographic record identifier
11
    description: Internal bibliographic record identifier
12
  batch_id:
13
    type:
14
      - integer
15
      - "null"
16
    description: Batch id this requests belongs to
12
  patron_id:
17
  patron_id:
13
    type:
18
    type:
14
      - integer
19
      - integer
(-)a/api/v1/swagger/paths/ill_requests.yaml (+50 lines)
Lines 63-65 Link Here
63
    x-koha-authorization:
63
    x-koha-authorization:
64
      permissions:
64
      permissions:
65
        ill: "1"
65
        ill: "1"
66
  post:
67
    x-mojo-to: Illrequests#add
68
    operationId: addIllrequest
69
    tags:
70
      - ill_request
71
    summary: Add ILL request
72
    parameters:
73
      - name: body
74
        in: body
75
        description: A JSON object containing informations about the new request
76
        required: true
77
        schema:
78
          $ref: "../swagger.yaml#/definitions/ill_request"
79
    produces:
80
      - application/json
81
    responses:
82
      "201":
83
        description: Request added
84
        schema:
85
          $ref: "../swagger.yaml#/definitions/ill_request"
86
      "400":
87
        description: Bad request
88
        schema:
89
          $ref: "../swagger.yaml#/definitions/error"
90
      "401":
91
        description: Authentication required
92
        schema:
93
          $ref: "../swagger.yaml#/definitions/error"
94
      "403":
95
        description: Access forbidden
96
        schema:
97
          $ref: "../swagger.yaml#/definitions/error"
98
      "409":
99
        description: Conflict in creating resource
100
        schema:
101
          $ref: "../swagger.yaml#/definitions/error"
102
      "500":
103
        description: |
104
          Internal server error. Possible `error_code` attribute values:
105
106
          * `internal_server_error`
107
        schema:
108
          $ref: "../swagger.yaml#/definitions/error"
109
      "503":
110
        description: Under maintenance
111
        schema:
112
          $ref: "../swagger.yaml#/definitions/error"
113
    x-koha-authorization:
114
      permissions:
115
        ill: "1"
(-)a/api/v1/swagger/swagger.yaml (+34 lines)
Lines 60-65 definitions: Link Here
60
    $ref: ./definitions/ill_status.yaml
60
    $ref: ./definitions/ill_status.yaml
61
  ill_request:
61
  ill_request:
62
    $ref: ./definitions/ill_request.yaml
62
    $ref: ./definitions/ill_request.yaml
63
  illbatch:
64
    $ref: ./definitions/illbatch.yaml
65
  illbatches:
66
    $ref: ./definitions/illbatches.yaml
67
  illbatchstatus:
68
    $ref: ./definitions/illbatchstatus.yaml
69
  illbatchstatuses:
70
    $ref: ./definitions/illbatchstatuses.yaml
63
  import_batch_profile:
71
  import_batch_profile:
64
    $ref: ./definitions/import_batch_profile.yaml
72
    $ref: ./definitions/import_batch_profile.yaml
65
  import_batch_profiles:
73
  import_batch_profiles:
Lines 257-262 paths: Link Here
257
    $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}"
265
    $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}"
258
  /ill/requests:
266
  /ill/requests:
259
    $ref: ./paths/ill_requests.yaml#/~1ill~1requests
267
    $ref: ./paths/ill_requests.yaml#/~1ill~1requests
268
  /illbatches:
269
    $ref: ./paths/illbatches.yaml#/~1illbatches
270
  "/illbatches/{illbatch_id}":
271
    $ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}"
272
  /illbatchstatuses:
273
    $ref: ./paths/illbatchstatuses.yaml#/~1illbatchstatuses
274
  "/illbatchstatuses/{illbatchstatus_code}":
275
    $ref: "./paths/illbatchstatuses.yaml#/~1illbatchstatuses~1{illbatchstatus_code}"
260
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
276
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
261
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
277
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
262
  /import_batch_profiles:
278
  /import_batch_profiles:
Lines 501-506 parameters: Link Here
501
    name: hold_id
517
    name: hold_id
502
    required: true
518
    required: true
503
    type: integer
519
    type: integer
520
  illbatch_id_pp:
521
    description: Internal ILL batch identifier
522
    in: path
523
    name: illbatch_id
524
    required: true
525
    type: integer
526
  illbatchstatus_code_pp:
527
    description: Internal ILL batch status identifier
528
    in: path
529
    name: illbatchstatus_code
530
    required: true
531
    type: string
504
  import_batch_profile_id_pp:
532
  import_batch_profile_id_pp:
505
    description: Internal profile identifier
533
    description: Internal profile identifier
506
    in: path
534
    in: path
Lines 803-808 tags: Link Here
803
  - description: "Manage ILL module backends\n"
831
  - description: "Manage ILL module backends\n"
804
    name: ill_backends
832
    name: ill_backends
805
    x-displayName: ILL backends
833
    x-displayName: ILL backends
834
  - description: "Manage ILL module batches\n"
835
    name: illbatches
836
    x-displayName: ILL batches
837
  - description: "Manage ILL module batch statuses\n"
838
    name: illbatchstatuses
839
    x-displayName: ILL batch statuses
806
  - description: "Manage ILL requests\n"
840
  - description: "Manage ILL requests\n"
807
    name: ill_requests
841
    name: ill_requests
808
    x-displayName: ILL requests
842
    x-displayName: ILL requests
(-)a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl (+54 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "30719",
5
    description => "Add ILL batches",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        $dbh->do(q{
10
            CREATE TABLE IF NOT EXISTS `illbatches` (
11
                `id` int(11) NOT NULL auto_increment, -- Batch ID
12
                `name` varchar(100) NOT NULL,         -- Unique name of batch
13
                `backend` varchar(20) NOT NULL,       -- Name of batch backend
14
                `borrowernumber` int(11),             -- Patron associated with batch
15
                `branchcode` varchar(50),             -- Branch associated with batch
16
                `statuscode` varchar(20),             -- Status of batch
17
                PRIMARY KEY (`id`),
18
                UNIQUE KEY `u_illbatches__name` (`name`)
19
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
20
        });
21
        $dbh->do(q{
22
            CREATE TABLE IF NOT EXISTS `illbatch_statuses` (
23
                `id` int(11) NOT NULL auto_increment, -- Status ID
24
                `name` varchar(100) NOT NULL,         -- Name of status
25
                `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
26
                `is_system` int(1),                   -- Is this status required for system operation
27
                PRIMARY KEY (`id`),
28
                UNIQUE KEY `u_illbatchstatuses__code` (`code`)
29
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
30
        });
31
        $dbh->do(q{
32
            ALTER TABLE `illrequests`
33
                ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
34
        });
35
        $dbh->do(q{
36
            ALTER TABLE `illrequests`
37
                ADD CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
38
        });
39
        $dbh->do(q{
40
            ALTER TABLE `illbatches`
41
                ADD CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
42
        });
43
        $dbh->do(q{
44
            ALTER TABLE `illbatches`
45
                ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
46
        });
47
        $dbh->do(q{
48
            ALTER TABLE `illbatches`
49
                ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
50
        });
51
52
        say $out "Bug 30719: Add ILL batches completed"
53
    },
54
};
(-)a/installer/data/mysql/kohastructure.sql (-1 / +33 lines)
Lines 3273-3278 CREATE TABLE `illrequestattributes` ( Link Here
3273
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3273
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3274
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3274
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3275
/*!40101 SET character_set_client = @saved_cs_client */;
3275
/*!40101 SET character_set_client = @saved_cs_client */;
3276
--
3277
-- Table structure for table `illbatch_statuses`
3278
--
3279
DROP TABLE IF EXISTS `illbatch_statuses`;
3280
CREATE TABLE `illbatch_statuses` (
3281
    `id` int(11) NOT NULL auto_increment, -- Status ID
3282
    `name` varchar(100) NOT NULL,         -- Name of status
3283
    `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
3284
    `is_system` int(1),                   -- Is this status required for system operation
3285
    PRIMARY KEY (`id`),
3286
    UNIQUE KEY `u_illbatchstatuses__code` (`code`)
3287
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3288
3289
--
3290
-- Table structure for table `illbatches`
3291
--
3292
DROP TABLE IF EXISTS `illbatches`;
3293
CREATE TABLE `illbatches` (
3294
    `id` int(11) NOT NULL auto_increment, -- Batch ID
3295
    `name` varchar(100) NOT NULL,         -- Unique name of batch
3296
    `backend` varchar(20) NOT NULL,       -- Name of batch backend
3297
    `borrowernumber` int(11),             -- Patron associated with batch
3298
    `branchcode` varchar(50),             -- Branch associated with batch
3299
    `statuscode` varchar(20),             -- Status of batch
3300
    PRIMARY KEY (`id`),
3301
    UNIQUE KEY `u_illbatches__name` (`name`),
3302
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3303
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
3304
    CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
3305
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3276
3306
3277
--
3307
--
3278
-- Table structure for table `illrequests`
3308
-- Table structure for table `illrequests`
Lines 3301-3306 CREATE TABLE `illrequests` ( Link Here
3301
  `notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
3331
  `notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
3302
  `orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
3332
  `orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
3303
  `backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
3333
  `backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
3334
  `batch_id` int(11) COMMENT 'Optional ID of batch that this request belongs to',
3304
  PRIMARY KEY (`illrequest_id`),
3335
  PRIMARY KEY (`illrequest_id`),
3305
  KEY `illrequests_bnfk` (`borrowernumber`),
3336
  KEY `illrequests_bnfk` (`borrowernumber`),
3306
  KEY `illrequests_bcfk_2` (`branchcode`),
3337
  KEY `illrequests_bcfk_2` (`branchcode`),
Lines 3308-3314 CREATE TABLE `illrequests` ( Link Here
3308
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3339
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3309
  CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3340
  CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3310
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3341
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3311
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE
3342
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE,
3343
  CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
3312
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3344
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3313
/*!40101 SET character_set_client = @saved_cs_client */;
3345
/*!40101 SET character_set_client = @saved_cs_client */;
3314
3346
(-)a/installer/data/mysql/mandatory/illbatch_statuses.sql (-1 / +5 lines)
Line 0 Link Here
0
- 
1
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES
2
('New', 'NEW', 1),
3
('In progress', 'IN_PROGRESS', 1),
4
('Completed', 'COMPLETED', 1),
5
('Unknown', 'UNKNOWN', 1);

Return to bug 30719