}
__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",);