JBAS-2285 Retain legacy headings extraction and authorized checks
authorBill Erickson <berickxx@gmail.com>
Wed, 22 May 2019 19:47:27 +0000 (12:47 -0700)
committerBill Erickson <berickxx@gmail.com>
Wed, 22 May 2019 19:47:36 +0000 (12:47 -0700)
The 3.2-era authority headings extraction code, which uses MADs is
resulting in unexpected headings, causing browse results to appear to be
unauthorized when they aren't.

This just reverts to the 2.12-era headings extraction logic and checks
for is-unauthorized, taking the new single browse_entry table into
effect.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/schema/deploy/2.12-3.2-db-upgrade-schema.sql
KCLS/sql/schema/deploy/3.2-additions.sql

index 8d31a52..de5d11e 100644 (file)
@@ -4444,7 +4444,8 @@ BEGIN
     FOR acsaf IN SELECT * FROM authority.control_set_authority_field WHERE control_set = cset LOOP
         res.atag := acsaf.id;
 
-        IF acsaf.heading_field IS NULL THEN
+        -- KCLS JBAS-2285
+        -- IF acsaf.heading_field IS NULL THEN
             tag_used := acsaf.tag;
             nfi_used := acsaf.nfi;
             joiner_text := COALESCE(acsaf.joiner, ' ');
@@ -4486,6 +4487,9 @@ BEGIN
                 END IF;
     
             END LOOP;
+
+        -- KCLS JBAS-2285
+        /*
         ELSE
             FOR heading_row IN SELECT * FROM authority.extract_headings(marcxml, ARRAY[acsaf.heading_field]) LOOP
                 res.value := heading_row.heading;
@@ -4494,6 +4498,7 @@ BEGIN
                 RETURN NEXT res;
             END LOOP;
         END IF;
+        */
     END LOOP;
 
     RETURN;
@@ -6928,14 +6933,8 @@ BEGIN
             RETURN;
         END IF;
 
-        --Is unauthorized?
         SELECT INTO unauthorized_entry *
-        FROM metabib.browse_entry_simple_heading_map mbeshm
-        INNER JOIN authority.simple_heading ash ON ( mbeshm.simple_heading = ash.id )
-        INNER JOIN authority.control_set_authority_field acsaf ON ( acsaf.id = ash.atag )
-        JOIN authority.heading_field ahf ON (ahf.id = acsaf.heading_field)
-        WHERE mbeshm.entry = rec.id
-        AND   ahf.heading_purpose = 'variant';
+        FROM metabib.browse_authority_is_unauthorized(rec.id, fields);
 
         -- Gather aggregate data based on the MBE row we're looking at now, authority axis
         IF (unauthorized_entry.record IS NOT NULL) THEN
index 3b80005..1138c5a 100644 (file)
@@ -177,22 +177,31 @@ END $INSERT$;
 -- returns 
 CREATE OR REPLACE FUNCTION 
     metabib.browse_authority_is_unauthorized (mbe_id BIGINT, field_class TEXT)
-    RETURNS TABLE (auth_tag CHARACTER(3), atag INTEGER, auth_record BIGINT) AS 
+    RETURNS TABLE (auth_tag CHARACTER(3), atag INTEGER, record BIGINT) AS 
+$$
+    SELECT metabib.browse_authority_is_unauthorized(
+        mbe_id, (SELECT ARRAY_AGG(id) 
+            FROM config.metabib_field WHERE field_class = $2)
+    );
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION 
+    metabib.browse_authority_is_unauthorized (mbe_id BIGINT, fields INTEGER[])
+    RETURNS TABLE (auth_tag CHARACTER(3), atag INTEGER, record BIGINT) AS 
 $$
     SELECT 
         acsaf.tag AS auth_tag,
         ash.atag AS atag,
         ash.record AS auth_record
-    FROM metabib.browse_entry_simple_heading_map map
-    JOIN authority.simple_heading ash ON (ash.id = map.simple_heading)
-    JOIN authority.control_set_authority_field acsaf on (acsaf.id = ash.atag)
-    JOIN authority.heading_field ahf ON (ahf.id = acsaf.heading_field)
-    JOIN authority.control_set_auth_field_metabib_field_map_refs refs_map 
-        ON (ash.atag = refs_map.authority_field)
-    JOIN config.metabib_field cmf ON (cmf.id = refs_map.metabib_field)
-    WHERE   map.entry = $1 
-        AND cmf.field_class = $2 
-        AND ahf.heading_purpose = 'variant'
+    FROM metabib.browse_entry_simple_heading_map mbeshm
+    JOIN authority.simple_heading ash ON (mbeshm.simple_heading = ash.id)
+    JOIN authority.control_set_authority_field acsaf
+        ON (acsaf.id = ash.atag AND acsaf.tag LIKE '4__')
+    JOIN authority.control_set_auth_field_metabib_field_map_refs refs_map
+        ON (acsaf.id = refs_map.authority_field)
+    JOIN config.metabib_field cmf ON 
+        (cmf.id = refs_map.metabib_field AND cmf.id = ANY($2))
+    WHERE mbeshm.entry = $1
     LIMIT 1
 $$ LANGUAGE SQL;