}
+# marcdoc is an XML::LibXML document
+# updates the doc and returns the entityized MARC string
+sub strip_marc_fields {
+ my ($class, $e, $marcdoc, $grps) = @_;
+
+ my $orgs = $class->get_org_ancestors($e->requestor->ws_ou);
+
+ my $query = {
+ select => {vibtf => ['field']},
+ from => {vibtf => 'vibtg'},
+ where => {'+vibtg' => {owner => $orgs}},
+ distinct => 1
+ };
+
+ # give me always-apply groups plus any selected groups
+ if ($grps and @$grps) {
+ $query->{where}->{'+vibtg'}->{'-or'} = [
+ {id => $grps},
+ {always_apply => 't'}
+ ];
+
+ } else {
+ $query->{where}->{'+vibtg'}->{always_apply} = 't';
+ }
+
+ my $fields = $e->json_query($query);
+
+ for my $field (@$fields) {
+ my $tag = $field->{field};
+ for my $node ($marcdoc->findnodes('//*[@tag="'.$tag.'"]')) {
+ $node->parentNode->removeChild($node);
+ }
+ }
+
+ return $class->entityize($marcdoc->documentElement->toString);
+}
+
+
1;
);
sub create_record_xml {
- my( $self, $client, $login, $xml, $source, $oargs ) = @_;
+ my( $self, $client, $login, $xml, $source, $oargs, $strip_grps ) = @_;
my $override = 1 if $self->api_name =~ /override/;
$oargs = { all => 1 } unless defined $oargs;
my( $user_obj, $evt ) = $U->checksesperm($login, 'CREATE_MARC');
return $evt if $evt;
- $$oargs{import_location} = $e->requestor->ws_ou;
-
$logger->activity("user ".$user_obj->id." creating new MARC record");
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;
- my ($s) = $meth->run($login, $xml, $source, $oargs);
+ my ($s) = $meth->run($login, $xml, $source, $oargs, $strip_grps);
return $s;
}
);
sub biblio_record_replace_marc {
- my( $self, $conn, $auth, $recid, $newxml, $source, $oargs ) = @_;
+ my( $self, $conn, $auth, $recid, $newxml, $source, $oargs, $strip_grps ) = @_;
my $e = new_editor(authtoken=>$auth, xact=>1);
return $e->die_event unless $e->checkauth;
return $e->die_event unless $e->allowed('UPDATE_MARC', $e->requestor->ws_ou);
$oargs = {};
}
- $$oargs{import_location} = $e->requestor->ws_ou;
-
my $res = OpenILS::Application::Cat::BibCommon->biblio_record_replace_marc(
- $e, $recid, $newxml, $source, $fix_tcn, $oargs);
+ $e, $recid, $newxml, $source, $fix_tcn, $oargs, $strip_grps);
$e->commit unless $U->event_code($res);
sub biblio_record_xml_import {
- my( $self, $client, $authtoken, $xml, $source, $auto_tcn, $oargs) = @_;
+ my( $self, $client, $authtoken, $xml, $source, $auto_tcn, $oargs, $strip_grps) = @_;
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);
} else {
$oargs = {};
}
- $$oargs{import_location} = $e->requestor->ws_ou;
my $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import(
- $e, $xml, $source, $auto_tcn, $oargs);
+ $e, $xml, $source, $auto_tcn, $oargs, $strip_grps);
return $record if $U->event_code($record);
sub biblio_record_replace_marc {
- my($class, $e, $recid, $newxml, $source, $fixtcn, $override) = @_;
+ my($class, $e, $recid, $newxml, $source, $fixtcn, $override, $strip_grps) = @_;
$override = { all => 1 } if($override && !ref $override);
$override = { all => 0 } if(!ref $override);
$marcdoc = __make_marc_doc($newxml);
}
- my $import_loc = $$override{import_location};
- my $ancestors = $U->get_org_ancestors($import_loc) if ($import_loc);
- my $trash_tags = $e->search_vandelay_import_bib_trash_fields({owner => $ancestors}) if ($ancestors);
-
- if ($trash_tags && @$trash_tags) {
- for my $tag (@$trash_tags) {
- for my $node ($marcdoc->findnodes('//*[@tag="'.$tag->field.'"]')) {
- $node->parentNode->removeChild($node);
- }
- }
- }
-
+ my $marc = $U->strip_marc_fields($e, $marcdoc, $strip_grps);
$rec->source(bib_source_from_name($source)) if $source;
$rec->editor($e->requestor->id);
$rec->edit_date('now');
- $rec->marc( $U->entityize( $marcdoc->documentElement->toString ) );
+ $rec->marc($marc);
$e->update_biblio_record_entry($rec) or return $e->die_event;
return $rec;
}
sub biblio_record_xml_import {
- my($class, $e, $xml, $source, $auto_tcn, $override) = @_;
+ my($class, $e, $xml, $source, $auto_tcn, $override, $strip_grps) = @_;
$override = { all => 1 } if($override && !ref $override);
$override = { all => 0 } if(!ref $override);
return $evt if $evt;
}
- my $import_loc = $$override{import_location};
- my $ancestors = $U->get_org_ancestors($import_loc) if ($import_loc);
- my $trash_tags = $e->search_vandelay_import_bib_trash_fields({owner => $ancestors}) if ($ancestors);
-
- if ($trash_tags && @$trash_tags) {
- for my $tag (@$trash_tags) {
- for my $node ($marcdoc->findnodes('//*[@tag="'.$tag.'"]')) {
- $node->parentNode->removeChild($node);
- }
- }
- }
-
# Silence warnings when _find_tcn_info() fails
$tcn ||= '';
$tcn_source ||= '';
$logger->info("user ".$e->requestor->id.
" creating new biblio entry with tcn=$tcn and tcn_source $tcn_source");
+ my $marc = $U->strip_marc_fields($e, $marcdoc, $strip_grps);
+
my $record = Fieldmapper::biblio::record_entry->new;
$record->source(bib_source_from_name($source)) if $source;
$record->editor($e->requestor->id);
$record->create_date('now');
$record->edit_date('now');
- $record->marc($U->entityize($marcdoc->documentElement->toString));
+ $record->marc($marc);
$record = $e->create_biblio_record_entry($record) or return $e->die_event;
my $ft_merge_profile = $$args{fall_through_merge_profile};
my $bib_source = $$args{bib_source};
my $import_no_match = $$args{import_no_match};
+ my $strip_grps = $$args{strip_field_groups}; # bib-only
my $overlay_func = 'vandelay.overlay_bib_record';
my $auto_overlay_func = 'vandelay.auto_overlay_bib_record';
$rec_class = 'vqar';
}
- my $import_loc = $requestor->ws_ou;
- my $ancestors = $U->get_org_ancestors($import_loc) if ($import_loc);
- my $trash_tags = $editor->search_vandelay_import_bib_trash_fields({owner => $ancestors}) if ($ancestors);
-
my $new_rec_perm_cache;
my @success_rec_ids;
for my $rec_id (@$rec_ids) {
next;
}
- if ($trash_tags && @$trash_tags) {
- my $marcxml = XML::LibXML->new->parse_string($rec->marc);
- if ($marcxml) {
- for my $tag (@$trash_tags) {
- for my $node ($marcxml->findnodes('//*[@tag="'.$tag->field.'"]')) {
- $node->parentNode->removeChild($node);
- }
- }
-
- $rec->marc( $U->entityize( $marcdoc->documentElement->toString ) );
- $e->$update_func($rec);
- }
- }
-
$$report_args{rec} = $rec;
$queues{$rec->queue} = 1;
my $record;
my $imported = 0;
+ if ($type eq 'bib') {
+ # strip configured / selected MARC tags from inbound records
+
+ my $marcdoc = XML::LibXML->new->parse_string($rec->marc);
+ $rec->marc($U->strip_marc_fields($e, $marcdoc, $strip_grps));
+
+ unless ($e->$update_func($rec)) {
+ $$report_args{evt} = $e->die_event;
+ finish_rec_import_attempt($report_args);
+ next;
+ }
+ }
+
if(defined $overlay_target) {
# Caller chose an explicit overlay target