3 INSERT INTO config.upgrade_log (version) VALUES ('0513'); -- miker
5 CREATE OR REPLACE FUNCTION unapi.mra ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL, include_xmlns BOOL DEFAULT TRUE ) RETURNS XML AS $F$
9 CASE WHEN $9 THEN 'http://open-ils.org/spec/indexing/v1' ELSE NULL END AS xmlns,
10 'tag:open-ils.org:U2@mra/' || mra.id AS id,
11 'tag:open-ils.org:U2@bre/' || mra.id AS record
14 FROM (SELECT XMLELEMENT(
18 cvm.value AS "coded-value",
24 FROM EACH(mra.attrs) AS x
25 JOIN config.record_attr_definition rad ON (x.key = rad.name)
26 LEFT JOIN config.coded_value_map cvm ON (cvm.ctype = x.key AND code = x.value)
30 FROM metabib.record_attr mra
34 CREATE OR REPLACE FUNCTION unapi.bre ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL, include_xmlns BOOL DEFAULT TRUE ) RETURNS XML AS $F$
36 me biblio.record_entry%ROWTYPE;
37 layout unapi.bre_output_layout%ROWTYPE;
38 xfrm config.xml_transform%ROWTYPE;
47 SELECT id INTO ouid FROM actor.org_unit WHERE shortname = org;
53 IF format = 'holdings_xml' THEN -- the special case
54 output := unapi.holdings_xml( obj_id, ouid, org, depth, includes, slimit, soffset, include_xmlns);
58 SELECT * INTO layout FROM unapi.bre_output_layout WHERE name = format;
60 IF layout.name IS NULL THEN
64 SELECT * INTO xfrm FROM config.xml_transform WHERE name = layout.transform;
66 SELECT * INTO me FROM biblio.record_entry WHERE id = obj_id;
68 -- grab SVF if we need them
69 IF ('mra' = ANY (includes)) THEN
70 axml := unapi.mra(obj_id,NULL,NULL,NULL,NULL);
75 -- grab hodlings if we need them
76 IF ('holdings_xml' = ANY (includes)) THEN
77 hxml := unapi.holdings_xml(obj_id, ouid, org, depth, evergreen.array_remove_item_by_value(includes,'holdings_xml'), slimit, soffset, include_xmlns);
83 -- generate our item node
86 IF format = 'marcxml' THEN
88 IF tmp_xml !~ E'<marc:' THEN -- If we're not using the prefixed namespace in this record, then remove all declarations of it
89 tmp_xml := REGEXP_REPLACE(tmp_xml, ' xmlns:marc="http://www.loc.gov/MARC21/slim"', '', 'g');
92 tmp_xml := oils_xslt_process(me.marc, xfrm.xslt)::XML;
95 top_el := REGEXP_REPLACE(tmp_xml, E'^.*?<((?:\\S+:)?' || layout.holdings_element || ').*$', E'\\1');
97 IF axml IS NOT NULL THEN
98 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
101 IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
102 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
105 IF ('bre.unapi' = ANY (includes)) THEN
106 output := REGEXP_REPLACE(
108 '</' || top_el || '>(.*?)',
112 'http://www.w3.org/1999/xhtml' AS xmlns,
114 'tag:open-ils.org:U2@bre/' || obj_id || '/' || org AS title
116 )::TEXT || '</' || top_el || E'>\\1'
124 $F$ LANGUAGE PLPGSQL;