From 46bdc6118036d26aff1787e11c44b4eafa3f9a85 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 27 Jul 2006 20:16:01 +0000 Subject: [PATCH] adding initial "full tag" authority validation git-svn-id: svn://svn.open-ils.org/ILS/trunk@5138 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Search/Authority.pm | 14 ++++++ .../Storage/Publisher/authority.pm | 47 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm index 7a7135ae4a..b8c9b2ce1c 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm @@ -15,6 +15,20 @@ use Time::HiRes qw(time); use OpenSRF::EX qw(:try); use Digest::MD5 qw(md5_hex); +sub validate_authority { + my $self = shift; + my $client = shift; + + my $session = OpenSRF::AppSession->create("open-ils.storage"); + return $session->request( 'open-ils.storage.authority.validate.tag' => @_ )->gather(1); +} +__PACKAGE__->register_method( + method => "validate_authority", + api_name => "open-ils.search.authority.validate.tag", + argc => 4, + note => "Validates authority data from existing controlled terms", +); + sub search_authority { my $self = shift; my $client = shift; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm index da3c7deaeb..913421de07 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm @@ -18,6 +18,53 @@ $VERSION = 1; my $parser = XML::LibXML->new; +sub validate_tag { + my $self = shift; + my $client = shift; + my %args = @_; + + my @tags = @{$args{tags}}; + my @searches = @{$args{searches}}; + + my $search_table = authority::full_rec->table; + + my @values; + my @selects; + for my $t ( @tags ) { + for my $search ( @searches ) { + my $sf = $$search{subfield}; + my $term = NFD(lc($$search{term})); + + $term =~ s/\pM+//sgo; + $term =~ s/\pC+//sgo; + $term =~ s/\W+$//o; + + $tag = [$tag] if (!ref($tag)); + + push @values, $t, $sf, $term; + + push @selects, + "SELECT record FROM $search_table ". + "WHERE tag = ? AND subfield = ? AND value = ?"; + } + + my $sql = 'SELECT COUNT(DISTINCT record) FROM ('; + $sql .= 'SELECT record FROM (('.join(') INTERSECT (', @selects).')) AS x '; + $sql .= "JOIN $search_table recheck USING (record) WHERE recheck.tag = ? "; + $sql .= "GROUP BY 1 HAVING (COUNT(recheck.id) - ?) = 0) AS foo;"; + + my $count = authority::full_rec->db_Main->selectcol_arrayref( $sql, {}, @values, $t, scalar(@searches) )->[0]; + return $count if ($count > 0); + } + + return 0; +} +__PACKAGE__->register_method( + api_name => "open-ils.storage.authority.validate.tag", + method => 'validate_tag', + api_level => 1, +); + sub find_authority_marc { my $self = shift; my $client = shift; -- 2.43.2