From abf20be081e1a4094f515ade4bb39e1ce312cd9f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 30 Nov 2016 12:06:18 -0500 Subject: [PATCH 1/1] LP#1117808: new methods for calculating MARC merges This patch adds three new middle-layer methods for calculating the result of MARC merges. open-ils.cat.merge.marc.per_profile: Calculate the result of merging one or more MARC records per the specified merge profile @param auth The login session key @param merge_profile ID of the record merge profile @param records Array of two or more MARCXML records to be merged. If two are supplied, the first is treated as the record to be overlaid, and the the incoming record that will overlay the first. If more than two are supplied, the first is treated as the record to be overlaid, and each following record in turn will be merged into that record. @return MARCXML string of the results of the merge open-ils.cat.merge.biblio.per_profile: Calculate the result of merging one or more bib records per the specified merge profile @param auth The login session key @param merge_profile ID of the record merge profile @param records Array of two or more bib record IDs of the bibs to be merged. @return MARCXML string of the results of the merge open-ils.cat.merge.authority.per_profile: Calculate the result of merging one or more authority records per the specified merge profile @param auth The login session key @param merge_profile ID of the record merge profile @param records Array of two or more bib record IDs of the bibs to be merged. @return MARCXML string of the results of the merge Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- .../perlmods/lib/OpenILS/Application/Cat.pm | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 87409e27d6..f48ff7a571 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -934,6 +934,122 @@ sub in_db_auth_merge { return $count; } +__PACKAGE__->register_method( + method => 'calculate_marc_merge', + api_name => 'open-ils.cat.merge.marc.per_profile', + signature => q/ + Calculate the result of merging one or more MARC records + per the specified merge profile + @param auth The login session key + @param merge_profile ID of the record merge profile + @param records Array of two or more MARCXML records to be + merged. If two are supplied, the first + is treated as the record to be overlaid, + and the the incoming record that will + overlay the first. If more than two are + supplied, the first is treated as the + record to be overlaid, and each following + record in turn will be merged into that + record. + @return MARCXML string of the results of the merge + / +); +__PACKAGE__->register_method( + method => 'calculate_bib_marc_merge', + api_name => 'open-ils.cat.merge.biblio.per_profile', + signature => q/ + Calculate the result of merging one or more bib records + per the specified merge profile + @param auth The login session key + @param merge_profile ID of the record merge profile + @param records Array of two or more bib record IDs of + the bibs to be merged. + @return MARCXML string of the results of the merge + / +); +__PACKAGE__->register_method( + method => 'calculate_authority_marc_merge', + api_name => 'open-ils.cat.merge.authority.per_profile', + signature => q/ + Calculate the result of merging one or more authority records + per the specified merge profile + @param auth The login session key + @param merge_profile ID of the record merge profile + @param records Array of two or more bib record IDs of + the bibs to be merged. + @return MARCXML string of the results of the merge + / +); + +sub _handle_marc_merge { + my ($e, $merge_profile_id, $records) = @_; + + my $result = shift @$records; + foreach my $incoming (@$records) { + my $response = $e->json_query({ + from => [ + 'vandelay.merge_record_xml_using_profile', + $incoming, $result, + $merge_profile_id + ] + }); + return unless ref($response); + $result = $response->[0]->{'vandelay.merge_record_xml_using_profile'}; + } + return $result; +} + +sub calculate_marc_merge { + my( $self, $conn, $auth, $merge_profile_id, $records ) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + + my $merge_profile = $e->retrieve_vandelay_merge_profile($merge_profile_id) + or return $e->die_event; + return $e->die_event unless ref($records) && @$records >= 2; + + return _handle_marc_merge($e, $merge_profile_id, $records) +} + +sub calculate_bib_marc_merge { + my( $self, $conn, $auth, $merge_profile_id, $bib_ids ) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + + my $merge_profile = $e->retrieve_vandelay_merge_profile($merge_profile_id) + or return $e->die_event; + return $e->die_event unless ref($bib_ids) && @$bib_ids >= 2; + + my $records = []; + foreach my $id (@$bib_ids) { + my $bre = $e->retrieve_biblio_record_entry($id) or return $e->die_event; + push @$records, $bre->marc(); + } + + return _handle_marc_merge($e, $merge_profile_id, $records) +} + +sub calculate_authority_marc_merge { + my( $self, $conn, $auth, $merge_profile_id, $authority_ids ) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + + my $merge_profile = $e->retrieve_vandelay_merge_profile($merge_profile_id) + or return $e->die_event; + return $e->die_event unless ref($authority_ids) && @$authority_ids >= 2; + + my $records = []; + foreach my $id (@$authority_ids) { + my $are = $e->retrieve_authority_record_entry($id) or return $e->die_event; + push @$records, $are->marc(); + } + + return _handle_marc_merge($e, $merge_profile_id, $records) +} + __PACKAGE__->register_method( method => "fleshed_volume_update", api_name => "open-ils.cat.asset.volume.fleshed.batch.update",); -- 2.43.2