From: Bill Erickson Date: Wed, 12 May 2021 20:31:20 +0000 (-0400) Subject: LP1928258 Vandelay separate bib edit update option X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=42169c4a29827c798ad299f0ac9e97a2864623bf;p=working%2FEvergreen.git LP1928258 Vandelay separate bib edit update option Adds a new field "Update Bib Edit Date" to Vandelay merge profiles which allows users to update the edit date and editor information on a merged/overlaid bib record without also having to modify the bib source. For backwards compatibility, any existing merge profiles that have "Update Bib Source" applied will also get "Update Bib Edit Date" applied. Signed-off-by: Bill Erickson Signed-off-by: Christine Morgan Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 0f0dff8a4f..62c547138d 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -201,7 +201,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + + diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 64fd6cdb15..2865b235e0 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -211,6 +211,7 @@ CREATE TABLE vandelay.merge_profile ( strip_spec TEXT, preserve_spec TEXT, update_bib_source BOOLEAN NOT NULL DEFAULT FALSE, + update_bib_editor BOOLEAN NOT NULL DEFAULT FALSE, lwm_ratio NUMERIC, CONSTRAINT vand_merge_prof_owner_name_idx UNIQUE (owner,name), CONSTRAINT add_replace_strip_or_preserve CHECK ((preserve_spec IS NOT NULL OR replace_spec IS NOT NULL) OR (preserve_spec IS NULL AND replace_spec IS NULL)) @@ -1676,7 +1677,8 @@ CREATE OR REPLACE FUNCTION vandelay.template_overlay_bib_record ( v_marc TEXT, e SELECT vandelay.template_overlay_bib_record( $1, $2, NULL); $$ LANGUAGE SQL; -CREATE OR REPLACE FUNCTION vandelay.overlay_bib_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$ +CREATE OR REPLACE FUNCTION vandelay.overlay_bib_record + ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$ DECLARE editor_string TEXT; editor_id INT; @@ -1684,7 +1686,8 @@ DECLARE v_bib_source INT; update_fields TEXT[]; update_query TEXT; - update_bib BOOL; + update_bib_source BOOL; + update_bib_editor BOOL; BEGIN SELECT q.marc, q.bib_source INTO v_marc, v_bib_source @@ -1697,51 +1700,56 @@ BEGIN RETURN FALSE; END IF; - IF vandelay.template_overlay_bib_record( v_marc, eg_id, merge_profile_id) THEN - UPDATE vandelay.queued_bib_record - SET imported_as = eg_id, - import_time = NOW() - WHERE id = import_id; + IF NOT vandelay.template_overlay_bib_record( v_marc, eg_id, merge_profile_id) THEN + -- no update happened, get outta here. + RETURN FALSE; + END IF; - SELECT q.update_bib_source INTO update_bib FROM vandelay.merge_profile q where q.id = merge_profile_Id; + UPDATE vandelay.queued_bib_record + SET imported_as = eg_id, + import_time = NOW() + WHERE id = import_id; - IF update_bib THEN - editor_string := (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1]; + SELECT q.update_bib_source INTO update_bib_source + FROM vandelay.merge_profile q where q.id = merge_profile_Id; - IF editor_string IS NOT NULL AND editor_string <> '' THEN - SELECT usr INTO editor_id FROM actor.card WHERE barcode = editor_string; + IF update_bib_source AND v_bib_source IS NOT NULL THEN + update_fields := ARRAY_APPEND(update_fields, 'source = ' || v_bib_source); + END IF; - IF editor_id IS NULL THEN - SELECT id INTO editor_id FROM actor.usr WHERE usrname = editor_string; - END IF; + SELECT q.update_bib_editor INTO update_bib_editor + FROM vandelay.merge_profile q where q.id = merge_profile_Id; - IF editor_id IS NOT NULL THEN - --only update the edit date if we have a valid editor - update_fields := ARRAY_APPEND(update_fields, 'editor = ' || editor_id || ', edit_date = NOW()'); - END IF; - END IF; + IF update_bib_editor THEN - IF v_bib_source IS NOT NULL THEN - update_fields := ARRAY_APPEND(update_fields, 'source = ' || v_bib_source); - END IF; + editor_string := (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1]; - IF ARRAY_LENGTH(update_fields, 1) > 0 THEN - update_query := 'UPDATE biblio.record_entry SET ' || ARRAY_TO_STRING(update_fields, ',') || ' WHERE id = ' || eg_id || ';'; - --RAISE NOTICE 'query: %', update_query; - EXECUTE update_query; - END IF; - END IF; + IF editor_string IS NOT NULL AND editor_string <> '' THEN + SELECT usr INTO editor_id FROM actor.card WHERE barcode = editor_string; - RETURN TRUE; - END IF; + IF editor_id IS NULL THEN + SELECT id INTO editor_id FROM actor.usr WHERE usrname = editor_string; + END IF; - -- RAISE NOTICE 'update of biblio.record_entry failed'; + IF editor_id IS NOT NULL THEN + --only update the edit date if we have a valid editor + update_fields := ARRAY_APPEND( + update_fields, 'editor = ' || editor_id || ', edit_date = NOW()'); + END IF; + END IF; + END IF; - RETURN FALSE; + IF ARRAY_LENGTH(update_fields, 1) > 0 THEN + update_query := 'UPDATE biblio.record_entry SET ' || + ARRAY_TO_STRING(update_fields, ',') || ' WHERE id = ' || eg_id || ';'; + EXECUTE update_query; + END IF; + RETURN TRUE; END; $$ LANGUAGE PLPGSQL; + CREATE OR REPLACE FUNCTION vandelay.auto_overlay_bib_record_with_best ( import_id BIGINT, merge_profile_id INT, lwm_ratio_value_p NUMERIC ) RETURNS BOOL AS $$ DECLARE eg_id BIGINT; 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 9ebc5d3a94..f7fc6862ca 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -15425,8 +15425,8 @@ INSERT INTO action_trigger.environment ( INSERT INTO vandelay.merge_profile (id, owner, name, replace_spec, update_bib_source) VALUES (1, 1, oils_i18n_gettext(1, 'Match-Only Merge', 'vmp', 'name'), '901c', false); -INSERT INTO vandelay.merge_profile (id, owner, name, preserve_spec, update_bib_source) - VALUES (2, 1, oils_i18n_gettext(2, 'Full Overlay', 'vmp', 'name'), '901c', true); +INSERT INTO vandelay.merge_profile (id, owner, name, preserve_spec, update_bib_source, update_bib_editor) + VALUES (2, 1, oils_i18n_gettext(2, 'Full Overlay', 'vmp', 'name'), '901c', true, true); SELECT SETVAL('vandelay.merge_profile_id_seq'::TEXT, 100); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-update-edit-date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-update-edit-date.sql new file mode 100644 index 0000000000..44a3fed46a --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.vandelay-update-edit-date.sql @@ -0,0 +1,84 @@ +BEGIN; + +-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); + +ALTER TABLE vandelay.merge_profile + ADD COLUMN update_bib_editor BOOLEAN NOT NULL DEFAULT FALSE; + +-- By default, updating bib source means updating the editor. +UPDATE vandelay.merge_profile SET update_bib_editor = update_bib_source; + +CREATE OR REPLACE FUNCTION vandelay.overlay_bib_record + ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$ +DECLARE + editor_string TEXT; + editor_id INT; + v_marc TEXT; + v_bib_source INT; + update_fields TEXT[]; + update_query TEXT; + update_bib_source BOOL; + update_bib_editor BOOL; +BEGIN + + SELECT q.marc, q.bib_source INTO v_marc, v_bib_source + FROM vandelay.queued_bib_record q + JOIN vandelay.bib_match m ON (m.queued_record = q.id AND q.id = import_id) + LIMIT 1; + + IF v_marc IS NULL THEN + -- RAISE NOTICE 'no marc for vandelay or bib record'; + RETURN FALSE; + END IF; + + IF NOT vandelay.template_overlay_bib_record( v_marc, eg_id, merge_profile_id) THEN + -- no update happened, get outta here. + RETURN FALSE; + END IF; + + UPDATE vandelay.queued_bib_record + SET imported_as = eg_id, + import_time = NOW() + WHERE id = import_id; + + SELECT q.update_bib_source INTO update_bib_source + FROM vandelay.merge_profile q where q.id = merge_profile_Id; + + IF update_bib_source AND v_bib_source IS NOT NULL THEN + update_fields := ARRAY_APPEND(update_fields, 'source = ' || v_bib_source); + END IF; + + SELECT q.update_bib_editor INTO update_bib_editor + FROM vandelay.merge_profile q where q.id = merge_profile_Id; + + IF update_bib_editor THEN + + editor_string := (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1]; + + IF editor_string IS NOT NULL AND editor_string <> '' THEN + SELECT usr INTO editor_id FROM actor.card WHERE barcode = editor_string; + + IF editor_id IS NULL THEN + SELECT id INTO editor_id FROM actor.usr WHERE usrname = editor_string; + END IF; + + IF editor_id IS NOT NULL THEN + --only update the edit date if we have a valid editor + update_fields := ARRAY_APPEND( + update_fields, 'editor = ' || editor_id || ', edit_date = NOW()'); + END IF; + END IF; + END IF; + + IF ARRAY_LENGTH(update_fields, 1) > 0 THEN + update_query := 'UPDATE biblio.record_entry SET ' || + ARRAY_TO_STRING(update_fields, ',') || ' WHERE id = ' || eg_id || ';'; + EXECUTE update_query; + END IF; + + RETURN TRUE; +END; +$$ LANGUAGE PLPGSQL; + +COMMIT; + diff --git a/docs/RELEASE_NOTES_NEXT/Cataloging/lp1928258-vand-set-edit-date.adoc b/docs/RELEASE_NOTES_NEXT/Cataloging/lp1928258-vand-set-edit-date.adoc new file mode 100644 index 0000000000..71f8c2120b --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/Cataloging/lp1928258-vand-set-edit-date.adoc @@ -0,0 +1,9 @@ +MARC Batch Import/Export Separate Edit Date/Editor Toggle +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Adds a new field "Update Bib Edit Date" to Vandelay merge profiles which +allows users to update the edit date and editor information on a +merged/overlaid bib record without also having to modify the bib source. + +For backwards compatibility, any existing merge profiles that have +"Update Bib Source" applied will also get "Update Bib Edit Date" applied.