3 INSERT INTO config.upgrade_log (version) VALUES ('0504'); -- miker
5 CREATE OR REPLACE FUNCTION lpad_number_substrings( TEXT, TEXT, INT ) RETURNS TEXT AS $$
11 while ($string =~ /(?:^|\D)(\d{1,$find})(?:$|\D)/) {
13 $padded = $pad x ($len - length($padded)) . $padded;
14 $string =~ s/$1/$padded/sg;
20 CREATE TABLE biblio.monograph_part (
21 id SERIAL PRIMARY KEY,
22 record BIGINT NOT NULL REFERENCES biblio.record_entry (id),
24 label_sortkey TEXT NOT NULL,
25 CONSTRAINT record_label_unique UNIQUE (record,label)
28 CREATE OR REPLACE FUNCTION biblio.normalize_biblio_monograph_part_sortkey () RETURNS TRIGGER AS $$
30 NEW.label_sortkey := REGEXP_REPLACE(
31 lpad_number_substrings(
32 naco_normalize(NEW.label),
44 CREATE TRIGGER norm_sort_label BEFORE INSERT OR UPDATE ON biblio.monograph_part FOR EACH ROW EXECUTE PROCEDURE biblio.normalize_biblio_monograph_part_sortkey();
46 CREATE TABLE asset.copy_part_map (
47 id SERIAL PRIMARY KEY,
48 target_copy BIGINT NOT NULL, -- points o asset.copy
49 part INT NOT NULL REFERENCES biblio.monograph_part (id) ON DELETE CASCADE
51 CREATE UNIQUE INDEX copy_part_map_cp_part_idx ON asset.copy_part_map (target_copy, part);
53 CREATE OR REPLACE FUNCTION asset.normalize_affix_sortkey () RETURNS TRIGGER AS $$
55 NEW.label_sortkey := REGEXP_REPLACE(
56 lpad_number_substrings(
57 naco_normalize(NEW.label),
69 CREATE TABLE asset.call_number_prefix (
70 id SERIAL PRIMARY KEY,
71 owning_lib INT NOT NULL REFERENCES actor.org_unit (id),
72 label TEXT NOT NULL, -- i18n
75 CREATE TRIGGER prefix_normalize_tgr BEFORE INSERT OR UPDATE ON asset.call_number_prefix FOR EACH ROW EXECUTE PROCEDURE asset.normalize_affix_sortkey();
76 CREATE UNIQUE INDEX asset_call_number_prefix_once_per_lib ON asset.call_number_prefix (label, owning_lib);
77 CREATE INDEX asset_call_number_prefix_sortkey_idx ON asset.call_number_prefix (label_sortkey);
79 CREATE TABLE asset.call_number_suffix (
80 id SERIAL PRIMARY KEY,
81 owning_lib INT NOT NULL REFERENCES actor.org_unit (id),
82 label TEXT NOT NULL, -- i18n
85 CREATE TRIGGER suffix_normalize_tgr BEFORE INSERT OR UPDATE ON asset.call_number_suffix FOR EACH ROW EXECUTE PROCEDURE asset.normalize_affix_sortkey();
86 CREATE UNIQUE INDEX asset_call_number_suffix_once_per_lib ON asset.call_number_suffix (label, owning_lib);
87 CREATE INDEX asset_call_number_suffix_sortkey_idx ON asset.call_number_suffix (label_sortkey);
89 INSERT INTO asset.call_number_suffix (id, owning_lib, label) VALUES (-1, 1, '');
90 INSERT INTO asset.call_number_prefix (id, owning_lib, label) VALUES (-1, 1, '');
92 DROP INDEX IF EXISTS asset.asset_call_number_label_once_per_lib;
94 ALTER TABLE asset.call_number
95 ADD COLUMN prefix INT NOT NULL DEFAULT -1 REFERENCES asset.call_number_prefix(id) DEFERRABLE INITIALLY DEFERRED,
96 ADD COLUMN suffix INT NOT NULL DEFAULT -1 REFERENCES asset.call_number_suffix(id) DEFERRABLE INITIALLY DEFERRED;
98 CREATE UNIQUE INDEX asset_call_number_label_once_per_lib ON asset.call_number (record, owning_lib, label, prefix, suffix) WHERE deleted = FALSE OR deleted IS FALSE;
100 INSERT INTO config.org_unit_setting_type ( name, label, description, datatype ) VALUES (
101 'ui.cat.volume_copy_editor.horizontal',
103 'ui.cat.volume_copy_editor.horizontal',
104 'GUI: Horizontal layout for Volume/Copy Creator/Editor.',
107 'ui.cat.volume_copy_editor.horizontal',
108 'The main entry point for this interface is in Holdings Maintenance, Actions for Selected Rows, Edit Item Attributes / Call Numbers / Replace Barcodes. This setting changes the top and bottom panes for that interface into left and right panes.',
109 'coust', 'description'),
114 CREATE OR REPLACE FUNCTION unapi.bmp ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL ) RETURNS XML AS $F$
118 'http://open-ils.org/spec/holdings/v1' AS xmlns,
119 'tag:open-ils.org:U2@bmp/' || id AS id,
123 'tag:open-ils.org:U2@bre/' || record AS record
126 WHEN ('acp' = ANY ($4)) THEN
127 XMLELEMENT( name copies,
128 (SELECT XMLAGG(acp) FROM (
129 SELECT unapi.acp( cp.id, 'xml', 'copy', array_remove_item_by_value($4,'bmp'), $5, $6, $7, $8)
131 JOIN asset.copy_part_map cpm ON (cpm.target_copy = cp.id)
133 ORDER BY COALESCE(cp.copy_number,0), cp.barcode
140 CASE WHEN ('bre' = ANY ($4)) THEN unapi.bre( record, 'marcxml', 'record', array_remove_item_by_value($4,'bmp'), $5, $6, $7, $8) ELSE NULL END
142 FROM biblio.monograph_part
144 GROUP BY id, label, label_sortkey, record;
147 CREATE OR REPLACE FUNCTION unapi.acnp ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL ) RETURNS XML AS $F$
149 name call_number_prefix,
151 'http://open-ils.org/spec/holdings/v1' AS xmlns,
156 unapi.aou( owning_lib, $2, 'owning_lib', array_remove_item_by_value($4,'acnp'), $5, $6, $7, $8)
158 FROM asset.call_number_prefix
162 CREATE OR REPLACE FUNCTION unapi.acns ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL ) RETURNS XML AS $F$
164 name call_number_suffix,
166 'http://open-ils.org/spec/holdings/v1' AS xmlns,
171 unapi.aou( owning_lib, $2, 'owning_lib', array_remove_item_by_value($4,'acns'), $5, $6, $7, $8)
173 FROM asset.call_number_suffix
177 CREATE OR REPLACE FUNCTION unapi.holdings_xml (bid BIGINT, ouid INT, org TEXT, depth INT DEFAULT NULL, includes TEXT[] DEFAULT NULL::TEXT[], slimit INT DEFAULT NULL, soffset INT DEFAULT NULL) RETURNS XML AS $F$
181 'http://open-ils.org/spec/holdings/v1' AS xmlns,
182 CASE WHEN ('bre' = ANY ('{acn,auri}'::TEXT[] || $5)) THEN 'tag:open-ils.org:U2@bre/' || $1 || '/' || $3 ELSE NULL END AS id
186 (SELECT XMLAGG(XMLELEMENT::XML) FROM (
189 XMLATTRIBUTES('public' as type, depth, org_unit, coalesce(transcendant,0) as transcendant, available, visible as count, unshadow)
191 FROM asset.opac_ou_record_copy_count($2, $1)
195 XMLATTRIBUTES('staff' as type, depth, org_unit, coalesce(transcendant,0) as transcendant, available, visible as count, unshadow)
197 FROM asset.staff_ou_record_copy_count($2, $1)
202 WHEN ('bmp' = ANY ($5)) THEN
203 XMLELEMENT( name monograph_parts,
204 XMLAGG((SELECT unapi.bmp( id, 'xml', 'monograph_part', array_remove_item_by_value( array_remove_item_by_value($5,'bre'), 'holdings_xml'), $3, $4, $6, $7) FROM biblio.monograph_part WHERE record = $1))
208 CASE WHEN ('acn' = ANY ('{acn,auri}'::TEXT[] || $5)) THEN
211 (SELECT XMLAGG(acn) FROM (
212 SELECT unapi.acn(acn.id,'xml','volume',array_remove_item_by_value(array_remove_item_by_value('{acn,auri}'::TEXT[] || $5,'holdings_xml'),'bre'), $3, $4, $6, $7)
213 FROM asset.call_number acn
214 WHERE acn.record = $1
218 JOIN actor.org_unit_descendants(
223 FROM actor.org_unit_type aout
224 JOIN actor.org_unit aou ON (aou.ou_type = aout.id AND aou.id = $2)
227 ) aoud ON (acp.circ_lib = aoud.id)
230 ORDER BY label_sortkey
236 CASE WHEN ('ssub' = ANY ('{acn,auri}'::TEXT[] || $5)) THEN
239 (SELECT XMLAGG(ssub) FROM (
240 SELECT unapi.ssub(id,'xml','subscription','{}'::TEXT[], $3, $4, $6, $7)
241 FROM serial.subscription
242 WHERE record_entry = $1
249 CREATE OR REPLACE FUNCTION unapi.acp ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL ) RETURNS XML AS $F$
253 'http://open-ils.org/spec/holdings/v1' AS xmlns,
254 'tag:open-ils.org:U2@acp/' || id AS id,
255 create_date, edit_date, copy_number, circulate, deposit,
256 ref, holdable, deleted, deposit_amount, price, barcode,
257 circ_modifier, circ_as_type, opac_visible
259 unapi.ccs( status, $2, 'status', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8),
260 unapi.acl( location, $2, 'location', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8),
261 unapi.aou( circ_lib, $2, 'circ_lib', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8),
262 unapi.aou( circ_lib, $2, 'circlib', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8),
263 CASE WHEN ('acn' = ANY ($4)) THEN unapi.acn( call_number, $2, 'call_number', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8) ELSE NULL END,
264 XMLELEMENT( name copy_notes,
266 WHEN ('acpn' = ANY ($4)) THEN
267 XMLAGG((SELECT unapi.acpn( id, 'xml', 'copy_note', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8) FROM asset.copy_note WHERE owning_copy = cp.id AND pub))
271 XMLELEMENT( name statcats,
273 WHEN ('ascecm' = ANY ($4)) THEN
274 XMLAGG((SELECT unapi.ascecm( stat_cat_entry, 'xml', 'statcat', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8) FROM asset.stat_cat_entry_copy_map WHERE owning_copy = cp.id))
279 WHEN ('bmp' = ANY ($4)) THEN
280 XMLELEMENT( name monograph_parts,
281 XMLAGG((SELECT unapi.bmp( part, 'xml', 'monograph_part', array_remove_item_by_value($4,'acp'), $5, $6, $7, $8) FROM asset.copy_part_map WHERE target_copy = cp.id))
288 GROUP BY id, status, location, circ_lib, call_number, create_date, edit_date, copy_number, circulate, deposit, ref, holdable, deleted, deposit_amount, price, barcode, circ_modifier, circ_as_type, opac_visible;
291 CREATE OR REPLACE FUNCTION unapi.acn ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL ) RETURNS XML AS $F$
295 'http://open-ils.org/spec/holdings/v1' AS xmlns,
296 'tag:open-ils.org:U2@acn/' || acn.id AS id,
298 o.opac_visible AS opac_visible,
299 deleted, label, label_sortkey, label_class, record
301 unapi.aou( owning_lib, $2, 'owning_lib', array_remove_item_by_value($4,'acn'), $5, $6, $7, $8),
302 XMLELEMENT( name copies,
304 WHEN ('acp' = ANY ($4)) THEN
305 (SELECT XMLAGG(acp) FROM (
306 SELECT unapi.acp( cp.id, 'xml', 'copy', array_remove_item_by_value($4,'acn'), $5, $6, $7, $8)
308 JOIN actor.org_unit_descendants(
309 (SELECT id FROM actor.org_unit WHERE shortname = $5),
310 (COALESCE($6,(SELECT aout.depth FROM actor.org_unit_type aout JOIN actor.org_unit aou ON (aou.ou_type = aout.id AND aou.shortname = $5))))
311 ) aoud ON (cp.circ_lib = aoud.id)
312 WHERE cp.call_number = acn.id
313 ORDER BY COALESCE(cp.copy_number,0), cp.barcode
322 (SELECT XMLAGG(auri) FROM (SELECT unapi.auri(uri,'xml','uri', array_remove_item_by_value($4,'acn'), $5, $6, $7, $8) FROM asset.uri_call_number_map WHERE call_number = acn.id)x)
324 CASE WHEN ('acnp' = ANY ($4)) THEN unapi.acnp( acn.prefix, 'marcxml', 'prefix', array_remove_item_by_value($4,'acn'), $5, $6, $7, $8) ELSE NULL END,
325 CASE WHEN ('acns' = ANY ($4)) THEN unapi.acns( acn.suffix, 'marcxml', 'suffix', array_remove_item_by_value($4,'acn'), $5, $6, $7, $8) ELSE NULL END,
326 CASE WHEN ('bre' = ANY ($4)) THEN unapi.bre( acn.record, 'marcxml', 'record', array_remove_item_by_value($4,'acn'), $5, $6, $7, $8) ELSE NULL END
328 FROM asset.call_number acn
329 JOIN actor.org_unit o ON (o.id = acn.owning_lib)
331 GROUP BY acn.id, o.shortname, o.opac_visible, deleted, label, label_sortkey, label_class, owning_lib, record, acn.prefix, acn.suffix;