line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::AlephX; |
2
|
1
|
|
|
1
|
|
110287
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
214360
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
654
|
use Catmandu::Util qw(:check :is); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
485
|
|
4
|
1
|
|
|
1
|
|
9
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
1031
|
use Catmandu::AlephX; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1145
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "1.073"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has url => (is => 'ro', required => 1); |
13
|
|
|
|
|
|
|
has base => (is => 'ro', required => 1); |
14
|
|
|
|
|
|
|
has query => (is => 'ro' ); |
15
|
|
|
|
|
|
|
has skip_deleted => (is => 'ro', default => sub { 0 }); |
16
|
|
|
|
|
|
|
has include_items => (is => 'ro',required => 0,lazy => 1,default => sub { 1; }); |
17
|
|
|
|
|
|
|
has limit => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => sub { check_natural($_[0]); }, |
20
|
|
|
|
|
|
|
lazy => 1, |
21
|
|
|
|
|
|
|
default => sub { 20; } |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
has alephx => (is => 'ro', init_arg => undef , lazy => 1 , builder => '_build_alephx'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build_alephx { |
26
|
0
|
|
|
0
|
|
|
Catmandu::AlephX->new(url => $_[0]->url); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _fetch_items { |
30
|
0
|
|
|
0
|
|
|
my ($self, $doc_number) = @_; |
31
|
0
|
|
|
|
|
|
my $item_data = $self->alephx->item_data(base => $self->base, doc_number => $doc_number); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
return [] unless $item_data->is_success; |
34
|
0
|
|
|
|
|
|
return $item_data->items; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub check_deleted { |
38
|
0
|
|
|
0
|
0
|
|
my $r = $_[0]; |
39
|
0
|
0
|
|
|
|
|
return 1 unless defined $r; |
40
|
0
|
|
|
|
|
|
for (@{$r->{record}}) { |
|
0
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
return 1 if ($_->[0] eq 'DEL'); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
return 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub generator { |
47
|
|
|
|
|
|
|
my $self = $_[0]; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#generator, based on a query (limited) |
50
|
|
|
|
|
|
|
if(is_string($self->query)){ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return sub { |
53
|
|
|
|
|
|
|
my $find = $self->alephx->find(request => $self->query , base => $self->base); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return unless $find->is_success; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
state $buffer = []; |
58
|
|
|
|
|
|
|
state $set_number = $find->set_number; |
59
|
|
|
|
|
|
|
state $no_records = int($find->no_records); |
60
|
|
|
|
|
|
|
state $no_entries = int($find->no_entries); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#warning: no_records is the number of records found, but only no_entries are stored in the set. |
63
|
|
|
|
|
|
|
# a call to 'present' with set_number higher than no_entries has no use. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
state $offset = 1; |
66
|
|
|
|
|
|
|
state $limit = $self->limit; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return if $no_entries == 0 || $offset > $no_entries; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
unless(@$buffer){ |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $set_entry; |
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
my $start = Catmandu::AlephX->format_doc_num($offset); |
75
|
|
|
|
|
|
|
my $l = $offset + $limit - 1; |
76
|
|
|
|
|
|
|
my $end = Catmandu::AlephX->format_doc_num($l > $no_entries ? $no_entries : $l); |
77
|
|
|
|
|
|
|
$set_entry = "$start-$end"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $present = $self->alephx->present(set_number => $set_number , set_entry => $set_entry); |
81
|
|
|
|
|
|
|
return unless $present->is_success; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
for my $record(@{ $present->records() }){ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $items = []; |
86
|
|
|
|
|
|
|
if($self->include_items){ |
87
|
|
|
|
|
|
|
$items = $self->_fetch_items($record->{doc_number}); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
#do NOT use $record->metadata->data->{_id}, for that uses the field '001' that can be empty |
90
|
|
|
|
|
|
|
push @$buffer,{ record => $record->metadata->data->{record} , items => $items, _id => $record->{doc_number} }; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$offset += $limit; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
shift(@$buffer); |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
#generator that tries to fetch all records |
103
|
|
|
|
|
|
|
else{ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return sub { |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
state $count = 1; |
108
|
|
|
|
|
|
|
state $alephx = $self->alephx; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $doc; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
do { |
113
|
|
|
|
|
|
|
my $doc_num = Catmandu::AlephX->format_doc_num($count++); |
114
|
|
|
|
|
|
|
my $find_doc = $alephx->find_doc(base => $self->base,doc_num => $doc_num); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
return unless $find_doc->is_success; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $items = []; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
if($self->include_items){ |
121
|
|
|
|
|
|
|
$items = $self->_fetch_items($doc_num); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$doc = { |
125
|
|
|
|
|
|
|
record => $find_doc->record->metadata->data->{record}, |
126
|
|
|
|
|
|
|
items => $items, |
127
|
|
|
|
|
|
|
#do NOT use $record->metadata->data->{_id}, for that uses the field '001' that can be empty |
128
|
|
|
|
|
|
|
_id => $doc_num |
129
|
|
|
|
|
|
|
}; |
130
|
|
|
|
|
|
|
} while ($self->skip_deleted && check_deleted($doc) == 1); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
return $doc; |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Catmandu::Importer::AlephX - Package that imports metadata records from the AlephX service |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SYNOPSIS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
use Catmandu::Importer::AlephX; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::AlephX->new( |
146
|
|
|
|
|
|
|
url => 'http://ram19:8995/X' , |
147
|
|
|
|
|
|
|
query => 'WRD=(art)' , |
148
|
|
|
|
|
|
|
base => 'usm01' , |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $n = $importer->each(sub { |
152
|
|
|
|
|
|
|
my $r = $_[0]; |
153
|
|
|
|
|
|
|
# ... |
154
|
|
|
|
|
|
|
say Dumper($r->{record}); |
155
|
|
|
|
|
|
|
say Dumper($r->{items}); |
156
|
|
|
|
|
|
|
}); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 METHODS |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 new(url => '...' , base => '...' , query => '...') |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Create a new AlephX importer. Required parameters are the url baseUrl of the AlephX service, an Aleph 'base' catalog name and a 'query'. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head3 common parameters |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
url base url of alephx service (e.g. "http://ram19:8995/X") |
167
|
|
|
|
|
|
|
include_items 0|1. When set to '1', the items of every bibliographical record are retrieved |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head3 alephx parameters |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
base name of catalog in Aleph where you want to search |
172
|
|
|
|
|
|
|
query the query of course |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head3 output |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
{ |
177
|
|
|
|
|
|
|
record => [ |
178
|
|
|
|
|
|
|
[ |
179
|
|
|
|
|
|
|
'FMT', |
180
|
|
|
|
|
|
|
'', |
181
|
|
|
|
|
|
|
'', |
182
|
|
|
|
|
|
|
'_', |
183
|
|
|
|
|
|
|
'MX' |
184
|
|
|
|
|
|
|
], |
185
|
|
|
|
|
|
|
[ |
186
|
|
|
|
|
|
|
'LDR', |
187
|
|
|
|
|
|
|
'', |
188
|
|
|
|
|
|
|
'', |
189
|
|
|
|
|
|
|
'_', |
190
|
|
|
|
|
|
|
'01236npca^22001937|^4500' |
191
|
|
|
|
|
|
|
] |
192
|
|
|
|
|
|
|
.. |
193
|
|
|
|
|
|
|
], |
194
|
|
|
|
|
|
|
items => [ |
195
|
|
|
|
|
|
|
{ |
196
|
|
|
|
|
|
|
'sub-library' => 'WID', |
197
|
|
|
|
|
|
|
'chronological-k' => '', |
198
|
|
|
|
|
|
|
'chronological-i' => '', |
199
|
|
|
|
|
|
|
'library' => 'USM50', |
200
|
|
|
|
|
|
|
'collection' => 'HD', |
201
|
|
|
|
|
|
|
'call-no-1' => '$$2ZHCL$$hH 810.80.20', |
202
|
|
|
|
|
|
|
'chronological-j' => '', |
203
|
|
|
|
|
|
|
'requested' => 'N', |
204
|
|
|
|
|
|
|
'expected' => 'N', |
205
|
|
|
|
|
|
|
'barcode' => 'HWM4M4', |
206
|
|
|
|
|
|
|
'description' => '', |
207
|
|
|
|
|
|
|
'note' => '', |
208
|
|
|
|
|
|
|
'item-status' => '01', |
209
|
|
|
|
|
|
|
'rec-key' => '000048762000010', |
210
|
|
|
|
|
|
|
'enumeration-a' => '', |
211
|
|
|
|
|
|
|
'call-no-2' => '', |
212
|
|
|
|
|
|
|
'enumeration-b' => '', |
213
|
|
|
|
|
|
|
'enumeration-c' => '', |
214
|
|
|
|
|
|
|
'on-hold' => 'N' |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
] |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 count |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 each(&callback) |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 ... |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The |
227
|
|
|
|
|
|
|
Catmandu::Importer::AlephX methods are not idempotent: Twitter feeds can only be read once. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 AUTHOR |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Patrick Hochstenbach C<< patrick dot hochstenbach at ugent dot be >> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 SEE ALSO |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
L<Catmandu::Iterable> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |