4 -- check whether patch can be applied
5 SELECT evergreen.upgrade_deps_block_check('0953', :eg_version);
7 CREATE OR REPLACE FUNCTION unapi.bre (
13 depth INT DEFAULT NULL,
14 slimit HSTORE DEFAULT NULL,
15 soffset HSTORE DEFAULT NULL,
16 include_xmlns BOOL DEFAULT TRUE,
17 pref_lib INT DEFAULT NULL
21 me biblio.record_entry%ROWTYPE;
22 layout unapi.bre_output_layout%ROWTYPE;
23 xfrm config.xml_transform%ROWTYPE;
33 IF org = '-' OR org IS NULL THEN
34 SELECT shortname INTO org FROM evergreen.org_top();
37 SELECT id INTO ouid FROM actor.org_unit WHERE shortname = org;
43 IF format = 'holdings_xml' THEN -- the special case
44 output := unapi.holdings_xml( obj_id, ouid, org, depth, includes, slimit, soffset, include_xmlns);
48 SELECT * INTO layout FROM unapi.bre_output_layout WHERE name = format;
50 IF layout.name IS NULL THEN
54 SELECT * INTO xfrm FROM config.xml_transform WHERE name = layout.transform;
56 SELECT * INTO me FROM biblio.record_entry WHERE id = obj_id;
58 -- grab bib_source, if any
59 IF ('cbs' = ANY (includes) AND me.source IS NOT NULL) THEN
60 source := unapi.cbs(me.source,NULL,NULL,NULL,NULL);
65 -- grab SVF if we need them
66 IF ('mra' = ANY (includes)) THEN
67 axml := unapi.mra(obj_id,NULL,NULL,NULL,NULL);
72 -- grab holdings if we need them
73 IF ('holdings_xml' = ANY (includes)) THEN
74 hxml := unapi.holdings_xml(obj_id, ouid, org, depth, evergreen.array_remove_item_by_value(includes,'holdings_xml'), slimit, soffset, include_xmlns, pref_lib);
80 -- generate our item node
83 IF format = 'marcxml' THEN
85 IF tmp_xml !~ E'<marc:' THEN -- If we're not using the prefixed namespace in this record, then remove all declarations of it
86 tmp_xml := REGEXP_REPLACE(tmp_xml, ' xmlns:marc="http://www.loc.gov/MARC21/slim"', '', 'g');
89 tmp_xml := oils_xslt_process(me.marc, xfrm.xslt)::XML;
92 top_el := REGEXP_REPLACE(tmp_xml, E'^.*?<((?:\\S+:)?' || layout.holdings_element || ').*$', E'\\1');
94 IF source IS NOT NULL THEN
95 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', source || '</' || top_el || E'>\\1');
98 IF axml IS NOT NULL THEN
99 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
102 IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
103 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
106 IF ('bre.unapi' = ANY (includes)) THEN
107 output := REGEXP_REPLACE(
109 '</' || top_el || '>(.*?)',
113 'http://www.w3.org/1999/xhtml' AS xmlns,
115 'tag:open-ils.org:U2@bre/' || obj_id || '/' || org AS title
117 )::TEXT || '</' || top_el || E'>\\1'
123 IF ('bre.extern' = ANY (includes)) THEN
124 output := REGEXP_REPLACE(
126 '</' || top_el || '>(.*?)',
130 'http://open-ils.org/spec/biblio/v1' AS xmlns,
131 me.creator AS creator,
133 me.create_date AS create_date,
134 me.edit_date AS edit_date,
135 me.quality AS quality,
136 me.fingerprint AS fingerprint,
137 me.tcn_source AS tcn_source,
138 me.tcn_value AS tcn_value,
140 me.share_depth AS share_depth,
142 me.deleted AS deleted
144 )::TEXT || '</' || top_el || E'>\\1'
150 output := REGEXP_REPLACE(output::TEXT,E'>\\s+<','><','gs')::XML;
153 $F$ LANGUAGE PLPGSQL STABLE;