Skip to content
Snippets Groups Projects
Commit bda87251 authored by pbarroca's avatar pbarroca
Browse files

OAI: ajout réponse GetRecord

parent 1d87ef97
Branches
Tags
No related merge requests found
...@@ -1763,6 +1763,7 @@ library/Class/WebService/LibraryThing.php -text ...@@ -1763,6 +1763,7 @@ library/Class/WebService/LibraryThing.php -text
library/Class/WebService/MappedSoapClient.php -text library/Class/WebService/MappedSoapClient.php -text
library/Class/WebService/OAI.php -text library/Class/WebService/OAI.php -text
library/Class/WebService/OAI/CatalogueVisitor.php -text library/Class/WebService/OAI/CatalogueVisitor.php -text
library/Class/WebService/OAI/Response/GetRecord.php -text
library/Class/WebService/OAI/Response/Identify.php -text library/Class/WebService/OAI/Response/Identify.php -text
library/Class/WebService/OAI/Response/ListSets.php -text library/Class/WebService/OAI/Response/ListSets.php -text
library/Class/WebService/OAI/Response/Null.php -text library/Class/WebService/OAI/Response/Null.php -text
...@@ -3488,6 +3489,7 @@ tests/library/Class/UserGroupTest.php -text ...@@ -3488,6 +3489,7 @@ tests/library/Class/UserGroupTest.php -text
tests/library/Class/UsersTest.php -text tests/library/Class/UsersTest.php -text
tests/library/Class/VodeclicLinkTest.php -text tests/library/Class/VodeclicLinkTest.php -text
tests/library/Class/WebService/BabelioTest.php -text tests/library/Class/WebService/BabelioTest.php -text
tests/library/Class/WebService/OAI/Response/GetRecordTest.php -text
tests/library/Class/WebService/OAI/Response/IdentifyTest.php -text tests/library/Class/WebService/OAI/Response/IdentifyTest.php -text
tests/library/Class/WebService/OAI/Response/ListSetsTest.php -text tests/library/Class/WebService/OAI/Response/ListSetsTest.php -text
tests/library/Class/WebService/OAIIdentify.xml -text tests/library/Class/WebService/OAIIdentify.xml -text
......
...@@ -989,6 +989,7 @@ class Class_Notice extends Storm_Model_Abstract ...@@ -989,6 +989,7 @@ class Class_Notice extends Storm_Model_Abstract
public function acceptVisitor($visitor) { public function acceptVisitor($visitor) {
$visitor->visitClefAlpha($this->getClefAlpha()); $visitor->visitClefAlpha($this->getClefAlpha());
$visitor->visitTitre($this->getTitrePrincipal()); $visitor->visitTitre($this->getTitrePrincipal());
$visitor->visitDateMaj($this->getDateMaj());
} }
} }
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
class Class_Notice_DublinCoreVisitor { class Class_Notice_DublinCoreVisitor {
protected $_xml; protected $_xml;
protected $_builder; protected $_builder;
protected $_identifier;
protected $_date;
public function __construct() { public function __construct() {
$this->_builder = new Class_Xml_Oai_DublinCoreBuilder(); $this->_builder = new Class_Xml_Oai_DublinCoreBuilder();
...@@ -39,16 +42,31 @@ class Class_Notice_DublinCoreVisitor { ...@@ -39,16 +42,31 @@ class Class_Notice_DublinCoreVisitor {
public function visitClefAlpha($clef) { public function visitClefAlpha($clef) {
$this->_xml .= $this->_builder->identifier(sprintf('http://%s%s/recherche/notice/%s', $this->_identifier = sprintf('http://%s%s/recherche/notice/%s',
$_SERVER['SERVER_NAME'], $_SERVER['SERVER_NAME'], BASE_URL, $clef);
BASE_URL, $this->_xml .= $this->_builder->identifier($this->_identifier);
$clef));
} }
public function visitTitre($titre) { public function visitTitre($titre) {
$this->_xml .= $this->_builder->title($titre); $this->_xml .= $this->_builder->title($titre);
} }
public function visitDateMaj($dateMaj) {
$this->_date = substr($dateMaj, 0, 10);
$this->_xml .= $this->_builder->date($this->_date);
}
public function getIdentifier() {
return $this->_identifier;
}
public function getDate() {
return $this->_date;
}
} }
?> ?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_WebService_OAI_Response_GetRecord extends Class_WebService_OAI_Response_Null {
protected $_notice;
protected $_dublin_core_visitor;
public function buildXmlOn($builder) {
if (null === $this->_notice)
return '';
$this->_dublin_core_visitor = new Class_Notice_DublinCoreVisitor();
$this->_dublin_core_visitor->visit($this->_notice);
return
$builder->request(array('verb' => 'GetRecord',
'metadataPrefix' => 'oai_dc'),
$this->_baseUrl)
. $builder->GetRecord($builder->record($this->_buildHeaders($builder)
. $this->_buildMetadata($builder)));
}
protected function _buildHeaders($builder) {
return
$builder->header($builder->identifier($this->_dublin_core_visitor->getIdentifier()))
. $builder->header($builder->datestamp($this->_dublin_core_visitor->getDate()));
}
protected function _buildMetadata($builder) {
return $builder->metadata($this->_dublin_core_visitor->xml());
}
public function setNotice($notice) {
$this->_notice = $notice;
}
}
?>
\ No newline at end of file
...@@ -37,7 +37,8 @@ class DublinCoreVisitorPotterTest extends DublinCoreVisitorTestCase { ...@@ -37,7 +37,8 @@ class DublinCoreVisitorPotterTest extends DublinCoreVisitorTestCase {
$potter = Class_Notice::getLoader() $potter = Class_Notice::getLoader()
->newInstanceWithId(4) ->newInstanceWithId(4)
->setClefAlpha('harrypotter-sorciers') ->setClefAlpha('harrypotter-sorciers')
->setTitrePrincipal('Harry Potter a l\'ecole des sorciers'); ->setTitrePrincipal('Harry Potter a l\'ecole des sorciers')
->setDateMaj('2012-04-23');
$this->_dublin_core_visitor->visit($potter); $this->_dublin_core_visitor->visit($potter);
} }
...@@ -74,9 +75,12 @@ class DublinCoreVisitorSouvignyTest extends DublinCoreVisitorTestCase { ...@@ -74,9 +75,12 @@ class DublinCoreVisitorSouvignyTest extends DublinCoreVisitorTestCase {
parent::setUp(); parent::setUp();
$souvigny = Class_Notice::getLoader() $souvigny = Class_Notice::getLoader()
->newInstanceWithId(5) ->newInstanceWithId(5)
->setClefAlpha('souvigny-bible-11eme'); ->setClefAlpha('souvigny-bible-11eme')
->setDateMaj('2012-04-23');
$oldServerName = $_SERVER['SERVER_NAME'];
$_SERVER['SERVER_NAME'] = 'moulins.fr'; $_SERVER['SERVER_NAME'] = 'moulins.fr';
$this->_dublin_core_visitor->visit($souvigny); $this->_dublin_core_visitor->visit($souvigny);
$_SERVER['SERVER_NAME'] = $oldServerName;
} }
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class OAIGetRecordTest extends Storm_Test_ModelTestCase {
const OAI_RECORD_PATH = '//oai:GetRecord/oai:record/';
const OAI_HEADER_PATH = 'oai:header/';
protected $_xpath;
protected $_response;
public function setUp() {
parent::setUp();
$this->_xpath = TestXPathFactory::newOai();
$this->_xpath->registerNameSpace('oai_dc', 'http://www.openarchives.org/OAI/2.0/oai_dc/');
$this->_response = new Class_WebService_OAI_Response_GetRecord('http://afi-sa.fr/oai/do');
$potter = Class_Notice::getLoader()
->newInstanceWithId(4)
->setClefAlpha('harrypotter-sorciers')
->setTitrePrincipal('Harry Potter a l\'ecole des sorciers')
->setDateMaj('2001-12-14 11:39:44');
$this->_response->setNotice($potter);
}
/** @test */
public function requestVerbShouldBeGetRecord() {
$this->_xpath->assertXpath($this->_response->xml(),
'//oai:request[@verb="GetRecord"]');
}
/** @test */
public function requestMetadataPrefixShouldBeOaiDc() {
$this->_xpath->assertXpath($this->_response->xml(),
'//oai:request[@metadataPrefix="oai_dc"]');
}
/** @test */
public function headerShouldContainRecordIdentifier() {
$this->_xpath->assertXPathContentContains($this->_response->xml(),
self::OAI_RECORD_PATH . self::OAI_HEADER_PATH . 'oai:identifier',
sprintf('http://localhost%s/recherche/notice/harrypotter-sorciers',
BASE_URL));
}
/** @test */
public function recordHeaderDateStampShouldBe2001DecemberFourteen() {
$this->_xpath->assertXPathContentContains($this->_response->xml(),
self::OAI_RECORD_PATH . self::OAI_HEADER_PATH . 'oai:datestamp',
'2001-12-14');
}
/** @test */
public function metadataShouldContainOaiDublinCore() {
$this->_xpath->assertXPath($this->_response->xml(),
self::OAI_RECORD_PATH . 'oai:metadata/oai_dc:dc');
}
}
\ No newline at end of file
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