Skip to content
Snippets Groups Projects
Commit ae162e40 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #124923 : fix cyberlibris harvesting

parent 4665e83c
Branches
Tags
1 merge request!3981hotline #124923 : fix cyberlibris harvesting
Pipeline #13126 passed with stage
in 48 minutes and 29 seconds
- ticket #124923 : Ressources numériques : Maintenance du moissonnage des documents Bibliovox
\ No newline at end of file
......@@ -27,9 +27,11 @@ class Class_WebService_BibNumerique_Cyberlibris extends Class_WebService_BibNume
public function __construct() {
$this->_oaiws = (new Class_WebService_OAI())
$this->_oaiws = (new Class_WebService_OAI)
->setOAIHandler(Class_AdminVar::get('CYBERLIBRIS_URL'))
->setNumericResourceClass('Class_WebService_BibNumerique_Cyberlibris_LivreNumerique');
->setNumericResourceClass(Class_WebService_BibNumerique_Cyberlibris_LivreNumerique::class)
->setParser(new Class_WebService_BibNumerique_Cyberlibris_Parser)
;
}
......@@ -39,7 +41,7 @@ class Class_WebService_BibNumerique_Cyberlibris extends Class_WebService_BibNume
protected function getUrlOrigine() {
return self::BASE_URL;
return static::BASE_URL;
}
......@@ -52,4 +54,3 @@ class Class_WebService_BibNumerique_Cyberlibris extends Class_WebService_BibNume
return $this->_oaiws;
}
}
?>
......@@ -23,12 +23,17 @@
class Class_WebService_BibNumerique_Cyberlibris_LivreNumerique
extends Class_WebService_BibNumerique_RessourceNumerique {
protected $_record;
protected $_titre;
public function getBaseUrl() {
return Class_WebService_BibNumerique_Cyberlibris::BASE_URL;
}
public function getBaseUrl(){
return Class_WebService_BibNumerique_Cyberlibris::BASE_URL;
public function import($update_constraints=false) {
if (!$this->getId())
$this->_debug(sprintf('record without matching dc:identifier (%s)',
$this->getTitle()));
return parent::import($update_constraints);
}
......@@ -40,13 +45,4 @@ class Class_WebService_BibNumerique_Cyberlibris_LivreNumerique
public function getRessourceCategorieLibelle() {
return Class_WebService_BibNumerique_Cyberlibris::CATEGORY_LABEL;
}
public function setOaiId($data) {
preg_match('|/book/([^/?]+)|i', $data, $matches)
? ($this->_id = $matches[1])
: $this->_debug('cannot read id from : ' . $data);
return $this->setExternalURI($data);
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_BibNumerique_Cyberlibris_Parser
extends Class_WebService_OAI_DublinCoreParser_ForRessourceNumerique {
public function enddc_identifier($data) {
if (!preg_match('|/book/([^/?]+)|i', $data, $matches))
return;
$this->_record['id_oai'] = $matches[1];
$this->_record['relation'][] = $data;
}
}
......@@ -32,8 +32,6 @@ class Class_WebService_OAI_DublinCoreParser extends Class_WebService_OAI_ParserA
protected $_record;
public function endns1_record($data) {
$this->endRecord($data);
}
......
......@@ -19,16 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Sait extraire informations du XML retourné par
* l'opération OAI ListRecords, format DublinCore
* Functions:
* - parse($xml): analyse le xml donné
* - getRecords: retourne tous les enregistrements sous forme de tableau associatif
* - getResumptionToken: retourne le token qui permet de rechercher
* les enregistrements suivants
*/
class Class_WebService_OAI_DublinCoreParser_ForRessourceNumerique extends Class_WebService_OAI_DublinCoreParser {
class Class_WebService_OAI_DublinCoreParser_ForRessourceNumerique
extends Class_WebService_OAI_DublinCoreParser {
protected
$visitor,
$_records_ressources,
......
......@@ -20,6 +20,7 @@
<dc:date>2004</dc:date>
<dc:language>fr</dc:language>
<dc:identifier>https://www.bibliovox.com/book/10104055</dc:identifier>
<dc:identifier>https://static2.cyberlibris.com/books_upload/136pix/9782847690279.jpg</dc:identifier>
<dc:rights> copyrighted </dc:rights>
</oai_dc:dc></metadata>
</record>
......@@ -80,7 +81,7 @@
<p>Apr&egrave;s un bilan sans concession, l'auteur donne des pistes d'actions concr&egrave;tes pour revoir la fa&ccedil;on de g&eacute;rer la carri&egrave;re des seniors. Cet ouvrage vous aidera &agrave; r&eacute;aliser un &eacute;tat des lieux de la GRH des seniors dans votre propre entreprise. Il explique aussi quelles actions lancer &agrave; court terme pour sensibiliser le management &agrave; la gestion des &acirc;ges... <br /></p>]]></dc:description>
<dc:date>2005</dc:date>
<dc:language>fr</dc:language>
<dc:identifier>https://www.bibliovox.com/book/10104077</dc:identifier>
<dc:identifier>https://www.bibliovox.com/</dc:identifier>
<dc:rights> copyrighted </dc:rights>
</oai_dc:dc></metadata>
</record>
......
......@@ -21,15 +21,15 @@
include_once('tests/fixtures/RessourcesNumeriquesFixtures.php');
class CyberlibrisHarvestSaveTest extends ModelTestCase {
protected $_storm_default_to_volatile = true;
protected $_log = "\n";
public function setUp() {
parent::setUp();
Class_AdminVar::set('CYBERLIBRIS_URL', 'http://oai-bibliovox.cyberlibris.fr/oai.aspx');
$catalogue_xml = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/cyberlibris_oai.xml');
$catalogue_xml_fin = file_get_contents(realpath(dirname(__FILE__)). '/../../../fixtures/cyberlibris_oai_fin.xml');
$catalogue_xml = file_get_contents(__DIR__ . '/../../../fixtures/cyberlibris_oai.xml');
$catalogue_xml_fin = file_get_contents(__DIR__ . '/../../../fixtures/cyberlibris_oai_fin.xml');
$this->_http_client = $this
->mock()
......@@ -43,8 +43,11 @@ class CyberlibrisHarvestSaveTest extends ModelTestCase {
->beStrict();
$this->_service = new Class_WebService_BibNumerique_Cyberlibris();
Class_WebService_BibNumerique_Cyberlibris::setDefaultHttpClient($this->_http_client);
$logger = $this->mock()->whenCalled('log')
->willDo(function($message) { $this->_log .= $message . "\n"; });
Class_WebService_BibNumerique_RessourceNumerique::setLogger($logger);
$this->_service = (new Class_WebService_BibNumerique_Cyberlibris)->setLogger($logger);
$this->_service->harvest();
}
......@@ -68,33 +71,45 @@ class CyberlibrisHarvestSaveTest extends ModelTestCase {
/** @test */
public function firstAlbumShouldNotHavePoster() {
public function logShouldContainsRecordWithoutMatchingIdentifier() {
$this->assertContains('record without matching dc:identifier (Manager la ', $this->_log);
}
/** @test */
public function firstBookShouldHaveNoPoster() {
$this->assertEquals('', Class_Album::find(1)->getPoster());
}
/** @test */
public function secondBookShouldBe() {
$this->assertContains('Stimuler la créativité', Class_Album::find(2)->getTitre());
public function firstBookExternalURIShouldBeBookSlash10104055() {
$this->assertEquals('https://www.bibliovox.com/book/10104055',
Class_Album::find(1)->getExternalUri());
}
/** @test */
public function lastBookAuthorShouldBeVerneEtienne() {
$this->assertEquals('Verne, Etienne', Class_Album::find(4)->getAuthorsNames()[0]);
public function firstBookIdOrigineShouldBe10104055() {
$this->assertEquals('10104055', Class_Album::find(1)->getIdOrigine());
}
/** @test */
public function idShouldBeSet() {
$this->assertEquals('10104081', Class_Album::find(4)->getIdOrigine());
public function secondBookTitleShouldBeStimulerLaCreativite() {
$this->assertContains('Stimuler la créativité', Class_Album::find(2)->getTitre());
}
/** @test */
public function firstAlbumExternalURIShouldBeSet() {
$this->assertEquals('https://www.bibliovox.com/book/10104055',
Class_Album::find(1)->getExternalUri());
public function lastBookAuthorShouldBeVerneEtienne() {
$this->assertEquals('Verne, Etienne', Class_Album::find(4)->getAuthorsNames()[0]);
}
/** @test */
public function lastBookIdOrigineShouldBe10104081() {
$this->assertEquals('10104081', Class_Album::find(4)->getIdOrigine());
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment