Koha/t/lib/KohaTest/ImportBatch.pm
Galen Charlton 438ed23337 staging import - enhance record overlay behavior
Enhanced the ability of catalogers to specify how
bib and item records should be added, replaced, or
ignored during a staging import.

When an import batch of bib records is staged and commit,
the user can now explicitly specify what should occur
when an incoming bib record has, or does not have, a match
with a record already in the database.  The options are:

if match found (overlay_action):
  create_new (just add the incoming record)
  replace (replace the matched record with the incoming one)
  use_template (option not implemented)
  ignore (do nothing with the incoming bib; however, the
          items attached to it may still be processed
           based on the item action)

if no match is found (nomatch_action):
  create_new (just add the incoming record)
  ignore (do nothing with the incoming bib; in this
          case, any items attached to it will be
          ignored since there will be nothing to
          attach them to)

The following options for handling items embedded in the
bib record are now available:

  always_add (add the items to the new or replaced bib)
  add_only_if_match (add the items only if the incoming bib
                     matches an existing bib)
  add_only_if_add (add the items only if the incoming bib
                   does *not* match an existing bib)
  ignore (ignore the items entirely)

With these changes, it is now possible to support the following use cases:

[1] A library joining an existing Koha database wishes to add their
    items to existing bib records if they match, but does not want
    to overlay the bib records themselves.
[2] A library wants to load a file of records, but only handle
    the new ones, not ones that are already in the database.
[3] A library wants to load a file of records, but only
    handle the ones that match existing records (e.g., if
    the records are coming back from an authority control vendor).

Documentation changes:

* See description above; also, screenshots of the 'stage MARC records
for import' and 'manage staged MARC records' should be updated.

Test cases:

* Added test cases to exercise staging and committing import batches.

UI changes:

* The pages for staging and managing import batches now have
  controls for setting the overlay action, action if no match,
  and item action separately.
* in the manage import batch tool, user is notified when they
  change overlay action, no-match action, and item action
* HTML for manage import batch tool now uses fieldsets

Database changes (DB rev 076):

* added import_batches.item_action
* added import_batches.nomatch_action
* added 'ignore' as a valid value for import_batches.overlay_action
* added 'ignored' as a valid value for import_records.status
* added 'status' as a valid value for import_items.status

API changes:

* new accessor routines for C4::ImportBatch

    GetImportBatchNoMatchAction
    SetImportBatchNoMatchAction
    GetImportBatchItemAction
    SetImportBatchItemAction

* new internal functions for C4::ImportBatch to
  determine how a given bib and item are to be
  processed, based on overlay_action, nomatch_action,
  and item_action:

    _get_commit_action
    _get_revert_action

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
2008-04-30 21:58:46 -05:00

106 lines
3.8 KiB
Perl

package KohaTest::ImportBatch;
use base qw(KohaTest);
use strict;
use warnings;
use Test::More;
use C4::ImportBatch;
use C4::Matcher;
sub testing_class { 'C4::ImportBatch' };
sub routines : Test( 1 ) {
my $self = shift;
my @routines = qw(
GetZ3950BatchId
GetImportRecordMarc
AddImportBatch
GetImportBatch
AddBiblioToBatch
ModBiblioInBatch
BatchStageMarcRecords
AddItemsToImportBiblio
BatchFindBibDuplicates
BatchCommitBibRecords
BatchCommitItems
BatchRevertBibRecords
BatchRevertItems
GetAllImportBatches
GetImportBatchRangeDesc
GetItemNumbersFromImportBatch
GetNumberOfNonZ3950ImportBatches
GetImportBibliosRange
GetBestRecordMatch
GetImportBatchStatus
SetImportBatchStatus
GetImportBatchOverlayAction
SetImportBatchOverlayAction
GetImportBatchNoMatchAction
SetImportBatchNoMatchAction
GetImportBatchItemAction
SetImportBatchItemAction
GetImportBatchItemAction
SetImportBatchItemAction
GetImportBatchMatcher
SetImportBatchMatcher
GetImportRecordOverlayStatus
SetImportRecordOverlayStatus
GetImportRecordStatus
SetImportRecordStatus
GetImportRecordMatches
SetImportRecordMatches
_create_import_record
_update_import_record_marc
_add_biblio_fields
_update_biblio_fields
_parse_biblio_fields
_update_batch_record_counts
_get_commit_action
_get_revert_action
);
can_ok($self->testing_class, @routines);
}
sub startup_50_add_matcher : Test( startup => 1 ) {
my $self = shift;
# create test MARC21 ISBN matcher
my $matcher = C4::Matcher->new('biblio');
$matcher->threshold(1000);
$matcher->code('TESTISBN');
$matcher->description('test MARC21 ISBN matcher');
$matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
my $matcher_id = $matcher->store();
like($matcher_id, qr/^\d+$/, "store new matcher and get back ID");
$self->{'matcher_id'} = $matcher_id;
}
sub shutdown_50_remove_matcher : Test( shutdown => 6) {
my $self = shift;
my @matchers = C4::Matcher::GetMatcherList();
cmp_ok(scalar(@matchers), ">=", 1, "at least one matcher present");
my $matcher_id;
my $testisbn_count = 0;
# look for TESTISBN
foreach my $matcher (@matchers) {
if ($matcher->{'code'} eq 'TESTISBN') {
$testisbn_count++;
$matcher_id = $matcher->{'matcher_id'};
}
}
ok($testisbn_count == 1, "only one TESTISBN matcher");
like($matcher_id, qr/^\d+$/, "matcher ID is valid");
my $matcher = C4::Matcher->fetch($matcher_id);
ok(defined($matcher), "got back a matcher");
ok($matcher_id == $matcher->{'id'}, "got back the correct matcher");
C4::Matcher->delete($matcher_id);
my $matcher2 = C4::Matcher->fetch($matcher_id);
ok(not(defined($matcher2)), "matcher removed");
delete $self->{'matcher_id'};
}
1;