From ee4db6d7631e8ed3ed211586daa3d471070b011d Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 23 Oct 2023 11:02:36 +0000 Subject: [PATCH] Bug 34587: Improve title uniqueness rules Improve robustness of unique matching here, to make sure we always match for same title if the case, Some report rows may correspond to the same title as the previous row but have an empty match field, or alternatively come with a filled match field (e.g. DOI or Print_ISSN in TR_J4. Because of this we only verify a uniqueness match field if both current row and previous have it non-empty, otherwise we keep checking the remaining uniqueness match fields. Example of this use-case, COUNTER report: title | publisher | platform | Proprietary_ID | Print_ISSN | DOI | YOP | usages examplet | examplep | examplepl | 1 | 123 | | 2020 | usages examplet | examplep | examplepl | 1 | 123 |someDOI | 2021 | usages The above 2 rows is the same title, same publisher, same proprietary_id, same Print_ISSN, etc. It just so happens that one was returned by SUSHI with DOI and the other wasnt. These 2 rows correspond to different usage statistics by YOP, not 2 different usage_titles Signed-off-by: Jessica Zairo Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/EUsage/CounterFile.pm | 40 ++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Koha/ERM/EUsage/CounterFile.pm b/Koha/ERM/EUsage/CounterFile.pm index a5171de94c..6ca792e98c 100644 --- a/Koha/ERM/EUsage/CounterFile.pm +++ b/Koha/ERM/EUsage/CounterFile.pm @@ -444,7 +444,12 @@ sub _search_for_usage_object { } elsif ( $self->type =~ /TR/i ) { return Koha::ERM::EUsage::UsageTitles->search( { - title_doi => $row->{DOI}, + print_issn => $row->{Print_ISSN}, + online_issn => $row->{Online_ISSN}, + proprietary_id => $row->{Proprietary_ID}, + publisher => $row->{Publisher}, + platform => $row->{Platform}, + title => $row->{Title}, usage_data_provider_id => $usage_data_provider->erm_usage_data_provider_id } )->last; @@ -474,7 +479,38 @@ sub _is_same_usage_object { && $previous_object->item eq $row->{Item} && $previous_object->publisher eq $row->{Publisher}; } elsif ( $self->type =~ /TR/i ) { - return $previous_object && $previous_object->title_doi eq $row->{DOI}; + + return unless $previous_object; + + if ( $previous_object->print_issn && $row->{Print_ISSN} ){ + return unless $previous_object->print_issn eq $row->{Print_ISSN}; + } + + if ( $previous_object->online_issn && $row->{Online_ISSN} ){ + return unless $previous_object->online_issn eq $row->{Online_ISSN}; + } + + if ( $previous_object->proprietary_id && $row->{Proprietary_ID} ){ + return unless $previous_object->proprietary_id eq $row->{Proprietary_ID}; + } + + if ( $previous_object->publisher && $row->{Publisher} ){ + return unless $previous_object->publisher eq $row->{Publisher}; + } + + if ( $previous_object->platform && $row->{Platform} ){ + return unless $previous_object->platform eq $row->{Platform}; + } + + if ( $previous_object->title_doi && $row->{DOI} ){ + return unless $previous_object->title_doi eq $row->{DOI}; + } + + if ( $previous_object->title && $row->{Title} ){ + return unless $previous_object->title eq $row->{Title}; + } + + return 1; } return 0; -- 2.39.5