Catmandu-AlephX
view release on metacpan or search on metacpan
lib/Catmandu/AlephX.pm view on Meta::CPAN
supply this xml as xml_full_req.
Every updates adds a CAT-field to the record. Your updates can be recognized by CAT$$a == "WWW-X".
When updating a record you need to include the old CAT fields (default), otherwise these fields will be deleted
(and all history will be lost).
"Unlike other X-Services, the parameters can include XML up to 20,000 characters in length"
When you update often (and therefore add a lot of CAT fields), this can lead to the error 'Server closed connection'.
This is due to the maximum of characters allowed in an XML request.
Possible solution:
1. retrieve record by 'find_doc'
2. get marc record:
my $marc = $res->record->metadata->data
3. filter out your CAT fields ($a == "WWW-X") to shorten the XML:
$marc = [grep { !( $_->[0] eq "CAT" && $_->[4] eq "WWW-X" ) } @$marc];
4. update $marc
5. send
$aleph->update_doc(library => 'usm01',doc_action => 'UPDATE',doc_number => $doc_number,marc => $marc);
=> your xml will now contain one CAT field with subfield 'a' equal to 'WWW-X'.
=head3 example
my $aleph = Catmandu::AlephX->new(url => "http://localhost/X");
my $doc_number = '000000444';
my $find_doc = $aleph->find_doc(
doc_num => $doc_number,
base => "usm01"
);
my $marc = $find_doc->record->metadata->data;
my $content_ref = $find_doc->content_ref;
my %args = (
'library' => 'usm01',
'doc_action' => 'UPDATE',
'doc_number' => $doc_number,
xml_full_req => $$content_ref
);
my $u = $aleph->update_doc(%args);
if($u->is_success){
say "all ok";
}else{
say STDERR join("\n",@{$u->errors});
}
=head3 special support for catmandu marc records
when you supply the argument 'marc', an xml document will be created for you,
and stored in the argument 'xml_full_req'. 'marc' must be an array of arrays.
When you already supplied 'xml_full_req', it will be overwritten.
=cut
sub update_doc {
my($self,%args)=@_;
my $doc_num = $args{doc_num} || $args{doc_number};
delete $args{$_} for qw(doc_number doc_num);
$args{doc_num} = $self->format_doc_num($doc_num);
require Catmandu::AlephX::Op::UpdateDoc;
$args{op} = Catmandu::AlephX::Op::UpdateDoc->op();
if($args{marc}){
require Catmandu::AlephX::Metadata::MARC::Aleph;
my $m = Catmandu::AlephX::Metadata::MARC::Aleph->to_xml($args{marc});
my $xml = <<EOF;
<?xml version = "1.0" encoding = "UTF-8"?>
<find-doc><record><metadata>$m</metadata></record></find-doc>
EOF
if(length($xml) > 20000){
confess "xml_full_req cannot be longer than 20000 characters";
}
$args{xml_full_req} = $xml;
delete $args{marc};
}elsif(is_string($args{doc_action}) && $args{doc_action} eq "DELETE" && !is_string($args{xml_full_req})){
#although this is a delete action, determined by 'doc_num', AlephX still needs an xml_full_req, even when empty
$args{xml_full_req} = <<EOF;
<?xml version = "1.0" encoding = "UTF-8"?>
<find-doc></find-doc>
EOF
}
my $res = $self->ua->request(\%args,"POST");
Catmandu::AlephX::Op::UpdateDoc->parse($res->content_ref(),\%args);
}
=head2 update_item
=head3 documentation from Aleph X
The service updates an existing item in the required ADM library after performing all relevant initial checks prior to that action.
=head3 notes
AlephX stores not only errors in 'errors', but also the success message.
Therefore the method 'is_success' of the Catmandu::AlephX::Response is not very usefull in this case.
Search for the last 'error', and check wether it contains 'updated successfully'.
The result of 'read_item' often contains translations, instead of the real values. But these
translation cannot be used when updating items.
e.g. z30-item-status contains 'Regular loan' instead of '001'.
=head3 example
my $alephx = Catmandu::AlephX->new(url => "http://localhost/X");
my $item_barcode = '32044044980076';
my %args = (
'library' => 'usm50',
'item_barcode' => $item_barcode,
);
my $z30 = $alephx->read_item(%args)->z30();
my $xml = XMLout($z30,,RootName=>"z30",NoAttr => 1);
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$xml;
$args{xml_full_req} = $xml;
my $u = alephx->update_item(%args);
if($u->is_success){
say "all ok";
}else{
say STDERR join("\n",@{$u->errors});
}
=cut
sub update_item {
my($self,%args)=@_;
require Catmandu::AlephX::Op::UpdateItem;
$args{op} = Catmandu::AlephX::Op::UpdateItem->op();
my $res = $self->ua->request(\%args,"POST");
Catmandu::AlephX::Op::UpdateItem->parse($res->content_ref(),\%args);
}
=head2 create_item
=head3 documentation from Aleph X
The service creates a new item in the required ADM library after performing all relevant initial checks prior to that action.
The item can be created for a bib record when no ADM record is linked to it yet, or it can be created to an ADM record with existing items.
=head3 notes
=head3 example
my $alephx = Catmandu::AlephX->new(url => "http://localhost/X");
my $item_barcode = '32044044980076';
my %args = (
'adm_library' => 'rug50',
'bib_library' => 'rug01',
'bib_doc_number' => '231843137',
);
my $xml = <<EOF;
<?xml version="1.0" encoding="UTF-8" ?>
<z30>
<z30-doc-number>15</z30-doc-number>
<z30-item-sequence>10</z30-item-sequence>
<z30-barcode>32044003924339</z30-barcode>
<z30-sub-library>WID</z30-sub-library>
<z30-material>BOOK</z30-material>
<z30-item-status>01</z30-item-status>
<z30-open-date>19980804</z30-open-date>
<z30-update-date>20020708</z30-update-date>
<z30-cataloger>EXLIBRIS</z30-cataloger>
<z30-date-last-return>20080607</z30-date-last-return>
<z30-hour-last-return>1631</z30-hour-last-return>
<z30-ip-last-return>CONV</z30-ip-last-return>
<z30-no-loans>011</z30-no-loans>
<z30-alpha>L</z30-alpha>
<z30-collection>GEN</z30-collection>
<z30-call-no-type>7</z30-call-no-type>
<z30-call-no>Heb 2106.385.5</z30-call-no>
<z30-call-no-key>7 selected</z30-call-no-key>
<z30-call-no-2-type />
<z30-call-no-2 />
<z30-call-no-2-key />
<z30-description>v.1</z30-description>
<z30-note-opac />
<z30-note-circulation />
<z30-note-internal />
<z30-order-number />
<z30-inventory-number />
<z30-inventory-number-date />
( run in 0.487 second using v1.01-cache-2.11-cpan-5735350b133 )