From 0ac9c3384a8cc3b5eeef998f34c68dc3777d23da Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 28 Feb 2005 21:39:08 +0000 Subject: [PATCH] EETS ALIVE!!!!!!! git-svn-id: svn://svn.open-ils.org/ILS/trunk@149 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/extras/import/import_clean_marc.pl | 41 +++-- .../perlmods/OpenILS/Application/Storage.pm | 12 +- .../OpenILS/Application/Storage/CDBI.pm | 26 +-- .../OpenILS/Application/Storage/CDBI/actor.pm | 12 +- .../Application/Storage/CDBI/biblio.pm | 21 ++- .../OpenILS/Application/Storage/Driver/Pg.pm | 39 ++-- .../Application/Storage/Publisher/biblio.pm | 167 ++++++++++++++++++ .../src/perlmods/OpenILS/Utils/FlatXML.pm | 18 +- 8 files changed, 269 insertions(+), 67 deletions(-) diff --git a/Open-ILS/src/extras/import/import_clean_marc.pl b/Open-ILS/src/extras/import/import_clean_marc.pl index 9d6b216cc4..80bef3654c 100755 --- a/Open-ILS/src/extras/import/import_clean_marc.pl +++ b/Open-ILS/src/extras/import/import_clean_marc.pl @@ -1,11 +1,14 @@ #!/usr/bin/perl -w use strict; +use lib '../../perlmods/'; +use lib '../../../../OpenSRF/src/perlmods/'; use OpenSRF::EX qw/:try/; use OpenSRF::System; use OpenSRF::Utils::SettingsClient; use OpenILS::Utils::FlatXML; use Time::HiRes; use Getopt::Long; +use Data::Dumper; my ($config, $userid, $sourceid, $wormize) = ('/pines/conf/bootstrap.conf', 1, 2); @@ -17,36 +20,50 @@ GetOptions ( ); OpenSRF::System->bootstrap_client( config_file => $config ); -my $st_server = OpenSRF::AppSession->new( 'storage' ); -my $worm_server = OpenSRF::AppSession->new( 'worm' ) if ($wormize); +my $st_server = OpenSRF::AppSession->create( 'storage' ); +my $worm_server = OpenSRF::AppSession->create( 'worm' ) if ($wormize); try { - $st_server->connect; - $worm_server->connect if ($wormize); + throw OpenSRF::EX::PANIC ("I can't connect to the storage server!") - unless ($st_server->connected); + if (!$st_server->connect); + + throw OpenSRF::EX::PANIC ("I can't connect to the worm server!") + if ($wormize && !$worm_server->connect); + } catch Error with { die shift; }; -while ( my $ns = OpenILS::Utils::FlatXML->new( xml => ) ) { +while ( my $xml = <> ) { + chomp $xml; + + my $ns = OpenILS::Utils::FlatXML->new( xml => $xml ); + + next unless ($ns->xml); my $doc = $ns->xml_to_doc; my $tcn = $doc->documentElement->findvalue( '/*/*[@tag="035"]' ); - + + warn "Adding record for TCN $tcn\n"; + + $ns->xml_to_nodeset; + #next; + my $req = $st_server->request( 'open-ils.storage.biblio.record_entry.create', - creator => $userid, + { creator => $userid, editor => $userid, source => $sourceid, tcn_value => $tcn, + }, ); $req->wait_complete; my $resp = $req->recv; - unless( $resp->content ) { + unless( $resp && $resp->can('content') ) { throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]!! -- $resp"); } @@ -55,19 +72,19 @@ while ( my $ns = OpenILS::Utils::FlatXML->new( xml => ) ) { $req->finish; if ($new_id) { - my $nodeset = $ns->xml_to_nodeset; + my $nodeset = $ns->nodeset; $_->{owner_doc} = $new_id for (@$nodeset); $req = $st_server->request( - 'open-ils.storage.record_node.batch.create', + 'open-ils.storage.biblio.record_node.batch.create', @$nodeset, ); $req->wait_complete; $resp = $req->recv; - unless( $resp->content ) { + unless( $resp && $resp->can('content') ) { throw OpenSRF::EX::ERROR ("Failed to create record_nodes for TCN [$tcn]!! -- $resp"); } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage.pm index e9d3a89c6b..a1b55d4fe2 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage.pm @@ -24,18 +24,18 @@ sub initialize { $log->debug('Initializing ' . __PACKAGE__ . '...', DEBUG); - my $driver = "OpenILS::App::Storage::Driver::". + my $driver = "OpenILS::Application::Storage::Driver::". $conf->config_value( apps => storage => app_settings => databases => 'driver'); - eval "use $driver;"; - throw OpenILS::EX::Config ( "Can't load $driver! : $@" ) if ($@); - - @OpenILS::Application::Storage::CDBI::ISA = ( $driver ); + $log->debug("Attempting to load $driver ...", DEBUG); - OpenILS::Application::Storage::CDBI->initialize if ($driver->can('initialize')); + eval "use $driver;"; + throw OpenILS::EX::PANIC ( "Can't load $driver! : $@" ) if ($@); + $log->debug("$driver loaded successfully", DEBUG); + @OpenILS::Application::Storage::CDBI::ISA = ( $driver ); } sub child_init { diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm index a84d60f49c..078c3feeb8 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm @@ -41,30 +41,30 @@ biblio::record_node->has_a( #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- -metabib::metarecord->has_a( master_record => 'biblio::record_entry' ); +#metabib::metarecord->has_a( master_record => 'biblio::record_entry' ); #------------------------------------------------------------------------------- -metabib::title_field_entry->has_a( field => 'config::metabib_field_map' ); +#metabib::title_field_entry->has_a( field => 'config::metabib_field_map' ); #------------------------------------------------------------------------------- -metabib::author_field_entry->has_a( field => 'config::metabib_field_map' ); +#metabib::author_field_entry->has_a( field => 'config::metabib_field_map' ); #------------------------------------------------------------------------------- -metabib::subject_field_entry->has_a( field => 'config::metabib_field_map' ); +#metabib::subject_field_entry->has_a( field => 'config::metabib_field_map' ); #------------------------------------------------------------------------------- -metabib::keyword_field_entry->has_a( field => 'config::metabib_field_map' ); +#metabib::keyword_field_entry->has_a( field => 'config::metabib_field_map' ); #------------------------------------------------------------------------------- # should we have just one field entry per class for each record???? (xslt vs xpath) -metabib::title_field_entry_source_map->has_a( field_entry => 'metabib::title_field_entry' ); -metabib::title_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); +#metabib::title_field_entry_source_map->has_a( field_entry => 'metabib::title_field_entry' ); +#metabib::title_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); #------------------------------------------------------------------------------- -metabib::subject_field_entry_source_map->has_a( field_entry => 'metabib::subject_field_entry' ); -metabib::subject_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); +#metabib::subject_field_entry_source_map->has_a( field_entry => 'metabib::subject_field_entry' ); +#metabib::subject_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); #------------------------------------------------------------------------------- -metabib::author_field_entry_source_map->has_a( field_entry => 'metabib::author_field_entry' ); -metabib::author_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); +#metabib::author_field_entry_source_map->has_a( field_entry => 'metabib::author_field_entry' ); +#metabib::author_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); #------------------------------------------------------------------------------- -metabib::keyword_field_entry_source_map->has_a( field_entry => 'metabib::keyword_field_entry' ); -metabib::keyword_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); +#metabib::keyword_field_entry_source_map->has_a( field_entry => 'metabib::keyword_field_entry' ); +#metabib::keyword_field_entry_source_map->has_a( source_record => 'biblio::record_entry' ); #------------------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm index 980eb2c1f2..60e5cfc67e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm @@ -5,14 +5,14 @@ our $VERSION = 1; package actor; use base qw/OpenILS::Application::Storage::CDBI/; #------------------------------------------------------------------------------- -package actor::usr; +package actor::user; use base qw/actor/; __PACKAGE__->table( 'actor_usr' ); -__PACKAGE__->columns( All => qw/id usrid usrname email prefix first_given_name +__PACKAGE__->columns( All => qw/id userid username email prefix first_given_name second_given_name family_name suffix address home_ou gender dob active master_account - super_user usrgoup passwd/ ); + super_user usergoup passwd/ ); #------------------------------------------------------------------------------- package actor::org_unit_type; @@ -25,7 +25,7 @@ __PACKAGE__->columns( All => qw/id name depth parent can_have_users/); package actor::org_unit; use base qw/actor/; #------------------------------------------------------------------------------- -package actor::usr_access_entry; +package actor::user_access_entry; use base qw/actor/; #------------------------------------------------------------------------------- package actor::perm_group; @@ -37,10 +37,10 @@ use base qw/actor/; package actor::perm_group_permission_map; use base qw/actor/; #------------------------------------------------------------------------------- -package actor::perm_group_usr_map; +package actor::perm_group_user_map; use base qw/actor/; #------------------------------------------------------------------------------- -package actor::usr_address; +package actor::user_address; use base qw/actor/; #------------------------------------------------------------------------------- 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/biblio.pm index 7d4f81b261..8faa0907e6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/biblio.pm @@ -19,21 +19,36 @@ package biblio::record_node::subnode; sub _load { my $intra_doc_id = shift; my $owner_doc = shift()->owner_doc; - return (biblio::record_node->search( owner_doc => $owner_doc, intra_doc_id => $intra_doc_id ))[0]; + return (biblio::record_node->search( + owner_doc => $owner_doc, + intra_doc_id => $intra_doc_id + ) + )[0]; } package biblio::record_node; use base qw/biblio/; biblio::record_node->table( 'biblio_record_data' ); -biblio::record_node->columns( All => qw/id owner_doc intra_doc_id parent_node node_type namespace_uri name value/ ); +biblio::record_node->columns( All => qw/id owner_doc intra_doc_id + parent_node node_type + namespace_uri name value/ ); + +biblio::record_node->has_a( + parent_node => 'biblio::record_node::subnode', + inflate => sub { + return biblio::record_node::subnode::_load(@_) + }, +); + #------------------------------------------------------------------------------- package biblio::record_note; use base qw/biblio/; biblio::record_note->table( 'biblio_record_note' ); -biblio::record_note->columns( All => qw/id record value creator editor create_date edit_date/ ); +biblio::record_note->columns( All => qw/id record value creator + editor create_date edit_date/ ); biblio::record_note->columns( Stringify => qw/value/ ); #------------------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm index 392c41205f..49a181b2a5 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm @@ -59,8 +59,8 @@ package OpenILS::Application::Storage::Driver::Pg; use base qw/Class::DBI OpenILS::Application::Storage/; use DBI; - use DBD::Pg; use OpenSRF::Utils::Logger qw/:level/; + my $log = 'OpenSRF::Utils::Logger'; __PACKAGE__->set_sql( retrieve_limited => 'SELECT * FROM __TABLE__ ORDER BY id LIMIT ?' ); @@ -68,6 +68,8 @@ sub child_init { my $self = shift; $_db_params = shift; + + $log->debug("Running child_init inside ".__PACKAGE__, INTERNAL); } my $_dbh; @@ -88,9 +90,10 @@ ChopBlanks => 1, ); + $log->debug(" Default connect info for this DB is:\n\t".join("\n\t",map { "$_\t==> $$_db_params{$_}" } keys %$_db_params), INTERNAL); $log->debug(" Default attributes for this DB connection are:\n\t".join("\n\t",map { "$_\t==> $attrs{$_}" } keys %attrs), INTERNAL); - $_dbh = DBI->connect( "dbi:Pg:host=$$_db_params{host};dbname=$$_db_params{database}",$$_db_params{user},$$_db_params{pw}, \%attrs ); + $_dbh = DBI->connect( "dbi:Pg:host=$$_db_params{host};dbname=$$_db_params{db}",$$_db_params{user},$$_db_params{pw}, \%attrs ); $_dbh->do("SET CLIENT_ENCODING TO 'SQL_ASCII';"); return $_dbh; @@ -117,44 +120,44 @@ #--------------------------------------------------------------------- package asset::call_number; - __PACKAGE__->table( 'asset.call_number' ); - __PACKAGE__->sequence( 'asset.call_number_id_seq' ); + asset::call_number->table( 'asset.call_number' ); + asset::call_number->sequence( 'asset.call_number_id_seq' ); #--------------------------------------------------------------------- package asset::copy; - __PACKAGE__->table( 'asset.copy' ); - __PACKAGE__->sequence( 'asset.copy_id_seq' ); + asset::copy->table( 'asset.copy' ); + asset::copy->sequence( 'asset.copy_id_seq' ); #--------------------------------------------------------------------- package biblio::record_entry; - __PACKAGE__->table( 'biblio.record_entry' ); - __PACKAGE__->sequence( 'biblio.record_entry_id_seq' ); - + biblio::record_entry->table( 'biblio.record_entry' ); + biblio::record_entry->sequence( 'biblio.record_entry_id_seq' ); + #--------------------------------------------------------------------- package biblio::record_node; - __PACKAGE__->table( 'biblio.record_data' ); - __PACKAGE__->sequence( 'biblio.record_data_id_seq' ); + biblio::record_node->table( 'biblio.record_data' ); + biblio::record_node->sequence( 'biblio.record_data_id_seq' ); #--------------------------------------------------------------------- package biblio::record_note; - __PACKAGE__->table( 'biblio.record_note' ); - __PACKAGE__->sequence( 'biblio.record_note_id_seq' ); + biblio::record_note->table( 'biblio.record_note' ); + biblio::record_note->sequence( 'biblio.record_note_id_seq' ); #--------------------------------------------------------------------- - package actor::usr; + package actor::user; - __PACKAGE__->table( 'actor.usr' ); - __PACKAGE__->sequence( 'actor.usr_id_seq' ); + actor::user->table( 'actor.usr' ); + actor::user->sequence( 'actor.usr_id_seq' ); #--------------------------------------------------------------------- package actor::org_unit_type; - __PACKAGE__->table( 'actor.org_unit_type' ); - __PACKAGE__->sequence( 'actor.org_unit_type_id_seq' ); + actor::org_unit_type->table( 'actor.org_unit_type' ); + actor::org_unit_type->sequence( 'actor.org_unit_type_id_seq' ); #--------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm index 19ccdc88e7..72a3971590 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/biblio.pm @@ -2,6 +2,122 @@ package OpenILS::Application::Storage::Publisher::biblio; use base qw/OpenILS::Application::Storage/; use OpenILS::Application::Storage::CDBI::biblio; +sub create_record_node { + my $self = shift; + my $client = shift; + my $node = shift;; + + my $n = biblio::record_node->create($node); + return $n->id; +} +__PACKAGE__->register_method( + method => 'create_record_node', + api_name => 'open-ils.storage.biblio.record_node.create', + api_level => 1, + argc => 1, +); + +sub update_record_node { + my $self = shift; + my $client = shift; + my $node = shift;; + + my $n = biblio::record_node->retrieve($$node{id}); + return undef unless ($n); + + for my $field ( keys %$node ) { + $n->$field( $$node{$field} ); + } + + $n->update; + return $n->id; +} +__PACKAGE__->register_method( + method => 'update_record_node', + api_name => 'open-ils.storage.biblio.record_node.update', + api_level => 1, + argc => 1, +); + + +sub create_record_nodeset { + my $self = shift; + my $client = shift; + + my $method = $self->method_lookup('open-ils.storage.biblio.record_node.create'); + + local biblio::record_node->db_Main->{AutoCommit} = 0; + + my @ids; + while ( my $node = shift(@_) ) { + $client->respond( $method->run( $node ) ); + } + return undef; +} +__PACKAGE__->register_method( + method => 'create_record_nodeset', + api_name => 'open-ils.storage.biblio.record_node.batch.create', + api_level => 1, + argc => 1, +); + +sub create_record_entry { + my $self = shift; + my $client = shift; + my $metadata = shift; + + my $rec = biblio::record_entry->create($metadata); + return $rec->id; +} +__PACKAGE__->register_method( + method => 'create_record_entry', + api_name => 'open-ils.storage.biblio.record_entry.create', + api_level => 1, + argc => 2, + note => <retrieve($$entry{id}); + return undef unless ($rec); + + for my $field ( keys %$node ) { + $rec->$field( $$node{$field} ); + } + + $rec->update; + return $rec->id; +} +__PACKAGE__->register_method( + method => 'update_record_node', + api_name => 'open-ils.storage.biblio.record_node.update', + api_level => 1, + argc => 1, +); + + + sub get_record_entry { my $self = shift; my $client = shift; @@ -31,4 +147,55 @@ __PACKAGE__->register_method( stream => 1, ); +sub get_record_node { + my $self = shift; + my $client = shift; + my @ids = @_; + + for my $id ( @ids ) { + next unless ($id); + + my $rec = biblio::record_node->retrieve($id); + $client->respond( $self->_cdbi2Hash( $rec ) ) if ($rec); + + last if ($self->api_name !~ /list/o); + } + return undef; +} +__PACKAGE__->register_method( + method => 'get_record_node', + api_name => 'open-ils.storage.biblio.record_node.retrieve', + api_level => 1, + argc => 1, +); +__PACKAGE__->register_method( + method => 'get_record_node', + api_name => 'open-ils.storage.biblio.record_node.retrieve.list', + api_level => 1, + argc => 1, + stream => 1, +); + +sub get_record_nodeset { + my $self = shift; + my $client = shift; + my @ids = @_; + + for my $id ( @ids ) { + next unless ($id); + + my $rec = biblio::record_entry->retrieve($id); + $client->respond( $self->_cdbi_list2AoH( $rec->nodes ) ) if ($rec); + } + return undef; +} +__PACKAGE__->register_method( + method => 'get_record_nodeset', + api_name => 'open-ils.storage.biblio.record_entry.nodeset.retrieve', + api_level => 1, + argc => 1, + stream => 1, +); + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/FlatXML.pm b/Open-ILS/src/perlmods/OpenILS/Utils/FlatXML.pm index 1cc7b969df..6286ea1d82 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/FlatXML.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/FlatXML.pm @@ -104,10 +104,10 @@ sub nodeset_to_xml { $xml = $doc->createComment( $node->{value} ); } elsif ( $node->{node_type} == XML_NAMESPACE_DECL ) { - if ($self->nodeset->[$node->{parent_node_id}]->{namespace_uri} eq $node->{value}) { - $_xmllist[$node->{parent_node_id}]->setNamespace($node->{value}, $node->{name}, 1); + if ($self->nodeset->[$node->{parent_node}]->{namespace_uri} eq $node->{value}) { + $_xmllist[$node->{parent_node}]->setNamespace($node->{value}, $node->{name}, 1); } else { - $_xmllist[$node->{parent_node_id}]->setNamespace($node->{value}, $node->{name}, 0); + $_xmllist[$node->{parent_node}]->setNamespace($node->{value}, $node->{name}, 0); } $seen_ns{$node->{value}} = $node->{name}; next; @@ -115,9 +115,9 @@ sub nodeset_to_xml { } elsif ( $node->{node_type} == XML_ATTRIBUTE_NODE ) { if ($node->{namespace_uri}) { - $_xmllist[$node->{parent_node_id}]->setAttributeNS($node->{namespace_uri}, $node->{name}, $node->{value}); + $_xmllist[$node->{parent_node}]->setAttributeNS($node->{namespace_uri}, $node->{name}, $node->{value}); } else { - $_xmllist[$node->{parent_node_id}]->setAttribute($node->{name}, $node->{value}); + $_xmllist[$node->{parent_node}]->setAttribute($node->{name}, $node->{value}); } next; @@ -127,8 +127,8 @@ sub nodeset_to_xml { $_xmllist[$node->{intra_doc_id}] = $xml; - if (defined $node->{parent_node_id}) { - $_xmllist[$node->{parent_node_id}]->addChild($xml); + if (defined $node->{parent_node}) { + $_xmllist[$node->{parent_node}]->addChild($xml); } } @@ -154,7 +154,7 @@ sub _xml_to_nodeset { push @{$self->{nodelist}}, { intra_doc_id => 0, - parent_node_id => undef, + parent_node => undef, name => $node->localname, value => undef, node_type => $node->nodeType, @@ -178,7 +178,7 @@ sub _nodeset_recurse { push @{$self->{nodelist}}, { intra_doc_id => ++$self->{next_id}, - parent_node_id => $parent, + parent_node => $parent, name => $kid->localname, value => _grab_content( $kid, $type ), node_type => $type, -- 2.43.2