From e1a11d540b5bf53999e6ce02c4fec336a5aebf53 Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Wed, 25 Apr 2012 09:53:04 +0000 Subject: [PATCH] OAI: Refacto construction commune des records --- .gitattributes | 2 + .../WebService/OAI/Response/GetRecord.php | 21 ++-------- .../OAI/Response/ListIdentifiers.php | 4 +- .../WebService/OAI/Response/RecordBuilder.php | 39 +++++++++++++++++++ .../OAI/Response/RecordHeadersBuilder.php | 26 +++++++++++++ .../OAI/Response/ListIdentifiersTest.php | 7 ++++ 6 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 library/Class/WebService/OAI/Response/RecordBuilder.php create mode 100644 library/Class/WebService/OAI/Response/RecordHeadersBuilder.php diff --git a/.gitattributes b/.gitattributes index c1296f7a8c2..8b90c09eb31 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1775,6 +1775,8 @@ library/Class/WebService/OAI/Response/ListIdentifiers.php -text library/Class/WebService/OAI/Response/ListMetadataFormats.php -text library/Class/WebService/OAI/Response/ListSets.php -text library/Class/WebService/OAI/Response/Null.php -text +library/Class/WebService/OAI/Response/RecordBuilder.php -text +library/Class/WebService/OAI/Response/RecordHeadersBuilder.php -text library/Class/WebService/OAI/ResponseFactory.php -text library/Class/WebService/Premiere.php -text library/Class/WebService/ReseauxSociaux.php -text diff --git a/library/Class/WebService/OAI/Response/GetRecord.php b/library/Class/WebService/OAI/Response/GetRecord.php index 79bf0b7b44a..d3f19265953 100644 --- a/library/Class/WebService/OAI/Response/GetRecord.php +++ b/library/Class/WebService/OAI/Response/GetRecord.php @@ -20,33 +20,20 @@ */ 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); + $visitor = new Class_Notice_DublinCoreVisitor(); + $visitor->visit($this->_notice); + $recordBuilder = new Class_WebService_OAI_Response_RecordBuilder(); 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->datestamp($this->_dublin_core_visitor->getDate())); - } - - - protected function _buildMetadata($builder) { - return $builder->metadata($this->_dublin_core_visitor->xml()); + . $builder->GetRecord($builder->record($recordBuilder->xml($builder, $visitor))); } diff --git a/library/Class/WebService/OAI/Response/ListIdentifiers.php b/library/Class/WebService/OAI/Response/ListIdentifiers.php index ae64d042860..fc09344a3c4 100644 --- a/library/Class/WebService/OAI/Response/ListIdentifiers.php +++ b/library/Class/WebService/OAI/Response/ListIdentifiers.php @@ -36,11 +36,11 @@ class Class_WebService_OAI_Response_ListIdentifiers extends Class_WebService_OAI public function headers($builder) { $visitor = new Class_Notice_DublinCoreVisitor(); + $recordBuilder = new Class_WebService_OAI_Response_RecordHeadersBuilder(); $headers = ''; foreach ($this->_notices as $notice) { $visitor->visit($notice); - $headers .= $builder->header($builder->identifier($visitor->getIdentifier()) - . $builder->datestamp($visitor->getDate())); + $headers .= $recordBuilder->xml($builder, $visitor); } return $headers; diff --git a/library/Class/WebService/OAI/Response/RecordBuilder.php b/library/Class/WebService/OAI/Response/RecordBuilder.php new file mode 100644 index 00000000000..a85c41cc008 --- /dev/null +++ b/library/Class/WebService/OAI/Response/RecordBuilder.php @@ -0,0 +1,39 @@ +<?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_RecordBuilder { + public function xml($builder, $visitor) { + return + $this->buildHeaders($builder, $visitor) + . $this->buildMetadata($builder, $visitor); + } + + + public function buildHeaders($builder, $visitor) { + return $builder->header($builder->identifier($visitor->getIdentifier()) + . $builder->datestamp($visitor->getDate())); + } + + + public function buildMetadata($builder, $visitor) { + return $builder->metadata($visitor->xml()); + } +} +?> \ No newline at end of file diff --git a/library/Class/WebService/OAI/Response/RecordHeadersBuilder.php b/library/Class/WebService/OAI/Response/RecordHeadersBuilder.php new file mode 100644 index 00000000000..b07516ac6b4 --- /dev/null +++ b/library/Class/WebService/OAI/Response/RecordHeadersBuilder.php @@ -0,0 +1,26 @@ +<?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_RecordHeadersBuilder extends Class_WebService_OAI_Response_RecordBuilder { + public function buildMetadata($builder, $visitor) { + return ''; + } +} +?> \ No newline at end of file diff --git a/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php b/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php index 2fea1bc9f9e..1b7889e2668 100644 --- a/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php +++ b/tests/library/Class/WebService/OAI/Response/ListIdentifiersTest.php @@ -56,6 +56,13 @@ class ListIdentifiersTest extends Storm_Test_ModelTestCase { 3); } + + /** @test */ + public function shouldNotHaveMetadata() { + $this->_xpath->assertNotXpath($this->_response->xml(), + '//oai:ListIdentifiers/oai:metadata'); + } + /** @test */ public function firstIdentifierShouldContainSorciers() { -- GitLab