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 (+10 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
Lines 113-118 properties: Link Here
113
      - array
118
      - array
114
      - "null"
119
      - "null"
115
    description: The linked extended ill request attributes (x-koha-embed)
120
    description: The linked extended ill request attributes (x-koha-embed)
121
  batch:
122
    type:
123
      - object
124
      - "null"
125
    description: The linked ill batch object (x-koha-embed)
116
  library:
126
  library:
117
    type:
127
    type:
118
      - object
128
      - object
(-)a/api/v1/swagger/paths/ill_requests.yaml (+51 lines)
Lines 28-33 Link Here
28
            - comments
28
            - comments
29
            - comments+count
29
            - comments+count
30
            - extended_attributes
30
            - extended_attributes
31
            - batch
31
            - library
32
            - library
32
            - id_prefix
33
            - id_prefix
33
            - patron
34
            - patron
Lines 63-65 Link Here
63
    x-koha-authorization:
64
    x-koha-authorization:
64
      permissions:
65
      permissions:
65
        ill: "1"
66
        ill: "1"
67
  post:
68
    x-mojo-to: Illrequests#add
69
    operationId: addIllrequest
70
    tags:
71
      - ill_request
72
    summary: Add ILL request
73
    parameters:
74
      - name: body
75
        in: body
76
        description: A JSON object containing informations about the new request
77
        required: true
78
        schema:
79
          $ref: "../swagger.yaml#/definitions/ill_request"
80
    produces:
81
      - application/json
82
    responses:
83
      "201":
84
        description: Request added
85
        schema:
86
          $ref: "../swagger.yaml#/definitions/ill_request"
87
      "400":
88
        description: Bad request
89
        schema:
90
          $ref: "../swagger.yaml#/definitions/error"
91
      "401":
92
        description: Authentication required
93
        schema:
94
          $ref: "../swagger.yaml#/definitions/error"
95
      "403":
96
        description: Access forbidden
97
        schema:
98
          $ref: "../swagger.yaml#/definitions/error"
99
      "409":
100
        description: Conflict in creating resource
101
        schema:
102
          $ref: "../swagger.yaml#/definitions/error"
103
      "500":
104
        description: |
105
          Internal server error. Possible `error_code` attribute values:
106
107
          * `internal_server_error`
108
        schema:
109
          $ref: "../swagger.yaml#/definitions/error"
110
      "503":
111
        description: Under maintenance
112
        schema:
113
          $ref: "../swagger.yaml#/definitions/error"
114
    x-koha-authorization:
115
      permissions:
116
        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 503-508 parameters: Link Here
503
    name: hold_id
519
    name: hold_id
504
    required: true
520
    required: true
505
    type: integer
521
    type: integer
522
  illbatch_id_pp:
523
    description: Internal ILL batch identifier
524
    in: path
525
    name: illbatch_id
526
    required: true
527
    type: integer
528
  illbatchstatus_code_pp:
529
    description: Internal ILL batch status identifier
530
    in: path
531
    name: illbatchstatus_code
532
    required: true
533
    type: string
506
  import_batch_profile_id_pp:
534
  import_batch_profile_id_pp:
507
    description: Internal profile identifier
535
    description: Internal profile identifier
508
    in: path
536
    in: path
Lines 805-810 tags: Link Here
805
  - description: "Manage ILL module backends\n"
833
  - description: "Manage ILL module backends\n"
806
    name: ill_backends
834
    name: ill_backends
807
    x-displayName: ILL backends
835
    x-displayName: ILL backends
836
  - description: "Manage ILL module batches\n"
837
    name: illbatches
838
    x-displayName: ILL batches
839
  - description: "Manage ILL module batch statuses\n"
840
    name: illbatchstatuses
841
    x-displayName: ILL batch statuses
808
  - description: "Manage ILL requests\n"
842
  - description: "Manage ILL requests\n"
809
    name: ill_requests
843
    name: ill_requests
810
    x-displayName: ILL requests
844
    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 3279-3284 CREATE TABLE `illrequestattributes` ( Link Here
3279
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3279
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3280
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3280
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3281
/*!40101 SET character_set_client = @saved_cs_client */;
3281
/*!40101 SET character_set_client = @saved_cs_client */;
3282
--
3283
-- Table structure for table `illbatch_statuses`
3284
--
3285
DROP TABLE IF EXISTS `illbatch_statuses`;
3286
CREATE TABLE `illbatch_statuses` (
3287
    `id` int(11) NOT NULL auto_increment, -- Status ID
3288
    `name` varchar(100) NOT NULL,         -- Name of status
3289
    `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
3290
    `is_system` int(1),                   -- Is this status required for system operation
3291
    PRIMARY KEY (`id`),
3292
    UNIQUE KEY `u_illbatchstatuses__code` (`code`)
3293
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3294
3295
--
3296
-- Table structure for table `illbatches`
3297
--
3298
DROP TABLE IF EXISTS `illbatches`;
3299
CREATE TABLE `illbatches` (
3300
    `id` int(11) NOT NULL auto_increment, -- Batch ID
3301
    `name` varchar(100) NOT NULL,         -- Unique name of batch
3302
    `backend` varchar(20) NOT NULL,       -- Name of batch backend
3303
    `borrowernumber` int(11),             -- Patron associated with batch
3304
    `branchcode` varchar(50),             -- Branch associated with batch
3305
    `statuscode` varchar(20),             -- Status of batch
3306
    PRIMARY KEY (`id`),
3307
    UNIQUE KEY `u_illbatches__name` (`name`),
3308
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3309
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
3310
    CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
3311
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3282
3312
3283
--
3313
--
3284
-- Table structure for table `illrequests`
3314
-- Table structure for table `illrequests`
Lines 3307-3312 CREATE TABLE `illrequests` ( Link Here
3307
  `notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
3337
  `notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
3308
  `orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
3338
  `orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
3309
  `backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
3339
  `backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
3340
  `batch_id` int(11) COMMENT 'Optional ID of batch that this request belongs to',
3310
  PRIMARY KEY (`illrequest_id`),
3341
  PRIMARY KEY (`illrequest_id`),
3311
  KEY `illrequests_bnfk` (`borrowernumber`),
3342
  KEY `illrequests_bnfk` (`borrowernumber`),
3312
  KEY `illrequests_bcfk_2` (`branchcode`),
3343
  KEY `illrequests_bcfk_2` (`branchcode`),
Lines 3314-3320 CREATE TABLE `illrequests` ( Link Here
3314
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3345
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3315
  CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3346
  CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3316
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3347
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3317
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE
3348
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE,
3349
  CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
3318
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3350
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3319
/*!40101 SET character_set_client = @saved_cs_client */;
3351
/*!40101 SET character_set_client = @saved_cs_client */;
3320
3352
(-)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