From 94252f55b82cfaa886b066a3d055b09a300fac06 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 20 Aug 2025 10:05:24 +0000 Subject: [PATCH] Bug 39345: Use data provider report release to establish service URL Signed-off-by: Eric Phetteplace Signed-off-by: Nick Clemens --- Koha/ERM/EUsage/UsageDataProvider.pm | 19 ++++++++++++------- Koha/REST/V1/ERM/EUsage/CounterRegistry.pm | 10 +++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Koha/ERM/EUsage/UsageDataProvider.pm b/Koha/ERM/EUsage/UsageDataProvider.pm index b7acc76ab53..876b6dc2f8e 100644 --- a/Koha/ERM/EUsage/UsageDataProvider.pm +++ b/Koha/ERM/EUsage/UsageDataProvider.pm @@ -269,7 +269,7 @@ Tests the connection of the harvester to the SUSHI service and returns any alert sub test_connection { my ($self) = @_; - my $url = _validate_url( $self->service_url, 'status' ); + my $url = $self->_validate_url( $self->service_url, 'status' ); $url .= 'status'; $url .= '?customer_id=' . $self->customer_id; $url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id; @@ -384,7 +384,7 @@ sub _build_url_query { $self->erm_usage_data_provider_id; } - my $url = _validate_url( $self->service_url, 'harvest' ); + my $url = $self->_validate_url( $self->service_url, 'harvest' ); $url .= lc $self->{report_type}; $url .= '?customer_id=' . $self->customer_id; @@ -401,22 +401,27 @@ sub _build_url_query { Checks whether the url ends in a trailing "/" and adds one if not -my $url = _validate_url($url, 'harvest') +my $url = $self->_validate_url($url, 'harvest') $caller is either the harvest_sushi function ("harvest") or the test_connection function ("status") =cut sub _validate_url { - my ( $url, $caller ) = @_; + my ( $self, $url, $caller ) = @_; if ( $caller eq 'harvest' ) { - # Not all urls will end in "/" - add one so they are standardised $url = _check_trailing_character($url); - # All SUSHI report requests should be to the "/reports" endpoint - # Not all providers in the counter registry include this in their data so we need to check and add it + # Default to 5.1 if anything other than '5' + my $report_release = $self->report_release eq '5' ? $self->report_release : '5.1'; + + if ( $report_release eq '5.1' ) { + my $reports_param = substr $url, -4; + $url .= 'r51/' if $reports_param ne 'r51/'; + } + my $reports_param = substr $url, -8; $url .= 'reports/' if $reports_param ne 'reports/'; } else { diff --git a/Koha/REST/V1/ERM/EUsage/CounterRegistry.pm b/Koha/REST/V1/ERM/EUsage/CounterRegistry.pm index 7cb336d86f5..8be354fd3ea 100644 --- a/Koha/REST/V1/ERM/EUsage/CounterRegistry.pm +++ b/Koha/REST/V1/ERM/EUsage/CounterRegistry.pm @@ -90,7 +90,15 @@ sub list { my @counter_5_supporting_platforms; foreach my $platform (@$result) { my $name_check = index( lc $platform->{name}, lc $search_string ); - my @services = grep { $_->{counter_release} eq '5' } @{ $platform->{sushi_services} }; + + # TODO: + # We should also consider COUNTER 5.1 here, but the COUNTER registry response is not great. + # Visit the following URL: + # /api/v1/erm/counter_registry?_per_page=-1&q={"name":"wiley"} + # Notice the response comes back as the only sushi service being counter release 5, + # but for all supported reports, both '5' and '5.1' are returned. + + my @services = grep { $_->{counter_release} eq '5' } @{ $platform->{sushi_services} }; if ( scalar(@services) > 0 && $name_check != -1 && scalar( @{ $platform->{reports} } ) > 0 ) -- 2.39.5