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 1981-1986 sub strings_map { Link Here
1981
        };
1996
        };
1982
    }
1997
    }
1983
1998
1999
    my $batch = $self->batch;
2000
    if ($batch) {
2001
        $strings->{"batch"} = {
2002
            id => $batch->id,
2003
            name => $batch->name,
2004
            backend => $batch->backend,
2005
            borrowernumber => $batch->borrowernumber,
2006
            branchcode => $batch->branchcode,
2007
            statuscode => $batch->statuscode
2008
        };
2009
    }
2010
1984
    return $strings;
2011
    return $strings;
1985
}
2012
}
1986
2013
(-)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 115-120 properties: Link Here
115
      - array
120
      - array
116
      - "null"
121
      - "null"
117
    description: The linked extended ill request attributes (x-koha-embed)
122
    description: The linked extended ill request attributes (x-koha-embed)
123
  batch:
124
    type:
125
      - object
126
      - "null"
127
    description: The linked ill batch object (x-koha-embed)
118
  library:
128
  library:
119
    type:
129
    type:
120
      - object
130
      - object
(-)a/api/v1/swagger/paths/ill_requests.yaml (+51 lines)
Lines 27-32 Link Here
27
            - comments
27
            - comments
28
            - comments+count
28
            - comments+count
29
            - extended_attributes
29
            - extended_attributes
30
            - batch
30
            - library
31
            - library
31
            - id_prefix
32
            - id_prefix
32
            - patron
33
            - patron
Lines 62-64 Link Here
62
    x-koha-authorization:
63
    x-koha-authorization:
63
      permissions:
64
      permissions:
64
        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 64-69 definitions: Link Here
64
    $ref: ./definitions/ill_status.yaml
64
    $ref: ./definitions/ill_status.yaml
65
  ill_request:
65
  ill_request:
66
    $ref: ./definitions/ill_request.yaml
66
    $ref: ./definitions/ill_request.yaml
67
  illbatch:
68
    $ref: ./definitions/illbatch.yaml
69
  illbatches:
70
    $ref: ./definitions/illbatches.yaml
71
  illbatchstatus:
72
    $ref: ./definitions/illbatchstatus.yaml
73
  illbatchstatuses:
74
    $ref: ./definitions/illbatchstatuses.yaml
67
  import_batch_profile:
75
  import_batch_profile:
68
    $ref: ./definitions/import_batch_profile.yaml
76
    $ref: ./definitions/import_batch_profile.yaml
69
  import_batch_profiles:
77
  import_batch_profiles:
Lines 269-274 paths: Link Here
269
    $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}"
277
    $ref: "./paths/ill_backends.yaml#/~1ill~1backends~1{ill_backend_id}"
270
  /ill/requests:
278
  /ill/requests:
271
    $ref: ./paths/ill_requests.yaml#/~1ill~1requests
279
    $ref: ./paths/ill_requests.yaml#/~1ill~1requests
280
  /illbatches:
281
    $ref: ./paths/illbatches.yaml#/~1illbatches
282
  "/illbatches/{illbatch_id}":
283
    $ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}"
284
  /illbatchstatuses:
285
    $ref: ./paths/illbatchstatuses.yaml#/~1illbatchstatuses
286
  "/illbatchstatuses/{illbatchstatus_code}":
287
    $ref: "./paths/illbatchstatuses.yaml#/~1illbatchstatuses~1{illbatchstatus_code}"
272
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
288
  "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen":
273
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
289
    $ref: "./paths/import_batches.yaml#/~1import_batches~1{import_batch_id}~1records~1{import_record_id}~1matches~1chosen"
274
  /import_batch_profiles:
290
  /import_batch_profiles:
Lines 521-526 parameters: Link Here
521
    name: hold_id
537
    name: hold_id
522
    required: true
538
    required: true
523
    type: integer
539
    type: integer
540
  illbatch_id_pp:
541
    description: Internal ILL batch identifier
542
    in: path
543
    name: illbatch_id
544
    required: true
545
    type: integer
546
  illbatchstatus_code_pp:
547
    description: Internal ILL batch status identifier
548
    in: path
549
    name: illbatchstatus_code
550
    required: true
551
    type: string
524
  import_batch_profile_id_pp:
552
  import_batch_profile_id_pp:
525
    description: Internal profile identifier
