display field / cmc.representative_field user/berick/lp1251394-metabib-display-fields
authorBill Erickson <berick@esilibrary.com>
Mon, 18 Nov 2013 16:48:49 +0000 (11:48 -0500)
committerBill Erickson <berick@esilibrary.com>
Mon, 18 Nov 2013 16:48:49 +0000 (11:48 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.metabib-display-field.sql

index 7babc13..d153495 100644 (file)
@@ -2414,10 +2414,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="B Weight" name="b_weight" reporter:datatype="float" />
                        <field reporter:label="C Weight" name="c_weight" reporter:datatype="float" />
                        <field reporter:label="D Weight" name="d_weight" reporter:datatype="float" />
+                       <field reporter:label="Representative Field" name="representative_field" reporter:datatype="link" />
                        <field reporter:label="Fields" name="fields" reporter:datatype="link" oils_persist:virtual="true"/>
                </fields>
                <links>
                        <link field="fields" reltype="has_many" key="name" map="" class="cmf"/>
+                       <link field="representative_field" reltype="has_a" key="id" map="" class="cmf"/>
                </links>
         <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
             <actions>
@@ -3331,15 +3333,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                oils_persist:field_safe="true"
                reporter:label="Flat Display Field Entry View" oils_persist:readonly="true">
                <oils_persist:source_definition>
-                       SELECT 
-                               mde.source, 
-                               mde.value, 
+                       SELECT
+                               mde.source,
+                               mde.value,
                                cmf.id AS field,
-                               cmf.field_class, 
-                               cmf.name, 
-                               cmf.label 
-                               FROM metabib.display_entry mde 
-                               JOIN config.metabib_field cmf ON (cmf.id = mde.field)
+                               cmf.field_class,
+                               cmf.name,
+                               cmf.label,
+                               cmc.name AS representative
+                       FROM metabib.display_entry mde
+                       JOIN config.metabib_field cmf ON (cmf.id = mde.field)                                                                                                                LEFT JOIN config.metabib_class cmc ON
+                               (cmc.name = cmf.field_class AND cmc.representative_field = cmf.id)
                </oils_persist:source_definition>
                <fields>
                        <field name="source" reporter:datatype="id" />
@@ -3348,6 +3352,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="field_class" reporter:datatype="text"/>
                        <field name="name" reporter:datatype="text"/>
                        <field name="label" reporter:datatype="text"/>
+                       <field name="representative" reporter:datatype="text"/>
                </fields>
                <links>
                        <link field="source" reltype="has_a" key="id" map="" class="bre"/>
index ac9fea8..462cab7 100644 (file)
@@ -169,6 +169,16 @@ INSERT INTO config.biblio_fingerprint (name, xpath, format, first_word)
         TRUE
     );
 
+CREATE OR REPLACE FUNCTION 
+    config.metabib_representative_field_is_valid(INTEGER, TEXT) RETURNS BOOLEAN AS $$
+    SELECT EXISTS (SELECT 1 FROM config.metabib_field WHERE id = $1 AND field_class = $2);
+$$ LANGUAGE SQL STRICT IMMUTABLE;
+
+COMMENT ON FUNCTION config.metabib_representative_field_is_valid(INTEGER, TEXT) IS $$
+Ensure the field_class value on the selected representative field matches
+the class name.
+$$;
+
 CREATE TABLE config.metabib_class (
     name     TEXT    PRIMARY KEY,
     label    TEXT    NOT NULL UNIQUE,
@@ -179,6 +189,12 @@ CREATE TABLE config.metabib_class (
     b_weight NUMERIC  DEFAULT 0.4 NOT NULL,
     c_weight NUMERIC  DEFAULT 0.2 NOT NULL,
     d_weight NUMERIC  DEFAULT 0.1 NOT NULL
+    representative_field INTEGER REFERENCES config.metabib_field(id),
+    CONSTRAINT rep_field_unique UNIQUE(representative_field),
+    CONSTRAINT rep_field_is_valid CHECK (
+        representative_field IS NULL OR
+        config.metabib_representative_field_is_valid(representative_field, name)
+    )
 );
 
 CREATE TABLE config.metabib_field (
index 7fc30a0..22c8715 100644 (file)
@@ -96,8 +96,8 @@ SELECT SETVAL('config.standing_penalty_id_seq', 100);
 
 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'identifier', oils_i18n_gettext('identifier', 'Identifier', 'cmc', 'label') );
 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'keyword', oils_i18n_gettext('keyword', 'Keyword', 'cmc', 'label') );
-INSERT INTO config.metabib_class ( name, label ) VALUES ( 'title', oils_i18n_gettext('title', 'Title', 'cmc', 'label') );
-INSERT INTO config.metabib_class ( name, label ) VALUES ( 'author', oils_i18n_gettext('author', 'Author', 'cmc', 'label') );
+INSERT INTO config.metabib_class ( name, label, representative_field ) VALUES ( 'title', oils_i18n_gettext('title', 'Title', 'cmc', 'label'), 6 );
+INSERT INTO config.metabib_class ( name, label, representative_field ) VALUES ( 'author', oils_i18n_gettext('author', 'Author', 'cmc', 'label'), 8 );
 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'subject', oils_i18n_gettext('subject', 'Subject', 'cmc', 'label') );
 INSERT INTO config.metabib_class ( name, label ) VALUES ( 'series', oils_i18n_gettext('series', 'Series', 'cmc', 'label') );
 
index b2ccd5d..775b5eb 100644 (file)
@@ -5,6 +5,25 @@ ALTER TABLE config.metabib_field
     ADD COLUMN display_xpath TEXT, 
     ADD COLUMN display_field BOOL NOT NULL DEFAULT TRUE;
 
+CREATE OR REPLACE FUNCTION 
+    config.metabib_representative_field_is_valid(INTEGER, TEXT) RETURNS BOOLEAN AS $$
+    SELECT EXISTS (SELECT 1 FROM config.metabib_field WHERE id = $1 AND field_class = $2);
+$$ LANGUAGE SQL STRICT IMMUTABLE;
+
+COMMENT ON FUNCTION config.metabib_representative_field_is_valid(INTEGER, TEXT) IS $$
+Ensure the field_class value on the selected representative field matches
+the class name.
+$$;
+
+ALTER TABLE config.metabib_class
+    ADD COLUMN representative_field 
+        INTEGER REFERENCES config.metabib_field(id),
+    ADD CONSTRAINT rep_field_unique UNIQUE(representative_field),
+    ADD CONSTRAINT rep_field_is_valid CHECK (
+        representative_field IS NULL OR
+        config.metabib_representative_field_is_valid(representative_field, name)
+    );
+
 CREATE TABLE metabib.display_entry (
     id      BIGSERIAL  PRIMARY KEY,
     source  BIGINT     NOT NULL,
@@ -398,6 +417,10 @@ UPDATE config.metabib_field SET display_field = FALSE
 INSERT INTO config.internal_flag (name, enabled) 
     VALUES ('ingest.skip_display_indexing', FALSE);
 
+-- personal author
+UPDATE config.metabib_class SET representative_field = 8 WHERE name = 'author';
+-- title proper
+UPDATE config.metabib_class SET representative_field = 6 WHERE name = 'title';
 
 COMMIT;