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,$idl,$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,
32 'encoding=s' => \$encoding,
38 --help or -h This screen.
39 --config or -c Configuration file [/openils/conf/bootstrap.conf]
40 --format or -f Output format (USMARC, UNIMARC, XML) [USMARC]
41 --encoding or -e Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8]
42 --items or -i Include items (holdings) in the output
43 --xml-idl or -x Location of the IDL XML
44 --location or -l MARC Location Code for holdings from
45 http://www.loc.gov/marc/organizations/orgshome.html
49 cat list_of_ids | $0 > output_file
55 $format = uc($format);
56 $encoding = uc($encoding);
58 binmode(STDOUT, ':raw') if ($encoding ne 'UTF-8');
59 binmode(STDOUT, ':utf8') if ($encoding eq 'UTF-8');
61 if (!grep { $format eq $_ } @formats) {
62 die "Please select a supported format. ".
63 "Right now that means one of [".
64 join('|',@formats). "]\n";
67 if ($format ne 'XML') {
68 my $type = 'MARC::File::' . $format;
72 OpenSRF::System->bootstrap_client( config_file => $config );
73 my $sc = OpenSRF::Utils::SettingsClient->new;
74 $idl ||= $sc->config_value("IDL");
76 Fieldmapper->import(IDL => $idl);
78 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
80 print <<HEADER if ($format eq 'XML');
81 <?xml version="1.0" encoding="$encoding"?>
82 <collection xmlns='http://www.loc.gov/MARC21/slim'>
87 my $o = $ses->request( 'open-ils.cstore.direct.actor.org_unit.search.atomic', { id => { '!=' => undef } } )->gather(1);
88 %orgs = map { ( $_->id => $_ ) } @$o;
93 my $s = $ses->request( 'open-ils.cstore.direct.asset.copy_location.search.atomic', { id => { '!=' => undef } } )->gather(1);
94 %shelves = map { ( $_->id => $_ ) } @$s;
97 while ( my $i = <> ) {
98 my $bib = $ses->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve', $i )->gather(1);
102 my $r = MARC::Record->new_from_xml( $bib->marc, $encoding, $format );
103 $r->delete_field( $_ ) for ($r->field(901));
108 a => $bib->tcn_value,
109 b => $bib->tcn_source
114 my $cn_list = $ses->request(
115 'open-ils.cstore.direct.asset.call_number.search.atomic',
116 { record => $i, deleted => 'f' }
120 my $cp_list = $ses->request(
121 'open-ils.cstore.direct.asset.copy.search.atomic',
122 { call_number => [ map { $_->id } @$cn_list ], deleted => 'f' }
126 push @{$cn_map{$_->call_number}}, $_ for (@$cp_list);
128 for my $cn ( @$cn_list ) {
129 my $cn_map_list = $cn_map{$cn->id};
130 for my $cp ( @$cn_map_list ) {
135 b => $orgs{$cn->owning_lib}->shortname,
136 b => $orgs{$cp->circ_lib}->shortname,
137 c => $shelves{$cp->location}->name,
139 ($cp->circ_modifier ? ( g => $cp->circ_modifier ) : ()),
141 ($cp->price ? ( y => $dollarsign.$cp->price ) : ()),
142 ($cp->copy_number ? ( t => $cp->copy_number ) : ()),
143 ($cp->ref eq 't' ? ( x => 'reference' ) : ()),
144 ($cp->holdable eq 'f' ? ( x => 'unholdable' ) : ()),
145 ($cp->circulate eq 'f' ? ( x => 'noncirculating' ) : ()),
146 ($cp->opac_visible eq 'f' ? ( x => 'hidden' ) : ()),
153 if (uc($format) eq 'XML') {
154 print $r->as_xml_record;
155 } elsif (uc($format) eq 'UNIMARC') {
157 } elsif (uc($format) eq 'USMARC') {
162 print "</collection>\n" if ($format eq 'XML');