From: Bill Erickson Date: Wed, 6 Jul 2011 16:52:04 +0000 (-0400) Subject: Seed data and schema cleanup for merge X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=11218af3531a20925b6a9fdc5aa0eb97777f15a7;p=evergreen%2Fmasslnc.git Seed data and schema cleanup for merge * Updated A/T event-def ID in seed data to match master * Move schema elements into the correct order in the baseline files (mike) Signed-off-by: Mike Rylander Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 56edddd272..8095e3bbb1 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -153,7 +153,7 @@ CREATE TABLE vandelay.import_item ( definition BIGINT NOT NULL REFERENCES vandelay.import_item_attr_definition (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, import_error TEXT REFERENCES vandelay.import_error (code) ON DELETE SET NULL ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, error_detail TEXT, - imported_as BIGINT REFERENCES asset.copy (id) DEFERRABLE INITIALLY DEFERRED, + imported_as BIGINT, import_time TIMESTAMP WITH TIME ZONE, owning_lib INT, circ_lib INT, @@ -1423,269 +1423,6 @@ CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_queue ( queue_id BIGINT ) R SELECT * FROM vandelay.auto_overlay_bib_queue( $1, NULL ); $$ LANGUAGE SQL; -CREATE OR REPLACE FUNCTION vandelay.ingest_items ( import_id BIGINT, attr_def_id BIGINT ) RETURNS SETOF vandelay.import_item AS $$ -DECLARE - - owning_lib TEXT; - circ_lib TEXT; - call_number TEXT; - copy_number TEXT; - status TEXT; - location TEXT; - circulate TEXT; - deposit TEXT; - deposit_amount TEXT; - ref TEXT; - holdable TEXT; - price TEXT; - barcode TEXT; - circ_modifier TEXT; - circ_as_type TEXT; - alert_message TEXT; - opac_visible TEXT; - pub_note TEXT; - priv_note TEXT; - - attr_def RECORD; - tmp_attr_set RECORD; - attr_set vandelay.import_item%ROWTYPE; - - xpath TEXT; - -BEGIN - - SELECT * INTO attr_def FROM vandelay.import_item_attr_definition WHERE id = attr_def_id; - - IF FOUND THEN - - attr_set.definition := attr_def.id; - - -- Build the combined XPath - - owning_lib := - CASE - WHEN attr_def.owning_lib IS NULL THEN 'null()' - WHEN LENGTH( attr_def.owning_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.owning_lib || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.owning_lib - END; - - circ_lib := - CASE - WHEN attr_def.circ_lib IS NULL THEN 'null()' - WHEN LENGTH( attr_def.circ_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_lib || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_lib - END; - - call_number := - CASE - WHEN attr_def.call_number IS NULL THEN 'null()' - WHEN LENGTH( attr_def.call_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.call_number || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.call_number - END; - - copy_number := - CASE - WHEN attr_def.copy_number IS NULL THEN 'null()' - WHEN LENGTH( attr_def.copy_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.copy_number || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.copy_number - END; - - status := - CASE - WHEN attr_def.status IS NULL THEN 'null()' - WHEN LENGTH( attr_def.status ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.status || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.status - END; - - location := - CASE - WHEN attr_def.location IS NULL THEN 'null()' - WHEN LENGTH( attr_def.location ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.location || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.location - END; - - circulate := - CASE - WHEN attr_def.circulate IS NULL THEN 'null()' - WHEN LENGTH( attr_def.circulate ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circulate || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circulate - END; - - deposit := - CASE - WHEN attr_def.deposit IS NULL THEN 'null()' - WHEN LENGTH( attr_def.deposit ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit - END; - - deposit_amount := - CASE - WHEN attr_def.deposit_amount IS NULL THEN 'null()' - WHEN LENGTH( attr_def.deposit_amount ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit_amount || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit_amount - END; - - ref := - CASE - WHEN attr_def.ref IS NULL THEN 'null()' - WHEN LENGTH( attr_def.ref ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.ref || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.ref - END; - - holdable := - CASE - WHEN attr_def.holdable IS NULL THEN 'null()' - WHEN LENGTH( attr_def.holdable ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.holdable || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.holdable - END; - - price := - CASE - WHEN attr_def.price IS NULL THEN 'null()' - WHEN LENGTH( attr_def.price ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.price || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.price - END; - - barcode := - CASE - WHEN attr_def.barcode IS NULL THEN 'null()' - WHEN LENGTH( attr_def.barcode ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.barcode || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.barcode - END; - - circ_modifier := - CASE - WHEN attr_def.circ_modifier IS NULL THEN 'null()' - WHEN LENGTH( attr_def.circ_modifier ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_modifier || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_modifier - END; - - circ_as_type := - CASE - WHEN attr_def.circ_as_type IS NULL THEN 'null()' - WHEN LENGTH( attr_def.circ_as_type ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_as_type || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_as_type - END; - - alert_message := - CASE - WHEN attr_def.alert_message IS NULL THEN 'null()' - WHEN LENGTH( attr_def.alert_message ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.alert_message || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.alert_message - END; - - opac_visible := - CASE - WHEN attr_def.opac_visible IS NULL THEN 'null()' - WHEN LENGTH( attr_def.opac_visible ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.opac_visible || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.opac_visible - END; - - pub_note := - CASE - WHEN attr_def.pub_note IS NULL THEN 'null()' - WHEN LENGTH( attr_def.pub_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.pub_note || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.pub_note - END; - priv_note := - CASE - WHEN attr_def.priv_note IS NULL THEN 'null()' - WHEN LENGTH( attr_def.priv_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.priv_note || '"]' - ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.priv_note - END; - - - xpath := - owning_lib || '|' || - circ_lib || '|' || - call_number || '|' || - copy_number || '|' || - status || '|' || - location || '|' || - circulate || '|' || - deposit || '|' || - deposit_amount || '|' || - ref || '|' || - holdable || '|' || - price || '|' || - barcode || '|' || - circ_modifier || '|' || - circ_as_type || '|' || - alert_message || '|' || - pub_note || '|' || - priv_note || '|' || - opac_visible; - - -- RAISE NOTICE 'XPath: %', xpath; - - FOR tmp_attr_set IN - SELECT * - FROM oils_xpath_table( 'id', 'marc', 'vandelay.queued_bib_record', xpath, 'id = ' || import_id ) - AS t( id INT, ol TEXT, clib TEXT, cn TEXT, cnum TEXT, cs TEXT, cl TEXT, circ TEXT, - dep TEXT, dep_amount TEXT, r TEXT, hold TEXT, pr TEXT, bc TEXT, circ_mod TEXT, - circ_as TEXT, amessage TEXT, note TEXT, pnote TEXT, opac_vis TEXT ) - LOOP - - tmp_attr_set.pr = REGEXP_REPLACE(tmp_attr_set.pr, E'[^0-9\\.]', '', 'g'); - tmp_attr_set.dep_amount = REGEXP_REPLACE(tmp_attr_set.dep_amount, E'[^0-9\\.]', '', 'g'); - - tmp_attr_set.pr := NULLIF( tmp_attr_set.pr, '' ); - tmp_attr_set.dep_amount := NULLIF( tmp_attr_set.dep_amount, '' ); - - SELECT id INTO attr_set.owning_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.ol); -- INT - SELECT id INTO attr_set.circ_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.clib); -- INT - SELECT id INTO attr_set.status FROM config.copy_status WHERE LOWER(name) = LOWER(tmp_attr_set.cs); -- INT - - SELECT id INTO attr_set.location - FROM asset.copy_location - WHERE LOWER(name) = LOWER(tmp_attr_set.cl) - AND asset.copy_location.owning_lib = COALESCE(attr_set.owning_lib, attr_set.circ_lib); -- INT - - attr_set.circulate := - LOWER( SUBSTRING( tmp_attr_set.circ, 1, 1)) IN ('t','y','1') - OR LOWER(tmp_attr_set.circ) = 'circulating'; -- BOOL - - attr_set.deposit := - LOWER( SUBSTRING( tmp_attr_set.dep, 1, 1 ) ) IN ('t','y','1') - OR LOWER(tmp_attr_set.dep) = 'deposit'; -- BOOL - - attr_set.holdable := - LOWER( SUBSTRING( tmp_attr_set.hold, 1, 1 ) ) IN ('t','y','1') - OR LOWER(tmp_attr_set.hold) = 'holdable'; -- BOOL - - attr_set.opac_visible := - LOWER( SUBSTRING( tmp_attr_set.opac_vis, 1, 1 ) ) IN ('t','y','1') - OR LOWER(tmp_attr_set.opac_vis) = 'visible'; -- BOOL - - attr_set.ref := - LOWER( SUBSTRING( tmp_attr_set.r, 1, 1 ) ) IN ('t','y','1') - OR LOWER(tmp_attr_set.r) = 'reference'; -- BOOL - - attr_set.copy_number := tmp_attr_set.cnum::INT; -- INT, - attr_set.deposit_amount := tmp_attr_set.dep_amount::NUMERIC(6,2); -- NUMERIC(6,2), - attr_set.price := tmp_attr_set.pr::NUMERIC(8,2); -- NUMERIC(8,2), - - attr_set.call_number := tmp_attr_set.cn; -- TEXT - attr_set.barcode := tmp_attr_set.bc; -- TEXT, - attr_set.circ_modifier := tmp_attr_set.circ_mod; -- TEXT, - attr_set.circ_as_type := tmp_attr_set.circ_as; -- TEXT, - attr_set.alert_message := tmp_attr_set.amessage; -- TEXT, - attr_set.pub_note := tmp_attr_set.note; -- TEXT, - attr_set.priv_note := tmp_attr_set.pnote; -- TEXT, - attr_set.alert_message := tmp_attr_set.amessage; -- TEXT, - - RETURN NEXT attr_set; - - END LOOP; - - END IF; - - RETURN; - -END; -$$ LANGUAGE PLPGSQL; - - CREATE OR REPLACE FUNCTION vandelay.ingest_bib_marc ( ) RETURNS TRIGGER AS $$ DECLARE value TEXT; @@ -1709,70 +1446,6 @@ BEGIN END; $$ LANGUAGE PLPGSQL; -CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$ -DECLARE - attr_def BIGINT; - item_data vandelay.import_item%ROWTYPE; -BEGIN - - IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN - RETURN NEW; - END IF; - - SELECT item_attr_def INTO attr_def FROM vandelay.bib_queue WHERE id = NEW.queue; - - FOR item_data IN SELECT * FROM vandelay.ingest_items( NEW.id::BIGINT, attr_def ) LOOP - INSERT INTO vandelay.import_item ( - record, - definition, - owning_lib, - circ_lib, - call_number, - copy_number, - status, - location, - circulate, - deposit, - deposit_amount, - ref, - holdable, - price, - barcode, - circ_modifier, - circ_as_type, - alert_message, - pub_note, - priv_note, - opac_visible - ) VALUES ( - NEW.id, - item_data.definition, - item_data.owning_lib, - item_data.circ_lib, - item_data.call_number, - item_data.copy_number, - item_data.status, - item_data.location, - item_data.circulate, - item_data.deposit, - item_data.deposit_amount, - item_data.ref, - item_data.holdable, - item_data.price, - item_data.barcode, - item_data.circ_modifier, - item_data.circ_as_type, - item_data.alert_message, - item_data.pub_note, - item_data.priv_note, - item_data.opac_visible - ); - END LOOP; - - RETURN NULL; -END; -$func$ LANGUAGE PLPGSQL; - CREATE OR REPLACE FUNCTION vandelay.match_bib_record ( ) RETURNS TRIGGER AS $func$ DECLARE attr RECORD; @@ -1877,10 +1550,6 @@ CREATE TRIGGER ingest_bib_trigger AFTER INSERT OR UPDATE ON vandelay.queued_bib_record FOR EACH ROW EXECUTE PROCEDURE vandelay.ingest_bib_marc(); -CREATE TRIGGER ingest_item_trigger - AFTER INSERT OR UPDATE ON vandelay.queued_bib_record - FOR EACH ROW EXECUTE PROCEDURE vandelay.ingest_bib_items(); - CREATE TRIGGER zz_match_bibs_trigger BEFORE INSERT OR UPDATE ON vandelay.queued_bib_record FOR EACH ROW EXECUTE PROCEDURE vandelay.match_bib_record(); diff --git a/Open-ILS/src/sql/Pg/030.schema.metabib.sql b/Open-ILS/src/sql/Pg/030.schema.metabib.sql index 9f00d0c59a..b70fae4768 100644 --- a/Open-ILS/src/sql/Pg/030.schema.metabib.sql +++ b/Open-ILS/src/sql/Pg/030.schema.metabib.sql @@ -595,7 +595,7 @@ CREATE OR REPLACE FUNCTION biblio.marc21_extract_fixed_field( rid BIGINT, ff TEX SELECT * FROM vandelay.marc21_extract_fixed_field( (SELECT marc FROM biblio.record_entry WHERE id = $1), $2 ); $func$ LANGUAGE SQL; -CREATE TYPE biblio.record_ff_map AS (record BIGINT, ff_name TEXT, ff_value TEXT); +-- CREATE TYPE biblio.record_ff_map AS (record BIGINT, ff_name TEXT, ff_value TEXT); CREATE OR REPLACE FUNCTION vandelay.marc21_extract_all_fixed_fields( marc TEXT ) RETURNS SETOF biblio.record_ff_map AS $func$ DECLARE tag_data TEXT; diff --git a/Open-ILS/src/sql/Pg/800.fkeys.sql b/Open-ILS/src/sql/Pg/800.fkeys.sql index d0ee8877c2..ad05dd7109 100644 --- a/Open-ILS/src/sql/Pg/800.fkeys.sql +++ b/Open-ILS/src/sql/Pg/800.fkeys.sql @@ -82,6 +82,8 @@ ALTER TABLE serial.unit ADD CONSTRAINT serial_unit_call_number_fkey FOREIGN KEY ALTER TABLE serial.unit ADD CONSTRAINT serial_unit_creator_fkey FOREIGN KEY (creator) REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; ALTER TABLE serial.unit ADD CONSTRAINT serial_unit_editor_fkey FOREIGN KEY (editor) REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE vandelay.import_item ADD CONSTRAINT imported_as_fkey FOREIGN KEY (imported_as) REFERENCES asset.copy (id) DEFERRABLE INITIALLY DEFERRED; + ALTER TABLE asset.copy_note ADD CONSTRAINT asset_copy_note_copy_fkey FOREIGN KEY (owning_copy) REFERENCES asset.copy (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE asset.copy_note ADD CONSTRAINT asset_copy_note_creator_fkey FOREIGN KEY (creator) REFERENCES actor.usr (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index fe7618deca..c7372edcf5 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -8816,13 +8816,7 @@ INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) ), 'bool' ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'general.unknown', oils_i18n_gettext('general.unknown', 'Import or Overlay failed', 'vie', 'description') ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'import.item.duplicate.barcode', oils_i18n_gettext('import.item.duplicate.barcode', 'Import failed due to barcode collision', 'vie', 'description') ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'import.duplicate.sysid', oils_i18n_gettext('import.duplicate.sysid', 'Import failed due to system id collision', 'vie', 'description') ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'overlay.missing.sysid', oils_i18n_gettext('overlay.missing.sysid', 'Overlay failed due to missing system id', 'vie', 'description') ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'import.auth.duplicate.acn', oils_i18n_gettext('import.auth.duplicate.acn', 'Import failed due to Accession Number collision', 'vie', 'description') ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'import.xml.malformed', oils_i18n_gettext('import.xml.malformed', 'Malformed record cause Import failure', 'vie', 'description') ); -INSERT INTO vandelay.import_error ( code, description ) VALUES ( 'overlay.xml.malformed', oils_i18n_gettext('overlay.xml.malformed', 'Malformed record cause Overlay failure', 'vie', 'description') ); + ---------------------------------------------------------------- -- Seed data for queued record/item exports ---------------------------------------------------------------- @@ -8940,7 +8934,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 38, + 39, TRUE, 1, 'Print Output for Queued Bib Records', @@ -8982,8 +8976,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 38, 'attributes') - ,( 38, 'queue') + 39, 'attributes') + ,( 39, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -8998,7 +8992,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 39, + 40, TRUE, 1, 'CSV Output for Queued Bib Records', @@ -9017,8 +9011,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 39, 'attributes') - ,( 39, 'queue') + 40, 'attributes') + ,( 40, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -9033,7 +9027,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 40, + 41, TRUE, 1, 'Email Output for Queued Bib Records', @@ -9079,9 +9073,9 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 40, 'attributes') - ,( 40, 'queue') - ,( 40, 'queue.owner') + 41, 'attributes') + ,( 41, 'queue') + ,( 41, 'queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -9096,7 +9090,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 41, + 42, TRUE, 1, 'Print Output for Queued Authority Records', @@ -9124,8 +9118,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 41, 'attributes') - ,( 41, 'queue') + 42, 'attributes') + ,( 42, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -9140,7 +9134,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 42, + 43, TRUE, 1, 'CSV Output for Queued Authority Records', @@ -9159,8 +9153,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 42, 'attributes') - ,( 42, 'queue') + 43, 'attributes') + ,( 43, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -9175,7 +9169,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 43, + 44, TRUE, 1, 'Email Output for Queued Authority Records', @@ -9207,9 +9201,9 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 43, 'attributes') - ,( 43, 'queue') - ,( 43, 'queue.owner') + 44, 'attributes') + ,( 44, 'queue') + ,( 44, 'queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -9224,7 +9218,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 44, + 45, TRUE, 1, 'Print Output for Import Items from Queued Bib Records', @@ -9276,10 +9270,10 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 44, 'record') - ,( 44, 'record.attributes') - ,( 44, 'record.queue') - ,( 44, 'record.queue.owner') + 45, 'record') + ,( 45, 'record.attributes') + ,( 45, 'record.queue') + ,( 45, 'record.queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -9294,7 +9288,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 45, + 46, TRUE, 1, 'CSV Output for Import Items from Queued Bib Records', @@ -9313,10 +9307,10 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 45, 'record') - ,( 45, 'record.attributes') - ,( 45, 'record.queue') - ,( 45, 'record.queue.owner') + 46, 'record') + ,( 46, 'record.attributes') + ,( 46, 'record.queue') + ,( 46, 'record.queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -9331,7 +9325,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 46, + 47, TRUE, 1, 'Email Output for Import Items from Queued Bib Records', @@ -9386,10 +9380,10 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 46, 'record') - ,( 46, 'record.attributes') - ,( 46, 'record.queue') - ,( 46, 'record.queue.owner') + 47, 'record') + ,( 47, 'record.attributes') + ,( 47, 'record.queue') + ,( 47, 'record.queue.owner') ; diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 0152417784..0faeea6cb8 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1457,3 +1457,334 @@ BEGIN RETURN config.interval_to_seconds( interval_string::INTERVAL ); END; $$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION vandelay.ingest_items ( import_id BIGINT, attr_def_id BIGINT ) RETURNS SETOF vandelay.import_item AS $$ +DECLARE + + owning_lib TEXT; + circ_lib TEXT; + call_number TEXT; + copy_number TEXT; + status TEXT; + location TEXT; + circulate TEXT; + deposit TEXT; + deposit_amount TEXT; + ref TEXT; + holdable TEXT; + price TEXT; + barcode TEXT; + circ_modifier TEXT; + circ_as_type TEXT; + alert_message TEXT; + opac_visible TEXT; + pub_note TEXT; + priv_note TEXT; + + attr_def RECORD; + tmp_attr_set RECORD; + attr_set vandelay.import_item%ROWTYPE; + + xpath TEXT; + +BEGIN + + SELECT * INTO attr_def FROM vandelay.import_item_attr_definition WHERE id = attr_def_id; + + IF FOUND THEN + + attr_set.definition := attr_def.id; + + -- Build the combined XPath + + owning_lib := + CASE + WHEN attr_def.owning_lib IS NULL THEN 'null()' + WHEN LENGTH( attr_def.owning_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.owning_lib || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.owning_lib + END; + + circ_lib := + CASE + WHEN attr_def.circ_lib IS NULL THEN 'null()' + WHEN LENGTH( attr_def.circ_lib ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_lib || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_lib + END; + + call_number := + CASE + WHEN attr_def.call_number IS NULL THEN 'null()' + WHEN LENGTH( attr_def.call_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.call_number || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.call_number + END; + + copy_number := + CASE + WHEN attr_def.copy_number IS NULL THEN 'null()' + WHEN LENGTH( attr_def.copy_number ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.copy_number || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.copy_number + END; + + status := + CASE + WHEN attr_def.status IS NULL THEN 'null()' + WHEN LENGTH( attr_def.status ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.status || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.status + END; + + location := + CASE + WHEN attr_def.location IS NULL THEN 'null()' + WHEN LENGTH( attr_def.location ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.location || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.location + END; + + circulate := + CASE + WHEN attr_def.circulate IS NULL THEN 'null()' + WHEN LENGTH( attr_def.circulate ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circulate || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circulate + END; + + deposit := + CASE + WHEN attr_def.deposit IS NULL THEN 'null()' + WHEN LENGTH( attr_def.deposit ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit + END; + + deposit_amount := + CASE + WHEN attr_def.deposit_amount IS NULL THEN 'null()' + WHEN LENGTH( attr_def.deposit_amount ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.deposit_amount || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.deposit_amount + END; + + ref := + CASE + WHEN attr_def.ref IS NULL THEN 'null()' + WHEN LENGTH( attr_def.ref ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.ref || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.ref + END; + + holdable := + CASE + WHEN attr_def.holdable IS NULL THEN 'null()' + WHEN LENGTH( attr_def.holdable ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.holdable || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.holdable + END; + + price := + CASE + WHEN attr_def.price IS NULL THEN 'null()' + WHEN LENGTH( attr_def.price ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.price || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.price + END; + + barcode := + CASE + WHEN attr_def.barcode IS NULL THEN 'null()' + WHEN LENGTH( attr_def.barcode ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.barcode || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.barcode + END; + + circ_modifier := + CASE + WHEN attr_def.circ_modifier IS NULL THEN 'null()' + WHEN LENGTH( attr_def.circ_modifier ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_modifier || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_modifier + END; + + circ_as_type := + CASE + WHEN attr_def.circ_as_type IS NULL THEN 'null()' + WHEN LENGTH( attr_def.circ_as_type ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.circ_as_type || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.circ_as_type + END; + + alert_message := + CASE + WHEN attr_def.alert_message IS NULL THEN 'null()' + WHEN LENGTH( attr_def.alert_message ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.alert_message || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.alert_message + END; + + opac_visible := + CASE + WHEN attr_def.opac_visible IS NULL THEN 'null()' + WHEN LENGTH( attr_def.opac_visible ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.opac_visible || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.opac_visible + END; + + pub_note := + CASE + WHEN attr_def.pub_note IS NULL THEN 'null()' + WHEN LENGTH( attr_def.pub_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.pub_note || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.pub_note + END; + priv_note := + CASE + WHEN attr_def.priv_note IS NULL THEN 'null()' + WHEN LENGTH( attr_def.priv_note ) = 1 THEN '//*[@tag="' || attr_def.tag || '"]/*[@code="' || attr_def.priv_note || '"]' + ELSE '//*[@tag="' || attr_def.tag || '"]/*' || attr_def.priv_note + END; + + + xpath := + owning_lib || '|' || + circ_lib || '|' || + call_number || '|' || + copy_number || '|' || + status || '|' || + location || '|' || + circulate || '|' || + deposit || '|' || + deposit_amount || '|' || + ref || '|' || + holdable || '|' || + price || '|' || + barcode || '|' || + circ_modifier || '|' || + circ_as_type || '|' || + alert_message || '|' || + pub_note || '|' || + priv_note || '|' || + opac_visible; + + -- RAISE NOTICE 'XPath: %', xpath; + + FOR tmp_attr_set IN + SELECT * + FROM oils_xpath_table( 'id', 'marc', 'vandelay.queued_bib_record', xpath, 'id = ' || import_id ) + AS t( id INT, ol TEXT, clib TEXT, cn TEXT, cnum TEXT, cs TEXT, cl TEXT, circ TEXT, + dep TEXT, dep_amount TEXT, r TEXT, hold TEXT, pr TEXT, bc TEXT, circ_mod TEXT, + circ_as TEXT, amessage TEXT, note TEXT, pnote TEXT, opac_vis TEXT ) + LOOP + + tmp_attr_set.pr = REGEXP_REPLACE(tmp_attr_set.pr, E'[^0-9\\.]', '', 'g'); + tmp_attr_set.dep_amount = REGEXP_REPLACE(tmp_attr_set.dep_amount, E'[^0-9\\.]', '', 'g'); + + tmp_attr_set.pr := NULLIF( tmp_attr_set.pr, '' ); + tmp_attr_set.dep_amount := NULLIF( tmp_attr_set.dep_amount, '' ); + + SELECT id INTO attr_set.owning_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.ol); -- INT + SELECT id INTO attr_set.circ_lib FROM actor.org_unit WHERE shortname = UPPER(tmp_attr_set.clib); -- INT + SELECT id INTO attr_set.status FROM config.copy_status WHERE LOWER(name) = LOWER(tmp_attr_set.cs); -- INT + + SELECT id INTO attr_set.location + FROM asset.copy_location + WHERE LOWER(name) = LOWER(tmp_attr_set.cl) + AND asset.copy_location.owning_lib = COALESCE(attr_set.owning_lib, attr_set.circ_lib); -- INT + + attr_set.circulate := + LOWER( SUBSTRING( tmp_attr_set.circ, 1, 1)) IN ('t','y','1') + OR LOWER(tmp_attr_set.circ) = 'circulating'; -- BOOL + + attr_set.deposit := + LOWER( SUBSTRING( tmp_attr_set.dep, 1, 1 ) ) IN ('t','y','1') + OR LOWER(tmp_attr_set.dep) = 'deposit'; -- BOOL + + attr_set.holdable := + LOWER( SUBSTRING( tmp_attr_set.hold, 1, 1 ) ) IN ('t','y','1') + OR LOWER(tmp_attr_set.hold) = 'holdable'; -- BOOL + + attr_set.opac_visible := + LOWER( SUBSTRING( tmp_attr_set.opac_vis, 1, 1 ) ) IN ('t','y','1') + OR LOWER(tmp_attr_set.opac_vis) = 'visible'; -- BOOL + + attr_set.ref := + LOWER( SUBSTRING( tmp_attr_set.r, 1, 1 ) ) IN ('t','y','1') + OR LOWER(tmp_attr_set.r) = 'reference'; -- BOOL + + attr_set.copy_number := tmp_attr_set.cnum::INT; -- INT, + attr_set.deposit_amount := tmp_attr_set.dep_amount::NUMERIC(6,2); -- NUMERIC(6,2), + attr_set.price := tmp_attr_set.pr::NUMERIC(8,2); -- NUMERIC(8,2), + + attr_set.call_number := tmp_attr_set.cn; -- TEXT + attr_set.barcode := tmp_attr_set.bc; -- TEXT, + attr_set.circ_modifier := tmp_attr_set.circ_mod; -- TEXT, + attr_set.circ_as_type := tmp_attr_set.circ_as; -- TEXT, + attr_set.alert_message := tmp_attr_set.amessage; -- TEXT, + attr_set.pub_note := tmp_attr_set.note; -- TEXT, + attr_set.priv_note := tmp_attr_set.pnote; -- TEXT, + attr_set.alert_message := tmp_attr_set.amessage; -- TEXT, + + RETURN NEXT attr_set; + + END LOOP; + + END IF; + + RETURN; + +END; +$$ LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION vandelay.ingest_bib_items ( ) RETURNS TRIGGER AS $func$ +DECLARE + attr_def BIGINT; + item_data vandelay.import_item%ROWTYPE; +BEGIN + + IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN + RETURN NEW; + END IF; + + SELECT item_attr_def INTO attr_def FROM vandelay.bib_queue WHERE id = NEW.queue; + + FOR item_data IN SELECT * FROM vandelay.ingest_items( NEW.id::BIGINT, attr_def ) LOOP + INSERT INTO vandelay.import_item ( + record, + definition, + owning_lib, + circ_lib, + call_number, + copy_number, + status, + location, + circulate, + deposit, + deposit_amount, + ref, + holdable, + price, + barcode, + circ_modifier, + circ_as_type, + alert_message, + pub_note, + priv_note, + opac_visible + ) VALUES ( + NEW.id, + item_data.definition, + item_data.owning_lib, + item_data.circ_lib, + item_data.call_number, + item_data.copy_number, + item_data.status, + item_data.location, + item_data.circulate, + item_data.deposit, + item_data.deposit_amount, + item_data.ref, + item_data.holdable, + item_data.price, + item_data.barcode, + item_data.circ_modifier, + item_data.circ_as_type, + item_data.alert_message, + item_data.pub_note, + item_data.priv_note, + item_data.opac_visible + ); + END LOOP; + + RETURN NULL; +END; +$func$ LANGUAGE PLPGSQL; + +CREATE TRIGGER ingest_item_trigger + AFTER INSERT OR UPDATE ON vandelay.queued_bib_record + FOR EACH ROW EXECUTE PROCEDURE vandelay.ingest_bib_items(); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.vandelay-record-matching-and-quality.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.vandelay-record-matching-and-quality.sql index 5093d5f722..34a0b90d11 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.vandelay-record-matching-and-quality.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.vandelay-record-matching-and-quality.sql @@ -1140,7 +1140,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 38, + 39, TRUE, 1, 'Print Output for Queued Bib Records', @@ -1182,8 +1182,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 38, 'attributes') - ,( 38, 'queue') + 39, 'attributes') + ,( 39, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -1198,7 +1198,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 39, + 40, TRUE, 1, 'CSV Output for Queued Bib Records', @@ -1217,8 +1217,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 39, 'attributes') - ,( 39, 'queue') + 40, 'attributes') + ,( 40, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -1233,7 +1233,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 40, + 41, TRUE, 1, 'Email Output for Queued Bib Records', @@ -1279,9 +1279,9 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 40, 'attributes') - ,( 40, 'queue') - ,( 40, 'queue.owner') + 41, 'attributes') + ,( 41, 'queue') + ,( 41, 'queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -1296,7 +1296,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 41, + 42, TRUE, 1, 'Print Output for Queued Authority Records', @@ -1324,8 +1324,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 41, 'attributes') - ,( 41, 'queue') + 42, 'attributes') + ,( 42, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -1340,7 +1340,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 42, + 43, TRUE, 1, 'CSV Output for Queued Authority Records', @@ -1359,8 +1359,8 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 42, 'attributes') - ,( 42, 'queue') + 43, 'attributes') + ,( 43, 'queue') ; INSERT INTO action_trigger.event_definition ( @@ -1375,7 +1375,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 43, + 44, TRUE, 1, 'Email Output for Queued Authority Records', @@ -1407,9 +1407,9 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 43, 'attributes') - ,( 43, 'queue') - ,( 43, 'queue.owner') + 44, 'attributes') + ,( 44, 'queue') + ,( 44, 'queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -1424,7 +1424,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 44, + 45, TRUE, 1, 'Print Output for Import Items from Queued Bib Records', @@ -1476,10 +1476,10 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 44, 'record') - ,( 44, 'record.attributes') - ,( 44, 'record.queue') - ,( 44, 'record.queue.owner') + 45, 'record') + ,( 45, 'record.attributes') + ,( 45, 'record.queue') + ,( 45, 'record.queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -1494,7 +1494,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 45, + 46, TRUE, 1, 'CSV Output for Import Items from Queued Bib Records', @@ -1513,10 +1513,10 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 45, 'record') - ,( 45, 'record.attributes') - ,( 45, 'record.queue') - ,( 45, 'record.queue.owner') + 46, 'record') + ,( 46, 'record.attributes') + ,( 46, 'record.queue') + ,( 46, 'record.queue.owner') ; INSERT INTO action_trigger.event_definition ( @@ -1531,7 +1531,7 @@ INSERT INTO action_trigger.event_definition ( granularity, template ) VALUES ( - 46, + 47, TRUE, 1, 'Email Output for Import Items from Queued Bib Records', @@ -1586,10 +1586,10 @@ $$ ; INSERT INTO action_trigger.environment ( event_def, path) VALUES ( - 46, 'record') - ,( 46, 'record.attributes') - ,( 46, 'record.queue') - ,( 46, 'record.queue.owner') + 47, 'record') + ,( 47, 'record.attributes') + ,( 47, 'record.queue') + ,( 47, 'record.queue.owner') ;