From 07cb30ad2c5d38f1a62e8bdf7e2004b66ee82a4e Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 7 Jul 2006 17:53:00 +0000 Subject: [PATCH] more in(de)gestion git-svn-id: svn://svn.open-ils.org/ILS/trunk@4934 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../backend/catalog/biblio_descriptor.js | 24 +++++++ .../javascript/backend/catalog/record_type.js | 38 ++++++---- .../perlmods/OpenILS/Application/Ingest.pm | 70 ++++++++++++++++++- 3 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js diff --git a/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js b/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js new file mode 100644 index 0000000000..4f1dbd6014 --- /dev/null +++ b/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js @@ -0,0 +1,24 @@ +// 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' ) ); + diff --git a/Open-ILS/src/javascript/backend/catalog/record_type.js b/Open-ILS/src/javascript/backend/catalog/record_type.js index 61d3c349b9..26f44c9da6 100644 --- a/Open-ILS/src/javascript/backend/catalog/record_type.js +++ b/Open-ILS/src/javascript/backend/catalog/record_type.js @@ -119,6 +119,14 @@ var ff_pos = { 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' }, @@ -295,22 +303,28 @@ function extractFixedField (rec, field) { 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; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm b/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm index 7dabc28294..73fd455718 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm @@ -88,6 +88,32 @@ sub entityize { 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; @@ -98,8 +124,9 @@ sub ro_biblio_ingest_single_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); - 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", @@ -125,6 +152,7 @@ sub ro_biblio_ingest_single_record { $_->source($rec) for (@{$res->{field_entries}}); $_->record($rec) for (@{$res->{full_rec}}); + $res->{descriptor}->record($rec); return $res; } @@ -213,7 +241,7 @@ sub rw_biblio_ingest_stream_import { $_->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; @@ -612,6 +640,44 @@ __PACKAGE__->register_method( 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; -- 2.43.2