From: Galen Charlton Date: Mon, 13 Apr 2015 16:38:45 +0000 (+0000) Subject: LP#1427287: allow coded value maps to be associated with subfields X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bbf2aff71c1a59448667ca864c110278a77f8f6c;p=working%2FEvergreen.git LP#1427287: allow coded value maps to be associated with subfields This change allows a set of values from a record attribute's coded value map to be associated with a MARC subfield and returned by the tag-table service. This is for supporting the use of controlled vocabularies for subfield values in the MARC editor. Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index a1ace2d59e..3193219c29 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -1460,12 +1460,25 @@ sub retrieve_tag_table { { from => [ 'config.ou_marc_subfields', 1, $marc_record_type, $context_ou ] } ); foreach my $sf (@$subfields) { - push @{ $sf_by_tag{$sf->{tag}} }, { + my $sf_data = { code => $sf->{code}, description => $sf->{description}, mandatory => $sf->{mandatory}, repeatable => $sf->{repeatable}, + }; + if ($sf->{value_ctype}) { + $sf_data->{value_list} = $e->json_query({ + select => { ccvm => [ + 'code', + { column => 'value', alias => 'description' } + ] + }, + from => 'ccvm', + where => { ctype => $sf->{value_ctype} }, + order_by => { ccvm => { code => {} } }, + }); } + push @{ $sf_by_tag{$sf->{tag}} }, $sf_data; } } diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 84bbbfb434..8a573c78d0 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -1160,6 +1160,9 @@ CREATE TABLE config.marc_subfield ( repeatable BOOLEAN, mandatory BOOLEAN, hidden BOOLEAN, + value_ctype TEXT + REFERENCES config.record_attr_definition (name) + DEFERRABLE INITIALLY DEFERRED, owner INTEGER REFERENCES actor.org_unit (id) -- if the owner is null, the data about the subfield is -- assumed to come from the controlling MARC standard @@ -1192,7 +1195,7 @@ ALTER TABLE config.marc_subfield CREATE OR REPLACE VIEW config.marc_field_for_ou AS WITH RECURSIVE ou_marc_fields(id, marc_format, marc_record_type, tag, name, description, fixed_field, repeatable, - mandatory, hidden, owner, depth) AS ( + mandatory, hidden, value_ctype, owner, depth) AS ( -- start with all MARC fields defined by the controlling national standard SELECT id, marc_format, marc_record_type, tag, name, description, fixed_field, repeatable, mandatory, hidden, owner, 0 FROM config.marc_field @@ -1236,12 +1239,14 @@ WITH RECURSIVE ou_marc_subfields(id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner, depth) AS ( -- start with all MARC subfields defined by the controlling national standard - SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner, 0 + SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, + hidden, value_ctype, owner, 0 FROM config.marc_subfield WHERE owner IS NULL UNION -- as well as any purely local ones that have been added - SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner, 0 + SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, + hidden, value_ctype, owner, 0 FROM config.marc_subfield WHERE ARRAY[marc_format::TEXT, marc_record_type::TEXT, tag, code] NOT IN ( SELECT ARRAY[marc_format::TEXT, marc_record_type::TEXT, tag, code] @@ -1257,6 +1262,7 @@ WITH RECURSIVE ou_marc_subfields(id, marc_format, marc_record_type, tag, code, COALESCE(c.repeatable, p.repeatable), COALESCE(c.mandatory, p.mandatory), COALESCE(c.hidden, p.hidden), + COALESCE(c.value_ctype, p.value_ctype), c.owner, depth + 1 FROM config.marc_subfield c @@ -1266,7 +1272,7 @@ WITH RECURSIVE ou_marc_subfields(id, marc_format, marc_record_type, tag, code, ) SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, - mandatory, hidden, owner, depth + mandatory, hidden, value_ctype, owner, depth FROM ou_marc_subfields; CREATE OR REPLACE FUNCTION config.ou_marc_fields(marc_format INTEGER, marc_record_type config.marc_record_type, ou INTEGER) RETURNS SETOF config.marc_field AS $func$ @@ -1286,10 +1292,11 @@ CREATE OR REPLACE FUNCTION config.ou_marc_fields(marc_format INTEGER, marc_recor $func$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION config.ou_marc_subfields(marc_format INTEGER, marc_record_type config.marc_record_type, ou INTEGER) RETURNS SETOF config.marc_subfield AS $func$ - SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner + SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, + hidden, value_ctype, owner FROM ( SELECT id, marc_format, marc_record_type, tag, code, description, - repeatable, mandatory, hidden, owner, depth, + repeatable, mandatory, hidden, value_ctype, owner, depth, MAX(depth) OVER (PARTITION BY marc_format, marc_record_type, tag, code) AS winner FROM config.marc_subfield_for_ou WHERE (owner IS NULL diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.marc-tag-tables.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.marc-tag-tables.sql index 30bbbd85d5..1ad66b2ef9 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.marc-tag-tables.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.marc-tag-tables.sql @@ -86,6 +86,9 @@ CREATE TABLE config.marc_subfield ( repeatable BOOLEAN, mandatory BOOLEAN, hidden BOOLEAN, + value_ctype TEXT + REFERENCES config.record_attr_definition (name) + DEFERRABLE INITIALLY DEFERRED, owner INTEGER REFERENCES actor.org_unit (id) -- if the owner is null, the data about the subfield is -- assumed to come from the controlling MARC standard @@ -160,14 +163,16 @@ FROM ou_marc_fields; CREATE OR REPLACE VIEW config.marc_subfield_for_ou AS WITH RECURSIVE ou_marc_subfields(id, marc_format, marc_record_type, tag, code, description, repeatable, - mandatory, hidden, owner, depth) AS ( + mandatory, hidden, value_ctype, owner, depth) AS ( -- start with all MARC subfields defined by the controlling national standard - SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner, 0 + SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, + hidden, value_ctype, owner, 0 FROM config.marc_subfield WHERE owner IS NULL UNION -- as well as any purely local ones that have been added - SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner, 0 + SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, + hidden, value_ctype, owner, 0 FROM config.marc_subfield WHERE ARRAY[marc_format::TEXT, marc_record_type::TEXT, tag, code] NOT IN ( SELECT ARRAY[marc_format::TEXT, marc_record_type::TEXT, tag, code] @@ -183,6 +188,7 @@ WITH RECURSIVE ou_marc_subfields(id, marc_format, marc_record_type, tag, code, COALESCE(c.repeatable, p.repeatable), COALESCE(c.mandatory, p.mandatory), COALESCE(c.hidden, p.hidden), + COALESCE(c.value_ctype, p.value_ctype), c.owner, depth + 1 FROM config.marc_subfield c @@ -192,7 +198,7 @@ WITH RECURSIVE ou_marc_subfields(id, marc_format, marc_record_type, tag, code, ) SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, - mandatory, hidden, owner, depth + mandatory, hidden, value_ctype, owner, depth FROM ou_marc_subfields; CREATE OR REPLACE FUNCTION config.ou_marc_fields(marc_format INTEGER, marc_record_type config.marc_record_type, ou INTEGER) RETURNS SETOF config.marc_field AS $func$ @@ -212,10 +218,11 @@ CREATE OR REPLACE FUNCTION config.ou_marc_fields(marc_format INTEGER, marc_recor $func$ LANGUAGE SQL; CREATE OR REPLACE FUNCTION config.ou_marc_subfields(marc_format INTEGER, marc_record_type config.marc_record_type, ou INTEGER) RETURNS SETOF config.marc_subfield AS $func$ - SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, hidden, owner + SELECT id, marc_format, marc_record_type, tag, code, description, repeatable, mandatory, + hidden, value_ctype, owner FROM ( SELECT id, marc_format, marc_record_type, tag, code, description, - repeatable, mandatory, hidden, owner, depth, + repeatable, mandatory, hidden, value_ctype, owner, depth, MAX(depth) OVER (PARTITION BY marc_format, marc_record_type, tag, code) AS winner FROM config.marc_subfield_for_ou WHERE (owner IS NULL