--- /dev/null
+// so we can tell if it's a book or other type
+load_lib('fmall.js');
+load_lib('fmgen.js');
+load_lib('record_type.js');
+
+var marcdoc = new XML(environment.marc);
+var marc_ns = new Namespace('http://www.loc.gov/MARC21/slim');
+
+default xml namespace = marc_ns;
+
+environment.result = new mrd();
+
+environment.result.item_type( extractFixedField( marcdoc, 'Type' ) );
+environment.result.item_form( extractFixedField( marcdoc, 'Form' ) );
+environment.result.bib_level( extractFixedField( marcdoc, 'BLvl' ) );
+environment.result.control_type( extractFixedField( marcdoc, 'Ctrl' ) );
+environment.result.enc_level( extractFixedField( marcdoc, 'ELvl' ) );
+environment.result.audience( extractFixedField( marcdoc, 'Audn' ) );
+environment.result.lit_form( extractFixedField( marcdoc, 'LitF' ) );
+environment.result.type_mat( extractFixedField( marcdoc, 'TMat' ) );
+environment.result.cat_form( extractFixedField( marcdoc, 'Desc' ) );
+environment.result.pub_status( extractFixedField( marcdoc, 'DtSt' ) );
+environment.result.item_lang( extractFixedField( marcdoc, 'Lang' ) );
+
COM : {start : 17, len : 1, def : ' ' },
}
},
+ TMat : {
+ _8 : {
+ VIS : {start : 33, len : 1, def : ' ' },
+ },
+ _6 : {
+ VIS : {start : 16, len : 1, def : ' ' },
+ }
+ },
Indx : {
_8 : {
BKS : {start : 31, len : 1, def : '0' },
var val;
if (ff_pos[field].ldr) {
- val = _l.substr(
- ff_pos[field].ldr[rtype].start,
- ff_pos[field].ldr[rtype].len
- );
+ if (ff_pos[field].ldr[rtype]) {
+ val = _l.substr(
+ ff_pos[field].ldr[rtype].start,
+ ff_pos[field].ldr[rtype].len
+ );
+ }
} else if (ff_pos[field]._8) {
- val = _8.substr(
- ff_pos[field]._8[rtype].start,
- ff_pos[field]._8[rtype].len
- );
+ if (ff_pos[field]._8[rtype]) {
+ val = _8.substr(
+ ff_pos[field]._8[rtype].start,
+ ff_pos[field]._8[rtype].len
+ );
+ }
}
if (!val && ff_pos[field]._6) {
- val = _6.substr(
- ff_pos[field]._6[rtype].start,
- ff_pos[field]._6[rtype].len
- );
+ if (ff_pos[field]._6[rtype]) {
+ val = _6.substr(
+ ff_pos[field]._6[rtype].start,
+ ff_pos[field]._6[rtype].len
+ );
+ }
}
return val;
return $stuff;
}
+sub ro_biblio_ingest_single_object {
+ my $self = shift;
+ my $client = shift;
+ my $bib = shift;
+ my $xml = $bib->marc;
+
+ my $document = $parser->parse_string($xml);
+
+ my @mfr = $self->method_lookup("open-ils.ingest.flat_marc.biblio.xml")->run($document);
+ my @mXfe = $self->method_lookup("open-ils.ingest.extract.field_entry.all.xml")->run($document);
+ my ($fp) = $self->method_lookup("open-ils.ingest.fingerprint.xml")->run($xml);
+ my ($rd) = $self->method_lookup("open-ils.ingest.descriptor.xml")->run($xml);
+
+ $_->source($bib->id) for (@mXfe);
+ $_->record($bib->id) for (@mfr);
+ $rd->record($bib->id);
+
+ return { full_rec => \@mfr, field_entries => \@mXfe, fingerprint => $fp, descriptor => $rd };
+}
+__PACKAGE__->register_method(
+ api_name => "open-ils.ingest.full.biblio.object.readonly",
+ method => "ro_biblio_ingest_single_object",
+ api_level => 1,
+ argc => 1,
+);
+
sub ro_biblio_ingest_single_xml {
my $self = shift;
my $client = shift;
my @mfr = $self->method_lookup("open-ils.ingest.flat_marc.biblio.xml")->run($document);
my @mXfe = $self->method_lookup("open-ils.ingest.extract.field_entry.all.xml")->run($document);
my ($fp) = $self->method_lookup("open-ils.ingest.fingerprint.xml")->run($xml);
+ my ($rd) = $self->method_lookup("open-ils.ingest.descriptor.xml")->run($xml);
- return { full_rec => \@mfr, field_entries => \@mXfe, fingerprint => $fp };
+ return { full_rec => \@mfr, field_entries => \@mXfe, fingerprint => $fp, descriptor => $rd };
}
__PACKAGE__->register_method(
api_name => "open-ils.ingest.full.biblio.xml.readonly",
$_->source($rec) for (@{$res->{field_entries}});
$_->record($rec) for (@{$res->{full_rec}});
+ $res->{descriptor}->record($rec);
return $res;
}
$_->source($bib->id) for (@{$res->{field_entries}});
$_->record($bib->id) for (@{$res->{full_rec}});
- $client->respond( @{$res->{field_entries}} + @{$res->{full_rec}} );
+ $client->respond( $res );
}
return undef;
argc => 1,
);
+our $rd_script;
+sub biblio_descriptor {
+ my $self = shift;
+ my $client = shift;
+ my $xml = shift;
+
+ $log->internal("Got MARC [$xml]");
+
+ if(!$rd_script) {
+ my @pfx = ( "apps", "open-ils.ingest","app_settings" );
+ my $conf = OpenSRF::Utils::SettingsClient->new;
+
+ my $libs = $conf->config_value(@pfx, 'script_path');
+ my $script_file = $conf->config_value(@pfx, 'scripts', 'biblio_descriptor');
+ my $script_libs = (ref($libs)) ? $libs : [$libs];
+
+ $log->debug("Loading script $script_file for biblio descriptor extraction...");
+
+ $rd_script = new OpenILS::Utils::ScriptRunner
+ ( file => $script_file,
+ paths => $script_libs,
+ reset_count => 1000 );
+ }
+
+ $rd_script->insert('environment' => {marc => $xml} => 1);
+
+ my $res = $rd_script->run || ($log->error( "Descriptor script died! $@" ) && return undef);
+ $log->debug("Script for biblio descriptor extraction completed successfully...");
+
+ return $res;
+}
+__PACKAGE__->register_method(
+ api_name => "open-ils.ingest.descriptor.xml",
+ method => "biblio_descriptor",
+ api_level => 1,
+ argc => 1,
+);
+
1;