[open-ils-commits] r8367 - in branches/acq-experiment/Open-ILS:
examples src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jan 9 14:58:08 EST 2008
Author: miker
Date: 2008-01-09 14:33:32 -0500 (Wed, 09 Jan 2008)
New Revision: 8367
Modified:
branches/acq-experiment/Open-ILS/examples/fm_IDL.xml
branches/acq-experiment/Open-ILS/src/sql/Pg/200.schema.acq.sql
Log:
adding picklist related model schema and IDL data
Modified: branches/acq-experiment/Open-ILS/examples/fm_IDL.xml
===================================================================
--- branches/acq-experiment/Open-ILS/examples/fm_IDL.xml 2008-01-09 16:17:20 UTC (rev 8366)
+++ branches/acq-experiment/Open-ILS/examples/fm_IDL.xml 2008-01-09 19:33:32 UTC (rev 8367)
@@ -2476,6 +2476,134 @@
</links>
</class>
+ <class id="acqpl" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist" oils_persist:tablename="acq.picklist">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Picklist ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Owner" name="owner" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="link" />
+ <field reporter:label="Name" name="name" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="Creation Time" name="create_time" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="timestamp" />
+ <field reporter:label="Edit Time" name="edit_time" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="timestamp" />
+ </fields>
+ <links>
+ <link field="owner" reltype="has_a" key="id" map="" class="au"/>
+ </links>
+ </class>
+
+ <class id="acqple" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_entry" oils_persist:tablename="acq.picklist_entry">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_entry_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Picklist Entry ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Picklist" name="picklist" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="link" />
+ <field reporter:label="Provider" name="provider" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="link" />
+ <field reporter:label="Creation Time" name="create_time" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="timestamp" />
+ <field reporter:label="Edit Time" name="edit_time" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="timestamp" />
+ <field reporter:label="MARC" name="marc" oils_obj:array_position="8" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Evergreen Bib ID" name="eg_bib_id" oils_obj:array_position="9" oils_persist:virtual="false" reporter:datatype="link" />
+ <field reporter:label="Source Label" name="source_label" oils_obj:array_position="10" oils_persist:virtual="false" reporter:datatype="text" />
+ </fields>
+ <links>
+ <link field="picklist" reltype="has_a" key="id" map="" class="acqpl"/>
+ <link field="provider" reltype="has_a" key="id" map="" class="acqpro"/>
+ <link field="eg_bib_id" reltype="has_a" key="id" map="" class="bre"/>
+ </links>
+ </class>
+
+ <class id="acqplea" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_entry_attr" oils_persist:tablename="acq.picklist_entry_attr">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_entry_attr_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Attribute Value ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Picklist Entry" name="picklist_entry" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="link" />
+ <field reporter:label="Type" name="attr_type" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Name" name="attr_name" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Value" name="atter_value" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="text" />
+ </fields>
+ <links>
+ <link field="picklist_entry" reltype="has_a" key="id" map="" class="acqpl"/>
+ </links>
+ </class>
+
+ <class id="acqplead" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_attr_definition" oils_persist:tablename="acq.picklist_attr_definition">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_attr_definition_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Definition ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Code" name="code" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Description" name="description" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="XPath" name="xpath" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="text" />
+ </fields>
+ <links>
+ <link field="picklist_entry" reltype="has_a" key="id" map="" class="acqpl"/>
+ </links>
+ </class>
+
+ <class id="acqplemad" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_marc_attr_definition" oils_persist:tablename="acq.picklist_marc_attr_definition">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_attr_definition_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Definition ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Code" name="code" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Description" name="description" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="XPath" name="xpath" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="text" />
+ </fields>
+ <links/>
+ </class>
+
+ <class id="acqplegad" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_generated_attr_definition" oils_persist:tablename="acq.picklist_generated_attr_definition">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_attr_definition_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Definition ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Code" name="code" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Description" name="description" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="XPath" name="xpath" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="text" />
+ </fields>
+ <links>
+ <link field="picklist_entry" reltype="has_a" key="id" map="" class="acqpl"/>
+ </links>
+ </class>
+
+ <class id="acqplepad" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_provider_attr_definition" oils_persist:tablename="acq.picklist_provider_attr_definition">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_attr_definition_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Definition ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Code" name="code" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Description" name="description" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="XPath" name="xpath" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Provider" name="provider" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="link" />
+ </fields>
+ <links>
+ <link field="provider" reltype="has_a" key="id" map="" class="acqpro"/>
+ </links>
+ </class>
+
+ <class id="acqpleuad" controller="open-ils.cstore open-ils.reporter-store" oils_obj:fieldmapper="acq::picklist_usr_attr_definition" oils_persist:tablename="acq.picklist_usr_attr_definition">
+ <fields oils_persist:primary="id" oils_persist:sequence="acq.picklist_attr_definition_id_seq">
+ <field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
+ <field name="ischanged" oils_obj:array_position="1" oils_persist:virtual="true" />
+ <field name="isdeleted" oils_obj:array_position="2" oils_persist:virtual="true" />
+ <field reporter:label="Definition ID" name="id" oils_obj:array_position="3" oils_persist:virtual="false" reporter:datatype="id" />
+ <field reporter:label="Code" name="code" oils_obj:array_position="4" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="Description" name="description" oils_obj:array_position="5" oils_persist:virtual="false" reporter:datatype="text" oils_persist:i18n="true" />
+ <field reporter:label="XPath" name="xpath" oils_obj:array_position="6" oils_persist:virtual="false" reporter:datatype="text" />
+ <field reporter:label="User" name="usr" oils_obj:array_position="7" oils_persist:virtual="false" reporter:datatype="link" />
+ </fields>
+ <links>
+ <link field="provider" reltype="has_a" key="id" map="" class="au"/>
+ </links>
+ </class>
+
<class id="rof" controller="open-ils.reporter-store" oils_obj:fieldmapper="reporter::output_folder" oils_persist:tablename="reporter.output_folder">
<fields oils_persist:primary="id" oils_persist:sequence="reporter.output_folder_id_seq">
<field name="isnew" oils_obj:array_position="0" oils_persist:virtual="true" />
Modified: branches/acq-experiment/Open-ILS/src/sql/Pg/200.schema.acq.sql
===================================================================
--- branches/acq-experiment/Open-ILS/src/sql/Pg/200.schema.acq.sql 2008-01-09 16:17:20 UTC (rev 8366)
+++ branches/acq-experiment/Open-ILS/src/sql/Pg/200.schema.acq.sql 2008-01-09 19:33:32 UTC (rev 8367)
@@ -76,34 +76,123 @@
owner INT NOT NULL REFERENCES actor.usr (id),
name TEXT NOT NULL,
create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ edit_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
CONSTRAINT name_once_per_owner UNIQUE (name,owner)
);
CREATE TABLE acq.picklist_entry (
- id SERIAL PRIMARY KEY,
- picklist INT NOT NULL REFERENCES acq.picklist (id),
- marc TEXT NOT NULL,
- marc_title TEXT,
- marc_author TEXT,
- marc_lanuage TEXT,
- marc_pagination TEXT,
- marc_isbn TEXT,
- marc_issn TEXT,
- marc_identifier TEXT,
- marc_publisher TEXT,
- marc_pubdate TEXT,
- marc_edition TEXT,
- marc_price TEXT,
- marc_currency TEXT REFERENCES acq.currency_type (code),
+ id BIGSERIAL PRIMARY KEY,
+ picklist INT NOT NULL REFERENCES acq.picklist (id),
+ provider INT REFERENCES acq.provider (id),
+ create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ edit_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ marc TEXT NOT NULL,
eg_bib_id INT,
- source_label TEXT,
- vendor_price TEXT,
- vendor_currency TEXT REFERENCES acq.currency_type (code),
- vendor_avail INT,
- vendor_po TEXT,
- vendor_identifier TEXT
+ source_label TEXT
);
+CREATE TABLE acq.picklist_entry_attr (
+ id BIGSERIAL PRIMARY KEY,
+ picklist_entry BIGINT NOT NULL REFERENCES acq.picklist_entry (id),
+ attr_type TEXT NOT NULL,
+ attr_name TEXT NOT NULL,
+ attr_value TEXT NOT NULL
+);
+
+CREATE OR REPLACE FUNCTION public.extract_marc_field ( TEXT, BIGINT, TEXT ) RETURNS TEXT AS $$
+ SELECT array_to_string( array_accum( output ),' ' ) FROM xpath_table('id', 'marc', $1, $3, 'id='||$2)x(id INT, output TEXT);
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION public.extract_acq_marc_field ( BIGINT, TEXT ) RETURNS TEXT AS $$
+ SELECT public.extract_marc_field('acq.picklist_entry', $1, $2);
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION public.extract_bib_marc_field ( BIGINT, TEXT ) RETURNS TEXT AS $$
+ SELECT public.extract_marc_field('biblio.record_entry', $1, $2);
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION public.extract_authority_marc_field ( BIGINT, TEXT ) RETURNS TEXT AS $$
+ SELECT public.extract_marc_field('authority.record_entry', $1, $2);
+$$ LANGUAGE SQL;
+
+CREATE TABLE acq.picklist_attr_definition (
+ id BIGSERIAL PRIMARY KEY,
+ code TEXT NOT NULL,
+ description TEXT NOT NULL,
+ xpath TEXT NOT NULL
+);
+
+CREATE TABLE acq.picklist_marc_attr_definition (
+ id BIGINT PRIMARY KEY DEFAULT NEXTVAL('acq.picklist_attr_definition_id_seq')
+) INHERITS (acq.picklist_attr_definition);
+
+CREATE TABLE acq.picklist_provider_attr_definition (
+ id BIGINT PRIMARY KEY DEFAULT NEXTVAL('acq.picklist_attr_definition_id_seq'),
+ provider INT NOT NULL REFERENCES acq.provider (id)
+) INHERITS (acq.picklist_attr_definition);
+
+CREATE TABLE acq.picklist_generated_attr_definition (
+ id BIGINT PRIMARY KEY DEFAULT NEXTVAL('acq.picklist_attr_definition_id_seq')
+) INHERITS (acq.picklist_attr_definition);
+
+CREATE TABLE acq.picklist_usr_attr_definition (
+ id BIGINT PRIMARY KEY DEFAULT NEXTVAL('acq.picklist_attr_definition_id_seq'),
+ usr INT NOT NULL REFERENCES actor.usr (id)
+) INHERITS (acq.picklist_attr_definition);
+
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('title','Title of work','//*[@tag="245"]/*[contains("abcmnopr", at code)]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('author','Author of work','//*[@tag="100" or @tag="110" or @tag="113"]/*[contains("ad", at code)]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('language','Lanuage of work','//*[@tag="240"]/*[@code="l"][1]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('pagination','Pagination','//*[@tag="300"]/*[@code="a"][1]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('isbn','ISBN','//*[@tag="020"]/*[@code="a"]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('issn','ISSN','//*[@tag="022"]/*[@code="a"]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('price','Price','//*[@tag="020" or @tag="022"]/*[@code="a"][1]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('identifier','Identifier','//*[@tag="001"]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('publisher','Publisher','//*[@tag="260"]/*[@code="b"][1]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('pubdate','Publication Date','//*[@tag="260"]/*[@code="c"][1]');
+INSERT INTO acq.picklist_marc_attr_definition ( code, description, xpath ) VALUES ('edition','Edition','//*[@tag="250"]/*[@code="a"][1]');
+
+-- For example:
+-- INSERT INTO acq.picklist_provider_attr_definition ( provider, code, description, xpath ) VALUES (1,'price','Price','//*[@tag="020" or @tag="022"]/*[@code="a"][1]');
+
+/*
+Suggested vendor fields:
+ vendor_price
+ vendor_currency
+ vendor_avail
+ vendor_po
+ vendor_identifier
+*/
+
+CREATE OR REPLACE FUNCTION public.ingest_acq_marc ( ) RETURNS TRIGGER AS $$
+DECLARE
+ value TEXT;
+ atype TEXT;
+ prov INT;
+ adef RECORD;
+BEGIN
+ FOR adef IN SELECT *,tableoid FROM acq.picklist_attr_definition LOOP
+
+ SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid;
+ IF (atype = 'picklist_provider_attr_definition') THEN
+ SELECT provider INTO prov FROM acq.picklist_provider_attr_definition WHERE id = adef.id;
+ CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider;
+ END IF;
+
+ SELECT extract_acq_marc_field(id, adef.xpath) INTO value FROM acq.picklist_entry WHERE id = NEW.id;
+ IF (value IS NOT NULL AND value <> '') THEN
+ INSERT INTO acq.picklist_entry_attr (picklist_entry, attr_type, attr_name, attr_value) VALUES (NEW.id, atype, adef.code, value);
+ END IF;
+ END LOOP;
+
+ RETURN NULL;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER ingest_picklist_entry_trigger
+ AFTER INSERT OR UPDATE ON acq.picklist_entry
+ FOR EACH ROW EXECUTE PROCEDURE public.ingest_acq_marc();
+
CREATE TABLE acq.budget (
id SERIAL PRIMARY KEY,
org INT NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE,
More information about the open-ils-commits
mailing list