Skip to content

Commit 8a07d8a

Browse files
committed
Add 35604 compatibility
1 parent 876543c commit 8a07d8a

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

Koha/Plugin/Com/PTFSEurope/PluginBackend.pm

+22
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ sub uninstall() {
143143
return 1;
144144
}
145145

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+
146166
=head2 ILL backend methods
147167
148168
=head3 new_backend
@@ -810,6 +830,8 @@ sub capabilities {
810830
# with Koha versions prior to bug 33716
811831
should_display_availability => sub { _can_create_request(@_) },
812832

833+
provides_backend_availability_check => sub { return 1; },
834+
813835
provides_batch_requests => sub { return 1; },
814836

815837
# We can create ILL requests with data passed from the API
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)