1 -- Include bib source in XML returned by unapi.bre.
4 -- check whether patch can be applied
5 SELECT evergreen.upgrade_deps_block_check('0923', :eg_version);
7 CREATE OR REPLACE FUNCTION unapi.cbs ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit HSTORE DEFAULT NULL, soffset HSTORE DEFAULT NULL, include_xmlns BOOL DEFAULT TRUE ) RETURNS XML AS $F$
11 NULL AS xmlns, -- TODO needs equivalent to http://open-ils.org/spec/holdings/v1
19 FROM config.bib_source
21 $F$ LANGUAGE SQL STABLE;
23 CREATE OR REPLACE FUNCTION unapi.bre (
29 depth INT DEFAULT NULL,
30 slimit HSTORE DEFAULT NULL,
31 soffset HSTORE DEFAULT NULL,
32 include_xmlns BOOL DEFAULT TRUE,
33 pref_lib INT DEFAULT NULL
37 me biblio.record_entry%ROWTYPE;
38 layout unapi.bre_output_layout%ROWTYPE;
39 xfrm config.xml_transform%ROWTYPE;
49 IF org = '-' OR org IS NULL THEN
50 SELECT shortname INTO org FROM evergreen.org_top();
53 SELECT id INTO ouid FROM actor.org_unit WHERE shortname = org;
59 IF format = 'holdings_xml' THEN -- the special case
60 output := unapi.holdings_xml( obj_id, ouid, org, depth, includes, slimit, soffset, include_xmlns);
64 SELECT * INTO layout FROM unapi.bre_output_layout WHERE name = format;
66 IF layout.name IS NULL THEN
70 SELECT * INTO xfrm FROM config.xml_transform WHERE name = layout.transform;
72 SELECT * INTO me FROM biblio.record_entry WHERE id = obj_id;
74 -- grab bib_source, if any
75 IF ('cbs' = ANY (includes) AND me.source IS NOT NULL) THEN
76 source := unapi.cbs(me.source,NULL,NULL,NULL,NULL);
81 -- grab SVF if we need them
82 IF ('mra' = ANY (includes)) THEN
83 axml := unapi.mra(obj_id,NULL,NULL,NULL,NULL);
88 -- grab holdings if we need them
89 IF ('holdings_xml' = ANY (includes)) THEN
90 hxml := unapi.holdings_xml(obj_id, ouid, org, depth, evergreen.array_remove_item_by_value(includes,'holdings_xml'), slimit, soffset, include_xmlns, pref_lib);
96 -- generate our item node
99 IF format = 'marcxml' THEN
101 IF tmp_xml !~ E'<marc:' THEN -- If we're not using the prefixed namespace in this record, then remove all declarations of it
102 tmp_xml := REGEXP_REPLACE(tmp_xml, ' xmlns:marc="http://www.loc.gov/MARC21/slim"', '', 'g');
105 tmp_xml := oils_xslt_process(me.marc, xfrm.xslt)::XML;
108 top_el := REGEXP_REPLACE(tmp_xml, E'^.*?<((?:\\S+:)?' || layout.holdings_element || ').*$', E'\\1');
110 IF source IS NOT NULL THEN
111 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', source || '</' || top_el || E'>\\1');
114 IF axml IS NOT NULL THEN
115 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
118 IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
119 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
122 IF ('bre.unapi' = ANY (includes)) THEN
123 output := REGEXP_REPLACE(
125 '</' || top_el || '>(.*?)',
129 'http://www.w3.org/1999/xhtml' AS xmlns,
131 'tag:open-ils.org:U2@bre/' || obj_id || '/' || org AS title
133 )::TEXT || '</' || top_el || E'>\\1'
139 output := REGEXP_REPLACE(output::TEXT,E'>\\s+<','><','gs')::XML;
142 $F$ LANGUAGE PLPGSQL STABLE;