Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priceavail #7

Merged
merged 5 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Koha/Plugin/Com/PTFSEurope/ReprintsDesk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use Cwd qw(abs_path);
use CGI;
use JSON qw( encode_json decode_json );

our $VERSION = "1.2.0";
our $VERSION = "2.0.0";

our $metadata = {
name => 'Reprints Desk',
author => 'PTFS-Europe',
date_authored => '2022-04-26',
date_updated => "2023-06-20",
date_updated => "2023-10-04",
minimum_version => '22.11.05.000',
maximum_version => undef,
version => $VERSION,
Expand Down
89 changes: 88 additions & 1 deletion Koha/Plugin/Com/PTFSEurope/ReprintsDesk/Api.pm
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,91 @@ sub GetOrderHistory {
);
}

sub CheckAvailability {
my $c = shift->openapi->valid_input or return;

my $body = $c->req->body;
my $ids_to_check = decode_json($body) || {};

my $client = _build_client('ArticleShelf_CheckAvailability');

my $smart = XML::Smart->new;
$smart->{wrapper}->{inputXmlNode}->{input}->{schemaversionid} = '1';

foreach my $id_to_check ( @{$ids_to_check} ) {
push @{ $smart->{wrapper}->{inputXmlNode}->{input}->{citations}->{citation} }, $id_to_check;
}

foreach my $citation ( @{ $smart->{wrapper}->{inputXmlNode}->{input}->{citations}->{citation} } ) {
$citation->{doi}->set_tag if !$citation->{pmid};
$citation->{doi}->set_cdata if !$citation->{pmid};
$citation->{pmid}->set_tag if !$citation->{doi};
$citation->{pmid}->set_cdata if !$citation->{doi};
}

$smart->{wrapper}->{inputXmlNode}->{input}->{citations}->{xmlns} = '';

my $dom = XML::LibXML->load_xml( string => $smart->data( noheader => 1, nometagen => 1 ) );
my @nodes = $dom->findnodes('/wrapper/inputXmlNode');

my $response = _make_request(
$client,
{ inputXmlNode => $nodes[0] },
'ArticleShelf_CheckAvailabilityResponse'
);

my $code = scalar @{ $response->{errors} } > 0 ? 500 : 200;

return $c->render(
status => $code,
openapi => $response
);
}

sub GetPriceEstimate {
my $c = shift->openapi->valid_input or return;

my $body = $c->validation->param('body');

my $plugin = Koha::Plugin::Com::PTFSEurope::ReprintsDesk->new();
my $config = decode_json( $plugin->retrieve_data("reprintsdesk_config") || {} );
my $metadata = $body || {};

my $client = _build_client('Order_GetPriceEstimate2');

my $smart = XML::Smart->new;
$smart->{wrapper}->{xmlInput}->{input}->{xmlns} = '';
$smart->{wrapper}->{xmlInput}->{input}->{schemaversionid} = '1';

$smart->{wrapper}->{xmlInput}->{input}->{standardnumber} = $metadata->{standardNumber};
$smart->{wrapper}->{xmlInput}->{input}->{standardnumber}->set_tag;

$smart->{wrapper}->{xmlInput}->{input}->{year} = $metadata->{year};
$smart->{wrapper}->{xmlInput}->{input}->{year}->set_tag;

$smart->{wrapper}->{xmlInput}->{input}->{totalpages} = 10;
$smart->{wrapper}->{xmlInput}->{input}->{totalpages}->set_tag;

$smart->{wrapper}->{xmlInput}->{input}->{pricetypeid} = $config->{pricetypeid};
$smart->{wrapper}->{xmlInput}->{input}->{pricetypeid}->set_tag;

my $dom = XML::LibXML->load_xml( string => $smart->data( noheader => 1, nometagen => 1 ) );
my @nodes = $dom->findnodes('/wrapper/xmlInput');

my $response = _make_request(
$client,
{ xmlInput => $nodes[0] },
'Order_GetPriceEstimate2Response'
);

my $code = scalar @{ $response->{errors} } > 0 ? 500 : 200;

return $c->render(
status => $code,
openapi => $response
);
}

sub Account_GetIntendedUses {
my $c = shift->openapi->valid_input or return;

Expand Down Expand Up @@ -309,7 +394,9 @@ sub _make_request {
my $errors = $response->{error} ? [ { message => $response->{error}->{reason} } ] : [];

return {
$result->{xmlData}->{_} ? ( xmlData => $result->{xmlData}->{_}->serialize ) : (),
$result->{xmlData}->{_} ? ( xmlData => $result->{xmlData}->{_}->serialize ) : (),
$result->{outputXmlNode}->{_} ? ( outputXmlNode => $result->{outputXmlNode}->{_}->serialize ) : (),
$result->{xmlOutput}->{_} ? ( xmlOutput => $result->{xmlOutput}->{_}->serialize ) : (),
result => $result,
errors => $errors
};
Expand Down
5 changes: 5 additions & 0 deletions Koha/Plugin/Com/PTFSEurope/ReprintsDesk/configure.tt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<input id="reprintsdesk_billingreference_input" class="required_input" placeholder="Enter billing reference" type="text" name="billingreference" value="[% config.billingreference | html %]">
<p>The billing reference as supplied by Reprints Desk</p>
</div>
<div id="reprintsdesk_pricetypeid" class="ill_config_field">
<label for="reprintsdesk_pricetypeid_input">Price type ID: </label>
<input id="reprintsdesk_pricetypeid_input" class="required_input" placeholder="Enter price type ID" type="text" name="pricetypeid" value="[% config.pricetypeid | html %]">
<p>The price type ID as supplied by Reprints Desk for Order_GetPriceEstimate2</p>
</div>
<h4 class="section_header">Delivery detail preferences</h4>
<div id="reprintsdesk_deliveryprofile_use_borrower_details" class="ill_config_field">
<label for="reprintsdesk_deliveryprofile_use_borrower_details_checkbox">Use borrower details if available: </label>
Expand Down
66 changes: 66 additions & 0 deletions Koha/Plugin/Com/PTFSEurope/ReprintsDesk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,72 @@
}
}
},
"/checkavailability": {
"post": {
"x-mojo-to": "Com::PTFSEurope::ReprintsDesk::Api#CheckAvailability",
"operationId": "ApiReprintsDeskILLCheckAvailability",
"tags": ["reprintsdesk", "checkavailability"],
"parameters": [
{
"name": "body",
"in": "body",
"description": "The request payload containing DOIs",
"required": true,
"schema": {
"type": "array"
}
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "The result of the checkavailability call"
}
}
}
},
"/getpriceestimate": {
"post": {
"x-mojo-to": "Com::PTFSEurope::ReprintsDesk::Api#GetPriceEstimate",
"operationId": "ApiReprintsDeskILLGetPriceEstimate",
"tags": ["reprintsdesk", "getpriceestimate"],
"parameters": [
{
"name": "body",
"in": "body",
"description": "The request payload containing standardNumber",
"required": true,
"schema": {
"type": "object",
"properties": {
"standardNumber": {
"type": "string",
"description": "The standardNumber for Order_GetPriceEstimate2",
"additionalProperties": false
},
"year": {
"type": "string",
"description": "The year for Order_GetPriceEstimate2",
"additionalProperties": false
}
},
"additionalProperties": false,
"required": [ "standardNumber" ]
}
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "The result of the getpriceestimate call"
}
}
}
},
"/account_getintendeduses": {
"get": {
"x-mojo-to": "Com::PTFSEurope::ReprintsDesk::Api#Account_GetIntendedUses",
Expand Down