LP1729620: Enable org unit OAI sets
authorJane Sandberg <sandbej@linnbenton.edu>
Wed, 24 Nov 2021 18:26:27 +0000 (10:26 -0800)
committerJane Sandberg <sandbergja@gmail.com>
Mon, 28 Mar 2022 02:59:09 +0000 (19:59 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/examples/opensrf.xml.example
Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat/OAI.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat/OAI.pm
Open-ILS/src/sql/Pg/600.schema.oai.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.oai_views.sql

index 7849f26..ca1ff3e 100644 (file)
@@ -816,7 +816,6 @@ vim:et:ts=4:sw=4:
                         <!-- <repository_identifier>mydomain.org</repository_identifier> -->
                         <!-- <delimiter>:</delimiter> -->
                         <!-- <sample_identifier>oai:mydomain.org:12345</sample_identifier> -->
-                        <!-- <list_sets>false</list_sets> -->
 
                         <!--
                         The metadataformat element contains the schema for the oai_dc and marcxml metadata formats.
index 8c6f810..8910735 100644 (file)
@@ -31,6 +31,7 @@ use OpenSRF::Utils::SettingsClient;
 use OpenSRF::Utils::Logger qw($logger);
 use XML::LibXML;
 use XML::LibXSLT;
+my $U = 'OpenILS::Application::AppUtils';
 
 my (
   $_parser,
@@ -441,9 +442,8 @@ sub oai_list_retrieve {
     my $max_count       = shift;
     my $deleted_record  = shift || 'yes';
 
-    my $query = {};
+    my $query = $set ? _set_spec_to_query($set) : {};
     $query->{'rec_id'}    = ($max_count eq 1) ? $rec_id : {'>=' => $rec_id} ;
-    $query->{'set_spec'}  = $set                     if ( $set ); # unsupported
     $query->{'deleted'}   = 'f'                      unless ( $deleted_record eq 'yes' );
     $query->{'datestamp'} = {'>=', $from}            if ( $from && !$until ) ;
     $query->{'datestamp'} = {'<=', $until}           if ( !$from && $until ) ;
@@ -511,5 +511,24 @@ __PACKAGE__->register_method(
     }
 );
 
+sub _set_spec_to_query {
+    my $self            = shift;
+    my $set_spec        = shift;
+
+    if (index($set_spec, 'ORG_UNIT:') == 0) {
+        my $shortname = (split ':', $set_spec)[-1];
+        my $org_unit = OpenSRF::AppSession
+            ->create('open-ils.actor')
+            ->request('open-ils.actor.org_unit.retrieve_by_shortname', $shortname)
+            ->gather(1);
+        if ($org_unit && ref($org_unit) ne 'HASH') {
+            return {
+                'id' => {'=' => ['oai.bib_is_visible_at_org', 'id', $org_unit->id]}
+            };
+        }
+    }
+    return {};
+}
+
 
 1;
index 2d59b53..a348ad1 100644 (file)
@@ -48,7 +48,6 @@ my (
     $scheme,
     $delimiter,
     $sample_identifier,
-    $list_sets,
     $oai_metadataformats,
     $oai_sets,
     $oai,
@@ -88,12 +87,9 @@ sub child_init {
     $scheme = $app_settings->{'scheme'} || 'oai';
     $delimiter = $app_settings->{'delimiter'} || ':';
     $sample_identifier = $app_settings->{'sample_identifier'} || $scheme . $delimiter . $repository_identifier . $delimiter . '12345' ;
-    $list_sets = $app_settings->{'list_sets'} || 0;
 
-    if ( $list_sets ) {
-        _load_oaisets_authority();
-        _load_oaisets_biblio();
-    }
+    _load_oaisets_authority();
+    _load_oaisets_biblio();
     _load_oai_metadataformats();
 
     return Apache2::Const::OK;
@@ -445,12 +441,13 @@ sub _load_oaisets_biblio {
 
     return unless ($node->opac_visible =~ /^[y1t]+/i);
 
-    my $spec = ($parent) ? $parent . ':' . $node->shortname : $node->shortname ;
+    my $ou_hierarchy_string = ($parent) ? $parent . ':' . $node->shortname : $node->shortname ;
+    my $spec = 'ORG_UNIT:'.$ou_hierarchy_string;
     $oai_sets->{$spec} = {id => $node->id, record_class => 'biblio' };
     $oai_sets->{$node->id} = {setSpec => $spec, setName => $node->name, record_class => 'biblio' };
 
     my $kids = $node->children;
-    _load_oaisets_biblio($_, $types, $spec) for (@$kids);
+    _load_oaisets_biblio($_, $types, $ou_hierarchy_string) for (@$kids);
 }
 
 
index 1b5f570..677e662 100644 (file)
@@ -23,3 +23,8 @@ CREATE VIEW oai.authority AS
   ORDER BY
     are.id;
 
+CREATE OR REPLACE function oai.bib_is_visible_at_org(bib BIGINT, org INT) RETURNS BOOL AS $F$
+WITH orgs AS (SELECT array_accum(id) id FROM actor.org_unit_descendants(org))
+SELECT EXISTS (SELECT 1 FROM asset.copy_vis_attr_cache, orgs WHERE vis_attr_vector @@ search.calculate_visibility_attribute_test('circ_lib', orgs.id)::query_int AND bib=record)
+$F$ LANGUAGE SQL STABLE;
+
index 58b766a..233f490 100644 (file)
@@ -27,5 +27,10 @@ CREATE VIEW oai.authority AS
   ORDER BY
     are.id;
 
+CREATE OR REPLACE function oai.bib_is_visible_at_org(bib BIGINT, org INT) RETURNS BOOL AS $F$
+WITH orgs AS (SELECT array_accum(id) id FROM actor.org_unit_descendants(org))
+SELECT EXISTS (SELECT 1 FROM asset.copy_vis_attr_cache, orgs WHERE vis_attr_vector @@ search.calculate_visibility_attribute_test('circ_lib', orgs.id)::query_int AND bib=record)
+$F$ LANGUAGE SQL STABLE;
+
 COMMIT;