[open-ils-commits] ***SPAM*** [GIT] Evergreen ILS branch rel_2_4 updated. a72b5ea9ff4b332a78f93a4cffb45ad77e910246
Evergreen Git
git at git.evergreen-ils.org
Fri Nov 1 16:56:51 EDT 2013
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".
The branch, rel_2_4 has been updated
via a72b5ea9ff4b332a78f93a4cffb45ad77e910246 (commit)
via 0089afe08d72b777bdc7696e883795021b266d46 (commit)
from e54bbbbe0c0462cbb07612f16b6c92c015ba47e4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a72b5ea9ff4b332a78f93a4cffb45ad77e910246
Author: Dan Wells <dbw2 at calvin.edu>
Date: Fri Nov 1 16:45:09 2013 -0400
Stamping 0847: improved auth overlay generation
Signed-off-by: Dan Wells <dbw2 at calvin.edu>
diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql
index 9da9581..576e38f 100644
--- a/Open-ILS/src/sql/Pg/002.schema.config.sql
+++ b/Open-ILS/src/sql/Pg/002.schema.config.sql
@@ -91,7 +91,7 @@ CREATE TRIGGER no_overlapping_deps
BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0846', :eg_version); -- eeevil/dbwells
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0847', :eg_version); -- eeevil/dbwells
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.auth_overlay_generator.sql b/Open-ILS/src/sql/Pg/upgrade/0847.function.auth_overlay_generator.sql
similarity index 98%
rename from Open-ILS/src/sql/Pg/upgrade/XXXX.function.auth_overlay_generator.sql
rename to Open-ILS/src/sql/Pg/upgrade/0847.function.auth_overlay_generator.sql
index d019c25..ea0c131 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.auth_overlay_generator.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/0847.function.auth_overlay_generator.sql
@@ -1,6 +1,6 @@
BEGIN;
-SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+SELECT evergreen.upgrade_deps_block_check('0847', :eg_version);
CREATE OR REPLACE FUNCTION authority.generate_overlay_template (source_xml TEXT) RETURNS TEXT AS $f$
DECLARE
commit 0089afe08d72b777bdc7696e883795021b266d46
Author: Mike Rylander <mrylander at gmail.com>
Date: Fri Nov 1 13:57:35 2013 -0400
Add indicators; Remove junk tags
First, we were not supplying authority tag indicators when generating the
overlay template. The xml merge function does not currently transfer
indicators, but we need to do this anyway because newer MARC::Field version
balk at fields with no indicators.
Second, PG 9.1+ adds wrapper tags to xml content that is passed to XMLELEMENT
as an array. So, we'll use XMLAGG to get around that.
Signed-off-by: Mike Rylander <mrylander at gmail.com>
Signed-off-by: Dan Wells <dbw2 at calvin.edu>
diff --git a/Open-ILS/src/sql/Pg/011.schema.authority.sql b/Open-ILS/src/sql/Pg/011.schema.authority.sql
index 4ac6b2c..73de93f 100644
--- a/Open-ILS/src/sql/Pg/011.schema.authority.sql
+++ b/Open-ILS/src/sql/Pg/011.schema.authority.sql
@@ -367,9 +367,12 @@ DECLARE
main_entry authority.control_set_authority_field%ROWTYPE;
bib_field authority.control_set_bib_field%ROWTYPE;
auth_id INT DEFAULT oils_xpath_string('//*[@tag="901"]/*[local-name()="subfield" and @code="c"]', source_xml)::INT;
+ tmp_data XML;
replace_data XML[] DEFAULT '{}'::XML[];
replace_rules TEXT[] DEFAULT '{}'::TEXT[];
auth_field XML[];
+ auth_i1 TEXT;
+ auth_i2 TEXT;
BEGIN
IF auth_id IS NULL THEN
RETURN NULL;
@@ -410,20 +413,30 @@ BEGIN
FOR main_entry IN SELECT * FROM authority.control_set_authority_field acsaf WHERE acsaf.control_set = cset AND acsaf.main_entry IS NULL LOOP
auth_field := XPATH('//*[@tag="'||main_entry.tag||'"][1]',source_xml::XML);
+ auth_i1 = (XPATH('@ind1',auth_field[1]))[1];
+ auth_i2 = (XPATH('@ind2',auth_field[1]))[1];
IF ARRAY_LENGTH(auth_field,1) > 0 THEN
FOR bib_field IN SELECT * FROM authority.control_set_bib_field WHERE authority_field = main_entry.id LOOP
- replace_data := replace_data || XMLELEMENT( name datafield, XMLATTRIBUTES(bib_field.tag AS tag), XPATH('//*[local-name()="subfield"]',auth_field[1])::XML[]);
+ SELECT XMLELEMENT( -- XMLAGG avoids magical <element> creation, but requires unnest subquery
+ name datafield,
+ XMLATTRIBUTES(bib_field.tag AS tag, auth_i1 AS ind1, auth_i2 AS ind2),
+ XMLAGG(UNNEST)
+ ) INTO tmp_data FROM UNNEST(XPATH('//*[local-name()="subfield"]', auth_field[1]));
+ replace_data := replace_data || tmp_data;
replace_rules := replace_rules || ( bib_field.tag || main_entry.sf_list || E'[0~\\)' || auth_id || '$]' );
+ tmp_data = NULL;
END LOOP;
EXIT;
END IF;
END LOOP;
+ SELECT XMLAGG(UNNEST) INTO tmp_data FROM UNNEST(replace_data);
+
RETURN XMLELEMENT(
name record,
XMLATTRIBUTES('http://www.loc.gov/MARC21/slim' AS xmlns),
XMLELEMENT( name leader, '00881nam a2200193 4500'),
- replace_data,
+ tmp_data,
XMLELEMENT(
name datafield,
XMLATTRIBUTES( '905' AS tag, ' ' AS ind1, ' ' AS ind2),
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.auth_overlay_generator.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.auth_overlay_generator.sql
new file mode 100644
index 0000000..d019c25
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.auth_overlay_generator.sql
@@ -0,0 +1,94 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION authority.generate_overlay_template (source_xml TEXT) RETURNS TEXT AS $f$
+DECLARE
+ cset INT;
+ main_entry authority.control_set_authority_field%ROWTYPE;
+ bib_field authority.control_set_bib_field%ROWTYPE;
+ auth_id INT DEFAULT oils_xpath_string('//*[@tag="901"]/*[local-name()="subfield" and @code="c"]', source_xml)::INT;
+ tmp_data XML;
+ replace_data XML[] DEFAULT '{}'::XML[];
+ replace_rules TEXT[] DEFAULT '{}'::TEXT[];
+ auth_field XML[];
+ auth_i1 TEXT;
+ auth_i2 TEXT;
+BEGIN
+ IF auth_id IS NULL THEN
+ RETURN NULL;
+ END IF;
+
+ -- Default to the LoC controll set
+ SELECT control_set INTO cset FROM authority.record_entry WHERE id = auth_id;
+
+ -- if none, make a best guess
+ IF cset IS NULL THEN
+ SELECT control_set INTO cset
+ FROM authority.control_set_authority_field
+ WHERE tag IN (
+ SELECT UNNEST(XPATH('//*[starts-with(@tag,"1")]/@tag',marc::XML)::TEXT[])
+ FROM authority.record_entry
+ WHERE id = auth_id
+ )
+ LIMIT 1;
+ END IF;
+
+ -- if STILL none, no-op change
+ IF cset IS NULL THEN
+ RETURN XMLELEMENT(
+ name record,
+ XMLATTRIBUTES('http://www.loc.gov/MARC21/slim' AS xmlns),
+ XMLELEMENT( name leader, '00881nam a2200193 4500'),
+ XMLELEMENT(
+ name datafield,
+ XMLATTRIBUTES( '905' AS tag, ' ' AS ind1, ' ' AS ind2),
+ XMLELEMENT(
+ name subfield,
+ XMLATTRIBUTES('d' AS code),
+ '901c'
+ )
+ )
+ )::TEXT;
+ END IF;
+
+ FOR main_entry IN SELECT * FROM authority.control_set_authority_field acsaf WHERE acsaf.control_set = cset AND acsaf.main_entry IS NULL LOOP
+ auth_field := XPATH('//*[@tag="'||main_entry.tag||'"][1]',source_xml::XML);
+ auth_i1 = (XPATH('@ind1',auth_field[1]))[1];
+ auth_i2 = (XPATH('@ind2',auth_field[1]))[1];
+ IF ARRAY_LENGTH(auth_field,1) > 0 THEN
+ FOR bib_field IN SELECT * FROM authority.control_set_bib_field WHERE authority_field = main_entry.id LOOP
+ SELECT XMLELEMENT( -- XMLAGG avoids magical <element> creation, but requires unnest subquery
+ name datafield,
+ XMLATTRIBUTES(bib_field.tag AS tag, auth_i1 AS ind1, auth_i2 AS ind2),
+ XMLAGG(UNNEST)
+ ) INTO tmp_data FROM UNNEST(XPATH('//*[local-name()="subfield"]', auth_field[1]));
+ replace_data := replace_data || tmp_data;
+ replace_rules := replace_rules || ( bib_field.tag || main_entry.sf_list || E'[0~\\)' || auth_id || '$]' );
+ tmp_data = NULL;
+ END LOOP;
+ EXIT;
+ END IF;
+ END LOOP;
+
+ SELECT XMLAGG(UNNEST) INTO tmp_data FROM UNNEST(replace_data);
+
+ RETURN XMLELEMENT(
+ name record,
+ XMLATTRIBUTES('http://www.loc.gov/MARC21/slim' AS xmlns),
+ XMLELEMENT( name leader, '00881nam a2200193 4500'),
+ tmp_data,
+ XMLELEMENT(
+ name datafield,
+ XMLATTRIBUTES( '905' AS tag, ' ' AS ind1, ' ' AS ind2),
+ XMLELEMENT(
+ name subfield,
+ XMLATTRIBUTES('r' AS code),
+ ARRAY_TO_STRING(replace_rules,',')
+ )
+ )
+ )::TEXT;
+END;
+$f$ STABLE LANGUAGE PLPGSQL;
+
+COMMIT;
-----------------------------------------------------------------------
Summary of changes:
Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +-
Open-ILS/src/sql/Pg/011.schema.authority.sql | 17 +++++++++-
...ql => 0847.function.auth_overlay_generator.sql} | 34 +++++++++++---------
3 files changed, 35 insertions(+), 18 deletions(-)
copy Open-ILS/src/sql/Pg/upgrade/{0612.schema.authority_overlay_protection.sql => 0847.function.auth_overlay_generator.sql} (72%)
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list