2 # Support multiscript records via alternate graphic 880 fields
3 # get_graphic_880s(target_field='100')
4 # See "Model A" in http://www.loc.gov/marc/bibliographic/ecbdmulti.html
5 # and $6 description in http://www.loc.gov/marc/bibliographic/ecbdcntf.html
6 MACRO get_graphic_880s BLOCK;
7 FOR node IN xml.findnodes('//*[@tag="' _ target_field _ '"]');
10 FOR subnode IN node.findnodes('./*[not(contains("w 0 4 5 6 8 9", @code))]');
11 raw_vals.push(subnode.textContent());
13 core_val = raw_vals.join(" ");
17 FOR sub IN node.findnodes('./*[@code="6"]');
18 linked_fields.push(sub.textContent);
23 primary => {"occur" => occurrence, "value" => core_val},
29 MACRO get_linked_880s BLOCK;
30 FOR link_field IN linked_fields;
31 target = target_field _ link_field.substr(3);
32 # Get the linked 880 value
37 FOR node IN xml.findnodes('//*[@tag="880"]');
38 # Operate only on the target linked fields
39 FOR linknode IN node.findnodes('./*[@code="6"]');
40 lf = linknode.textContent();
41 IF lf.substr(0, target.length) == target;
42 occurrence = lf.substr(4, 2);
43 rawscript = lf.substr(7, 2);
59 rawdir = lf.substr(9, 1);
66 FOR subnode IN node.findnodes('./*[not(contains("w 0 5 6 8 9", @code))]');
67 raw_vals.push(subnode.textContent());
69 raw_val = raw_vals.join(" ");
83 ctx.media_prefix _ '/images/format_icons/' _ ccvm.ctype _ '/' _ ccvm.code _ '.png';
86 # Extract MARC fields from XML
87 # get_marc_attrs( { marc_xml => doc } )
91 # Map item types to schema.org types; impedance mismatch :(
92 args.schema.itemtype = {};
95 schema_typemap.bluray = 'Movie'; # Movie could also be TVSeries
96 schema_typemap.book = 'Book';
97 schema_typemap.braille = 'Book';
98 schema_typemap.casaudiobook = 'Book AudioObject';
99 schema_typemap.casmusic = 'MusicAlbum';
100 schema_typemap.cdaudiobook = 'Book AudioObject';
101 schema_typemap.cdmusic = 'MusicAlbum';
102 schema_typemap.dvd = 'Movie';
103 schema_typemap.eaudio = 'AudioObject';
104 schema_typemap.ebook = 'Book';
105 # schema_typemap.equip = '';
106 schema_typemap.evideo = 'Movie';
107 # schema_typemap.kit = '';
108 schema_typemap.lpbook = 'Book';
109 schema_typemap.map = 'Map';
110 # schema_typemap.microform = '';
111 schema_typemap.music = 'MusicAlbum';
112 schema_typemap.phonomusic = 'MusicAlbum';
113 # schema_typemap.phonospoken = '';
114 # schema_typemap.picture = ''; Painting or Photograph?
115 schema_typemap.score = 'Book'; # schema.org has no generic Music type
116 schema_typemap.serial = 'Periodical';
117 schema_typemap.software = 'SoftwareApplication';
118 schema_typemap.vhs = 'Movie';
120 schema_typemap.a = 'Book';
121 schema_typemap.e = 'Map';
122 schema_typemap.j = 'MusicAlbum';
124 # Hard-coded to match defaults in config.copy_status for all OPAC-visible statuses
125 schema_copy_status = {};
126 schema_copy_status.0 = '<link property="availability" href="http://schema.org/InStock" />'; # Available
127 schema_copy_status.1 = '<link property="availability" href="http://schema.org/OutOfStock" />'; # Checked out
128 schema_copy_status.5 = '<link property="availability" href="http://schema.org/PreOrder" />'; # In process
129 schema_copy_status.6 = '<link property="availability" href="http://schema.org/PreOrder" />'; # In transit
130 schema_copy_status.7 = '<link property="availability" href="http://schema.org/InStock" />'; # Reshelving
131 schema_copy_status.8 = '<link property="availability" href="http://schema.org/OutOfStock" />'; # On holds shelf
132 schema_copy_status.9 = '<link property="availability" href="http://schema.org/PreOrder" />'; # On order
133 schema_copy_status.12 = '<link property="availability" href="http://schema.org/InStoreOnly" />'; # Reserves
136 FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
137 args.isbns.push(isbn.textContent);
141 FOR upc IN xml.findnodes('//*[@tag="024"]/*[@code="a"]');
142 args.upcs.push(upc.textContent);
144 args.upc = args.upcs.0; # use first UPC as the default
147 FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
148 args.issns.push(sub.textContent);
150 args.issn = (args.issns.size) ? args.issn.0 : '';
153 get_graphic_880s(target_field='100');
154 get_graphic_880s(target_field='110');
155 get_graphic_880s(target_field='111');
156 args.graphic_authors = graphic_880s;
158 FOR author IN args.graphic_authors;
159 args.authors.push(author.primary.value);
161 args.author = (args.authors.size) ? args.authors.0 : '';
163 # Include subfields 'abnp' to generate a more comprehensive title display in search results
164 titresults = xml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b" or @code="n" or @code="p"]');
165 titresults_content = [];
166 FOR sub IN titresults; titresults_content.push(sub.textContent); END;
167 args.title = titresults_content.join(" ");
168 # Avoid ugly trailing syntax on brief titles
169 args.title = args.title | replace('[:;/]$', '');
172 get_graphic_880s(target_field='245');
173 args.graphic_titles = graphic_880s;
175 FOR title IN args.graphic_titles;
176 args.titles.push(title.primary.value);
178 args.title_extended = (args.titles.size) ? args.titles.0 : '';
181 pubplace_hunt = xml.findnodes('//*[@tag="260"]/*[@code="a"]') ||
182 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="a"]');
183 FOR sub IN pubplace_hunt;
184 args.pubplaces.push(sub.textContent);
186 args.pubplace = (args.pubplaces.size) ? args.pubplaces.0 : '';
188 args.publishers = [];
189 publishers_hunt = xml.findnodes('//*[@tag="260"]/*[@code="b"]') ||
190 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="b"]');
191 FOR sub IN publishers_hunt;
192 args.publishers.push(sub.textContent);
194 args.publisher = (args.publishers.size) ? args.publishers.0 : '';
197 pubdates_hunt = xml.findnodes('//*[@tag="260"]/*[@code="c"]') ||
198 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="c"]');
199 FOR sub IN pubdates_hunt;
200 args.pubdates.push(sub.textContent);
202 args.pubdate = (args.pubdates.size) ? args.pubdates.0 : '';
204 # Get RDA Copyright Info.
205 args.copyrights = [];
206 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="4"]/*[@code="c"]');
207 args.copyrights.push(sub.textContent);
209 args.copyright = (args.copyrights.size) ? args.copyrights.0 : '';
211 IF args.copyright.length >= 4;
212 args.copyrightYear = args.copyright.match('(\d{4})');
213 IF args.copyrightYear;
214 args.copyrightYear = args.copyrightYear.0;
218 # Get the RDA Production info.
220 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="b"]');
221 args.producers.push(sub.textContent);
223 args.producer = (args.producers.size) ? args.producers.0 : '';
225 args.prodplaces = [];
226 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="a"]');
227 args.prodplaces.push(sub.textContent);
229 args.prodplace = (args.prodplaces.size) ? args.prodplaces.0 : '';
232 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="c"]');
233 args.proddates.push(sub.textContent);
235 args.proddate = (args.proddates.size) ? args.proddates.0 : '';
237 # Get the RDA Distribution args.
238 args.distributors = [];
239 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="b"]');
240 args.distributors.push(sub.textContent);
242 args.distributor = (args.distributors.size) ? args.distributors.0 : '';
244 args.distplaces = [];
245 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="a"]');
246 args.distplaces.push(sub.textContent);
248 args.distplace = (args.distplaces.size) ? args.distplaces.0 : '';
251 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="c"]');
252 args.distdates.push(sub.textContent);
254 args.distdate = (args.distdates.size) ? args.distdates.0 : '';
256 # Get the RDA Manufacture args.
257 args.manufacturers = [];
258 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="b"]');
259 args.manufacturers.push(sub.textContent);
261 args.manufacturer = (args.manufacturers.size) ? args.manufacturers.0 : '';
264 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="a"]');
265 args.manplaces.push(sub.textContent);
267 args.manplace = (args.manplaces.size) ? args.manplaces.0 : '';
270 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="c"]');
271 args.mandates.push(sub.textContent);
273 args.mandate = (args.mandates.size) ? args.mandates.0 : '';
275 # RDA adds 264 to the pubinfo 880 consideration mix
277 get_graphic_880s(target_field='260');
278 get_graphic_880s(target_field='264');
279 args.graphic_pubinfos = graphic_880s;
281 FOR pubinfo IN args.graphic_pubinfos;
282 args.pubinfos.push(pubinfo.primary.value);
284 args.pubinfo = (args.pubinfos.size) ? args.pubinfos.0 : '';
287 FOR sub IN xml.findnodes('//*[@tag="520"]/*[@code="a"]');
288 args.summaries.push(sub.textContent);
290 args.summary = (args.summaries.size) ? args.summaries.0 : '';
292 # 250 gets pride of place for edition statement, and is the
293 # only logical choice for 880 graphic fields
295 get_graphic_880s(target_field='250');
296 args.graphic_editions = graphic_880s;
298 FOR edition IN args.graphic_editions;
299 args.editions.push(edition.primary.value);
302 ed_hunt = xml.findnodes('//*[@tag="250"]/*[@code="a"]') ||
303 xml.findnodes('//*[@tag="534"]/*[@code="b"]') ||
304 xml.findnodes('//*[@tag="775"]/*[@code="b"]');
306 args.editions.push(sub.textContent);
308 args.edition = (args.editions.size) ? args.editions.0 : '';
311 FOR sub IN xml.findnodes(
312 '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
314 phys_content.push(sub.textContent);
316 args.phys_desc = phys_content.join(" ");
319 get_graphic_880s(target_field='505');
320 args.graphic_contents = graphic_880s;
321 FOR content IN args.graphic_contents;
322 args.contents.push(content.primary.value);
324 args.content = (args.contents.size) ? args.contents.0 : '';
326 # Maintain contents_list in case any custom use was made of it
327 args.contents_list = [];
328 FOR sub IN xml.findnodes('//*[@tag="505"]');
329 args.contents_list.push(sub.textContent);
334 FOR sub IN xml.findnodes('//*[@tag="092" or @tag="099"]/*');
335 args.marc_cns.push(sub.textContent);
337 args.marc_cn = (args.marc_cns.size ) ? args.marc_cns.0 : '';
341 args.isbn_clean = args.isbns.0.replace('\ .*', '');
342 FOR isbn IN args.isbns;
343 clean_isbn = isbn.replace('\ .*', '');
344 clean_isbn = clean_isbn.replace('-', '');
345 IF clean_isbn.length == 13;
346 args.gtin13 = clean_isbn;
351 # Extract the 856 URLs that are not otherwise represented by asset.uri's
352 args.online_res = [];
353 FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
354 IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
355 label = node.findnodes('./*[@code="y"]');
356 notes = node.findnodes('./*[@code="z" or @code="3"]');
357 FOR href IN node.findnodes('./*[@code="u"]');
359 # it's possible for multiple $u's to exist within 1 856 tag.
360 # in that case, honor the label/notes data for the first $u, but
361 # leave any subsequent $u's as unadorned href's.
362 # use href/link/note keys to be consistent with args.uri's
363 args.online_res.push({
364 href => href.textContent,
365 link => (loop.first AND label) ? label.textContent : href.textContent,
366 note => (loop.first) ? notes.textContent : ''
374 args.resolver_isbns = [];
375 args.resolver_issns = [];
377 # we use $9 of ISBN and ISSN as a flag for e-version
378 FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]');
379 IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS";
380 my_parent = resolver_isbn.parentNode();
381 FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]');
382 args.resolver_isbns.push(
383 resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '')
389 FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]');
390 IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS";
391 my_parent = resolver_issn.parentNode();
392 FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]');
393 args.resolver_issns.push(
394 resolver_issn_val.textContent.replace('[^\d\-X]', '')
401 FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
403 rawissn.textContent.replace('[^\d\-X]', '')
407 ou_hiding_disabled = ctx.org_hiding_disabled();
409 FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
411 # Check volume visibility - could push this into XPath
412 vol.label = volume.getAttribute('label');
414 # Prepend prefix, if any
415 prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
416 IF prefix.getAttribute('label') != '';
417 vol.label = prefix.getAttribute('label') _ " " _ vol.label;
420 # Append prefix, if any
421 suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
422 IF suffix.getAttribute('label') != '';
423 vol.label = vol.label _ " " _ suffix.getAttribute('label');
426 vol.id = volume.getAttribute('id');
427 NEXT IF volume.getAttribute('opac_visible') == 'false';
428 NEXT IF volume.getAttribute('deleted') == 'true';
430 IF vol.label == '##URI##';
431 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
433 res.href = uri.getAttribute('href');
434 res.link = uri.getAttribute('label');
435 res.note = uri.getAttribute('use_restriction');
436 # Avoid displaying the href as the link text if we can display the note instead
437 IF res.link == res.href AND res.note;
445 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
447 parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
448 FOREACH part IN parts;
449 part_label = part.getAttribute('label');
450 LAST IF part_label != '';
452 # Check copy visibility
453 cp.deleted = copy.getAttribute('deleted');
454 cp.visible = copy.getAttribute('opac_visible');
455 NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
457 # Iterate through all of the children to determine visibility
458 FOR node IN cp.childNodes;
459 NEXT IF cp.visible == 'false';
460 vis = node.getAttribute('opac_visible');
461 del = node.getAttribute('deleted');
462 IF vis == 'false' or del == 'true';
463 cp.visible = 'false';
467 NEXT IF cp.visible == 'false';
469 loc = copy.findnodes('./*[local-name()="location"]');
470 NEXT IF loc.getAttribute('opac_visible') == 'false';
472 circlib = copy.findnodes('./*[local-name()="circlib"]');
473 NEXT IF circlib.getAttribute('opac_visible') == 'false';
475 status = copy.findnodes('./*[local-name()="status"]');
476 NEXT IF status.getAttribute('opac_visible') == 'false';
478 # extract the circ_lib id from the circ_lib node
479 circ_lib = copy.findnodes('./*[local-name()="circ_lib"]');
480 circ_lib_id = circ_lib.getAttribute('id').replace('.*/', '');
482 UNLESS ou_hiding_disabled;
483 NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id);
487 circ_lib => circ_lib_id,
489 part_label => part_label,
490 location => loc.textContent,
491 library => circlib.textContent,
492 status => status.textContent,
493 status_code => status.getAttribute('ident'),
494 barcode => copy.getAttribute('barcode'),
495 owner => volume.getAttribute('lib')
497 args.holdings.push(holding);
503 # Extract the copy count summary
504 count_type = (ctx.is_staff) ? 'staff' : 'public';
506 # Consortial copy count summary first
507 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
508 args.copy_counts = {};
509 FOR node IN xml.findnodes(xpath);
510 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
511 depth = node.getAttribute('depth');
512 count_org_unit = node.getAttribute('org_unit');
513 args.copy_counts.$depth.$attr = node.getAttribute(attr);
514 args.org_copy_counts.$count_org_unit.$attr = node.getAttribute(attr);
518 # Get preferred library copy count
519 args.plib_copy_counts = {};
520 count_type = 'pref_lib';
521 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
522 FOR node IN xml.findnodes(xpath);
523 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
524 depth = node.getAttribute('depth');
525 args.plib_copy_counts.$depth.$attr = node.getAttribute(attr);
529 # "mattype" == "custom marc format specifier"
530 icon_style = ctx.get_cgf('opac.icon_attr').value || 'item_type';
531 formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]';
533 args.all_formats = [];
534 FOR node IN xml.findnodes(formats_xpath);
535 IF node AND node.textContent;
536 ccvm = ctx.get_ccvm(node.getAttribute('cvmid'));
537 NEXT IF ccvm.opac_visible == 'f';
540 type = ccvm.code.remove('-'); # blu-ray to bluray
541 format.label = ccvm.search_label || ccvm.value;
542 format.icon = PROCESS get_ccvm_icon ccvm=ccvm;
543 format.itemtype = schema_typemap.$type || 'CreativeWork';
545 args.all_formats.push(format); # metarecords want all formats
547 IF !args.format_label;
548 # use the first format as the default
549 args.format_label = format.label;
550 args.schema.itemtype = format.itemtype;
551 args.format_icon = format.icon;
557 FOR bibid IN xml.findnodes('//*[@tag="901"]/*[@code="c"]');
558 args.bibid.push(bibid.textContent);
560 args.bibid = args.bibid.0;
564 # Get the library or location group
566 # magically upgrades any use of 'loc' to 'locg',
567 # which is a superset of 'loc'.
570 loc_value = ctx.copy_location_group_org || # resolved locg
571 CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou;