From 063f0581f484ff990ac57f3dffbb9f4a9e5af030 Mon Sep 17 00:00:00 2001 From: dbs Date: Thu, 28 Oct 2010 15:08:00 +0000 Subject: [PATCH] Normalize whitespace in O:A:Cat There was a great mix of tabs and spaces in O:A:Cat, and as I just got bit by that I thought I might as well make it consistent. Tried to keep all of the var assignments lined up as well. git-svn-id: svn://svn.open-ils.org/ILS/trunk@18517 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Cat.pm | 890 ++++++++++++----------- 1 file changed, 446 insertions(+), 444 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm index 10c9da566..b78799989 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat.pm @@ -28,136 +28,136 @@ my $conf; my %marctemplates; __PACKAGE__->register_method( - method => "retrieve_marc_template", - api_name => "open-ils.cat.biblio.marc_template.retrieve", - notes => <<" NOTES"); - Returns a MARC 'record tree' based on a set of pre-defined templates. - Templates include : book - NOTES + method => "retrieve_marc_template", + api_name => "open-ils.cat.biblio.marc_template.retrieve", + notes => <<" NOTES"); + Returns a MARC 'record tree' based on a set of pre-defined templates. + Templates include : book + NOTES sub retrieve_marc_template { - my( $self, $client, $type ) = @_; - return $marctemplates{$type} if defined($marctemplates{$type}); - $marctemplates{$type} = _load_marc_template($type); - return $marctemplates{$type}; + my( $self, $client, $type ) = @_; + return $marctemplates{$type} if defined($marctemplates{$type}); + $marctemplates{$type} = _load_marc_template($type); + return $marctemplates{$type}; } __PACKAGE__->register_method( - method => 'fetch_marc_template_types', - api_name => 'open-ils.cat.marc_template.types.retrieve' + method => 'fetch_marc_template_types', + api_name => 'open-ils.cat.marc_template.types.retrieve' ); my $marc_template_files; sub fetch_marc_template_types { - my( $self, $conn ) = @_; - __load_marc_templates(); - return [ keys %$marc_template_files ]; + my( $self, $conn ) = @_; + __load_marc_templates(); + return [ keys %$marc_template_files ]; } sub __load_marc_templates { - return if $marc_template_files; - if(!$conf) { $conf = OpenSRF::Utils::SettingsClient->new; } + return if $marc_template_files; + if(!$conf) { $conf = OpenSRF::Utils::SettingsClient->new; } - $marc_template_files = $conf->config_value( - "apps", "open-ils.cat","app_settings", "marctemplates" ); + $marc_template_files = $conf->config_value( + "apps", "open-ils.cat","app_settings", "marctemplates" ); - $logger->info("Loaded marc templates: " . Dumper($marc_template_files)); + $logger->info("Loaded marc templates: " . Dumper($marc_template_files)); } sub _load_marc_template { - my $type = shift; + my $type = shift; - __load_marc_templates(); + __load_marc_templates(); - my $template = $$marc_template_files{$type}; - open( F, $template ) or - throw OpenSRF::EX::ERROR ("Unable to open MARC template file: $template : $@"); + my $template = $$marc_template_files{$type}; + open( F, $template ) or + throw OpenSRF::EX::ERROR ("Unable to open MARC template file: $template : $@"); - my @xml = ; - close(F); - my $xml = join('', @xml); + my @xml = ; + close(F); + my $xml = join('', @xml); - return XML::LibXML->new->parse_string($xml)->documentElement->toString; + return XML::LibXML->new->parse_string($xml)->documentElement->toString; } __PACKAGE__->register_method( - method => 'fetch_bib_sources', - api_name => 'open-ils.cat.bib_sources.retrieve.all'); + method => 'fetch_bib_sources', + api_name => 'open-ils.cat.bib_sources.retrieve.all'); sub fetch_bib_sources { - return OpenILS::Application::Cat::BibCommon->fetch_bib_sources(); + return OpenILS::Application::Cat::BibCommon->fetch_bib_sources(); } __PACKAGE__->register_method( - method => "create_record_xml", - api_name => "open-ils.cat.biblio.record.xml.create.override", - signature => q/@see open-ils.cat.biblio.record.xml.create/); + method => "create_record_xml", + api_name => "open-ils.cat.biblio.record.xml.create.override", + signature => q/@see open-ils.cat.biblio.record.xml.create/); __PACKAGE__->register_method( - method => "create_record_xml", - api_name => "open-ils.cat.biblio.record.xml.create", - signature => q/ - Inserts a new biblio with the given XML - / + method => "create_record_xml", + api_name => "open-ils.cat.biblio.record.xml.create", + signature => q/ + Inserts a new biblio with the given XML + / ); sub create_record_xml { - my( $self, $client, $login, $xml, $source ) = @_; + my( $self, $client, $login, $xml, $source ) = @_; - my $override = 1 if $self->api_name =~ /override/; + my $override = 1 if $self->api_name =~ /override/; - my( $user_obj, $evt ) = $U->checksesperm($login, 'CREATE_MARC'); - return $evt if $evt; + my( $user_obj, $evt ) = $U->checksesperm($login, 'CREATE_MARC'); + return $evt if $evt; - $logger->activity("user ".$user_obj->id." creating new MARC record"); + $logger->activity("user ".$user_obj->id." creating new MARC record"); - my $meth = $self->method_lookup("open-ils.cat.biblio.record.xml.import"); + my $meth = $self->method_lookup("open-ils.cat.biblio.record.xml.import"); - $meth = $self->method_lookup( - "open-ils.cat.biblio.record.xml.import.override") if $override; + $meth = $self->method_lookup( + "open-ils.cat.biblio.record.xml.import.override") if $override; - my ($s) = $meth->run($login, $xml, $source); - return $s; + my ($s) = $meth->run($login, $xml, $source); + return $s; } __PACKAGE__->register_method( - method => "biblio_record_replace_marc", - api_name => "open-ils.cat.biblio.record.xml.update", - argc => 3, - signature => q/ - Updates the XML for a given biblio record. - This does not change any other aspect of the record entry - exception the XML, the editor, and the edit date. - @return The update record object - / + method => "biblio_record_replace_marc", + api_name => "open-ils.cat.biblio.record.xml.update", + argc => 3, + signature => q/ + Updates the XML for a given biblio record. + This does not change any other aspect of the record entry + exception the XML, the editor, and the edit date. + @return The update record object + / ); __PACKAGE__->register_method( - method => 'biblio_record_replace_marc', - api_name => 'open-ils.cat.biblio.record.marc.replace', - signature => q/ - @param auth The authtoken - @param recid The record whose MARC we're replacing - @param newxml The new xml to use - / + method => 'biblio_record_replace_marc', + api_name => 'open-ils.cat.biblio.record.marc.replace', + signature => q/ + @param auth The authtoken + @param recid The record whose MARC we're replacing + @param newxml The new xml to use + / ); __PACKAGE__->register_method( - method => 'biblio_record_replace_marc', - api_name => 'open-ils.cat.biblio.record.marc.replace.override', - signature => q/@see open-ils.cat.biblio.record.marc.replace/ + method => 'biblio_record_replace_marc', + api_name => 'open-ils.cat.biblio.record.marc.replace.override', + signature => q/@see open-ils.cat.biblio.record.marc.replace/ ); sub biblio_record_replace_marc { - my( $self, $conn, $auth, $recid, $newxml, $source ) = @_; - my $e = new_editor(authtoken=>$auth, xact=>1); - return $e->die_event unless $e->checkauth; - return $e->die_event unless $e->allowed('CREATE_MARC', $e->requestor->ws_ou); + my( $self, $conn, $auth, $recid, $newxml, $source ) = @_; + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + return $e->die_event unless $e->allowed('CREATE_MARC', $e->requestor->ws_ou); my $fix_tcn = $self->api_name =~ /replace/o; my $override = $self->api_name =~ /override/o; @@ -174,9 +174,9 @@ sub biblio_record_replace_marc { } __PACKAGE__->register_method( - method => "template_overlay_biblio_record_entry", - api_name => "open-ils.cat.biblio.record_entry.template_overlay", - stream => 1, + method => "template_overlay_biblio_record_entry", + api_name => "open-ils.cat.biblio.record_entry.template_overlay", + stream => 1, signature => q# Overlays biblio.record_entry MARC values @param auth The authtoken @@ -214,9 +214,9 @@ sub template_overlay_biblio_record_entry { } __PACKAGE__->register_method( - method => "template_overlay_container", - api_name => "open-ils.cat.container.template_overlay", - stream => 1, + method => "template_overlay_container", + api_name => "open-ils.cat.container.template_overlay", + stream => 1, signature => q# Overlays biblio.record_entry MARC values @param auth The authtoken @@ -227,9 +227,9 @@ __PACKAGE__->register_method( ); __PACKAGE__->register_method( - method => "template_overlay_container", - api_name => "open-ils.cat.container.template_overlay.background", - stream => 1, + method => "template_overlay_container", + api_name => "open-ils.cat.container.template_overlay.background", + stream => 1, signature => q# Overlays biblio.record_entry MARC values @param auth The authtoken @@ -324,8 +324,8 @@ sub template_overlay_container { } __PACKAGE__->register_method( - method => "update_biblio_record_entry", - api_name => "open-ils.cat.biblio.record_entry.update", + method => "update_biblio_record_entry", + api_name => "open-ils.cat.biblio.record_entry.update", signature => q/ Updates a biblio.record_entry @param auth The authtoken @@ -345,8 +345,8 @@ sub update_biblio_record_entry { } __PACKAGE__->register_method( - method => "undelete_biblio_record_entry", - api_name => "open-ils.cat.biblio.record_entry.undelete", + method => "undelete_biblio_record_entry", + api_name => "open-ils.cat.biblio.record_entry.undelete", signature => q/ Un-deletes a record and sets active=true @param auth The authtoken @@ -385,30 +385,30 @@ sub undelete_biblio_record_entry { __PACKAGE__->register_method( - method => "biblio_record_xml_import", - api_name => "open-ils.cat.biblio.record.xml.import.override", - signature => q/@see open-ils.cat.biblio.record.xml.import/); + method => "biblio_record_xml_import", + api_name => "open-ils.cat.biblio.record.xml.import.override", + signature => q/@see open-ils.cat.biblio.record.xml.import/); __PACKAGE__->register_method( - method => "biblio_record_xml_import", - api_name => "open-ils.cat.biblio.record.xml.import", - notes => <<" NOTES"); - Takes a marcxml record and imports the record into the database. In this - case, the marcxml record is assumed to be a complete record (i.e. valid - MARC). The title control number is taken from (whichever comes first) - tags 001, 039[ab], 020a, 022a, 010, 035a and whichever does not already exist - in the database. - user_session must have IMPORT_MARC permissions - NOTES + method => "biblio_record_xml_import", + api_name => "open-ils.cat.biblio.record.xml.import", + notes => <<" NOTES"); + Takes a marcxml record and imports the record into the database. In this + case, the marcxml record is assumed to be a complete record (i.e. valid + MARC). The title control number is taken from (whichever comes first) + tags 001, 039[ab], 020a, 022a, 010, 035a and whichever does not already exist + in the database. + user_session must have IMPORT_MARC permissions + NOTES sub biblio_record_xml_import { - my( $self, $client, $authtoken, $xml, $source, $auto_tcn) = @_; + my( $self, $client, $authtoken, $xml, $source, $auto_tcn) = @_; my $e = new_editor(xact=>1, authtoken=>$authtoken); return $e->die_event unless $e->checkauth; return $e->die_event unless $e->allowed('IMPORT_MARC', $e->requestor->ws_ou); - my $override = $self->api_name =~ /override/; + my $override = $self->api_name =~ /override/; my $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import( $e, $xml, $source, $auto_tcn, $override); @@ -423,45 +423,45 @@ sub biblio_record_xml_import { } __PACKAGE__->register_method( - method => "biblio_record_record_metadata", - api_name => "open-ils.cat.biblio.record.metadata.retrieve", + method => "biblio_record_record_metadata", + api_name => "open-ils.cat.biblio.record.metadata.retrieve", authoritative => 1, - argc => 1, #(session_id, biblio_tree ) - notes => "Walks the tree and commits any changed nodes " . - "adds any new nodes, and deletes any deleted nodes", + argc => 1, #(session_id, biblio_tree ) + notes => "Walks the tree and commits any changed nodes " . + "adds any new nodes, and deletes any deleted nodes", ); sub biblio_record_record_metadata { - my( $self, $client, $authtoken, $ids ) = @_; + my( $self, $client, $authtoken, $ids ) = @_; - return [] unless $ids and @$ids; + return [] unless $ids and @$ids; - my $editor = new_editor(authtoken => $authtoken); - return $editor->event unless $editor->checkauth; - return $editor->event unless $editor->allowed('VIEW_USER'); + my $editor = new_editor(authtoken => $authtoken); + return $editor->event unless $editor->checkauth; + return $editor->event unless $editor->allowed('VIEW_USER'); - my @results; + my @results; - for(@$ids) { - return $editor->event unless - my $rec = $editor->retrieve_biblio_record_entry($_); - $rec->creator($editor->retrieve_actor_user($rec->creator)); - $rec->editor($editor->retrieve_actor_user($rec->editor)); - $rec->clear_marc; # slim the record down - push( @results, $rec ); - } + for(@$ids) { + return $editor->event unless + my $rec = $editor->retrieve_biblio_record_entry($_); + $rec->creator($editor->retrieve_actor_user($rec->creator)); + $rec->editor($editor->retrieve_actor_user($rec->editor)); + $rec->clear_marc; # slim the record down + push( @results, $rec ); + } - return \@results; + return \@results; } __PACKAGE__->register_method( method => "biblio_record_marc_cn", - api_name => "open-ils.cat.biblio.record.marc_cn.retrieve", - argc => 1, #(bib id ) + api_name => "open-ils.cat.biblio.record.marc_cn.retrieve", + argc => 1, #(bib id ) signature => { - desc => 'Extracts call number candidates from a bibliographic record', + desc => 'Extracts call number candidates from a bibliographic record', params => [ {desc => 'Record ID', type => 'number'}, {desc => '(Optional) Classification scheme ID', type => 'number'}, @@ -519,10 +519,10 @@ sub biblio_record_marc_cn { } __PACKAGE__->register_method( - method => 'autogen_barcodes', - api_name => "open-ils.cat.item.barcode.autogen", + method => 'autogen_barcodes', + api_name => "open-ils.cat.item.barcode.autogen", signature => { - desc => 'Returns N generated barcodes following a specified barcode.', + desc => 'Returns N generated barcodes following a specified barcode.', params => [ {desc => 'Authentication token', type => 'string'}, {desc => 'Barcode which the sequence should follow from', type => 'string'}, @@ -592,144 +592,144 @@ sub add_codabar_checkdigit { } __PACKAGE__->register_method( - method => "orgs_for_title", + method => "orgs_for_title", authoritative => 1, - api_name => "open-ils.cat.actor.org_unit.retrieve_by_title" + api_name => "open-ils.cat.actor.org_unit.retrieve_by_title" ); sub orgs_for_title { - my( $self, $client, $record_id ) = @_; + my( $self, $client, $record_id ) = @_; - my $vols = $U->simple_scalar_request( - "open-ils.cstore", - "open-ils.cstore.direct.asset.call_number.search.atomic", - { record => $record_id, deleted => 'f' }); + my $vols = $U->simple_scalar_request( + "open-ils.cstore", + "open-ils.cstore.direct.asset.call_number.search.atomic", + { record => $record_id, deleted => 'f' }); - my $orgs = { map {$_->owning_lib => 1 } @$vols }; - return [ keys %$orgs ]; + my $orgs = { map {$_->owning_lib => 1 } @$vols }; + return [ keys %$orgs ]; } __PACKAGE__->register_method( - method => "retrieve_copies", + method => "retrieve_copies", authoritative => 1, - api_name => "open-ils.cat.asset.copy_tree.retrieve"); + api_name => "open-ils.cat.asset.copy_tree.retrieve"); __PACKAGE__->register_method( - method => "retrieve_copies", - api_name => "open-ils.cat.asset.copy_tree.global.retrieve"); + method => "retrieve_copies", + api_name => "open-ils.cat.asset.copy_tree.global.retrieve"); # user_session may be null/undef sub retrieve_copies { - my( $self, $client, $user_session, $docid, @org_ids ) = @_; + my( $self, $client, $user_session, $docid, @org_ids ) = @_; - if(ref($org_ids[0])) { @org_ids = @{$org_ids[0]}; } + if(ref($org_ids[0])) { @org_ids = @{$org_ids[0]}; } - $docid = "$docid"; + $docid = "$docid"; - # grabbing copy trees should be available for everyone.. - if(!@org_ids and $user_session) { + # grabbing copy trees should be available for everyone.. + if(!@org_ids and $user_session) { my($user_obj, $evt) = OpenILS::Application::AppUtils->checkses($user_session); return $evt if $evt; @org_ids = ($user_obj->home_ou); - } + } - if( $self->api_name =~ /global/ ) { - return _build_volume_list( { record => $docid, deleted => 'f', label => { '<>' => '##URI##' } } ); + if( $self->api_name =~ /global/ ) { + return _build_volume_list( { record => $docid, deleted => 'f', label => { '<>' => '##URI##' } } ); - } else { + } else { - my @all_vols; - for my $orgid (@org_ids) { - my $vols = _build_volume_list( - { record => $docid, owning_lib => $orgid, deleted => 'f', label => { '<>' => '##URI##' } } ); - push( @all_vols, @$vols ); - } - - return \@all_vols; - } + my @all_vols; + for my $orgid (@org_ids) { + my $vols = _build_volume_list( + { record => $docid, owning_lib => $orgid, deleted => 'f', label => { '<>' => '##URI##' } } ); + push( @all_vols, @$vols ); + } + + return \@all_vols; + } - return undef; + return undef; } sub _build_volume_list { - my $search_hash = shift; + my $search_hash = shift; - $search_hash->{deleted} = 'f'; - my $e = new_editor(); + $search_hash->{deleted} = 'f'; + my $e = new_editor(); - my $vols = $e->search_asset_call_number([$search_hash, { 'order_by' => { + my $vols = $e->search_asset_call_number([$search_hash, { 'order_by' => { 'acn' => 'oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib' } } ] ); - my @volumes; + my @volumes; - for my $volume (@$vols) { + for my $volume (@$vols) { - my $copies = $e->search_asset_copy( - { call_number => $volume->id , deleted => 'f' }); + my $copies = $e->search_asset_copy( + { call_number => $volume->id , deleted => 'f' }); - $copies = [ sort { $a->barcode cmp $b->barcode } @$copies ]; + $copies = [ sort { $a->barcode cmp $b->barcode } @$copies ]; - for my $c (@$copies) { - if( $c->status == OILS_COPY_STATUS_CHECKED_OUT ) { - $c->circulations( - $e->search_action_circulation( - [ - { target_copy => $c->id }, - { - order_by => { circ => 'xact_start desc' }, - limit => 1 - } - ] - ) - ) - } - } + for my $c (@$copies) { + if( $c->status == OILS_COPY_STATUS_CHECKED_OUT ) { + $c->circulations( + $e->search_action_circulation( + [ + { target_copy => $c->id }, + { + order_by => { circ => 'xact_start desc' }, + limit => 1 + } + ] + ) + ) + } + } - $volume->copies($copies); - push( @volumes, $volume ); - } + $volume->copies($copies); + push( @volumes, $volume ); + } - #$session->disconnect(); - return \@volumes; + #$session->disconnect(); + return \@volumes; } __PACKAGE__->register_method( - method => "fleshed_copy_update", - api_name => "open-ils.cat.asset.copy.fleshed.batch.update",); + method => "fleshed_copy_update", + api_name => "open-ils.cat.asset.copy.fleshed.batch.update",); __PACKAGE__->register_method( - method => "fleshed_copy_update", - api_name => "open-ils.cat.asset.copy.fleshed.batch.update.override",); + method => "fleshed_copy_update", + api_name => "open-ils.cat.asset.copy.fleshed.batch.update.override",); sub fleshed_copy_update { - my( $self, $conn, $auth, $copies, $delete_stats ) = @_; - return 1 unless ref $copies; - my( $reqr, $evt ) = $U->checkses($auth); - return $evt if $evt; - my $editor = new_editor(requestor => $reqr, xact => 1); - my $override = $self->api_name =~ /override/; + my( $self, $conn, $auth, $copies, $delete_stats ) = @_; + return 1 unless ref $copies; + my( $reqr, $evt ) = $U->checkses($auth); + return $evt if $evt; + my $editor = new_editor(requestor => $reqr, xact => 1); + my $override = $self->api_name =~ /override/; my $retarget_holds = []; - $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies( + $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies( $editor, $override, undef, $copies, $delete_stats, $retarget_holds, undef); - if( $evt ) { - $logger->info("fleshed copy update failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt)); - $editor->rollback; - return $evt; - } + if( $evt ) { + $logger->info("fleshed copy update failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt)); + $editor->rollback; + return $evt; + } - $editor->commit; - $logger->info("fleshed copy update successfully updated ".scalar(@$copies)." copies"); + $editor->commit; + $logger->info("fleshed copy update successfully updated ".scalar(@$copies)." copies"); reset_hold_list($auth, $retarget_holds); - return 1; + return 1; } sub reset_hold_list { @@ -742,21 +742,21 @@ sub reset_hold_list { __PACKAGE__->register_method( - method => 'in_db_merge', - api_name => 'open-ils.cat.biblio.records.merge', - signature => q/ - Merges a group of records - @param auth The login session key - @param master The id of the record all other records should be merged into - @param records Array of records to be merged into the master record - @return 1 on success, Event on error. - / + method => 'in_db_merge', + api_name => 'open-ils.cat.biblio.records.merge', + signature => q/ + Merges a group of records + @param auth The login session key + @param master The id of the record all other records should be merged into + @param records Array of records to be merged into the master record + @return 1 on success, Event on error. + / ); sub in_db_merge { - my( $self, $conn, $auth, $master, $records ) = @_; + my( $self, $conn, $auth, $master, $records ) = @_; - my $editor = new_editor( authtoken => $auth, xact => 1 ); + my $editor = new_editor( authtoken => $auth, xact => 1 ); return $editor->die_event unless $editor->checkauth; return $editor->die_event unless $editor->allowed('MERGE_BIB_RECORDS'); # TODO see below about record ownership @@ -784,7 +784,7 @@ sub in_db_merge { } - $editor->commit; + $editor->commit; return $count; } @@ -828,92 +828,92 @@ sub in_db_auth_merge { } __PACKAGE__->register_method( - method => "fleshed_volume_update", - api_name => "open-ils.cat.asset.volume.fleshed.batch.update",); + method => "fleshed_volume_update", + api_name => "open-ils.cat.asset.volume.fleshed.batch.update",); __PACKAGE__->register_method( - method => "fleshed_volume_update", - api_name => "open-ils.cat.asset.volume.fleshed.batch.update.override",); + method => "fleshed_volume_update", + api_name => "open-ils.cat.asset.volume.fleshed.batch.update.override",); sub fleshed_volume_update { - my( $self, $conn, $auth, $volumes, $delete_stats, $options ) = @_; - my( $reqr, $evt ) = $U->checkses($auth); - return $evt if $evt; + my( $self, $conn, $auth, $volumes, $delete_stats, $options ) = @_; + my( $reqr, $evt ) = $U->checkses($auth); + return $evt if $evt; $options ||= {}; - my $override = ($self->api_name =~ /override/); - my $editor = new_editor( requestor => $reqr, xact => 1 ); + my $override = ($self->api_name =~ /override/); + my $editor = new_editor( requestor => $reqr, xact => 1 ); my $retarget_holds = []; my $auto_merge_vols = $options->{auto_merge_vols}; - for my $vol (@$volumes) { - $logger->info("vol-update: investigating volume ".$vol->id); + for my $vol (@$volumes) { + $logger->info("vol-update: investigating volume ".$vol->id); - $vol->editor($reqr->id); - $vol->edit_date('now'); + $vol->editor($reqr->id); + $vol->edit_date('now'); - my $copies = $vol->copies; - $vol->clear_copies; + my $copies = $vol->copies; + $vol->clear_copies; - $vol->editor($editor->requestor->id); - $vol->edit_date('now'); + $vol->editor($editor->requestor->id); + $vol->edit_date('now'); - if( $vol->isdeleted ) { + if( $vol->isdeleted ) { - $logger->info("vol-update: deleting volume"); - my $cs = $editor->search_asset_copy( - { call_number => $vol->id, deleted => 'f' } ); - return OpenILS::Event->new( - 'VOLUME_NOT_EMPTY', payload => $vol->id ) if @$cs; + $logger->info("vol-update: deleting volume"); + my $cs = $editor->search_asset_copy( + { call_number => $vol->id, deleted => 'f' } ); + return OpenILS::Event->new( + 'VOLUME_NOT_EMPTY', payload => $vol->id ) if @$cs; - $vol->deleted('t'); - return $editor->event unless - $editor->update_asset_call_number($vol); + $vol->deleted('t'); + return $editor->event unless + $editor->update_asset_call_number($vol); - - } elsif( $vol->isnew ) { - $logger->info("vol-update: creating volume"); - $evt = OpenILS::Application::Cat::AssetCommon->create_volume( $override, $editor, $vol ); - return $evt if $evt; + + } elsif( $vol->isnew ) { + $logger->info("vol-update: creating volume"); + $evt = OpenILS::Application::Cat::AssetCommon->create_volume( $override, $editor, $vol ); + return $evt if $evt; - } elsif( $vol->ischanged ) { - $logger->info("vol-update: update volume"); - my $resp = update_volume($vol, $editor, ($override or $auto_merge_vols)); - return $resp->{evt} if $resp->{evt}; + } elsif( $vol->ischanged ) { + $logger->info("vol-update: update volume"); + my $resp = update_volume($vol, $editor, ($override or $auto_merge_vols)); + return $resp->{evt} if $resp->{evt}; $vol = $resp->{merge_vol}; - } + } - # now update any attached copies - if( $copies and @$copies and !$vol->isdeleted ) { - $_->call_number($vol->id) for @$copies; - $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies( + # now update any attached copies + if( $copies and @$copies and !$vol->isdeleted ) { + $_->call_number($vol->id) for @$copies; + $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies( $editor, $override, $vol, $copies, $delete_stats, $retarget_holds, undef); - return $evt if $evt; - } - } + return $evt if $evt; + } + } - $editor->finish; + $editor->finish; reset_hold_list($auth, $retarget_holds); - return scalar(@$volumes); + return scalar(@$volumes); } sub update_volume { - my $vol = shift; - my $editor = shift; + my $vol = shift; + my $editor = shift; my $auto_merge = shift; - my $evt; + my $evt; my $merge_vol; - return {evt => $evt} + return {evt => $evt} if ( $evt = OpenILS::Application::Cat::AssetCommon->org_cannot_have_vols($editor, $vol->owning_lib) ); - my $vols = $editor->search_asset_call_number({ - owning_lib => $vol->owning_lib, - record => $vol->record, - label => $vol->label, - deleted => 'f', - id => {'!=' => $vol->id} + my $vols = $editor->search_asset_call_number({ + owning_lib => $vol->owning_lib, + record => $vol->record, + label => $vol->label, + deleted => 'f', + id => {'!=' => $vol->id} }); if(@$vols) { @@ -926,19 +926,19 @@ sub update_volume { return {evt => $evt, merge_vol => $merge_vol}; } else { - return {evt => OpenILS::Event->new('VOLUME_LABEL_EXISTS', payload => $vol->id)}; + return {evt => OpenILS::Event->new('VOLUME_LABEL_EXISTS', payload => $vol->id)}; } } - return {evt => $editor->die_event} unless $editor->update_asset_call_number($vol); - return {}; + return {evt => $editor->die_event} unless $editor->update_asset_call_number($vol); + return {}; } __PACKAGE__->register_method ( - method => 'delete_bib_record', - api_name => 'open-ils.cat.biblio.record_entry.delete'); + method => 'delete_bib_record', + api_name => 'open-ils.cat.biblio.record_entry.delete'); sub delete_bib_record { my($self, $conn, $auth, $rec_id) = @_; @@ -956,141 +956,141 @@ sub delete_bib_record { __PACKAGE__->register_method ( - method => 'batch_volume_transfer', - api_name => 'open-ils.cat.asset.volume.batch.transfer', + method => 'batch_volume_transfer', + api_name => 'open-ils.cat.asset.volume.batch.transfer', ); __PACKAGE__->register_method ( - method => 'batch_volume_transfer', - api_name => 'open-ils.cat.asset.volume.batch.transfer.override', + method => 'batch_volume_transfer', + api_name => 'open-ils.cat.asset.volume.batch.transfer.override', ); sub batch_volume_transfer { - my( $self, $conn, $auth, $args ) = @_; + my( $self, $conn, $auth, $args ) = @_; - my $evt; - my $rec = $$args{docid}; - my $o_lib = $$args{lib}; - my $vol_ids = $$args{volumes}; + my $evt; + my $rec = $$args{docid}; + my $o_lib = $$args{lib}; + my $vol_ids = $$args{volumes}; - my $override = 1 if $self->api_name =~ /override/; + my $override = 1 if $self->api_name =~ /override/; - $logger->info("merge: transferring volumes to lib=$o_lib and record=$rec"); + $logger->info("merge: transferring volumes to lib=$o_lib and record=$rec"); - my $e = new_editor(authtoken => $auth, xact =>1); - return $e->event unless $e->checkauth; - return $e->event unless $e->allowed('UPDATE_VOLUME', $o_lib); + my $e = new_editor(authtoken => $auth, xact =>1); + return $e->event unless $e->checkauth; + return $e->event unless $e->allowed('UPDATE_VOLUME', $o_lib); - my $dorg = $e->retrieve_actor_org_unit($o_lib) - or return $e->event; + my $dorg = $e->retrieve_actor_org_unit($o_lib) + or return $e->event; - my $ou_type = $e->retrieve_actor_org_unit_type($dorg->ou_type) - or return $e->event; + my $ou_type = $e->retrieve_actor_org_unit_type($dorg->ou_type) + or return $e->event; - return $evt if ( $evt = OpenILS::Application::Cat::AssetCommon->org_cannot_have_vols($e, $o_lib) ); + return $evt if ( $evt = OpenILS::Application::Cat::AssetCommon->org_cannot_have_vols($e, $o_lib) ); - my $vols = $e->batch_retrieve_asset_call_number($vol_ids); - my @seen; + my $vols = $e->batch_retrieve_asset_call_number($vol_ids); + my @seen; my @rec_ids; - for my $vol (@$vols) { + for my $vol (@$vols) { # if we've already looked at this volume, go to the next next if !$vol or grep { $vol->id == $_ } @seen; - # grab all of the volumes in the list that have - # the same label so they can be merged - my @all = grep { $_->label eq $vol->label } @$vols; + # grab all of the volumes in the list that have + # the same label so they can be merged + my @all = grep { $_->label eq $vol->label } @$vols; - # take note of the fact that we've looked at this set of volumes - push( @seen, $_->id ) for @all; + # take note of the fact that we've looked at this set of volumes + push( @seen, $_->id ) for @all; push( @rec_ids, $_->record ) for @all; - # for each volume, see if there are any copies that have a - # remote circ_lib (circ_lib != vol->owning_lib and != $o_lib ). - # if so, warn them - unless( $override ) { - for my $v (@all) { - - $logger->debug("merge: searching for copies with remote circ_lib for volume ".$v->id); - my $args = { - call_number => $v->id, - circ_lib => { "not in" => [ $o_lib, $v->owning_lib ] }, - deleted => 'f' - }; - - my $copies = $e->search_asset_copy($args, {idlist=>1}); - - # if the copy's circ_lib matches the destination lib, - # that's ok too - return OpenILS::Event->new('COPY_REMOTE_CIRC_LIB') if @$copies; - } - } - - # see if there is a volume at the destination lib that - # already has the requested label - my $existing_vol = $e->search_asset_call_number( - { - label => $vol->label, - record =>$rec, - owning_lib =>$o_lib, - deleted => 'f' - } - )->[0]; - - if( $existing_vol ) { - - if( grep { $_->id == $existing_vol->id } @all ) { - # this volume is already accounted for in our list of volumes to merge - $existing_vol = undef; - - } else { - # this volume exists on the destination record/owning_lib and must - # be used as the destination for merging - $logger->debug("merge: volume already exists at destination record: ". - $existing_vol->id.' : '.$existing_vol->label) if $existing_vol; - } - } - - if( @all > 1 || $existing_vol ) { - $logger->info("merge: found collisions in volume transfer"); - my @args = ($e, \@all); - @args = ($e, \@all, $existing_vol) if $existing_vol; - ($vol, $evt) = OpenILS::Application::Cat::Merge::merge_volumes(@args); - return $evt if $evt; - } - - if( !$existing_vol ) { - - $vol->owning_lib($o_lib); - $vol->record($rec); - $vol->editor($e->requestor->id); - $vol->edit_date('now'); - - $logger->info("merge: updating volume ".$vol->id); - $e->update_asset_call_number($vol) or return $e->event; - - } else { - $logger->info("merge: bypassing volume update because existing volume used as target"); - } - - # regardless of what volume was used as the destination, - # update any copies that have moved over to the new lib - my $copies = $e->search_asset_copy({call_number=>$vol->id, deleted => 'f'}); - - # update circ lib on the copies - make this a method flag? - for my $copy (@$copies) { - next if $copy->circ_lib == $o_lib; - $logger->info("merge: transfer moving circ lib on copy ".$copy->id); - $copy->circ_lib($o_lib); - $copy->editor($e->requestor->id); - $copy->edit_date('now'); - $e->update_asset_copy($copy) or return $e->event; - } - - # Now see if any empty records need to be deleted after all of this + # for each volume, see if there are any copies that have a + # remote circ_lib (circ_lib != vol->owning_lib and != $o_lib ). + # if so, warn them + unless( $override ) { + for my $v (@all) { + + $logger->debug("merge: searching for copies with remote circ_lib for volume ".$v->id); + my $args = { + call_number => $v->id, + circ_lib => { "not in" => [ $o_lib, $v->owning_lib ] }, + deleted => 'f' + }; + + my $copies = $e->search_asset_copy($args, {idlist=>1}); + + # if the copy's circ_lib matches the destination lib, + # that's ok too + return OpenILS::Event->new('COPY_REMOTE_CIRC_LIB') if @$copies; + } + } + + # see if there is a volume at the destination lib that + # already has the requested label + my $existing_vol = $e->search_asset_call_number( + { + label => $vol->label, + record => $rec, + owning_lib => $o_lib, + deleted => 'f' + } + )->[0]; + + if( $existing_vol ) { + + if( grep { $_->id == $existing_vol->id } @all ) { + # this volume is already accounted for in our list of volumes to merge + $existing_vol = undef; + + } else { + # this volume exists on the destination record/owning_lib and must + # be used as the destination for merging + $logger->debug("merge: volume already exists at destination record: ". + $existing_vol->id.' : '.$existing_vol->label) if $existing_vol; + } + } + + if( @all > 1 || $existing_vol ) { + $logger->info("merge: found collisions in volume transfer"); + my @args = ($e, \@all); + @args = ($e, \@all, $existing_vol) if $existing_vol; + ($vol, $evt) = OpenILS::Application::Cat::Merge::merge_volumes(@args); + return $evt if $evt; + } + + if( !$existing_vol ) { + + $vol->owning_lib($o_lib); + $vol->record($rec); + $vol->editor($e->requestor->id); + $vol->edit_date('now'); + + $logger->info("merge: updating volume ".$vol->id); + $e->update_asset_call_number($vol) or return $e->event; + + } else { + $logger->info("merge: bypassing volume update because existing volume used as target"); + } + + # regardless of what volume was used as the destination, + # update any copies that have moved over to the new lib + my $copies = $e->search_asset_copy({call_number=>$vol->id, deleted => 'f'}); + + # update circ lib on the copies - make this a method flag? + for my $copy (@$copies) { + next if $copy->circ_lib == $o_lib; + $logger->info("merge: transfer moving circ lib on copy ".$copy->id); + $copy->circ_lib($o_lib); + $copy->editor($e->requestor->id); + $copy->edit_date('now'); + $e->update_asset_copy($copy) or return $e->event; + } + + # Now see if any empty records need to be deleted after all of this for(@rec_ids) { $logger->debug("merge: seeing if we should delete record $_..."); @@ -1098,25 +1098,25 @@ sub batch_volume_transfer { if OpenILS::Application::Cat::BibCommon->title_is_empty($e, $_); return $evt if $evt; } - } + } - $logger->info("merge: transfer succeeded"); - $e->commit; - return 1; + $logger->info("merge: transfer succeeded"); + $e->commit; + return 1; } __PACKAGE__->register_method( - api_name => 'open-ils.cat.call_number.find_or_create', - method => 'find_or_create_volume', + api_name => 'open-ils.cat.call_number.find_or_create', + method => 'find_or_create_volume', ); sub find_or_create_volume { - my( $self, $conn, $auth, $label, $record_id, $org_id ) = @_; - my $e = new_editor(authtoken=>$auth, xact=>1); - return $e->die_event unless $e->checkauth; + my( $self, $conn, $auth, $label, $record_id, $org_id ) = @_; + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; my ($vol, $evt, $exists) = OpenILS::Application::Cat::AssetCommon->find_or_create_volume($e, $label, $record_id, $org_id); return $evt if $evt; @@ -1127,47 +1127,47 @@ sub find_or_create_volume { __PACKAGE__->register_method( - method => "create_serial_record_xml", - api_name => "open-ils.cat.serial.record.xml.create.override", - signature => q/@see open-ils.cat.serial.record.xml.create/); + method => "create_serial_record_xml", + api_name => "open-ils.cat.serial.record.xml.create.override", + signature => q/@see open-ils.cat.serial.record.xml.create/); __PACKAGE__->register_method( - method => "create_serial_record_xml", - api_name => "open-ils.cat.serial.record.xml.create", - signature => q/ - Inserts a new serial record with the given XML - / + method => "create_serial_record_xml", + api_name => "open-ils.cat.serial.record.xml.create", + signature => q/ + Inserts a new serial record with the given XML + / ); sub create_serial_record_xml { - my( $self, $client, $login, $source, $owning_lib, $record_id, $xml ) = @_; - - my $override = 1 if $self->api_name =~ /override/; # not currently used - - my $e = new_editor(xact=>1, authtoken=>$login); - return $e->die_event unless $e->checkauth; - return $e->die_event unless $e->allowed('CREATE_MFHD_RECORD', $owning_lib); - - # Auto-populate the location field of a placeholder MFHD record with the library name - my $aou = $e->retrieve_actor_org_unit($owning_lib) or return $e->die_event; - - my $mfhd = Fieldmapper::serial::record_entry->new; - - $mfhd->source($source) if $source; - $mfhd->record($record_id); - $mfhd->creator($e->requestor->id); - $mfhd->editor($e->requestor->id); - $mfhd->create_date('now'); - $mfhd->edit_date('now'); - $mfhd->owning_lib($owning_lib); - - # If the caller did not pass in MFHD XML, create a placeholder record. - # The placeholder will only contain the name of the owning library. - # The goal is to generate common patterns for the caller in the UI that - # then get passed in here. - if (!$xml) { - my $aou_name = $aou->name; - $xml = <api_name =~ /override/; # not currently used + + my $e = new_editor(xact=>1, authtoken=>$login); + return $e->die_event unless $e->checkauth; + return $e->die_event unless $e->allowed('CREATE_MFHD_RECORD', $owning_lib); + + # Auto-populate the location field of a placeholder MFHD record with the library name + my $aou = $e->retrieve_actor_org_unit($owning_lib) or return $e->die_event; + + my $mfhd = Fieldmapper::serial::record_entry->new; + + $mfhd->source($source) if $source; + $mfhd->record($record_id); + $mfhd->creator($e->requestor->id); + $mfhd->editor($e->requestor->id); + $mfhd->create_date('now'); + $mfhd->edit_date('now'); + $mfhd->owning_lib($owning_lib); + + # If the caller did not pass in MFHD XML, create a placeholder record. + # The placeholder will only contain the name of the owning library. + # The goal is to generate common patterns for the caller in the UI that + # then get passed in here. + if (!$xml) { + my $aou_name = $aou->name; + $xml = < $aou_name HERE - } - my $marcxml = XML::LibXML->new->parse_string($xml); - $marcxml->documentElement->setNamespace("http://www.loc.gov/MARC21/slim", "marc", 1 ); - $marcxml->documentElement->setNamespace("http://www.loc.gov/MARC21/slim"); + } + my $marcxml = XML::LibXML->new->parse_string($xml); + $marcxml->documentElement->setNamespace("http://www.loc.gov/MARC21/slim", "marc", 1 ); + $marcxml->documentElement->setNamespace("http://www.loc.gov/MARC21/slim"); - $mfhd->marc($U->entityize($marcxml->documentElement->toString)); + $mfhd->marc($U->entityize($marcxml->documentElement->toString)); - $e->create_serial_record_entry($mfhd) or return $e->die_event; + $e->create_serial_record_entry($mfhd) or return $e->die_event; - $e->commit; - return $mfhd->id; + $e->commit; + return $mfhd->id; } __PACKAGE__->register_method( - method => "create_update_asset_copy_template", - api_name => "open-ils.cat.asset.copy_template.create_or_update" + method => "create_update_asset_copy_template", + api_name => "open-ils.cat.asset.copy_template.create_or_update" ); sub create_update_asset_copy_template { @@ -1225,3 +1225,5 @@ sub create_update_asset_copy_template { } 1; + +# vi:et:ts=4:sw=4 -- 2.11.0