fleshed out "actor.usr" interface, and stream behavior adjustment
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 14 Apr 2005 16:48:58 +0000 (16:48 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 14 Apr 2005 16:48:58 +0000 (16:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@497 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/WORM.pm
Open-ILS/src/sql/Postgres/090.schema.action.sql
OpenSRF/src/perlmods/OpenSRF/Application.pm

index 1744a87..afbca80 100644 (file)
@@ -13,7 +13,7 @@ use OpenILS::Application::Storage::CDBI::money;
 use OpenSRF::Utils::Logger;
 use OpenSRF::EX qw/:try/;
 
-our $VERSION;
+our $VERSION = undef;
 my $log = 'OpenSRF::Utils::Logger';
 
 sub child_init {
@@ -272,146 +272,129 @@ sub modify_from_fieldmapper {
 
 
 
-sub import {
-       return if ($VERSION);
-
        #-------------------------------------------------------------------------------
        actor::user->has_a( home_ou => 'actor::org_unit' );
-       actor::user->has_many( survey_responses => 'action::survey_response' );
-       #-------------------------------------------------------------------------------
-       actor::org_unit->has_many( users => 'actor::user' );
+       actor::user->has_a( card => 'actor::card' );
+       actor::user->has_a( standing => 'config::standing' );
+       actor::user->has_a( profile => 'actor::profile' );
+       actor::user->has_a( address => 'actor::user_address' );
+       actor::user->has_a( ident_type => 'config::identification_type' );
+
+       actor::user_address->has_a( usr => 'actor::user' );
+       
+       actor::card->has_a( usr => 'actor::user' );
+       
        actor::org_unit->has_a( parent_ou => 'actor::org_unit' );
        actor::org_unit->has_a( ou_type => 'actor::org_unit_type' );
-       #actor::org_unit->has_a( address => 'actor::address' );
-       #-------------------------------------------------------------------------------
+       #actor::org_unit->has_a( address => 'actor::org_address' );
 
-       #-------------------------------------------------------------------------------
        action::survey_response->has_a( usr => 'actor::user' );
        action::survey_response->has_a( survey => 'action::survey' );
        action::survey_response->has_a( question => 'action::survey_question' );
        action::survey_response->has_a( answer => 'action::survey_answer' );
-       #-------------------------------------------------------------------------------
-       action::survey->has_many( questions => 'action::survey_question' );
-       action::survey->has_many( responses => 'action::survey_response' );
-       #-------------------------------------------------------------------------------
+
        action::survey_question->has_a( survey => 'action::survey' );
-       action::survey_question->has_many( answers => 'action::survey_answer' );
-       action::survey_question->has_many( responses => 'action::survey_response' );
-       #-------------------------------------------------------------------------------
+
        action::survey_answer->has_a( question => 'action::survey' );
-       action::survey_answer->has_many( responses => 'action::survey_response' );
-       #-------------------------------------------------------------------------------
 
-       #-------------------------------------------------------------------------------
        asset::copy_note->has_a( owning_copy => 'asset::copy' );
-       #-------------------------------------------------------------------------------
+
        asset::copy->has_a( call_number => 'asset::call_number' );
-       asset::copy->has_many( notes => 'asset::copy_note' );
        asset::copy->has_a( creator => 'actor::user' );
        asset::copy->has_a( editor => 'actor::user' );
-       #-------------------------------------------------------------------------------
+
        asset::call_number_note->has_a( owning_call_number => 'asset::call_number' );
-       #-------------------------------------------------------------------------------
+
        asset::call_number->has_a( record => 'biblio::record_entry' );
-       asset::call_number->has_many( copies => 'asset::copy' );
-       asset::call_number->has_many( notes => 'asset::call_number_note' );
        asset::call_number->has_a( creator => 'actor::user' );
        asset::call_number->has_a( editor => 'actor::user' );
-       #-------------------------------------------------------------------------------
-       
 
-       #-------------------------------------------------------------------------------
        biblio::record_note->has_a( record => 'biblio::record_entry' );
-       #-------------------------------------------------------------------------------
+       
        biblio::record_entry->has_a( creator => 'actor::user' );
        biblio::record_entry->has_a( editor => 'actor::user' );
-       biblio::record_entry->has_many( record_descriptor => 'metabib::record_descriptor' );
-       biblio::record_entry->has_many( notes => 'biblio::record_note' );
-       biblio::record_entry->has_many( call_numbers => 'asset::call_number' );
        
-       # should we have just one field entry per class for each record???? (xslt vs xpath)
-       biblio::record_entry->has_many( full_record_entries => 'metabib::full_rec' );
-       biblio::record_entry->has_many( title_field_entries => 'metabib::title_field_entry' );
-       biblio::record_entry->has_many( author_field_entries => 'metabib::author_field_entry' );
-       biblio::record_entry->has_many( subject_field_entries => 'metabib::subject_field_entry' );
-       biblio::record_entry->has_many( keyword_field_entries => 'metabib::keyword_field_entry' );
-       #-------------------------------------------------------------------------------
-
-
-       #-------------------------------------------------------------------------------
        metabib::metarecord->has_a( master_record => 'biblio::record_entry' );
-       metabib::metarecord->has_many( source_records => [ 'metabib::metarecord_source_map' => 'source'] );
-       #-------------------------------------------------------------------------------
+       
        metabib::record_descriptor->has_a( record => 'biblio::record_entry' );
-       #-------------------------------------------------------------------------------
+       
        metabib::full_rec->has_a( record => 'biblio::record_entry' );
-       #-------------------------------------------------------------------------------
+       
        metabib::title_field_entry->has_a( source => 'biblio::record_entry' );
        metabib::title_field_entry->has_a( field => 'config::metabib_field' );
-       #-------------------------------------------------------------------------------
+       
        metabib::author_field_entry->has_a( source => 'biblio::record_entry' );
        metabib::author_field_entry->has_a( field => 'config::metabib_field' );
-       #-------------------------------------------------------------------------------
+       
        metabib::subject_field_entry->has_a( source => 'biblio::record_entry' );
        metabib::subject_field_entry->has_a( field => 'config::metabib_field' );
-       #-------------------------------------------------------------------------------
+       
        metabib::keyword_field_entry->has_a( source => 'biblio::record_entry' );
        metabib::keyword_field_entry->has_a( field => 'config::metabib_field' );
-       #-------------------------------------------------------------------------------
+       
        metabib::metarecord_source_map->has_a( metarecord => 'metabib::metarecord' );
        metabib::metarecord_source_map->has_a( source => 'biblio::record_entry' );
-       #-------------------------------------------------------------------------------
 
        action::circulation->has_a( usr => 'actor::user' );
        action::circulation->has_a( target_copy => 'asset::copy' );
+       action::circulation->has_a( circ_lib => 'actor::org_unit' );
 
+       money::billable_transaction->has_a( usr => 'actor::user' );
+       
+       
        #-------------------------------------------------------------------------------
+       actor::user->has_many( survey_responses => 'action::survey_response' );
+       actor::user->has_many( addresses => 'actor::user_address' );
+       actor::user->has_many( cards => 'actor::card' );
+
+       actor::org_unit->has_many( users => 'actor::user' );
+       actor::profile->has_many( users => 'actor::user' );
+
+       action::survey->has_many( questions => 'action::survey_question' );
+       action::survey->has_many( responses => 'action::survey_response' );
+       
+       action::survey_question->has_many( answers => 'action::survey_answer' );
+       action::survey_question->has_many( responses => 'action::survey_response' );
+
+       action::survey_answer->has_many( responses => 'action::survey_response' );
+
+       asset::copy->has_many( notes => 'asset::copy_note' );
+       asset::call_number->has_many( copies => 'asset::copy' );
+       asset::call_number->has_many( notes => 'asset::call_number_note' );
+
+       biblio::record_entry->has_many( record_descriptor => 'metabib::record_descriptor' );
+       biblio::record_entry->has_many( notes => 'biblio::record_note' );
+       biblio::record_entry->has_many( call_numbers => 'asset::call_number' );
+       biblio::record_entry->has_many( full_record_entries => 'metabib::full_rec' );
+       biblio::record_entry->has_many( title_field_entries => 'metabib::title_field_entry' );
+       biblio::record_entry->has_many( author_field_entries => 'metabib::author_field_entry' );
+       biblio::record_entry->has_many( subject_field_entries => 'metabib::subject_field_entry' );
+       biblio::record_entry->has_many( keyword_field_entries => 'metabib::keyword_field_entry' );
+
+       metabib::metarecord->has_many( source_records => [ 'metabib::metarecord_source_map' => 'source'] );
 
-       money::billable_transaction->has_a( usr => 'actor::user' );
        money::billable_transaction->has_many( billings => 'money::billing' );
        money::billable_transaction->has_many( payments => 'money::payment' );
 
-       money::billing->has_a( transaction => 'money::billable_transaction' );
-       money::payment->has_a( transaction => 'money::billable_transaction' );
+       money::billing->has_a( xact => 'money::billable_transaction' );
+       money::payment->has_a( xact => 'money::billable_transaction' );
 
-       money::cash_payment->has_a( transaction => 'money::billable_transaction' );
+       money::cash_payment->has_a( xact => 'money::billable_transaction' );
        money::cash_payment->has_a( accepting_usr => 'actor::user' );
 
-       money::check_payment->has_a( transaction => 'money::billable_transaction' );
+       money::check_payment->has_a( xact => 'money::billable_transaction' );
        money::check_payment->has_a( accepting_usr => 'actor::user' );
 
-       money::credit_card_payment->has_a( transaction => 'money::billable_transaction' );
+       money::credit_card_payment->has_a( xact => 'money::billable_transaction' );
        money::credit_card_payment->has_a( accepting_usr => 'actor::user' );
 
-       money::forgive_payment->has_a( transaction => 'money::billable_transaction' );
+       money::forgive_payment->has_a( xact => 'money::billable_transaction' );
        money::forgive_payment->has_a( accepting_usr => 'actor::user' );
 
-       money::work_payment->has_a( transaction => 'money::billable_transaction' );
+       money::work_payment->has_a( xact => 'money::billable_transaction' );
        money::work_payment->has_a( accepting_usr => 'actor::user' );
 
-       money::credit_payment->has_a( transaction => 'money::billable_transaction' );
+       money::credit_payment->has_a( xact => 'money::billable_transaction' );
        money::credit_payment->has_a( accepting_usr => 'actor::user' );
 
-
-       # 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( metarecord => 'metabib::metarecord' );
-       #-------------------------------------------------------------------------------
-       #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( metarecord => 'metabib::metarecord' );
-       #-------------------------------------------------------------------------------
-       #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( metarecord => 'metabib::metarecord' );
-       #-------------------------------------------------------------------------------
-       #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( metarecord => 'metabib::metarecord' );
-       #-------------------------------------------------------------------------------
-       $VERSION = 1;
-}
-
-
 1;
index e8c87e2..7a04094 100644 (file)
@@ -92,6 +92,20 @@ use base qw/actor/;
 #-------------------------------------------------------------------------------
 package actor::user_address;
 use base qw/actor/;
+
+__PACKAGE__->table( 'actor_card' );
+__PACKAGE__->columns( Primary => qw/id/ );
+__PACKAGE__->columns( Essential => qw/valid address_type usr street1 street2
+                                     county state country post_code/ );
+
+#-------------------------------------------------------------------------------
+package actor::profile;
+use base qw/actor/;
+
+__PACKAGE__->table( 'actor_card' );
+__PACKAGE__->columns( Primary => qw/id/ );
+__PACKAGE__->columns( Essential => qw/name/ );
+
 #-------------------------------------------------------------------------------
 1;
 
index 7de5574..b5f1382 100644 (file)
        
        actor::user->table( 'actor.usr' );
        actor::user->sequence( 'actor.usr_id_seq' );
+
+       #---------------------------------------------------------------------
+       package actor::user_address;
+       
+       actor::user_address->table( 'actor.usr_address' );
+       actor::user_address->sequence( 'actor.usr_address_id_seq' );
        
        #---------------------------------------------------------------------
        package actor::profile;
index 6876221..2be7622 100644 (file)
@@ -2,7 +2,7 @@ package OpenILS::Application::Storage::Publisher;
 use base qw/OpenILS::Application::Storage/;
 our $VERSION = 1;
 
-use Data::Dumper;
+use Digest::MD5 qw/md5_hex/;
 use OpenSRF::EX qw/:try/;;
 use OpenSRF::Utils::Logger;
 my $log = 'OpenSRF::Utils::Logger';
@@ -60,14 +60,16 @@ sub cachable_wrapper {
                        $ind++;
                        my $value_ind = $ind;
                        $cache_args{$args[$key_ind]} = $args[$value_ind];
-                       $log->debug("Cache limiter value for $args[$key_ind] is $args[$value_ind]", DEBUG);
+                       $log->debug("Cache limiter value for $args[$key_ind] is $args[$value_ind]", INTERNAL);
                        next;
                }
                $key_string .= $args[$ind];
+               $log->debug("Partial cache key value is $args[$ind]", INTERNAL);
                push @real_args, $args[$ind];
        }
 
        my $cache_key = md5_hex($key_string);
+       $log->debug("Key string for cache lookup is $key_string -> $cache_key", DEBUG);
 
        my $cached_res = OpenSRF::Utils::Cache->new->get_cache( $cache_key );
        if (defined $cached_res) {
@@ -83,7 +85,7 @@ sub cachable_wrapper {
 
         $client->respond( $_ ) for ( grep { defined } @res[$cache_args{offset} .. int($cache_args{offset} + $cache_args{limit} - 1)] );
 
-        OpenSRF::Utils::Cache->new->put_cache( $cache_key => \@res => $cach_args{timeout});
+        OpenSRF::Utils::Cache->new->put_cache( $cache_key => \@res => $cache_args{timeout});
 
        return undef;
 }
index 39213a7..b6034cf 100644 (file)
@@ -6,6 +6,127 @@ use OpenILS::Utils::Fieldmapper;
 
 my $log = 'OpenSRF::Utils::Logger';
 
+sub user_by_barcode {
+       my $self = shift;
+       my $client = shift;
+       my @barcodes = shift;
+
+       return undef unless @barcodes;
+
+       for my $card ( actor::card->search( { barcode => @barcodes } ) ) {
+
+               next unless $card;
+
+               my $usr_fm = flesh_user( $card->usr );
+               $client->respond( $usr_fm );
+       }
+       return undef;
+}
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.fleshed.actor.user.search.barcode',
+       api_level       => 1,
+       method          => 'user_by_barcode',
+       stream          => 1,
+       cachable        => 1,
+);
+
+sub fleshed_search {
+       my $self = shift;
+       my $client = shift;
+       my $searches = shift;
+
+       return undef unless (defined $searches);
+
+       for my $usr ( actor::user->search( $searches ) ) {
+               next unless $usr;
+               $client->respond( flesh_user( $usr ) );
+       }
+       return undef;
+}
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.fleshed.actor.user.search',
+       api_level       => 1,
+       method          => 'fleshed_search',
+       stream          => 1,
+       cachable        => 1,
+);
+
+sub fleshed_search_like {
+       my $self = shift;
+       my $client = shift;
+       my $searches = shift;
+
+       return undef unless (defined $searches);
+
+       for my $usr ( actor::user->search_like( $searches ) ) {
+               next unless $usr;
+               $client->respond( flesh_user( $usr ) );
+       }
+       return undef;
+}
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.fleshed.actor.user.search_like',
+       api_level       => 1,
+       method          => 'user_by_barcode',
+       stream          => 1,
+       cachable        => 1,
+);
+
+sub retrieve_fleshed_user {
+       my $self = shift;
+       my $client = shift;
+       my @ids = shift;
+
+       return undef unless @ids;
+
+       @ids = ($ids[0]) unless ($self->api_name =~ /batch/o); 
+
+       $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
+
+       return undef;
+}
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.fleshed.actor.user.retrieve',
+       api_level       => 1,
+       method          => 'retrieve_fleshed_user',
+       cachable        => 1,
+);
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
+       api_level       => 1,
+       method          => 'retrieve_fleshed_user',
+       stream          => 1,
+       cachable        => 1,
+);
+
+sub flesh_user {
+       my $usr = shift;
+
+
+       my $standing = $usr->standing;
+       my $profile = $usr->profile;
+       my $ident_type = $usr->ident_type;
+               
+       my $address = $usr->address;
+       my $card = $usr->card;
+
+       my @addresses = $usr->addresses;
+       my @cards = $usr->cards;
+
+       my $usr_fm = $usr->to_fieldmapper;
+       $usr_fm->standing( $standing->to_fieldmapper );
+       $usr_fm->profile( $profile->to_fieldmapper );
+       $usr_fm->ident_type( $ident_type->to_fieldmapper );
+
+       $usr_fm->card( $card->to_fieldmapper );
+       $usr_fm->address( $address->to_fieldmapper ) if ($address);
+
+       $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
+       $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
+
+       return $usr_fm;
+}
+
 sub org_unit_list {
        my $self = shift;
        my $client = shift;
index 582e1d0..81af7b5 100644 (file)
@@ -177,6 +177,7 @@ my $rollback;
 my $lookup;
 my $update_entry;
 my $mr_lookup;
+my $mr_update;
 my $mr_create;
 my $create_source_map;
 my $sm_lookup;
@@ -226,6 +227,8 @@ sub wormize {
                unless ($sm_lookup);
        $mr_lookup = $self->method_lookup('open-ils.storage.direct.metabib.metarecord.search.fingerprint')
                unless ($mr_lookup);
+       $mr_update = $self->method_lookup('open-ils.storage.direct.metabib.metarecord.batch.update')
+               unless ($mr_update);
        $mr_create = $self->method_lookup('open-ils.storage.direct.metabib.metarecord.create')
                unless ($mr_create);
        $create_source_map = $self->method_lookup('open-ils.storage.direct.metabib.metarecord_source_map.batch.create')
@@ -274,6 +277,7 @@ sub wormize {
 
        my @source_maps;
        my @entry_list;
+       my @mr_list;
        my @rd_list;
        my @ns_list;
        my @mods_data;
@@ -306,6 +310,8 @@ sub wormize {
                                }
                        } else {
                                $mr = $$mr[0];
+                               $mr->mods('');
+                               push @mr_list, $mr;
                        }
 
                        my $sm = new Fieldmapper::metabib::metarecord_source_map;
@@ -349,6 +355,10 @@ sub wormize {
                unless (defined $sm) {
                        throw OpenSRF::EX::PANIC ("Couldn't run open-ils.storage.direct.metabib.metarecord_source_map.batch.create!")
                }
+               my ($mr) = $mr_update->run(@mr_list);
+               unless (defined $mr) {
+                       throw OpenSRF::EX::PANIC ("Couldn't run open-ils.storage.direct.metabib.metarecord.batch.update!")
+               }
        }
 
        my ($re) = $update_entry->run(@entry_list);
index beb078f..3422723 100644 (file)
@@ -27,7 +27,7 @@ CREATE TABLE action.survey_answer (
 
 CREATE TABLE action.survey_response (
        id              BIGSERIAL       PRIMARY KEY,
-       usr             BIGINT          NOT NULL, -- REFERENCES actor.usr
+       usr             INT             NOT NULL, -- REFERENCES actor.usr
        survey          INT             NOT NULL REFERENCES action.survey,
        question        INT             NOT NULL REFERENCES action.survey_question,
        answer          INT             NOT NULL REFERENCES action.survey_answer,
index 1e7493a..6899175 100644 (file)
@@ -504,9 +504,6 @@ sub make_stream_atomic {
        (my $m_name = $self->api_name) =~ s/\.atomic$//o;
        my @results = $self->method_lookup($m_name)->run(@args);
 
-       if (@results == 1) {
-               return $results[0];
-       }
        return \@results;
 }