Lines 18-25
Link Here
|
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use Test::More tests => 9; |
21 |
use Test::More tests => 24; |
22 |
use Test::Exception; |
22 |
use Test::Exception; |
|
|
23 |
use File::Temp qw/tempfile/; |
23 |
|
24 |
|
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
25 |
use HTTP::OAI; |
26 |
use HTTP::OAI; |
Lines 36-42
my $builder = t::lib::TestBuilder->new;
Link Here
|
36 |
|
37 |
|
37 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
38 |
|
39 |
|
39 |
my $new_oai_1 = Koha::OAIServer->new( |
40 |
my $new_oai_biblio = Koha::OAIServer->new( |
40 |
{ |
41 |
{ |
41 |
endpoint => 'my_host1.org', |
42 |
endpoint => 'my_host1.org', |
42 |
oai_set => 'set1', |
43 |
oai_set => 'set1', |
Lines 47-53
my $new_oai_1 = Koha::OAIServer->new(
Link Here
|
47 |
} |
48 |
} |
48 |
)->store; |
49 |
)->store; |
49 |
|
50 |
|
50 |
my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_1, verbose => 1, days => 1, force => 1 } ); |
51 |
my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 1 } ); |
51 |
|
52 |
|
52 |
my $record = |
53 |
my $record = |
53 |
'<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>'; |
54 |
'<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>'; |
Lines 77-83
is( $status, 'added', 'Record is added' );
Link Here
|
77 |
$status = $harvester->processRecord($r); |
78 |
$status = $harvester->processRecord($r); |
78 |
is( $status, 'updated', 'When force is used, record is updated' ); |
79 |
is( $status, 'updated', 'When force is used, record is updated' ); |
79 |
|
80 |
|
80 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_1, verbose => 1, days => 1, force => 0 } ); |
81 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 0 } ); |
81 |
$status = $harvester->processRecord($r); |
82 |
$status = $harvester->processRecord($r); |
82 |
is( $status, 'skipped', 'When force is not used, record is skipped (already up to date)' ); |
83 |
is( $status, 'skipped', 'When force is not used, record is skipped (already up to date)' ); |
83 |
|
84 |
|
Lines 86-92
$status = $harvester->processRecord($r);
Link Here
|
86 |
is( $status, 'updated', 'When force is not used, record is updated if newer' ); |
87 |
is( $status, 'updated', 'When force is not used, record is updated if newer' ); |
87 |
|
88 |
|
88 |
my $imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
89 |
my $imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
89 |
my $added_datestamp = $imported_record->datestamp; |
90 |
my $added_datestamp = '2017-05-10T09:18:13Z'; |
|
|
91 |
$imported_record->update( |
92 |
{ |
93 |
datestamp => $added_datestamp, |
94 |
} |
95 |
); |
96 |
|
90 |
$r->header->datestamp(undef); |
97 |
$r->header->datestamp(undef); |
91 |
$status = $harvester->processRecord($r); |
98 |
$status = $harvester->processRecord($r); |
92 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
99 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
Lines 96-99
isnt(
Link Here
|
96 |
'local datestamp is updated even if there is no datestamp in incoming record' |
103 |
'local datestamp is updated even if there is no datestamp in incoming record' |
97 |
); |
104 |
); |
98 |
|
105 |
|
|
|
106 |
$r->header->status('deleted'); |
107 |
$status = $harvester->processRecord($r); |
108 |
is( $status, 'deleted', 'When a record is marked to be deleted, status is deleted' ); |
109 |
|
110 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
111 |
is( $imported_record, undef, 'Record has been deleted' ); |
112 |
|
113 |
$status = $harvester->processRecord($r); |
114 |
is( $status, 'skipped', 'Status is skipped for already deleted record' ); |
115 |
|
116 |
# Authorities |
117 |
my $file = xsl_file(); |
118 |
my $new_oai_auth = Koha::OAIServer->new( |
119 |
{ |
120 |
endpoint => 'my_host1.org', |
121 |
oai_set => 'set1', |
122 |
servername => 'my_test_1', |
123 |
dataformat => 'oai_dc', |
124 |
recordtype => 'authority', |
125 |
add_xslt => $file, |
126 |
} |
127 |
)->store; |
128 |
|
129 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 1 } ); |
130 |
|
131 |
my $auth = |
132 |
'<metadata xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:FamilyName>Emerson</dc:FamilyName><dc:GivenName>Everett H.</dc:GivenName></oai_dc:dc></metadata>'; |
133 |
|
134 |
$r = HTTP::OAI::Record->new(); |
135 |
$r->metadata( HTTP::OAI::Metadata->new( dom => $auth ) ); |
136 |
|
137 |
$status = $harvester->processRecord($r); |
138 |
is( $status, 'skipped', 'Authority with no identifier is skipped' ); |
139 |
|
140 |
$r->header->identifier('oai:myarchive.org:oid-161'); |
141 |
$status = $harvester->processRecord($r); |
142 |
is( $status, 'added', 'Authority with no date is added' ); |
143 |
|
144 |
$status = $harvester->processRecord($r); |
145 |
is( $status, 'updated', 'Authority with no date is updated' ); |
146 |
|
147 |
$status = $harvester->processRecord($r); |
148 |
is( $status, 'updated', 'Authority with no date is updated even without force' ); |
149 |
|
150 |
$r->header->identifier('oai:myarchive.org:oid-162'); |
151 |
$r->header->datestamp('2017-05-10T09:18:13Z'); |
152 |
|
153 |
$status = $harvester->processRecord($r); |
154 |
is( $status, 'added', 'Authority is added' ); |
155 |
|
156 |
$status = $harvester->processRecord($r); |
157 |
is( $status, 'updated', 'When force is used, authority is updated' ); |
158 |
|
159 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 0 } ); |
160 |
$status = $harvester->processRecord($r); |
161 |
is( $status, 'skipped', 'When force is not used, authority is skipped (already up to date)' ); |
162 |
|
163 |
$r->header->datestamp('2018-05-10T09:18:13Z'); |
164 |
$status = $harvester->processRecord($r); |
165 |
is( $status, 'updated', 'When force is not used, authority is updated if newer' ); |
166 |
|
167 |
my $imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
168 |
$imported_authority->update( |
169 |
{ |
170 |
datestamp => $added_datestamp, |
171 |
} |
172 |
); |
173 |
|
174 |
$r->header->datestamp(undef); |
175 |
|
176 |
$status = $harvester->processRecord($r); |
177 |
$imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
178 |
$updated_datestamp = $imported_authority->datestamp; |
179 |
isnt( |
180 |
$added_datestamp, $updated_datestamp, |
181 |
'local datestamp is updated even if there is no datestamp in incoming authority' |
182 |
); |
183 |
|
184 |
$r->header->status('deleted'); |
185 |
$status = $harvester->processRecord($r); |
186 |
is( $status, 'deleted', 'When an authority is marked to be deleted, status is deleted' ); |
187 |
|
188 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
189 |
is( $imported_record, undef, 'Authority has been deleted' ); |
190 |
|
191 |
$status = $harvester->processRecord($r); |
192 |
is( $status, 'skipped', 'Status is skipped for already deleted authority' ); |
193 |
|
99 |
$schema->storage->txn_rollback; |
194 |
$schema->storage->txn_rollback; |
100 |
- |
195 |
|
|
|
196 |
sub xsl_file { |
197 |
return mytempfile( |
198 |
q{<?xml version="1.0" encoding="UTF-8"?> |
199 |
<xsl:stylesheet version="1.0" |
200 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
201 |
xmlns:dcterms="http://purl.org/dc/terms/1.1" |
202 |
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" |
203 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
204 |
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ |
205 |
http://www.openarchives.org/OAI/2.0/oai_dc.xsd" |
206 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
207 |
xmlns="http://www.loc.gov/MARC21/slim" exclude-result-prefixes="dc dcterms oai_dc"> |
208 |
|
209 |
<xsl:output method="xml" encoding="UTF-8" indent="yes"/> |
210 |
|
211 |
<xsl:template match="/"> |
212 |
<collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" > |
213 |
<xsl:apply-templates /> |
214 |
</collection> |
215 |
</xsl:template> |
216 |
|
217 |
<xsl:template match="oai_dc:dc"> |
218 |
<record> |
219 |
|
220 |
<xsl:variable name="FamilyName" select="dc:FamilyName"/> |
221 |
<xsl:variable name="GivenName" select="dc:GivenName"/> |
222 |
|
223 |
<datafield tag="100" ind1="0" ind2=" "> |
224 |
<subfield code="a"> |
225 |
<xsl:value-of select="concat($FamilyName,', ',$GivenName)"/> |
226 |
</subfield> |
227 |
</datafield> |
228 |
|
229 |
</record> |
230 |
</xsl:template> |
231 |
|
232 |
</xsl:stylesheet> |
233 |
} |
234 |
); |
235 |
} |
236 |
|
237 |
sub mytempfile { |
238 |
my ( $fh, $fn ) = tempfile( SUFFIX => '.xsl', UNLINK => 1 ); |
239 |
print $fh $_[0] // ''; |
240 |
close $fh; |
241 |
return $fn; |
242 |
} |