__PACKAGE__->register_method(
method => "update_patron",
- api_name => "open-ils.actor.patron.create",
-);
-
-__PACKAGE__->register_method(
- method => "update_patron",
api_name => "open-ils.actor.patron.update",
);
sub update_patron {
- my( $self, $client, $patron ) = @_;
+ my( $self, $client, $user_session, $patron ) = @_;
my $session = $apputils->start_db_session();
my $err = undef;
+ warn $user_session . " " . $patron . "\n";
+ _d($patron);
+
+ my $user_obj =
+ OpenILS::Application::AppUtils->check_user_session(
+ $user_session ); #throws EX on error
+
+ # XXX does this user have permission to add/create users. Granularity?
# $new_patron is the patron in progress. $patron is the original patron
# passed in with the method. new_patron will change as the components
try {
# create/update the patron first so we can use his id
- if( $self->api_name =~ /create/ ) {
+ if( $patron->isnew() ) {
$new_patron = _add_patron(
$session, _clone_patron($patron));
} else {
$user->addresses( $add_req->gather(1) );
if($kill) { $session->disconnect(); }
+ $user->clear_passwd();
+ warn Dumper $user;
return $user;
my $session = shift;
my $patron = shift;
+ warn "Creating new patron\n";
+ _d($patron);
+
my $req = $session->request(
"open-ils.storage.direct.actor.user.create",$patron);
my $id = $req->gather(1);
} elsif( ref($address) and $address->ischanged() ) {
warn "Updating address at street " . $address->street1();
+ $address->usr($new_patron->id());
_update_address($session,$address);
} elsif( ref($address) and $address->isdeleted() ) {
warn "Deleting address at street " . $address->street1();
+
+ if( $address->id() == $new_patron->mailing_address() ) {
+ $new_patron->clear_mailing_address();
+ _update_patron($session, $new_patron);
+ }
+
+ if( $address->id() == $new_patron->billing_address() ) {
+ $new_patron->clear_billing_address();
+ _update_patron($session, $new_patron);
+ }
+
_delete_address($session,$address);
}
}
}
} elsif( ref($card) and $card->ischanged() ) {
+ $card->usr($new_patron->id());
_update_card($session, $card);
}
}
throw OpenSRF::EX::ERROR
("Unknown error updating address");
}
+ warn "Delete address status is $status\n";
}
__PACKAGE__->register_method(
method => "get_org_unit",
api_name => "open-ils.actor.org_unit.retrieve",
- argc => 1,
- note => "Returns the entire org tree structure",
);
sub get_org_unit {
}
+# turns an org list into an org tree
sub build_org_tree {
my( $self, $orglist) = @_;
}
+__PACKAGE__->register_method(
+ method => "get_org_descendants",
+ api_name => "open-ils.actor.org_tree.descendants.retrieve"
+);
+
+# depth is optional. org_unit is the id
+sub get_org_descendants {
+ my( $self, $client, $org_unit, $depth ) = @_;
+ my $orglist = $apputils->simple_scalar_request(
+ "open-ils.storage",
+ "open-ils.storage.actor.org_unit.descendants.atomic",
+ $org_unit, $depth );
+ return $self->build_org_tree($orglist);
+}
+
+
+__PACKAGE__->register_method(
+ method => "get_org_ancestors",
+ api_name => "open-ils.actor.org_tree.ancestors.retrieve"
+);
+
+# depth is optional. org_unit is the id
+sub get_org_ancestors {
+ my( $self, $client, $org_unit, $depth ) = @_;
+ my $orglist = $apputils->simple_scalar_request(
+ "open-ils.storage",
+ "open-ils.storage.actor.org_unit.ancestors.atomic",
+ $org_unit, $depth );
+ return $self->build_org_tree($orglist);
+}
+
+
+__PACKAGE__->register_method(
+ method => "get_standings",
+ api_name => "open-ils.actor.standings.retrieve"
+);
+
+sub get_standings {
+ return $apputils->simple_scalar_request(
+ "open-ils.storage",
+ "open-ils.storage.direct.config.standing.retrieve.all.atomic" );
+}
__END__
+some old methods that may be good to keep around for now
+
sub _delete_card {
my( $session, $card ) = @_;
return 1;
}
-
-
sub _delete_patron {
my( $session, $patron ) = @_;
use OpenSRF::Utils::Cache;
-my $cache_client = OpenSRF::Utils::Cache->new( "global", 0 );
-#my $cache_client;
+my $cache_client = "OpenSRF::Utils::Cache";
# ---------------------------------------------------------------------------
# Pile of utilty methods used accross applications.
if($tree) { return $tree; }
# see if it's in the cache
- $tree = $cache_client->get_cache('orgtree');
+ $tree = $cache_client->new()->get_cache('_orgtree');
if($tree) { return $tree; }
if(!$orglist) {
warn "Retrieving Org Tree\n";
$orglist = $self->simple_scalar_request(
"open-ils.storage",
- "open-ils.storage.direct.actor.org_unit.retrieve.all" );
+ "open-ils.storage.direct.actor.org_unit.retrieve.all.atomic" );
}
if( ! $org_typelist ) {
warn "Retrieving org types\n";
$org_typelist = $self->simple_scalar_request(
"open-ils.storage",
- "open-ils.storage.direct.actor.org_unit_type.retrieve.all" );
+ "open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic" );
$self->build_org_type($org_typelist);
}
$tree = $self->build_org_tree($orglist,1);
- $cache_client->put_cache('orgtree', $tree);
+ $cache_client->new()->put_cache('_orgtree', $tree);
return $tree;
}
if($slimtree) { return $slimtree; }
# see if it's in the cache
- $slimtree = $cache_client->get_cache('slimorgtree');
+ $slimtree = $cache_client->new()->get_cache('slimorgtree');
if($slimtree) { return $slimtree; }
if(!$orglist) {
warn "Retrieving Org Tree\n";
$orglist = $self->simple_scalar_request(
"open-ils.storage",
- "open-ils.storage.direct.actor.org_unit.retrieve.all" );
+ "open-ils.storage.direct.actor.org_unit.retrieve.all.atomic" );
}
$slimtree = $self->build_org_tree($orglist);
- $cache_client->put_cache('slimorgtree', $slimtree);
+ $cache_client->new->put_cache('slimorgtree', $slimtree);
return $slimtree;
}
warn "No User returned from retrieve_session $sessionid\n";
}
if($user) {$user->clear_password();}
+ use Data::Dumper;
+ warn Dumper $user;
return $user;
}
__PACKAGE__->register_method(
method => "retrieve_copies",
api_name => "open-ils.cat.asset.copy_tree.retrieve",
- argc => 2, #(user_session, record_id)
- note => <<TEXT
- Returns the copies for a given bib record and for the users home library
-TEXT
+);
+
+__PACKAGE__->register_method(
+ method => "retrieve_copies",
+ api_name => "open-ils.cat.asset.copy_tree.global.retrieve",
);
sub retrieve_copies {
$docid = "$docid";
- #my $results = [];
-
if(!$home_ou) {
my $user_obj =
OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
$home_ou = $user_obj->home_ou;
}
- my $session = OpenSRF::AppSession->create( "open-ils.storage" );
-
- # ------------------------------------------------------
- # grab the short name of the library location
- my $request = $session->request(
- "open-ils.storage.direct.actor.org_unit.retrieve", $home_ou );
-
- my $org_unit = $request->recv();
- if(!$org_unit) {
- throw OpenSRF::EX::ERROR
- ("No response from storage for org unit search");
+ my $search_hash;
+ if( $self->api_name =~ /global/ ) {
+ $search_hash = { record => $docid };
+ } else {
+ $search_hash = { record => $docid, owning_lib => $home_ou };
}
- if($org_unit->isa("Error")) { throw $org_unit ($org_unit->stringify);}
- my $location = $org_unit->content->shortname;
- $request->finish();
- # ------------------------------------------------------
+ my $vols = _build_volume_list( $search_hash );
- # ------------------------------------------------------
- # grab all the volumes for the given record and location
- my $search_hash = { record => $docid, owning_lib => $location };
+ return $vols;
+
+}
+sub _build_volume_list {
+ my $search_hash = shift;
- $request = $session->request(
+ my $session = OpenSRF::AppSession->create( "open-ils.storage" );
+ my $request = $session->request(
"open-ils.storage.direct.asset.call_number.search", $search_hash );
my $volume;
- my @volume_ids;
+ my @volumes;
while( $volume = $request->recv() ) {
- if($volume->isa("Error")) {
+ if(UNIVERSAL::isa($volume,"Error")) {
throw $volume ($volume->stringify);}
$volume = $volume->content;
warn "Grabbing copies for volume: " . $volume->id . "\n";
- my $copies =
- OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
- "open-ils.storage.direct.asset.copy.search.call_number", $volume->id );
-
- $volume->copies($copies);
-
- $client->respond( $volume );
-
- #push @$results, $volume;
-
- }
- $request->finish();
- $session->finish();
- $session->disconnect();
- $session->kill_me();
+ my $creq = $session->request(
+ "open-ils.storage.direct.asset.copy.search.call_number",
+ $volume->id );
+ my $copies = $creq->gather(1);
- return undef;
-
-}
-
-
-
-
-__PACKAGE__->register_method(
- method => "retrieve_copies_global",
- api_name => "open-ils.cat.asset.copy_tree.global.retrieve",
- argc => 2, #(user_session, record_id)
- note => <<TEXT
- Returns all volumes and attached copies for a given bib record
-TEXT
-);
-
-sub retrieve_copies_global {
-
- my( $self, $client, $user_session, $docid ) = @_;
-
- $docid = "$docid";
-
- my $session = OpenSRF::AppSession->create( "open-ils.storage" );
-
- # ------------------------------------------------------
- # grab all the volumes for the given record and location
- my $request = $session->request(
- "open-ils.storage.direct.asset.call_number.search.record", $docid );
-
- my $volumes = $request->recv();
-
-
- if($volumes->isa("Error")) {
- throw $volumes ($volumes->stringify);}
-
- $volumes = $volumes->content;
-
- $request->finish();
-
- my $vol_hash = {};
-
- my @volume_ids;
- for my $volume (@$volumes) {
- $vol_hash->{$volume->id} = $volume;
- }
-
- my @ii = keys %$vol_hash;
- warn "Searching volumes @ii\n";
-
- $request = $session->request(
- "open-ils.storage.direct.asset.copy.search.call_number", keys %$vol_hash );
-
- while( my $copylist = $request->recv ) {
-
- if(UNIVERSAL::isa( $copylist, "Error")) {
- throw $copylist ($copylist->stringify);
- }
+ $volume->copies($copies);
- $copylist = $copylist->content;
+ push( @volumes, $volume );
- my $vol;
- for my $copy (@$copylist) {
- $vol = $vol_hash->{$copy->call_number} unless $vol;
- $vol->copies([]) unless $vol->copies();
- push @{$vol->copies}, $copy;
- }
- $client->respond( $vol );
}
-
-
-
$request->finish();
- $session->finish();
- $session->disconnect();
- $session->kill_me();
+ return \@volumes;
- return undef;
-
}
);
sub checkouts_by_user {
- my( $self, $client, $user_id ) = @_;
+ my( $self, $client, $user_session, $user_id ) = @_;
my $session = OpenSRF::AppSession->create("open-ils.storage");
my @results;
for my $circ (@$circs) {
+
+ my $copy = $session->request(
+ "open-ils.storage.direct.asset.copy.retrieve",
+ $circ->target_copy );
+
my $record = $session->request(
"open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
$circ->target_copy );
+
+ $copy = $copy->gather(1);
$record = $record->gather(1);
+
my $due_date =
OpenSRF::Utils->interval_to_seconds(
$circ->duration ) + int(time());
$u->start_mods_batch( $record->marc() );
my $mods = $u->finish_mods_batch();
- push( @results, { circ => $circ, record => $mods } );
+ push( @results, { copy => $copy, circ => $circ, record => $mods } );
}
return \@results;
api_name => "open-ils.circ.patron.create",
);
-__PACKAGE__->register_method(
- method => "update_patron",
- api_name => "open-ils.circ.patron.update",
-);
-
-
-sub update_patron {
- my( $self, $client, $patron ) = @_;
-
- my $session = $apputils->start_db_session();
- my $err = undef;
-
-
- # $new_patron is the patron in progress. $patron is the original patron
- # passed in with the method. new_patron will change as the components
- # of patron are added/updated.
-
- try {
-
- my $new_patron;
-
- # create/update the patron first so we can use his id
- if( $self->api_name =~ /create/ ) {
- $new_patron = _add_patron(
- $session, _clone_patron($patron));
- } else {
- $new_patron = $patron;
- }
-
- $new_patron = _add_update_addresses($session, $patron, $new_patron);
- $new_patron = _add_update_cards($session, $patron, $new_patron);
-
- # re-update the patron if anything has happened to him during this process
- if($new_patron->ischanged()) {
- $new_patron = _update_patron($session, $new_patron);
- }
- $apputils->commit_db_session($session);
-
- } catch Error with {
- my $e = shift;
- $err = "-*- Failure adding user: $e";
- $apputils->rollback_db_session($session);
- warn $e;
- };
-
- warn "Patron Update/Create complete\n";
-
- if($err) { throw OpenSRF::EX::ERROR ($err); }
-
- return 1;
-}
-
-
-# clone and clear stuff that would break the database
-sub _clone_patron {
- my $patron = shift;
-
- my $new_patron = Fieldmapper::actor::user->new();
-
- my $fmap = $Fieldmapper::fieldmap;
- no strict; # shallow clone, may be useful in the fieldmapper
- for my $field
- (keys %{$fmap->{"Fieldmapper::actor::user"}->{'fields'}}) {
- $new_patron->$field( $patron->$field() );
- }
- use strict;
-
- # clear these
- $new_patron->clear_billing_address();
- $new_patron->clear_mailing_address();
- $new_patron->clear_addresses();
- $new_patron->clear_card();
- $new_patron->clear_cards();
- $new_patron->clear_id();
- $new_patron->clear_isnew();
- $new_patron->clear_changed();
- $new_patron->clear_deleted();
-
- return $new_patron;
-}
-
-
-sub _add_patron {
- my $session = shift;
- my $patron = shift;
-
- my $req = $session->request(
- "open-ils.storage.direct.actor.user.create",$patron);
- my $id = $req->gather(1);
- if(!$id) { throw OpenSRF::EX::ERROR ("Unable to create new user"); }
- warn "Created new patron with id $id\n";
- $patron->id($id);
-
- return $patron;
-}
-
-
-sub _update_patron {
- my( $session, $patron) = @_;
-
- my $req = $session->request(
- "open-ils.storage.direct.actor.user.update",$patron );
- my $status = $req->gather(1);
- if(!defined($status)) {
- throw OpenSRF::EX::ERROR
- ("Unknown error updating patron");
- }
- return $patron;
-}
-
-
-sub _add_update_addresses {
- my $session = shift;
- my $patron = shift;
- my $new_patron = shift;
-
- my $current_id; # id of the address before creation
-
- for my $address (@{$patron->addresses()}) {
-
- $address->usr($new_patron->id());
-
- if(ref($address) and $address->isnew()) {
- warn "Adding new address at street " . $address->street1() . "\n";
-
- $current_id = $address->id();
- $address = _add_address($session,$address);
-
- if( $patron->billing_address() == $current_id ) {
- $new_patron->billing_address($address->id());
- $new_patron->ischanged(1);
- }
-
- if( $patron->mailing_address() == $current_id ) {
- $new_patron->mailing_address($address->id());
- $new_patron->ischanged(1);
- }
-
- } elsif( ref($address) and $address->ischanged() ) {
- warn "Updating address at street " . $address->street1();
- _update_address($session,$address);
- }
- }
-
- return $new_patron;
-}
-
-
-# adds an address to the db and returns the address with new id
-sub _add_address {
- my($session, $address) = @_;
- $address->clear_id();
-
- # put the address into the database
- my $req = $session->request(
- "open-ils.storage.direct.actor.user_address.create",
- $address );
-
- #update the id
- my $id = $req->gather(1);
- if(!$id) {
- throw OpenSRF::EX::ERROR
- ("Unable to create new user address");
- }
-
- warn "Created address with id $id\n";
-
- # update all the necessary id's
- $address->id( $id );
- return $address;
-}
-
-
-sub _update_address {
- my( $session, $address ) = @_;
- my $req = $session->request(
- "open-ils.storage.direct.actor.user_address.update",
- $address );
- my $status = $req->gather(1);
- if(!defined($status)) {
- throw OpenSRF::EX::ERROR
- ("Unknown error updating address");
- }
- return $address;
-}
-
-
-
-sub _add_update_cards {
-
- my $session = shift;
- my $patron = shift;
- my $new_patron = shift;
-
- my $virtual_id; #id of the card before creation
- for my $card (@{$patron->cards()}) {
-
- $card->usr($new_patron->id());
-
- if(ref($card) and $card->isnew()) {
-
- $virtual_id = $card->id();
- $card = _add_card($session,$card);
-
- if($patron->card() == $virtual_id) {
- $new_patron->card($card->id());
- $new_patron->ischanged(1);
- }
-
- } elsif( ref($card) and $card->ischanged() ) {
- _update_card($session, $card);
- }
- }
- return $new_patron;
-}
-
-
-# adds an card to the db and returns the card with new id
-sub _add_card {
- my( $session, $card ) = @_;
- $card->clear_id();
-
- warn "Adding card with barcode " . $card->barcode() . "\n";
- my $req = $session->request(
- "open-ils.storage.direct.actor.card.create",
- $card );
-
- my $id = $req->gather(1);
- if(!$id) {
- throw OpenSRF::EX::ERROR
- ("Unknown error creating card");
- }
-
- $card->id($id);
- warn "Created patron card with id $id\n";
- return $card;
-}
-
-
-sub _update_card {
- my( $session, $card ) = @_;
- warn Dumper $card;
-
- my $req = $session->request(
- "open-ils.storage.direct.actor.card.update",
- $card );
- my $status = $req->gather(1);
- if(!defined($status)) {
- throw OpenSRF::EX::ERROR
- ("Unknown error updating card");
- }
- return $card;
-}
-
-
-1;
sub filter_search {
my($self, $string) = @_;
- $string =~ s/\s+the\s+//i;
- $string =~ s/\s+an\s+//i;
- $string =~ s/\s+a\s+//i;
+ $string =~ s/\s+the\s+/ /i;
+ $string =~ s/\s+an\s+/ /i;
+ $string =~ s/\s+a\s+/ /i;
$string =~ s/^the\s+//i;
$string =~ s/^an\s+//i;
use base qw/OpenSRF::Application/;
use strict; use warnings;
use OpenILS::Application::AppUtils;
+my $apputils = "OpenILS::Application::AppUtils";
$barcode );
my $card = $creq->gather(1);
$card = $card->[0];
+ my $user = flesh_user($card->usr(), $session);
+ $session->disconnect();
+ return $user;
+
+}
+
+
+__PACKAGE__->register_method(
+ method => "actor_user_retrieve_by_session",
+ api_name => "open-ils.search.actor.user.session",
+);
+
+sub actor_user_retrieve_by_session {
+ my($self, $client, $user_session) = @_;
+ warn "Searching for user with user_session $user_session\n";
+ my $user_obj = $apputils->check_user_session($user_session);
+ my $session = OpenSRF::AppSession->create("open-ils.storage");
+ return flesh_user($user_obj->id);
+}
+
+
+sub flesh_user {
+ my $id = shift;
+ my $session = shift;
+ my $kill = 0;
+
+ if(!$session) {
+ $session = OpenSRF::AppSession->create("open-ils.storage");
+ $kill = 1;
+ }
# grab the user with the given card
my $ureq = $session->request(
"open-ils.storage.direct.actor.user.retrieve",
- $card->usr());
+ $id);
my $user = $ureq->gather(1);
# grab the cards
$user->id() );
$user->addresses( $add_req->gather(1) );
+ if($kill) { $session->disconnect(); }
+
return $user;
}
my( $self, $client, $user_session ) = @_;
+=head
if( $user_session ) { # keep for now for backwards compatibility
my $user_obj =
return $home_ou;
}
+=cut
warn "Getting ORG Tree\n";
my $org_tree = OpenILS::Application::AppUtils->get_org_tree();
);
sub get_org_tree_slim {
-
my( $self, $client, $user_session ) = @_;
-
warn "Getting ORG Tree\n";
- my $org_tree = OpenILS::Application::AppUtils->get_slim_org_tree();
- warn "Returning Org Tree\n";
-
- return $org_tree;
+ warn "Call: " . $self->api_name() . "\n";
+ return OpenILS::Application::AppUtils->get_slim_org_tree();
}
my $org_typelist = OpenILS::Application::AppUtils->simple_scalar_request(
"open-ils.storage",
- "open-ils.storage.direct.actor.org_unit_type.retrieve.all" );
+ "open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic" );
return $org_typelist;
}
__PACKAGE__->register_method(
method => "get_user_profiles",
- api_name => "open-ils.search.actor.user.profiles",
+ api_name => "open-ils.search.actor.user.profiles.retrieve",
);
-
sub get_user_profiles {
return OpenILS::Application::AppUtils->simple_scalar_request(
"open-ils.storage",
- "open-ils.storage.direct.actor.profile.batch.retrieve.atomic",
+ "open-ils.storage.direct.actor.profile.retrieve.all.atomic",
( "1", "2", "3" ) );
}
+
+__PACKAGE__->register_method(
+ method => "get_user_ident_types",
+ api_name => "open-ils.search.actor.user.ident_types.retrieve",
+);
+sub get_user_ident_types {
+ return OpenILS::Application::AppUtils->simple_scalar_request(
+ "open-ils.storage",
+ "open-ils.storage.direct.config.identification_type.retrieve.all.atomic" );
+}
+
+
+
+
+__PACKAGE__->register_method(
+ method => "get_org_unit",
+ api_name => "open-ils.search.actor.org_unit.retrieve",
+ argc => 1,
+ note => "Returns the entire org tree structure",
+);
+
+sub get_org_unit {
+
+ my( $self, $client, $user_session ) = @_;
+
+ my $user_obj =
+ OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
+
+ my $home_ou = OpenILS::Application::AppUtils->simple_scalar_request(
+ "open-ils.storage",
+ "open-ils.storage.direct.actor.org_unit.retrieve",
+ $user_obj->home_ou );
+
+ return $home_ou;
+}
+
+
+
+
1;
}
+
__PACKAGE__->register_method(
method => "biblio_record_to_marc_html",
api_name => "open-ils.search.biblio.record.html" );
my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
-my $xslt_doc = $parser->parse_file(
- "/pines/cvs/ILS/Open-ILS/xsl/MARC21slim2HTML.xsl");
-my $marc_sheet = $xslt->parse_stylesheet( $xslt_doc );
-
+my $marc_sheet;
+my $settings_client = OpenSRF::Utils::SettingsClient->new();
sub biblio_record_to_marc_html {
my( $self, $client, $recordid ) = @_;
+ if( !$marc_sheet ) {
+ my $dir = $settings_client->config_value( "dirs", "xsl" );
+ my $xsl = $settings_client->config_value(
+ "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
+
+ $xsl = $parser->parse_file("$dir/$xsl");
+ $marc_sheet = $xslt->parse_stylesheet( $xsl );
+ }
+
my $record = $apputils->simple_scalar_request(
"open-ils.storage",
__PACKAGE__->register_method(
method => "retrieve_all_copy_locations",
- api_name => "open-ils.search.config.copy_location.retreive.all" );
+ api_name => "open-ils.search.config.copy_location.retrieve.all" );
my $shelving_locations;
sub retrieve_all_copy_locations {