From 38863c168ef67442dbb4ee6ce390de0aeca33706 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Wed, 5 Jul 2017 17:04:16 +0200 Subject: [PATCH] dev #60742 La Souris Qui Raconte: harvest startup --- library/Class/Album.php | 23 +-- .../LaSourisQuiRaconte/Config.php | 4 + .../LaSourisQuiRaconte/Service.php | 45 ++++++ .../LaSourisQuiRaconte/Service/Story.php | 24 +++ .../LaSourisQuiRaconte/Service/XMLParser.php | 74 +++++++++ .../tests/LaSourisQuiRaconteTest.php | 69 +++++++++ .../LaSourisQuiRaconte/tests/lsqr.xml | 146 ++++++++++++++++++ 7 files changed, 376 insertions(+), 9 deletions(-) create mode 100644 library/digital_resources/LaSourisQuiRaconte/Service.php create mode 100644 library/digital_resources/LaSourisQuiRaconte/Service/Story.php create mode 100644 library/digital_resources/LaSourisQuiRaconte/Service/XMLParser.php create mode 100644 library/digital_resources/LaSourisQuiRaconte/tests/lsqr.xml diff --git a/library/Class/Album.php b/library/Class/Album.php index 0c66bb9263a..848ad57939d 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -1494,27 +1494,32 @@ class Class_Album extends Storm_Model_Abstract { /** * add author in unimarc container if not present with the same function + * @param author string or Class_Notice_Author + * @param function string */ - public function addAuthor($name, $function = '') { - if (!$name) + public function addAuthor($author, $responsibility = '') { + if (!$author) return $this; - $datas = ['a' => $name]; - if (null !== $function) - $datas['4'] = $function; + if (is_string($author)) + $author = new Class_Notice_Author($author, $responsibility); - if (!in_array((string)$name, $this->getAuthorsNames())) { + $datas = ['a' => $author->getName()]; + if ($author->getResponsibility()) + $datas['4'] = $author->getResponsibility(); + + if (!in_array($author->getName(), $this->getAuthorsNames())) { $this->getMarc()->addZone(self::AUTHOR_FIELD, $datas); return $this; } - if (!$function) + if (!$author->getResponsibility()) return $this; $found = false; - foreach($this->getAuthors() as $author) { - if ($name == $author->getName() && $function == $author->getResponsibility()) { + foreach($this->getAuthors() as $other) { + if ($author->getName() == $other->getName() && $author->getResponsibility() == $other->getResponsibility()) { $found = true; break; } diff --git a/library/digital_resources/LaSourisQuiRaconte/Config.php b/library/digital_resources/LaSourisQuiRaconte/Config.php index a29efcbe961..57b3f7cfebc 100644 --- a/library/digital_resources/LaSourisQuiRaconte/Config.php +++ b/library/digital_resources/LaSourisQuiRaconte/Config.php @@ -63,4 +63,8 @@ class LaSourisQuiRaconte_Config extends Class_DigitalResource_Config { return static::LSQR_URL . '?url_controle=' . $url; } + + public function getExportUrl() { + return static::LSQR_URL . '/espaces/export_bokeh.php?token=' . $this->getAdminVar('TOKEN'); + } } \ No newline at end of file diff --git a/library/digital_resources/LaSourisQuiRaconte/Service.php b/library/digital_resources/LaSourisQuiRaconte/Service.php new file mode 100644 index 00000000000..f691c1df61a --- /dev/null +++ b/library/digital_resources/LaSourisQuiRaconte/Service.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright (c) 2012, 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 LaSourisQuiRaconte_Service extends Class_DigitalResource_Service { + protected + $_stories = []; + + protected function loadPage($page_number = 1) { + $xml = $this->httpGet($this->_config->getExportUrl()); + + $this->_parser = new LaSourisQuiRaconte_Service_XMLParser(); + $this->_parser->parseXML($xml); + + $this->_stories = $this->_parser->getStories(); + return $this; + } + + + public function getPageCount() { + return 1; + } + + + public function getRessourcesNumeriques() { + return $this->_stories; + } +} \ No newline at end of file diff --git a/library/digital_resources/LaSourisQuiRaconte/Service/Story.php b/library/digital_resources/LaSourisQuiRaconte/Service/Story.php new file mode 100644 index 00000000000..a8798aa8666 --- /dev/null +++ b/library/digital_resources/LaSourisQuiRaconte/Service/Story.php @@ -0,0 +1,24 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 LaSourisQuiRaconte_Service_Story extends Class_WebService_BibNumerique_RessourceNumerique { +} \ No newline at end of file diff --git a/library/digital_resources/LaSourisQuiRaconte/Service/XMLParser.php b/library/digital_resources/LaSourisQuiRaconte/Service/XMLParser.php new file mode 100644 index 00000000000..9c822fe544a --- /dev/null +++ b/library/digital_resources/LaSourisQuiRaconte/Service/XMLParser.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright (c) 2012, 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 LaSourisQuiRaconte_Service_XMLParser { + protected + $_stories = [], + $_current_story; + + public function parseXML($xml) { + $this->_parser = new Class_WebService_FasterXMLParser(); + $this->_parser->setElementHandler($this); + $this->_parser->parse($xml); + return $this; + } + + + public function startHistoire() { + $this->_current_story = new LaSourisQuiRaconte_Service_Story(); + } + + + public function endTitle($data) { + $this->_current_story->setTitle($data); + } + + + public function endIdentifier($data) { + $this->_current_story->setId($data); + } + + + public function endContentDescription($data) { + $this->_current_story->setDescription($data); + } + + + public function endAuthor($data) { + $this->_current_story->addAuthor(new Class_Notice_Author($data, '005')); + } + + + public function endContributor($data) { + list($name, $responsibility) = explode('.', $data); + $this->_current_story->addAuthor(new Class_Notice_Author(trim($name), + trim($responsibility))); + } + + + public function endHistoire() { + $this->_stories[] = $this->_current_story; + } + + + public function getStories() { + return $this->_stories; + } +} \ No newline at end of file diff --git a/library/digital_resources/LaSourisQuiRaconte/tests/LaSourisQuiRaconteTest.php b/library/digital_resources/LaSourisQuiRaconte/tests/LaSourisQuiRaconteTest.php index e88ad890482..85b2c5c440b 100644 --- a/library/digital_resources/LaSourisQuiRaconte/tests/LaSourisQuiRaconteTest.php +++ b/library/digital_resources/LaSourisQuiRaconte/tests/LaSourisQuiRaconteTest.php @@ -121,4 +121,73 @@ class LaSourisQuiRaconteSSoTest extends AbstractControllerTestCase { 'error' => 'L\'utilisateur n\'est pas autorisé à accéder à cette ressource']], json_decode($this->_response->getBody(), true)); } +} + + + + +class LaSourisQuiRaconteHarvestTest extends ModelTestCase { + protected + $_storm_default_to_volatile = true, + $_leon_geant; + + public function setUp() { + parent::setUp(); + Class_AdminVar::set('LaSourisQuiRaconte_TOKEN', 'bokeh_export'); + + $lsqr_xml = file_get_contents(__DIR__ . '/lsqr.xml'); + + $http_client = $this->mock() + ->whenCalled('open_url') + ->with('https://www.lasourisquiraconte.com/espaces/export_bokeh.php?token=bokeh_export') + ->answers($lsqr_xml) + + ->whenCalled('open_url') + ->answers('a picture'); + + $this->_service = new LaSourisQuiRaconte_Service( + new LaSourisQuiRaconte_Config( + new Class_DigitalResource_Wrapper(Class_DigitalResource::getInstance(), + 'LaSourisQuiRaconte'))); + LaSourisQuiRaconte_Service::setDefaultHttpClient($http_client); + $this->_service->harvest(); + Class_Album::clearCache(); + $this->_leon_geant = Class_Album::find(2); + } + + + /** @test */ + public function leonTitleShouldBeLeonEtLeGeant() { + $this->assertEquals('Léon et le géant', $this->_leon_geant->getTitre()); + } + + + /** @test */ + public function leonIdOrigineShouldBeSixty() { + $this->assertEquals(60, $this->_leon_geant->getIdOrigine()); + } + + + /** @test */ + public function leonMainAuthorShouldBeCecileGivernet() { + $author = $this->_leon_geant->getAuthors()[0]; + $this->assertEquals('Givernet, Cécile', $author->getName()); + $this->assertEquals('005', $author->getResponsibility()); + } + + + /** @test */ + public function leonSecondAuthorShouldBeJulieDeTerssacAsIllustrateur() { + $author = $this->_leon_geant->getAuthors()[1]; + $this->assertEquals('de Terssac, Julie', $author->getName()); + $this->assertEquals('Illustrateur', $author->getResponsibility()); + } + + + /** @test */ + public function thirdSecondAuthorShouldBeThierryRagueneauAsConteur() { + $author = $this->_leon_geant->getAuthors()[2]; + $this->assertEquals('Ragueneau, Thierry', $author->getName()); + $this->assertEquals('Conteur', $author->getResponsibility()); + } } \ No newline at end of file diff --git a/library/digital_resources/LaSourisQuiRaconte/tests/lsqr.xml b/library/digital_resources/LaSourisQuiRaconte/tests/lsqr.xml new file mode 100644 index 00000000000..812b724ee12 --- /dev/null +++ b/library/digital_resources/LaSourisQuiRaconte/tests/lsqr.xml @@ -0,0 +1,146 @@ +<?xml version='1.0' encoding='utf-8'?> +<histoires> + <histoire> + <Identifier>61</Identifier> + <Title>Le prénom du monde</Title> + <Author>Dutruch, Cathy</Author> + <Contributor>Fauché, Claire. Illustrateur</Contributor> + <Contributor>Prêtre, Françoise. Conteur</Contributor> + <Classification>Histoire à lire</Classification> + <Note>Destiné aux 7-8 ans</Note> + <YearOfPublication>2017</YearOfPublication> + <SubjectTopic>Prénom</SubjectTopic> + <SubjectTopic>Naissance</SubjectTopic> + <SubjectTopic>Enfant</SubjectTopic> + <Publisher>La Souris Qui Raconte</Publisher> + <TypeOfDocument>MONI</TypeOfDocument> + <Audience>Elémentaire</Audience> + <Language>français</Language> + <Isbn>978-2-36302-128-1</Isbn> + <ContentDescription>« Un prénom est un mot que l’enfant + entendra tous les jours de sa vie, il sera dans son cœur et + dans sa langue maternelle. Ce sera un mot universel et pourtant + unique… » « Le prénom du monde » est initialement un + livre de commande. En 2015, la maternité Etoile en Provence + avait fait appel à La Souris Qui Raconte pour la création + d’un ouvrage anniversaire sur le thème des prénoms. Avec + l’accord du directeur de la maternité et celui des auteure + et illustratrice, ce très beau livre vous est offert dans sa + version intégrale.</ContentDescription> + <ThumbSmall> + http://www.lasourisquiraconte.com/70-ThumbSmall/le-prenom-du-monde.jpg</ThumbSmall> + <ThumbMedium> + http://www.lasourisquiraconte.com/70-ThumbMedium/le-prenom-du-monde.jpg</ThumbMedium> + <ThumbLarge> + http://www.lasourisquiraconte.com/70-ThumbLarge/le-prenom-du-monde.jpg</ThumbLarge> + <PrimaryDocUrl> + http://www.lasourisquiraconte.com/espaces/61-le-prenom-du-monde</PrimaryDocUrl> + </histoire> + <histoire> + <Identifier>60</Identifier> + <Title>Léon et le géant</Title> + <Author>Givernet, Cécile</Author> + <Contributor>de Terssac, Julie. Illustrateur</Contributor> + <Contributor>Ragueneau, Thierry. Conteur</Contributor> + <Classification>Histoire à jouer</Classification> + <Note>Destiné aux 5-6 ans</Note> + <YearOfPublication>2017</YearOfPublication> + <Publisher>La Souris Qui Raconte</Publisher> + <TypeOfDocument>MONI</TypeOfDocument> + <Audience>Elémentaire</Audience> + <Language>français</Language> + <Isbn>978-2-36302-127-4</Isbn> + <ContentDescription>Léon est un petit garçon qui, séparé + momentanément de sa maman, est face au géant « Letan ». + De toute sa haute taille, Letan empêche Léon de voir sa maman + et cela le rend un peu ronchonchon. L’éloignement de + l’être le plus cher au cœur de l’enfant, peut parfois + s’avérer difficile. Cette histoire décrit avec humour la + confrontation de Léon face au temps et à + l’absence.</ContentDescription> + <ThumbSmall> + http://www.lasourisquiraconte.com/68-ThumbSmall/leon-et-le-geant.jpg</ThumbSmall> + <ThumbMedium> + http://www.lasourisquiraconte.com/68-ThumbMedium/leon-et-le-geant.jpg</ThumbMedium> + <ThumbLarge> + http://www.lasourisquiraconte.com/68-ThumbLarge/leon-et-le-geant.jpg</ThumbLarge> + <PrimaryDocUrl> + http://www.lasourisquiraconte.com/espaces/60-leon-et-le-geant</PrimaryDocUrl> + </histoire> + <histoire> + <Identifier>59</Identifier> + <Title>Le drôle de chat qui mord</Title> + <Author>Sauveur, Pauline</Author> + <Contributor>Gazzi, Giovanna. Illustrateur</Contributor> + <Contributor>Givernet, Cécile. Conteur</Contributor> + <Classification>Histoire à lire</Classification> + <Note>Destiné aux 9-10 ans</Note> + <SubjectTopic>amour</SubjectTopic> + <SubjectTopic>enfants</SubjectTopic> + <SubjectTopic>deuil</SubjectTopic> + <Publisher>La Souris Qui Raconte</Publisher> + <TypeOfDocument>MONI</TypeOfDocument> + <Audience>Elémentaire</Audience> + <Language>français</Language> + <Isbn>978-2-36302-126-7</Isbn> + <ContentDescription>Quelle est cette ombre triste et glacée ? + Installée dans la maison, dans la clairière, dans la forêt ? + À côté du champ d'orge et de blé ? Un jeune couple amoureux + s’installe dans un grand pré, au bord d’une forêt. Ils + labourent et coupent du bois pour construire la maison qui + abritera l’enfant qu’elle porte. Ils sont heureux. + Malheureusement, l’enfant naît mais ne vit que le temps + d’une saison. Alors dans la maison, s’installe une grande + ombre noire. Mais aux jours de malheur, succèdent les jours de + bonheur avec l’arrivée d’autres enfants. L’ombre se fait + plus discrète, ainsi va la vie !</ContentDescription> + <ThumbSmall> + http://www.lasourisquiraconte.com/66-ThumbSmall/le-drole-de-chat-qui-mord.jpg</ThumbSmall> + <ThumbMedium> + http://www.lasourisquiraconte.com/66-ThumbMedium/le-drole-de-chat-qui-mord.jpg</ThumbMedium> + <ThumbLarge> + http://www.lasourisquiraconte.com/66-ThumbLarge/le-drole-de-chat-qui-mord.jpg</ThumbLarge> + <PrimaryDocUrl> + http://www.lasourisquiraconte.com/espaces/59-le-drole-de-chat-qui-mord</PrimaryDocUrl> + </histoire> + <histoire> + <Identifier>1</Identifier> + <Title>Polo le clodo</Title> + <Author>Prêtre, Françoise</Author> + <Contributor>Boréal, Carole. Illustrateur</Contributor> + <Contributor>Montalto, Jean-Marco. Conteur</Contributor> + <Classification>Histoire à jouer</Classification> + <Note>Destiné aux 9-10 ans</Note> + <YearOfPublication>2010</YearOfPublication> + <SubjectTopic>pauvreté</SubjectTopic> + <SubjectTopic>vie</SubjectTopic> + <SubjectTopic>liberté</SubjectTopic> + <SubjectTopic>exclusion</SubjectTopic> + <SubjectTopic>discrimination</SubjectTopic> + <Publisher>La Souris Qui Raconte</Publisher> + <TypeOfDocument>MONI</TypeOfDocument> + <Audience>Elémentaire</Audience> + <Language>français</Language> + <Isbn>978-2-36302-000-0</Isbn> + <ContentDescription>Polo le clodo est l’histoire d’un + clochard confronté à l’indifférence générale. Comme + beaucoup de SDF, il dérange la majorité de ceux qui le + croisent. Est-il seulement responsable de sa condition ? Ce + texte court, interroge l’enfant sur l’exclusion, sans + préjugé. Les illustrations, riches de clics interactifs, + dédramatisent un texte difficile qui pointe du doigt + l’apathie dans laquelle se réfugient trop souvent les + grandes personnes. Polo le Clodo est le texte fétiche de + « La souris qui raconte ». C’est avec cette histoire que + son aventure a commencé en février 2009. Un très grand merci + à Carole. Critiquez ce livre numérique.</ContentDescription> + <ThumbSmall> + http://www.lasourisquiraconte.com/1-ThumbSmall/polo-le-clodo.jpg</ThumbSmall> + <ThumbMedium> + http://www.lasourisquiraconte.com/1-ThumbMedium/polo-le-clodo.jpg</ThumbMedium> + <ThumbLarge> + http://www.lasourisquiraconte.com/1-ThumbLarge/polo-le-clodo.jpg</ThumbLarge> + <PrimaryDocUrl> + http://www.lasourisquiraconte.com/espaces/1-polo-le-clodo</PrimaryDocUrl> + </histoire> +</histoires> -- GitLab