553
    description: Internal profile identifier
526
    in: path
554
    in: path
Lines 851-856 tags: Link Here
851
  - description: "Manage ILL module backends\n"
879
  - description: "Manage ILL module backends\n"
852
    name: ill_backends
880
    name: ill_backends
853
    x-displayName: ILL backends
881
    x-displayName: ILL backends
882
  - description: "Manage ILL module batches\n"
883
    name: illbatches
884
    x-displayName: ILL batches
885
  - description: "Manage ILL module batch statuses\n"
886
    name: illbatchstatuses
887
    x-displayName: ILL batch statuses
854
  - description: "Manage ILL requests\n"
888
  - description: "Manage ILL requests\n"
855
    name: ill_requests
889
    name: ill_requests
856
    x-displayName: ILL requests
890
    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 3301-3306 CREATE TABLE `illrequestattributes` ( Link Here
3301
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3301
  CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE
3302
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3302
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3303
/*!40101 SET character_set_client = @saved_cs_client */;
3303
/*!40101 SET character_set_client = @saved_cs_client */;
3304
--
3305
-- Table structure for table `illbatch_statuses`
3306
--
3307
DROP TABLE IF EXISTS `illbatch_statuses`;
3308
CREATE TABLE `illbatch_statuses` (
3309
    `id` int(11) NOT NULL auto_increment, -- Status ID
3310
    `name` varchar(100) NOT NULL,         -- Name of status
3311
    `code` varchar(20) NOT NULL,          -- Unique, immutable code for status
3312
    `is_system` int(1),                   -- Is this status required for system operation
3313
    PRIMARY KEY (`id`),
3314
    UNIQUE KEY `u_illbatchstatuses__code` (`code`)
3315
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3316
3317
--
3318
-- Table structure for table `illbatches`
3319
--
3320
DROP TABLE IF EXISTS `illbatches`;
3321
CREATE TABLE `illbatches` (
3322
    `id` int(11) NOT NULL auto_increment, -- Batch ID
3323
    `name` varchar(100) NOT NULL,         -- Unique name of batch
3324
    `backend` varchar(20) NOT NULL,       -- Name of batch backend
3325
    `borrowernumber` int(11),             -- Patron associated with batch
3326
    `branchcode` varchar(50),             -- Branch associated with batch
3327
    `statuscode` varchar(20),             -- Status of batch
3328
    PRIMARY KEY (`id`),
3329
    UNIQUE KEY `u_illbatches__name` (`name`),
3330
    CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3331
    CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
3332
    CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
3333
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3304
3334
3305
--
3335
--
3306
-- Table structure for table `illrequests`
3336
-- Table structure for table `illrequests`
Lines 3330-3335 CREATE TABLE `illrequests` ( Link Here
3330
  `notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
3360
  `notesstaff` mediumtext DEFAULT NULL COMMENT 'Staff notes attached to request',
3331
  `orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
3361
  `orderid` varchar(50) DEFAULT NULL COMMENT 'Backend id attached to request',
3332
  `backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
3362
  `backend` varchar(20) DEFAULT NULL COMMENT 'The backend used to create request',
3363
  `batch_id` int(11) COMMENT 'Optional ID of batch that this request belongs to',
3333
  PRIMARY KEY (`illrequest_id`),
3364
  PRIMARY KEY (`illrequest_id`),
3334
  KEY `illrequests_bnfk` (`borrowernumber`),
3365
  KEY `illrequests_bnfk` (`borrowernumber`),
3335
  KEY `illrequests_bcfk_2` (`branchcode`),
3366
  KEY `illrequests_bcfk_2` (`branchcode`),
Lines 3338-3344 CREATE TABLE `illrequests` ( Link Here
3338
  CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3369
  CONSTRAINT `illrequests_bcfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
3339
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3370
  CONSTRAINT `illrequests_bibfk` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE,
3340
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3371
  CONSTRAINT `illrequests_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3341
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE
3372
  CONSTRAINT `illrequests_safk` FOREIGN KEY (`status_alias`) REFERENCES `authorised_values` (`authorised_value`) ON DELETE SET NULL ON UPDATE CASCADE,
3373
  CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
3342
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3374
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3343
/*!40101 SET character_set_client = @saved_cs_client */;
3375
/*!40101 SET character_set_client = @saved_cs_client */;
3344
3376
(-)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