From d7da72ece09cd8ec9bf1406f5674afc3101cd1ad Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 20 Aug 2008 12:08:48 +0000 Subject: [PATCH 1/1] Vandelay item extraction and field removal; setting true AND false values for booleans on export, instead of just the non-default value git-svn-id: svn://svn.open-ils.org/ILS/trunk@10378 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/WWW/Exporter.pm | 8 +- Open-ILS/src/sql/Pg/012.schema.vandelay.sql | 407 +++++++++++++++++- 2 files changed, 406 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/Exporter.pm b/Open-ILS/src/perlmods/OpenILS/WWW/Exporter.pm index fba5fe6d85..e5713bc70d 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/Exporter.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/Exporter.pm @@ -253,10 +253,10 @@ sub handler { p => $cp->barcode, ($cp->price ? ( y => $cp->price ) : ()), ($cp->copy_number ? ( t => $cp->copy_number ) : ()), - ($cp->ref eq 't' ? ( x => 'reference' ) : ()), - ($cp->holdable eq 'f' ? ( x => 'unholdable' ) : ()), - ($cp->circulate eq 'f' ? ( x => 'noncirculating' ) : ()), - ($cp->opac_visible eq 'f' ? ( x => 'hidden' ) : ()), + ($cp->ref eq 't' ? ( x => 'reference' ) : ( x => 'nonreference' )), + ($cp->holdable eq 'f' ? ( x => 'unholdable' ) : ( x => 'holdable' )), + ($cp->circulate eq 'f' ? ( x => 'noncirculating' ) : ( x => 'circulating' )), + ($cp->opac_visible eq 'f' ? ( x => 'hidden' ) : ( x => 'visible' )), z => $statuses{$cp->status}->name, ) ); diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 3475e199f0..c481a879d7 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -42,16 +42,18 @@ INSERT INTO vandelay.bib_attr_definition ( code, description, xpath ) VALUES ('p INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident, remove ) VALUES ('isbn','ISBN','//*[@tag="020"]/*[@code="a"]', TRUE, $r$(?:-|\s.+$)$r$); INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident, remove ) VALUES ('issn','ISSN','//*[@tag="022"]/*[@code="a"]', TRUE, $r$(?:-|\s.+$)$r$); INSERT INTO vandelay.bib_attr_definition ( code, description, xpath ) VALUES ('price','Price','//*[@tag="020" or @tag="022"]/*[@code="c"][1]'); -INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident ) VALUES ('rec_identifier','Identifier','//*[@tag="001"]', TRUE); -INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident ) VALUES ('eg_identifier','Identifier','//*[@tag="901"]/*[@code="c"]', TRUE); -INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident ) VALUES ('eg_tcn','Identifier','//*[@tag="901"]/*[@code="a"]', TRUE); +INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident ) VALUES ('rec_identifier','Accession Number','//*[@tag="001"]', TRUE); +INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident ) VALUES ('eg_tcn','TCN Value','//*[@tag="901"]/*[@code="a"]', TRUE); +INSERT INTO vandelay.bib_attr_definition ( code, description, xpath ) VALUES ('eg_tcn_source','TCN Source','//*[@tag="901"]/*[@code="b"]', TRUE); +INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, ident ) VALUES ('eg_identifier','Internal ID','//*[@tag="901"]/*[@code="c"]', TRUE); INSERT INTO vandelay.bib_attr_definition ( code, description, xpath ) VALUES ('publisher','Publisher','//*[@tag="260"]/*[@code="b"][1]'); INSERT INTO vandelay.bib_attr_definition ( code, description, xpath, remove ) VALUES ('pubdate','Publication Date','//*[@tag="260"]/*[@code="c"][1]',$r$\D$r$); INSERT INTO vandelay.bib_attr_definition ( code, description, xpath ) VALUES ('edition','Edition','//*[@tag="250"]/*[@code="a"][1]'); CREATE TABLE vandelay.bib_queue ( - queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type = 'bib'), + queue_type TEXT NOT NULL DEFAULT 'bib' CHECK (queue_type = 'bib'), + item_attr_def TEXT REFERENCES vandelay.import_item_attr_definition (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, CONSTRAINT vand_bib_queue_name_once_per_owner_const UNIQUE (owner,name,queue_type) ) INHERITS (vandelay.queue); ALTER TABLE vandelay.bib_queue ADD PRIMARY KEY (id); @@ -75,9 +77,404 @@ CREATE TABLE vandelay.bib_match ( field_type TEXT NOT NULL CHECK (field_type in ('isbn','tcn_value','id')), matched_attr INT REFERENCES vandelay.queued_bib_record_attr (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, queued_record BIGINT REFERENCES vandelay.queued_bib_record (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, - eg_record BIGINT REFERENCES biblio.record_entry (id) DEFERRABLE INITIALLY DEFERRED + eg_record BIGINT REFERENCES biblio.record_entry (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +-- Each TEXT field (other than 'name') should hold an XPath predicate for pulling the data needed +-- DROP TABLE vandelay.import_item_attr_definition CASCADE; +CREATE TABLE vandelay.import_item_attr_definition ( + id BIGSERIAL PRIMARY KEY, + owner INT NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + name TEXT NOT NULL, + tag TEXT NOT NULL, + keep BOOL NOT NULL DEFAULT FALSE, + owning_lib TEXT, + circ_lib TEXT, + call_number TEXT, + copy_number TEXT, + status TEXT, + location TEXT, + circulate TEXT, + deposit TEXT, + deposit_amount TEXT, + ref TEXT, + holdable TEXT, + price TEXT, + barcode TEXT, + circ_modifier TEXT, + circ_as_type TEXT, + alert_message TEXT, + opac_visible TEXT, + pub_note_title TEXT, + pub_note TEXT, + priv_note_title TEXT, + priv_note TEXT, + CONSTRAINT vand_import_item_attr_def_idx UNIQUE (owner,name) +); + +INSERT INTO vandelay.import_item_attr_definition ( + owner, name, tag, owning_lib, circ_lib, location, + call_number, circ_modifier, barcode, price, copy_number, + circulate, ref, holdable, opac_visible, status +) VALUES ( + 1, + 'Evergreen 852 export format', + '852', + '[@code = "b"][1]', + '[@code = "b"][2]', + 'c', + 'j', + 'g', + 'p', + 'y', + 't', + '[@code = "x" and text() = "ncirculating"]', + '[@code = "x" and text() = "reference"]', + '[@code = "x" and text() = "holdable"]', + '[@code = "x" and text() = "visible"]', + 'z' +); + +INSERT INTO vandelay.import_item_attr_definition ( + owner, + name, + tag, + owning_lib, + location, + call_number, + circ_modifier, + barcode, + price, + status +) VALUES ( + 1, + 'Unicorn Import format -- 999', + '999', + 'm', + 'l', + 'a', + 't', + 'i', + 'p', + 'k' +); + +-- DROP TABLE vandelay.import_item CASCADE; +CREATE TABLE vandelay.import_item ( + id BIGSERIAL PRIMARY KEY, + definition BIGINT NOT NULL REFERENCES vandelay.import_item_attr_definition (id), + owning_lib INT, + circ_lib INT, + call_number TEXT, + copy_number INT, + status INT, + location INT, + circulate BOOL, + deposit BOOL, + deposit_amount NUMERIC(8,2), + ref BOOL, + holdable BOOL, + price NUMERIC(8,2), + barcode TEXT, + circ_modifier TEXT, + circ_as_type TEXT, + alert_message TEXT, + pub_note TEXT, + priv_note TEXT, + opac_visible BOOL +); + +CREATE TABLE vandelay.import_bib_trash_fields ( + id BIGSERIAL PRIMARY KEY, + owner INT NOT NULL REFERENCES actor.org_unit (id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + field TEXT NOT NULL, + CONSTRAINT vand_import_bib_trash_fields_idx UNIQUE (owner,field) +); + +CREATE OR REPLACE FUNCTION vandelay.strip_field ( xml TEXT, field TEXT ) RETURNS TEXT AS $_$ + + use MARC::Record; + use MARC::File::XML; + + my $xml = shift; + my $field_spec = shift; + + my @fields + + my $r = MARC::Record->new_from_xml( $xml ); + $r->delete_field( $_ ) for ( $r->field( $field_spec ) ); + + $xml = $r->as_xml_record; + $xml =~ s/^<\?.+?\?>$//mo; + $xml =~ s/\n//sgo; + $xml =~ s/>\s+