adding initial "full tag" authority validation
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 27 Jul 2006 20:16:01 +0000 (20:16 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 27 Jul 2006 20:16:01 +0000 (20:16 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5138 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/Authority.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/authority.pm

index 7a7135a..b8c9b2c 100644 (file)
@@ -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;
index da3c7de..913421d 100644 (file)
@@ -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;