Commit 8a07d8a 1 parent 876543c commit 8a07d8a Copy full SHA for 8a07d8a
File tree 3 files changed +103
-0
lines changed
Koha/Plugin/Com/PTFSEurope
3 files changed +103
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,26 @@ sub uninstall() {
143
143
return 1;
144
144
}
145
145
146
+ =head2 ILL availability methods
147
+
148
+ =head3 availability_check_info
149
+
150
+ Utilized if the AutoILLBackend sys pref is enabled
151
+ Required for bug 35604
152
+
153
+ =cut
154
+
155
+ sub availability_check_info {
156
+ my ( $self , $params ) = @_ ;
157
+
158
+ my $endpoint = ' /api/v1/contrib/' . $self -> api_namespace . ' /ill_backend_availability_pluginbackend?metadata=' ;
159
+
160
+ return {
161
+ endpoint => $endpoint ,
162
+ name => $metadata -> {name },
163
+ };
164
+ }
165
+
146
166
=head2 ILL backend methods
147
167
148
168
=head3 new_backend
@@ -810,6 +830,8 @@ sub capabilities {
810
830
# with Koha versions prior to bug 33716
811
831
should_display_availability => sub { _can_create_request(@_ ) },
812
832
833
+ provides_backend_availability_check => sub { return 1; },
834
+
813
835
provides_batch_requests => sub { return 1; },
814
836
815
837
# We can create ILL requests with data passed from the API
Original file line number Diff line number Diff line change
1
+ package Koha::Plugin::Com::PTFSEurope::PluginBackend::Api ;
2
+
3
+ use strict;
4
+ use warnings;
5
+
6
+ use JSON qw( decode_json ) ;
7
+ use MIME::Base64 qw( decode_base64 ) ;
8
+ use URI::Escape qw ( uri_unescape ) ;
9
+
10
+ use Mojo::Base ' Mojolicious::Controller' ;
11
+
12
+ sub ill_backend_availability {
13
+ my $controller = shift -> openapi-> valid_input or return ;
14
+
15
+ # Wait 2 seconds to simulate a real request to a third-party provider
16
+ sleep (2);
17
+
18
+ my $metadata = decode_json( decode_base64( uri_unescape( $controller -> validation-> param(' metadata' ) || ' ' ) ) );
19
+
20
+ # Example of missing required metadata for availability check
21
+ unless ( $metadata -> {doi } || $metadata -> {pubmedid } ) {
22
+ return $controller -> render(
23
+ status => 400,
24
+ openapi => {
25
+ error => ' Missing required ISBN input data' ,
26
+ }
27
+ );
28
+ }
29
+
30
+ # 50% of the time will return success
31
+ if ( rand (100) >= 50){
32
+ return $controller -> render(
33
+ status => 200,
34
+ openapi => {
35
+ success => ' ' ,
36
+ }
37
+ );
38
+ # 50% of the time will return unavailable
39
+ }else {
40
+ return $controller -> render(
41
+ status => 404,
42
+ openapi => {
43
+ error => ' Provided ISBN is not available in PluginBackend' ,
44
+ }
45
+ );
46
+ }
47
+ }
48
+
49
+ 1;
Original file line number Diff line number Diff line change
1
+ {
2
+ "/ill_backend_availability_pluginbackend" : {
3
+ "get" : {
4
+ "x-mojo-to" : " Com::PTFSEurope::PluginBackend::Api#ill_backend_availability" ,
5
+ "operationId" : " PluginBackendBackendAvailability" ,
6
+ "tags" : [" ill" ," backend_availability" ],
7
+ "parameters" : [
8
+ {
9
+ "name" : " metadata" ,
10
+ "in" : " query" ,
11
+ "description" : " The metadata to use for checking availability" ,
12
+ "required" : true ,
13
+ "type" : " string"
14
+ }
15
+ ],
16
+ "produces" : [
17
+ " application/json"
18
+ ],
19
+ "responses" : {
20
+ "200" : {
21
+ "description" : " True or false"
22
+ },
23
+ "400" : {
24
+ "description" : " Missing required metadata"
25
+ },
26
+ "404" : {
27
+ "description" : " Not found"
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments