<fields>
<field name="source" reporter:datatype="id" />
<field name="name" reporter:datatype="text"/>
+ <field name="multi" reporter:datatype="bool"/>
+ <field name="label" reporter:datatype="text"/>
<field name="field" reporter:datatype="link"/>
<field name="value" reporter:datatype="text"/>
</fields>
</actions>
</permacrud>
</class>
+ <class id="mwde" controller="open-ils.cstore open-ils.pcrud"
+ oils_persist:tablename="metabib.wide_display_entry"
+ oils_obj:fieldmapper="metabib::wide_display_entry"
+ oils_persist:field_safe="true"
+ reporter:label="Wide Display Entry"
+ oils_persist:readonly="true">
+ <fields>
+ <field name="source" reporter:datatype="id" />
+ <field name="title" reporter:datatype="text"/>
+ <field name="author" reporter:datatype="text"/>
+ <field name="subject" reporter:datatype="text"/>
+ <field name="topic_subject" reporter:datatype="text"/>
+ <!-- TODO add all well-known fields -->
+ </fields>
+ <links>
+ <link field="source" reltype="has_a" key="id" map="" class="bre"/>
+ </links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <retrieve/>
+ </actions>
+ </permacrud>
+ </class>
<class id="cdfm" controller="open-ils.cstore open-ils.pcrud"
oils_persist:tablename="config.display_field_map"
ADD COLUMN display_xpath TEXT,
ADD COLUMN display_field BOOL NOT NULL DEFAULT FALSE;
+CREATE TABLE config.display_field_map (
+ name TEXT PRIMARY KEY,
+ field INTEGER REFERENCES config.metabib_field (id),
+ multi BOOLEAN DEFAULT FALSE
+);
+
CREATE TABLE metabib.display_entry (
id BIGSERIAL PRIMARY KEY,
source BIGINT NOT NULL REFERENCES biblio.record_entry (id),
value TEXT NOT NULL
);
-CREATE TABLE config.display_field_map (
- name TEXT PRIMARY KEY,
- field INTEGER REFERENCES config.metabib_field (id),
- multi BOOLEAN DEFAULT FALSE
-);
+CREATE INDEX metabib_display_entry_field_idx ON metabib.display_entry (field);
+CREATE INDEX metabib_display_entry_source_idx ON metabib.display_entry (source);
+-- one row per display entry fleshed with field info
CREATE VIEW metabib.flat_display_entry AS
SELECT
mde.source,
JOIN config.display_field_map cdfm ON (cdfm.field = mde.field)
;
+-- like flat_display_entry except values are compressed
+-- into one row per display_field_map and JSON-ified.
CREATE VIEW metabib.compressed_display_entry AS
- SELECT
+ SELECT
source,
name,
+ multi,
+ label,
field,
- multi, -- required for group-by
CASE WHEN multi THEN
TO_JSON(ARRAY_AGG(value))
ELSE
TO_JSON(MIN(value))
END AS value
FROM metabib.flat_display_entry
- GROUP BY 1,2,3,4
+ GROUP BY 1, 2, 3, 4, 5
+;
+
+-- TODO: expand to encompass all well-known fields
+CREATE VIEW metabib.wide_display_entry AS
+ SELECT
+ mcde.source,
+ mcde_title.value AS title,
+ mcde_author.value AS author,
+ mcde_subject.value AS subject,
+ mcde_topic_subject.value AS topic_subject
+ FROM metabib.compressed_display_entry mcde
+ LEFT JOIN metabib.compressed_display_entry mcde_title
+ ON (mcde.source = mcde_title.source AND mcde_title.name = 'title')
+ LEFT JOIN metabib.compressed_display_entry mcde_author
+ ON (mcde.source = mcde_author.source AND mcde_author.name = 'author')
+ LEFT JOIN metabib.compressed_display_entry mcde_subject
+ ON (mcde.source = mcde_subject.source AND mcde_subject.name = 'subject')
+ LEFT JOIN metabib.compressed_display_entry mcde_topic_subject
+ ON (mcde.source = mcde_topic_subject.source AND mcde_topic_subject.name = 'topic_subject')
;
-CREATE INDEX metabib_display_entry_field_idx
- ON metabib.display_entry (field);
-CREATE INDEX metabib_display_entry_source_idx
- ON metabib.display_entry (source);
CREATE OR REPLACE FUNCTION metabib.display_field_normalize_trigger ()
RETURNS TRIGGER AS $$