try {
# create/update the patron first so we can use his id
- if( $patron->isnew() ) {
+ if($patron->isnew()) {
$new_patron = _add_patron(
$session, _clone_patron($patron));
} else {
$new_patron = _add_update_addresses($session, $patron, $new_patron);
$new_patron = _add_update_cards($session, $patron, $new_patron);
+ $new_patron = _add_survey_responses($session, $patron, $new_patron);
+ $new_patron = _create_stat_maps($user_session, $patron, $new_patron);
# re-update the patron if anything has happened to him during this process
if($new_patron->ischanged()) {
$user->id() );
$user->addresses( $add_req->gather(1) );
+ my $stat_req = $session->request(
+ "open-ils.storage.direct.actor.stat_cat_entry_user_map.search.target_usr",
+ $user->id() );
+ $user->stat_cat_entries($stat_req->gather(1));
+
if($kill) { $session->disconnect(); }
$user->clear_passwd();
warn Dumper $user;
$new_patron->clear_isnew();
$new_patron->clear_changed();
$new_patron->clear_deleted();
+ $new_patron->clear_stat_cat_entries();
return $new_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;
+ # retrieve the patron from the db to collect defaults
+ my $ureq = $session->request(
+ "open-ils.storage.direct.actor.user.retrieve",
+ $id);
+ return $ureq->gather(1);
}
sub _update_patron {
my( $session, $patron) = @_;
- warn "updating patron " . $patron->usrname() . "\n";
+ warn "updating patron " . Dumper($patron) . "\n";
+
my $req = $session->request(
"open-ils.storage.direct.actor.user.update",$patron );
my $status = $req->gather(1);
+sub _add_survey_responses {
+ my ($session, $patron, $new_patron) = @_;
+
+ warn "updating responses for user " . $new_patron->id . "\n";
+
+ my $responses = $patron->survey_responses;
+ for my $resp( @$responses ) {
+ $resp->usr($new_patron->id);
+ }
+
+ my $status = $apputils->simple_scalar_request(
+ "open-ils.circ",
+ "open-ils.circ.survey.submit.user_id",
+ $responses );
+
+ return $new_patron;
+}
+
+
+sub _create_stat_maps {
+
+ my($user_session, $patron, $new_patron) = @_;
+ my $maps = $patron->stat_cat_entries();
+
+ my $session = OpenSRF::AppSession->create("open-ils.circ");
+
+ for my $map (@$maps) {
+
+ next unless($map->isnew() || $map->ischanged());
+
+ my $method = "open-ils.circ.stat_cat.actor.user_map.update";
+ if($map->isnew()) {
+ $method = "open-ils.circ.stat_cat.actor.user_map.create";
+ }
+
+ warn "Updating stat entry with method $method and
+ session $user_session and map $map\n";
+
+ my $req = $session->request($method, $user_session, $map);
+ my $status = $req->gather(1);
+
+ warn "Updated\n";
+
+ if(!$status) {
+ throw OpenSRF::EX::ERROR
+ ("Error updating stat map with method $method");
+ }
+ }
+
+ $session->disconnect();
+ return $new_patron;
+}
+
+
__PACKAGE__->register_method(
method => "search_username",
}
+
+
__PACKAGE__->register_method(
method => "user_retrieve_by_barcode",
api_name => "open-ils.actor.user.fleshed.retrieve_by_barcode",
+__PACKAGE__->register_method(
+ method => "get_user_by_id",
+ api_name => "open-ils.actor.user.retrieve",);
+
+sub get_user_by_id {
+ my ($self, $client, $user_session, $id) = @_;
+
+ my $user_obj = $apputils->check_user_session( $user_session );
+
+ return $apputils->simple_scalar_request(
+ "open-ils.storage",
+ "open-ils.storage.direct.actor.user.retrieve",
+ $id );
+}
+
+
__PACKAGE__->register_method(
method => "get_org_types",
- api_name => "open-ils.actor.org_types.retrieve",
-);
+ api_name => "open-ils.actor.org_types.retrieve",);
+
my $org_types;
sub get_org_types {
my($self, $client) = @_;
}
+
__PACKAGE__->register_method(
method => "get_user_profiles",
api_name => "open-ils.actor.user.profiles.retrieve",
use Data::Dumper;
warn "patron adv with $staff_login and search " .
Dumper($search_hash) . "\n";
+
+ my $session = OpenSRF::AppSession->create("open-ils.storage");
+ my $req = $session->request(
+ "open-ils.storage.actor.user.crazy_search", $search_hash);
+
+ my $ans = $req->gather(1);
+ $session->disconnect();
+ return $ans;
+
}
use OpenSRF::EX qw(:try);
use JSON;
use OpenILS::Utils::Fieldmapper;
+use XML::LibXML;
+use Data::Dumper;
+use OpenILS::Utils::FlatXML;
my $apputils = "OpenILS::Application::AppUtils";
my $utils = "OpenILS::Application::Cat::Utils";
+__PACKAGE__->register_method(
+ method => "biblio_record_tree_import",
+ api_name => "open-ils.cat.biblio.record.tree.import",
+);
+
+sub biblio_record_tree_import {
+ my( $self, $client, $user_session, $tree) = @_;
+ my $user_obj = $apputils->check_user_session($user_session);
+
+ warn "importing new record " . Dumper($tree) . "\n";
+
+ my $nodeset = $utils->tree2nodeset($tree);
+ warn "turned into nodeset " . Dumper($nodeset) . "\n";
+
+ # copy the doc so that we can mangle the namespace.
+ my $marcxml = OpenILS::Utils::FlatXML->new()->nodeset_to_xml($nodeset);
+ my $copy_marcxml = XML::LibXML->new->parse_string($marcxml);
+
+ $marcxml->documentElement->setNamespace( "http://www.loc.gov/MARC21/slim", "marc", 1 );
+ my $tcn;
+
+ my $xpath = '//controlfield[@tag="001"]';
+ $tcn = $marcxml->documentElement->findvalue($xpath);
+ my $tcn_source = "External";
+ my $source = 2; # system local source
+
+ warn "Starting db session in import\n";
+ my $session = $apputils->start_db_session();
+
+ if(!$tcn) {
+ $xpath = '//datafield[@tag="020"]';
+ $tcn = $marcxml->documentElement->findvalue($xpath);
+ $tcn_source = "ISBN";
+ if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+ }
+
+ if(!$tcn) {
+ $xpath = '//datafield[@tag="022"]';
+ $tcn = $marcxml->documentElement->findvalue($xpath);
+ $tcn_source = "ISSN";
+ if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+ }
+
+ if(!$tcn) {
+ $xpath = '//datafield[@tag="010"]';
+ $tcn = $marcxml->documentElement->findvalue($xpath);
+ $tcn_source = "LCCN";
+ if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+ }
+
+ if(!$tcn) {
+ $xpath = '//datafield[@tag="035"]';
+ $tcn = $marcxml->documentElement->findvalue($xpath);
+ $tcn_source = "System";
+ if(_tcn_exists($session, $tcn)) {$tcn = undef;}
+ }
+
+ warn "Record import with tcn: $tcn\n";
+
+ my $record = Fieldmapper::biblio::record_entry->new;
+
+ $record->source($source);
+ $record->tcn_source($tcn_source);
+ $record->tcn_value($tcn);
+ $record->creator($user_obj->id);
+ $record->editor($user_obj->id);
+ $record->marc($copy_marcxml->toString);
+
+
+ my $req = $session->request(
+ "open-ils.storage.direct.biblio.record_entry.create",
+ $record );
+ my $id = $req->gather(1);
+
+ my $wreq = $session->request("open-ils.worm.wormize", $id);
+ $wreq->gather(1);
+
+ $apputils->commit_db_session($session);
+
+ return $self->biblio_record_tree_retrieve($client, $id);
+}
+
+sub _tcn_exists {
+ my $session = shift;
+ my $tcn = shift;
+
+ if(!$tcn) {return 0;}
+
+ my $req = $session->request(
+ "open-ils.storage.direct.biblio.record_entry.search.tcn_value",
+ $tcn );
+ my $recs = $req->gather(1);
+
+ if($recs and $recs->[0]) {
+ return 1;
+ }
+ return 0;
+}
+
__PACKAGE__->register_method(
method => "biblio_record_tree_retrieve",
api_name => "open-ils.cat.biblio.record.tree.retrieve",
- argc => 1,
- note => "Returns the tree associated with the nodeset of the given doc id"
);
sub biblio_record_tree_retrieve {
sub biblio_record_tree_commit {
my( $self, $client, $user_session, $tree ) = @_;
- new Fieldmapper::biblio::record_node ($tree);
-
- use Data::Dumper;
throw OpenSRF::EX::InvalidArg
("Not enough args to to open-ils.cat.biblio.record.tree.commit")
# turn the tree into a nodeset
my $nodeset = $utils->tree2nodeset($tree);
- $nodeset = $utils->clean_nodeset( $nodeset );
+ $nodeset = $utils->clean_nodeset($nodeset);
if(!defined($docid)) { # be sure
for my $node (@$nodeset) {
}
-
-
-=head
-__PACKAGE__->register_method(
- method => "generic_edit_copies_volumes",
- api_name => "open-ils.cat.asset.volume.batch.update",
-);
-
-__PACKAGE__->register_method(
- method => "generic_edit_copies_volumes",
- api_name => "open-ils.cat.asset.volume.batch.delete",
-);
-
-__PACKAGE__->register_method(
- method => "generic_edit_copies_volumes",
- api_name => "open-ils.cat.asset.copy.batch.update",
-);
-
-__PACKAGE__->register_method(
- method => "generic_edit_copies_volumes",
- api_name => "open-ils.cat.asset.copy.batch.delete",
-);
-
-
-sub generic_edit_copies_volumes {
-
- my( $self, $client, $user_session, $items ) = @_;
-
- my $method = $self->api_name;
- $method =~ s/open-ils\.cat/open-ils\.storage\.direct/og;
- warn "our method is $method\n";
-
- my $user_obj =
- OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
-
- warn "updating editor info\n";
-
- for my $item (@$items) {
- $item->editor( $user_obj->id );
- }
-
- my $session = OpenILS::Application::AppUtils->start_db_session;
- my $request = $session->request( $method, @$items );
- my $result = $request->gather(1);
-
- OpenILS::Application::AppUtils->commit_db_session($session);
-
- warn "looks like we succeeded\n";
- return $result;
-}
-
-=cut
-
-
-
# -----------------------------------------------------------------
# Fleshed volume tree batch add/update. This does everything a
# volume tree could want, add, update, delete
my $update_copy_list = $volume->copies;
- if( $volume->isnew ) {
+
+ if( $volume->isdeleted) {
+ my $status = _delete_volume($session, $volume);
+ if(!$status) {
+ throw OpenSRF::EX::ERROR
+ ("Volume delete failed for volume " . $volume->id);
+ }
+
+ } elsif( $volume->isnew ) {
$volume->clear_id;
$volume->editor($user_obj->id);
$volume = _add_volume($session, $volume);
} elsif( $volume->ischanged ) {
+
$volume->editor($user_obj->id);
_update_volume($session, $volume);
-
- } elsif( $volume->isdeleted) {
- return _delete_volume($session, $volume);
}
- for my $copy (@{$update_copy_list}) {
-
- $copy->editor($user_obj->id);
- warn "updating copy for volume " . $volume->id . "\n";
- if( $copy->isnew ) {
-
- $copy->clear_id;
- $copy->call_number($volume->id);
- $copy->creator($user_obj->id);
- $copy = _fleshed_copy_update($session,$copy,$user_obj->id);
-
- } elsif( $copy->ischanged ) {
- $copy->call_number($volume->id);
- $copy = _fleshed_copy_update($session, $copy, $user_obj->id);
- } elsif( $copy->isdeleted ) {
- _fleshed_copy_update($session, $copy, $user_obj->id);
+ if( ! $volume->isdeleted ) {
+ for my $copy (@{$update_copy_list}) {
+
+ $copy->editor($user_obj->id);
+ warn "updating copy for volume " . $volume->id . "\n";
+
+ if( $copy->isnew ) {
+
+ $copy->clear_id;
+ $copy->call_number($volume->id);
+ $copy->creator($user_obj->id);
+ $copy = _fleshed_copy_update($session,$copy,$user_obj->id);
+
+ } elsif( $copy->ischanged ) {
+ $copy->call_number($volume->id);
+ $copy = _fleshed_copy_update($session, $copy, $user_obj->id);
+
+ } elsif( $copy->isdeleted ) {
+ warn "Deleting copy " . $copy->id . " for volume " . $volume->id . "\n";
+ my $status = _fleshed_copy_update($session, $copy, $user_obj->id);
+ warn "Copy delete returned a status of $status\n";
+ }
}
}
}
}
-#XXX make me
sub _delete_volume {
my( $session, $volume ) = @_;
- $volume = _find_volume($session, $volume);
+ #$volume = _find_volume($session, $volume);
+ warn "Deleting volume " . $volume->id . "\n";
-# my $copies = $session->request(
-# "open-ils.storage.direct.asset.copy.search.call_number",
-# $volume-id )->gather(1);
-# if(@$copies) {
-# throw OpenSRF::EX::ERROR
-# ("Cannot remove volume with copies attached");
-# }
+ my $copies = $session->request(
+ "open-ils.storage.direct.asset.copy.search.call_number",
+ $volume->id )->gather(1);
+ if(@$copies) {
+ throw OpenSRF::EX::ERROR
+ ("Cannot remove volume with copies attached");
+ }
+ my $req = $session->request(
+ "open-ils.storage.direct.asset.call_number.delete",
+ $volume );
+ return $req->gather(1);
}
-=head
-sub _find_volume {
- my( $session, $volume ) = @_;
- my $cn_req = $session->request(
- 'open-ils.storage.direct.asset.call_number.search' =>
- { owning_lib => $volume->owning_lib,
- label => $volume->label,
- record => $volume->record,
- });
-
- return $cn_req->gather(1);
-}
-=cut
sub _update_volume {
my($session, $volume) = @_;
-=head
-__PACKAGE__->register_method(
- method => "volume_tree_add",
- api_name => "open-ils.cat.asset.volume.tree.batch.add",
-);
-
-sub volume_tree_add {
-
- my( $self, $client, $user_session, $volumes ) = @_;
- return undef unless $volumes;
-
- use Data::Dumper;
- warn "Volumes:\n";
- warn Dumper $volumes;
-
- my $user_obj =
- OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
-
- warn "volume_tree_add creating new db session\n";
-
- my $session = OpenILS::Application::AppUtils->start_db_session;
-
- for my $volume (@$volumes) {
-
- warn "Looping on volumes\n";
-
- my $new_copy_list = $volume->copies;
-
- warn "Searching for volume with ".$volume->owning_lib . " " .
- $volume->label . " " . $volume->record . "\n";
-
- my $cn = _find_volume($session, $volume);
-
-
- if($cn) {
-
- $volume = $cn;
- $volume->editor( $user_obj->id );
-
- } else {
-
- $volume->creator( $user_obj->id );
- $volume->editor( $user_obj->id );
- $volume = _add_volume($volume);
-
- }
-
- for my $copy (@{$new_copy_list}) {
-
- warn "adding a copy for volume $id\n";
-
- $copy->call_number($id);
- $copy->creator($user_obj->id);
- $copy->editor($user_obj->id);
-
- warn Dumper $copy;
-
- if( $copy->isnew() ) {
-
- my $req = $session->request(
- "open-ils.storage.direct.asset.copy.create", $copy );
- my $cid = $req->gather(1);
-
- if(!$cid) {
- OpenILS::Application::AppUtils->rollback_db_session($session);
- throw OpenSRF::EX::ERROR ("Error adding copy to volume $id" );
- }
-
- warn "got new copy id $cid\n";
-
- } elsif( $copy->ischanged() ) {
-
- }
-
- }
-
- warn "completed adding copies for $id\n";
-
-
- }
-
- warn "committing volume tree add db session\n";
- OpenILS::Application::AppUtils->commit_db_session($session);
-
- return scalar(@$volumes);
-
-}
-
-__PACKAGE__->register_method(
- method => "copy_update",
- api_name => "open-ils.cat.asset.copy.batch.update",
-);
-
-sub copy_update {
- my($self, $client, $user_session, $copies) = @_;
-
- my $user_obj = $apputils->check_user_session( $user_session ); #throws EX on error
-
- my $session = $apputils->start_db_session();
- for my $copy (@$copies) {
- $copy->editor($user_obj->id);
- my $req = $session->request(
- "open-ils.storage.direct.asset.copy.update",
- $copy );
- my $status = $req->gather(1);
- }
-
- $apputils->commit_db_session($session);
- return 1;
-}
-
-=cut
-
-
__PACKAGE__->register_method(
method => "fleshed_copy_update",
api_name => "open-ils.cat.asset.copy.fleshed.batch.update",
my $session = $apputils->start_db_session();
for my $copy (@$copies) {
- _fleshed_copy_update($session, $copies, $user_obj->id);
+ _fleshed_copy_update($session, $copy, $user_obj->id);
}
$apputils->commit_db_session($session);
}
+
sub _delete_copy {
my($session, $copy) = @_;
warn "Deleting copy " . $copy->id . "\n";
sub _update_copy {
my($session, $copy) = @_;
my $request = $session->request(
- "open-ils.storage.asset.copy.update",
- $copy );
+ "open-ils.storage.direct.asset.copy.update", $copy );
+ my $status = $request->gather(1);
warn "Updated copy " . $copy->id . "\n";
- return $request->gather(1);
+ return $status;
}
if(ref($copy->location)) {$copy->location( $copy->location->id ); }
if(ref($copy->circ_lib)) {$copy->circ_lib( $copy->circ_lib->id ); }
+ warn "Updating copy " . Dumper($copy) . "\n";
if( $copy->isdeleted ) {
return _delete_copy($session, $copy);
_update_copy($session, $copy);
}
- warn "Updating copy " . Dumper($copy) . "\n";
if(!@$stat_cat_entries) { return 1; }
"open-ils.storage.direct.asset.stat_cat_entry_copy_map.search.owning_copy",
$copy->id )->gather(1);
- if( ! $copy->isnew ) { _delete_stale_maps($session, $copy); }
+ if(!$copy->isnew) { _delete_stale_maps($session, $stat_maps, $copy); }
# go through the stat cat update/create process
for my $stat_entry (@{$stat_cat_entries}){
-=head
-__PACKAGE__->register_method(
- method => "volume_tree_delete",
- api_name => "open-ils.cat.asset.volume.tree.batch.delete",
-);
-
-sub volume_tree_delete {
-
- my( $self, $client, $user_session, $volumes ) = @_;
- return undef unless $volumes;
-
- my $user_obj =
- OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
-
- my $session = OpenILS::Application::AppUtils->start_db_session;
-
- for my $volume (@$volumes) {
-
- $volume->editor($user_obj->id);
-
- new Fieldmapper::asset::call_number($volume);
-
- for my $copy (@{$volume->copies}) {
-
- new Fieldmapper::asset::copy($copy);
-
- $copy->editor( $user_obj->id );
-
- warn "Deleting copy " . $copy->id . " from db\n";
-
- my $req = $session->request(
- "open-ils.storage.direct.asset.copy.delete", $copy );
-
- my $resp = $req->recv();
-
- if( !$req->complete ) {
- OpenILS::Application::AppUtils->rollback_db_session($session);
- throw OpenSRF::EX::ERROR (
- "No response from storage on copy delete");
- }
-
- if(UNIVERSAL::isa($resp, "Error")) {
- OpenILS::Application::AppUtils->rollback_db_session($session);
- throw $resp ($resp->stringify);
- }
-
- $req->finish();
- }
-
- warn "Deleting volume " . $volume->id . " from database\n";
-
- my $vol_req = $session->request(
- "open-ils.storage.direct.asset.call_number.delete", $volume );
- my $vol_resp = $vol_req;
-
- if(!$vol_req->complete) {
- OpenILS::Application::AppUtils->rollback_db_session($session);
- throw OpenSRF::EX::ERROR
- ("No response from storage on volume delete");
- }
-
- if( $vol_resp and UNIVERSAL::isa($vol_resp, "Error")) {
- OpenILS::Application::AppUtils->rollback_db_session($session);
- throw $vol_resp ($vol_resp->stringify);
- }
-
- $vol_req->finish();
-
- }
-
- warn "committing delete volume tree add db session\n";
-
- OpenILS::Application::AppUtils->commit_db_session($session);
-
- return scalar(@$volumes);
-
-}
-
-
-=cut
-
-
1;
__PACKAGE__->register_method(
- method => "retrieve_ranged_stat_cats",
- api_name => "open-ils.circ.stat_cat.asset.multirange.retrieve");
+ method => "retrieve_ranged_intersect_stat_cats",
+ api_name => "open-ils.circ.stat_cat.asset.multirange.intersect.retrieve");
-sub retrieve_ranged_stat_cats {
+sub retrieve_ranged_intersect_stat_cats {
my( $self, $client, $user_session, $orglist ) = @_;
my $user_obj = $apputils->check_user_session($user_session);
warn "range: @$orglist\n";
- my $method = "open-ils.storage.multiranged.fleshed.asset.stat_cat.all.atomic";
+ my $method = "open-ils.storage.multiranged.intersect.fleshed.asset.stat_cat.all.atomic";
return $apputils->simple_scalar_request(
"open-ils.storage", $method, $orglist );
}
+__PACKAGE__->register_method(
+ method => "retrieve_ranged_union_stat_cats",
+ api_name => "open-ils.circ.stat_cat.asset.multirange.union.retrieve");
+
+sub retrieve_ranged_union_stat_cats {
+ my( $self, $client, $user_session, $orglist ) = @_;
+
+ my $user_obj = $apputils->check_user_session($user_session);
+ if(!$orglist) { $orglist = [ $user_obj->home_ou ]; }
+
+ # uniquify, yay!
+ my %hash = map { ($_ => 1) } @$orglist;
+ $orglist = [ keys %hash ];
+
+ warn "range: @$orglist\n";
+
+ my $method = "open-ils.storage.multiranged.union.fleshed.asset.stat_cat.all.atomic";
+ return $apputils->simple_scalar_request(
+ "open-ils.storage", $method, $orglist );
+}
+
+
+
__PACKAGE__->register_method(
sub _create_stat_entry {
my( $session, $stat_entry, $method) = @_;
+
warn "Creating new stat entry with value " . $stat_entry->value . "\n";
$stat_entry->clear_id();
+
my $req = $session->request($method, $stat_entry);
my $id = $req->gather(1);
+
+ warn "Stat entry " . Dumper($stat_entry) . "\n";
+
if(!$id) {
throw OpenSRF::EX::ERROR
("Error creating new stat cat entry"); }
}
+__PACKAGE__->register_method(
+ method => "update_stat",
+ api_name => "open-ils.circ.stat_cat.actor.update");
+
+__PACKAGE__->register_method(
+ method => "update_stat",
+ api_name => "open-ils.circ.stat_cat.asset.update");
+
+sub update_stat {
+ my( $self, $client, $user_session, $cat ) = @_;
+
+ my $user_obj = $apputils->check_user_session($user_session);
+
+ my $method = "open-ils.storage.direct.actor.stat_cat.update";
+ if($self->api_name =~ /asset/) {
+ $method = "open-ils.storage.direct.asset.stat_cat.update";
+ }
+
+ my $session = $apputils->start_db_session();
+ my $req = $session->request($method, $cat);
+ my $status = $req->gather(1);
+ $apputils->commit_db_session($session);
+ warn "stat cat with id " . $cat->id . " updated with status $status\n";
+ return 1;
+}
+
+
+__PACKAGE__->register_method(
+ method => "create_stat_entry",
+ api_name => "open-ils.circ.stat_cat.actor.entry.create");
+
+__PACKAGE__->register_method(
+ method => "create_stat_entry",
+ api_name => "open-ils.circ.stat_cat.asset.entry.create");
+
+sub create_stat_entry {
+ my( $self, $client, $user_session, $entry ) = @_;
+
+ my $user_obj = $apputils->check_user_session($user_session);
+
+ $entry->clear_id();
+ use Data::Dumper;
+ warn Dumper($entry);
+
+ my $method = "open-ils.storage.direct.actor.stat_cat_entry.create";
+ if($self->api_name =~ /asset/) {
+ $method = "open-ils.storage.direct.asset.stat_cat_entry.create";
+ }
+
+ my $session = $apputils->start_db_session();
+ my $req = $session->request($method, $entry);
+ my $status = $req->gather(1);
+ $apputils->commit_db_session($session);
+
+ warn "stat cat entry with id " . $status . " updated with status $status\n";
+ return $status;
+}
+
+
__PACKAGE__->register_method(
method => "create_stat_map",
}
+__PACKAGE__->register_method(
+ method => "update_stat_map",
+ api_name => "open-ils.circ.stat_cat.actor.user_map.update");
+
+__PACKAGE__->register_method(
+ method => "update_stat_map",
+ api_name => "open-ils.circ.stat_cat.asset.copy_map.update");
+
+sub update_stat_map {
+ my( $self, $client, $user_session, $map ) = @_;
+
+ my $user_obj = $apputils->check_user_session($user_session);
+
+ warn "Updating stat_cat_map\n";
+
+ my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update";
+ if($self->api_name =~ /asset/) {
+ $method = "open-ils.storage.direct.asset.stat_cat_entry_copy_map.update";
+ }
+
+ my $session = $apputils->start_db_session();
+ my $req = $session->request($method, $map);
+ my $newid = $req->gather(1);
+ warn "Updated new stat cat map with id $newid\n";
+ $apputils->commit_db_session($session);
+
+ return $newid;
+}
+
+
__PACKAGE__->register_method(
method => "retrieve_maps",
+__PACKAGE__->register_method(
+ method => "delete_stats",
+ api_name => "open-ils.circ.stat_cat.actor.delete");
+__PACKAGE__->register_method(
+ method => "delete_stats",
+ api_name => "open-ils.circ.stat_cat.asset.delete");
+sub delete_stats {
+ my( $self, $client, $user_session, $target ) = @_;
+ my $user_obj = $apputils->check_user_session($user_session);
+ my $session = OpenSRF::AppSession->create("open-ils.storage");
+ my $type = "actor";
+ if($self->api_name =~ /asset/) { $type = "asset"; }
+ return _delete_stats($session, $target, $type);
+}
+sub _delete_stats {
+ my( $session, $stat, $type) = @_;
+ my $method = "open-ils.storage.direct.asset.stat_cat.delete";
+ if($type =~ /actor/ ) {
+ $method = "open-ils.storage.direct.actor.stat_cat.delete";
+ }
+ return $session->request($method, $stat)->gather(1);
+}
+
+
+
+__PACKAGE__->register_method(
+ method => "delete_entry",
+ api_name => "open-ils.circ.stat_cat.actor.entry.delete");
+
+__PACKAGE__->register_method(
+ method => "delete_entry",
+ api_name => "open-ils.circ.stat_cat.asset.entry.delete");
+
+sub delete_entry {
+ my( $self, $client, $user_session, $target ) = @_;
+ my $user_obj = $apputils->check_user_session($user_session);
+ my $session = OpenSRF::AppSession->create("open-ils.storage");
+ my $type = "actor";
+ if($self->api_name =~ /asset/) { $type = "asset"; }
+ return _delete_entry($session, $target, $type);
+}
+
+sub _delete_entry {
+ my( $session, $stat_entry, $type) = @_;
+
+ my $method = "open-ils.storage.direct.asset.stat_cat_entry.delete";
+ if($type =~ /actor/ ) {
+ $method = "open-ils.storage.direct.actor.stat_cat_entry.delete";
+ }
+
+ return $session->request($method, $stat_entry)->gather(1);
+}
OpenILS::Application::SearchCache->child_init();
}
+sub initialize {
+ OpenILS::Application::Search::Z3950->initialize();
+}
+
sub filter_search {
my($self, $str, $full) = @_;
method => "record_id_to_copy_count",
api_name => "open-ils.search.biblio.metarecord.copy_count",
);
+
+__PACKAGE__->register_method(
+ method => "record_id_to_copy_count",
+ api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
+);
sub record_id_to_copy_count {
my( $self, $client, $org_id, $record_id ) = @_;
$key = "metarecord";
}
+ if($self->api_name =~ /staff/ ) {
+ $method =~ s/atomic/staff\.atomic/og;
+ warn "Doing staff search $method\n";
+ }
+
+
my $session = OpenSRF::AppSession->create("open-ils.storage");
warn "copy_count retrieve $record_id\n";
return undef unless(defined $record_id);
__PACKAGE__->register_method(
method => "biblio_search_class_count",
api_name => "open-ils.search.biblio.class.count",
- argc => 3,
- note => "Searches biblio information by search class and returns the IDs",
);
+
+__PACKAGE__->register_method(
+ method => "biblio_search_class_count",
+ api_name => "open-ils.search.biblio.class.count.staff",
+);
+
sub biblio_search_class_count {
my( $self, $client, $class, $string, $org_id, $org_type ) = @_;
$class =~ s/\s+//g;
if( ($class ne "title") and ($class ne "author") and
- ($class ne "subject") and ($class ne "keyword") ) {
+ ($class ne "subject") and ($class ne "keyword")
+ and ($class ne "series" )) {
warn "Invalid search class: $class\n";
throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
}
# grab the mr id's from storage
my $method = "open-ils.storage.metabib.$class.search_fts.metarecord_count";
+ if($self->api_name =~ /staff/) { $method = "$method.staff"; }
warn "Performing count method $method\n";
+ warn "API name " . $self->api_name() . "\n";
+
my $session = OpenSRF::AppSession->create('open-ils.storage');
my $request = $session->request( $method,
api_name => "open-ils.search.biblio.class.unordered",
);
+__PACKAGE__->register_method(
+ method => "biblio_search_class",
+ api_name => "open-ils.search.biblio.class.staff",
+);
+
+__PACKAGE__->register_method(
+ method => "biblio_search_class",
+ api_name => "open-ils.search.biblio.class.unordered.staff",
+);
+
sub biblio_search_class {
my( $self, $client, $class, $string,
$class =~ s/\s+//g;
if( ($class ne "title") and ($class ne "author") and
- ($class ne "subject") and ($class ne "keyword") ) {
+ ($class ne "subject") and ($class ne "keyword")
+ and ($class ne "series") ) {
warn "Invalid search class: $class\n";
throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
}
$method = "open-ils.storage.metabib.$class.search_fts.metarecord.unordered.atomic";
}
+ if($self->api_name =~ /staff/) {
+ $method =~ s/atomic/staff\.atomic/og;
+ }
+
+ warn "Performing search method $method\n";
warn "MR search method is $method\n";
my $session = OpenSRF::AppSession->create('open-ils.storage');
my $apputils = "OpenILS::Application::AppUtils";
use OpenILS::Utils::ModsParser;
+use Data::Dumper;
my $output = "USMARC"; # only support output for now
my $host;
for( my $x = 0; $x != $hash->{count}; $x++ ) {
+ warn "Churning on z39 record count $x\n";
+
my $rec = $rs->record($x+1);
my $marc = MARC::Record->new_from_usmarc($rec->rawdata());
- my $nodes = OpenILS::Utils::FlatXML->new()->xml_to_nodeset( $marc->as_xml() );
+ my $marcxml = $marc->as_xml();
+ my $flat = OpenILS::Utils::FlatXML->new( xml => $marcxml );
+ my $doc = $flat->xml_to_doc();
+
+
+ if( $doc->documentElement->nodeName =~ /collection/io ) {
+ $doc->setDocumentElement( $doc->documentElement->firstChild );
+ $doc->documentElement->setNamespace(
+ "http://www.loc.gov/MARC21/slim", undef, 1);
+ }
+
+ warn $doc->toString . "\n";
+
+ my $nodes = $flat->xmldoc_to_nodeset($doc);
+
warn "turning nodeset into tree\n";
my $tree = $utils->nodeset2tree( $nodes->nodeset );
my $tcn_xpath = "//mods:mods/mods:recordInfo/mods:recordIdentifier";
my $publisher_xpath = "//mods:mods/mods:originInfo//mods:publisher[1]";
+my $edition_xpath = "//mods:mods/mods:originInfo//mods:edition[1]";
+
my $xpathset = {
+
title => {
abbreviated =>
"//mods:mods/mods:titleInfo[mods:title and (\@type='abreviated')]",
proper =>
"//mods:mods/mods:titleInfo[mods:title and not (\@type)]",
},
+
author => {
corporate =>
"//mods:mods/mods:name[\@type='corporate']/*[local-name()='namePart']".
other =>
"//mods:mods/mods:name[\@type='personal']/*[local-name()='namePart']",
},
+
subject => {
topic =>
($self->{master_doc}->{publisher}) =
$self->get_field_value( $mods, $publisher_xpath );
+ ($self->{master_doc}->{edition}) =
+ $self->get_field_value( $mods, $edition_xpath );
+
}
# ---------------------------------------------------------------------------
push @series, (split( /\s*;/, $s ))[0];
}
+ # uniquify the types of resource
+ my $rtypes = $perl->{type_of_resource};
+ my %hash = map { ($_ => 1) } @$rtypes;
+ $rtypes = [ keys %hash ];
+
$record->title($title);
$record->author($author);
$record->publisher($perl->{publisher});
$record->tcn($perl->{tcn});
+ $record->edition($perl->{edition});
+
$record->subject($perl->{subject});
- $record->types_of_resource($perl->{types_of_resource});
+ $record->types_of_resource($rtypes);
$record->series(\@series);
$self->{master_doc} = undef;
- #return $perl
return $record;
}
box(id='progress_bar_percent_location');
INCLUDE opac/pages/chunks/opac_search_bar.ttk;
lines(1);
+
INCLUDE opac/pages/chunks/status_bar.ttk;
+
+ WRAPPER html/div class='hit_count_selector_div';
+
+ WRAPPER html/div class='hit_count_cell' id='hit_count_cell';
+ END;
+
+ "Hits per page ";
+ WRAPPER html/select name='hits_per_page' id='hits_per_page';
+ option(value='5', content="5");
+ option(value='10', selected='selected', content="10");
+ option(value='15', content="15");
+ option(value='25', content="25");
+ option(value='50', content="50");
+ option(value='100', content="100");
+ END;
+ END;
+
INCLUDE opac/pages/chunks/org_tree.ttk;
%]
value=tm.search, onclick='alert("help");' );
space(1);
+
+
END;
WRAPPER html/cell class='search_range_cell' nowrap='nowrap';
+
WRAPPER html/span;
space(3);
"Expand search to ";
);
+
END;
END;
WRAPPER html/table class='record_result_box', id='record_result_box';
WRAPPER html/thead class='record_result_thead';
WRAPPER html/row id='record_result_thead_row';
- cell(id='hit_count_cell', nowrap='nowrap', colspan='2', class='hit_count_cell');
+ cell(nowrap='nowrap', colspan='2' );
END;
END;
END;