3 INSERT INTO config.upgrade_log (version) VALUES ('0193'); -- miker
5 CREATE OR REPLACE FUNCTION vandelay.overlay_authority_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
7 merge_profile vandelay.merge_profile%ROWTYPE;
8 dyn_profile vandelay.compile_profile%ROWTYPE;
17 SELECT b.marc INTO eg_marc
18 FROM authority.record_entry b
19 JOIN vandelay.authority_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
22 SELECT q.marc INTO v_marc
23 FROM vandelay.queued_record q
24 JOIN vandelay.authority_match m ON (m.queued_record = q.id AND q.id = import_id)
27 IF eg_marc IS NULL OR v_marc IS NULL THEN
28 -- RAISE NOTICE 'no marc for vandelay or authority record';
32 dyn_profile := vandelay.compile_profile( v_marc );
34 IF merge_profile_id IS NOT NULL THEN
35 SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
37 dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
38 dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
39 dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
40 dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
44 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
45 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
49 IF dyn_profile.replace_rule <> '' THEN
51 target_marc = eg_marc;
52 replace_rule = dyn_profile.replace_rule;
54 source_marc = eg_marc;
56 replace_rule = dyn_profile.preserve_rule;
59 UPDATE authority.record_entry
60 SET marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
64 UPDATE vandelay.queued_authority_record
65 SET imported_as = eg_id,
71 -- RAISE NOTICE 'update of authority.record_entry failed';
78 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_authority_record ( import_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
83 SELECT COUNT(*) INTO match_count FROM vandelay.authority_match WHERE queued_record = import_id;
85 IF match_count <> 1 THEN
86 -- RAISE NOTICE 'not an exact match';
90 SELECT m.eg_record INTO eg_id
91 FROM vandelay.authority_match m
92 WHERE m.queued_record = import_id
99 RETURN vandelay.overlay_authority_record( import_id, eg_id, merge_profile_id );
103 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_authority_queue ( queue_id BIGINT, merge_profile_id INT ) RETURNS SETOF BIGINT AS $$
105 queued_record vandelay.queued_authority_record%ROWTYPE;
109 FOR queued_record IN SELECT * FROM vandelay.queued_authority_record WHERE queue = queue_id AND import_time IS NULL LOOP
110 success := vandelay.auto_overlay_authority_record( queued_record.id, merge_profile_id );
113 RETURN NEXT queued_record.id;
123 CREATE OR REPLACE FUNCTION vandelay.auto_overlay_authority_queue ( queue_id BIGINT ) RETURNS SETOF BIGINT AS $$
124 SELECT * FROM vandelay.auto_overlay_authority_queue( $1, NULL );