7 use OpenSRF::EX qw/:try/;
8 use OpenSRF::AppSession;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenILS::Application::AppUtils;
11 use OpenILS::Utils::Fieldmapper;
15 use UNIVERSAL::require;
20 my @formats = qw/USMARC UNIMARC XML/;
22 my ($config,$format,$encoding,$location,$dollarsign,$help,$holdings) = ('/openils/conf/bootstrap.conf','USMARC','MARC8','','$');
26 'items' => \$holdings,
27 'location=s' => \$location,
28 'money=s' => \$dollarsign,
29 'config=s' => \$config,
30 'format=s' => \$format,
31 'encoding=s' => \$encoding,
37 --help or -h This screen.
38 --config or -c Configuration file [/openils/conf/bootstrap.conf]
39 --format or -f Output format (USMARC, UNIMARC, XML) [USMARC]
40 --encoding or -e Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8]
41 --items or -i Include items (holdings) in the output
42 --location or -l MARC Location Code for holdings from
43 http://www.loc.gov/marc/organizations/orgshome.html
47 cat list_of_ids | $0 > output_file
53 $format = uc($format);
54 $encoding = uc($encoding);
56 binmode(STDOUT, ':raw') if ($encoding ne 'UTF-8');
57 binmode(STDOUT, ':utf8') if ($encoding eq 'UTF-8');
59 if (!grep { $format eq $_ } @formats) {
60 die "Please select a supported format. ".
61 "Right now that means one of [".
62 join('|',@formats). "]\n";
65 if ($format ne 'XML') {
66 my $type = 'MARC::File::' . $format;
70 OpenSRF::System->bootstrap_client( config_file => $config );
71 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
73 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
75 print <<HEADER if ($format eq 'XML');
76 <?xml version="1.0" encoding="$encoding"?>
77 <collection xmlns='http://www.loc.gov/MARC21/slim'>
82 my $o = $ses->request( 'open-ils.cstore.direct.actor.org_unit.search.atomic', { id => { '!=' => undef } } )->gather(1);
83 %orgs = map { ( $_->id => $_ ) } @$o;
88 my $s = $ses->request( 'open-ils.cstore.direct.asset.copy_location.search.atomic', { id => { '!=' => undef } } )->gather(1);
89 %shelves = map { ( $_->id => $_ ) } @$s;
92 while ( my $i = <> ) {
93 my $bib = $ses->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve', $i )->gather(1);
97 my $r = MARC::Record->new_from_xml( $bib->marc, $encoding, $format );
98 $r->delete_field( $_ ) for ($r->field(901));
103 a => $bib->tcn_value,
104 b => $bib->tcn_source
109 my $cn_list = $ses->request(
110 'open-ils.cstore.direct.asset.call_number.search.atomic',
111 { record => $i, deleted => 'f' }
115 my $cp_list = $ses->request(
116 'open-ils.cstore.direct.asset.copy.search.atomic',
117 { call_number => [ map { $_->id } @$cn_list ], deleted => 'f' }
121 push @{$cn_map{$_->call_number}}, $_ for (@$cp_list);
123 for my $cn ( @$cn_list ) {
124 my $cn_map_list = $cn_map{$cn->id};
125 for my $cp ( @$cn_map_list ) {
130 b => $orgs{$cn->owning_lib}->shortname,
131 b => $orgs{$cp->circ_lib}->shortname,
132 c => $shelves{$cp->location}->name,
134 ($cp->circ_modifier ? ( g => $cp->circ_modifier ) : ()),
136 ($cp->price ? ( y => $dollarsign.$cp->price ) : ()),
137 ($cp->copy_number ? ( t => $cp->copy_number ) : ()),
138 ($cp->ref eq 't' ? ( x => 'reference' ) : ()),
139 ($cp->holdable eq 'f' ? ( x => 'unholdable' ) : ()),
140 ($cp->circulate eq 'f' ? ( x => 'noncirculating' ) : ()),
141 ($cp->opac_visible eq 'f' ? ( x => 'hidden' ) : ()),
148 if (uc($format) eq 'XML') {
149 print $r->as_xml_record;
150 } elsif (uc($format) eq 'UNIMARC') {
152 } elsif (uc($format) eq 'USMARC') {
157 print "</collection>\n" if ($format eq 'XML');