Skip to content

Commit

Permalink
MetaData: implement trivial default set in OAI PMH interface
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias authored and chlulei committed Oct 16, 2024
1 parent 64f756f commit 7179a33
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public function writeRecord(
return new \DOMDocument();
}

public function writeSet(
string $spec,
string $name
): \DOMDocument {
return new \DOMDocument();
}


public function writeResumptionToken(
string $token,
int $complete_list_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class RequestProcessor implements RequestProcessorInterface
protected TokenHandlerInterface $token_handler;

protected readonly string $valid_md_prefix;
protected readonly string $default_set;
protected readonly int $max_list_size;

public function __construct(
Expand All @@ -52,6 +53,7 @@ public function __construct(
$this->token_handler = $token_handler;

$this->valid_md_prefix = 'oai_dc';
$this->default_set = 'default';
$this->max_list_size = 100;
}

Expand Down Expand Up @@ -202,14 +204,20 @@ protected function listSets(RequestInterface $request): \DomDocument
...$request->argumentKeys()
);
}
$errors[] = $this->writer->writeError(
Error::NO_SET_HIERARCHY,
'This repository does not support sets.'
);

return $this->writer->writeErrorResponse(
if ($request->hasArgument(Argument::RESUMPTION_TOKEN)) {
$errors[] = $this->writer->writeError(
Error::BAD_RESUMTPION_TOKEN,
'ListSets does not issue resumption tokens.'
);
}

if (!empty($errors)) {
return $this->writer->writeErrorResponse($request, ...$errors);
}
return $this->writer->writeResponse(
$request,
...$errors
$this->writer->writeSet($this->default_set, $this->default_set)
);
}

Expand All @@ -228,10 +236,13 @@ protected function listRecordsOrIdentifiers(
);
}

if ($request->hasArgument(Argument::SET)) {
if (
$request->hasArgument(Argument::SET) &&
$request->argumentValue(Argument::SET) !== $this->default_set
) {
$errors[] = $this->writer->writeError(
Error::NO_SET_HIERARCHY,
'This repository does not support sets.'
Error::NO_RECORDS_MATCH,
"This repository only supports a trivial set named 'default'."
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ public function writeRecord(
return $xml;
}

public function writeSet(
string $spec,
string $name
): \DOMDocument {
$xml = new \DomDocument('1.0', 'UTF-8');

$root = $xml->createElement('set');
$xml->appendChild($root);

$spec_xml = $xml->createElement('setSpec', $spec);
$root->appendChild($spec_xml);

$name_xml = $xml->createElement('setName', $name);
$root->appendChild($name_xml);

return $xml;
}

public function writeResumptionToken(
string $token,
int $complete_list_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public function writeRecord(
\DOMDocument $metadata
): \DOMDocument;

public function writeSet(
string $spec,
string $name
): \DOMDocument;

public function writeResumptionToken(
string $token,
int $complete_list_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,43 @@ public function testGetResponseToRequestListIdentifiers(): void
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListIdentifiersWithDefaultSet(): void
{
$processor = new RequestProcessor(
$this->getWriter(),
$this->getSettings('prefix_'),
$repo = $this->getRepository(
null,
3,
'id1+2022-11-27',
'id2+2022-11-27',
'id3+2021-11-13'
),
$this->getTokenHandler()
);

$expected_response = <<<XML
<response>
<response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,set=default</response_info>
<header>prefix_id1+2022-11-27:2022-11-27</header>
<header>prefix_id2+2022-11-27:2022-11-27</header>
<header>prefix_id3+2021-11-13:2021-11-13</header>
</response>
XML;

$response = $processor->getResponseToRequest($this->getRequest(
'base url',
Verb::LIST_IDENTIFIERS,
[Argument::MD_PREFIX->value => 'oai_dc', Argument::SET->value => 'default'],
));

$this->assertEquals(
[['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
$repo->exposed_parameters
);
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListIdentifiersWithFromDate(): void
{
$processor = new RequestProcessor(
Expand Down Expand Up @@ -591,7 +628,7 @@ public function testGetResponseToRequestListIdentifiersNoRecordsFoundError(): vo
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListIdentifiersNoSetsError(): void
public function testGetResponseToRequestListIdentifiersNonDefaultSetError(): void
{
$processor = new RequestProcessor(
$this->getWriter(),
Expand All @@ -609,7 +646,7 @@ public function testGetResponseToRequestListIdentifiersNoSetsError(): void
$expected_response = <<<XML
<error_response>
<response_info>base url:ListIdentifiers:metadataPrefix=oai_dc,set=set</response_info>
<error>noSetHierarchy</error>
<error>noRecordsMatch</error>
</error_response>
XML;

Expand All @@ -635,7 +672,7 @@ public function testGetResponseToRequestListIdentifiersMultipleErrors(): void
<error_response>
<response_info>base url:ListIdentifiers:metadataPrefix=invalid,until=also invalid,from=more invalid,set=set,identifier=id</response_info>
<error>badArgument</error>
<error>noSetHierarchy</error>
<error>noRecordsMatch</error>
<error>cannotDisseminateFormat</error>
<error>badArgument</error>
<error>badArgument</error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,43 @@ public function testGetResponseToRequestListRecords(): void
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListRecordsWithDefaultSet(): void
{
$processor = new RequestProcessor(
$this->getWriter(),
$this->getSettings('prefix_'),
$repo = $this->getRepository(
null,
3,
'id1+2022-11-27',
'id2+2022-11-27',
'id3+2021-11-13'
),
$this->getTokenHandler()
);

$expected_response = <<<XML
<response>
<response_info>base url:ListRecords:metadataPrefix=oai_dc,set=default</response_info>
<record><record_info>prefix_id1+2022-11-27:2022-11-27</record_info><md>md for id1+2022-11-27</md></record>
<record><record_info>prefix_id2+2022-11-27:2022-11-27</record_info><md>md for id2+2022-11-27</md></record>
<record><record_info>prefix_id3+2021-11-13:2021-11-13</record_info><md>md for id3+2021-11-13</md></record>
</response>
XML;

$response = $processor->getResponseToRequest($this->getRequest(
'base url',
Verb::LIST_RECORDS,
[Argument::MD_PREFIX->value => 'oai_dc', Argument::SET->value => 'default'],
));

$this->assertEquals(
[['from' => null, 'until' => null, 'limit' => 100, 'offset' => 0]],
$repo->exposed_parameters
);
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListRecordsWithFromDate(): void
{
$processor = new RequestProcessor(
Expand Down Expand Up @@ -591,7 +628,7 @@ public function testGetResponseToRequestListRecordsNoRecordsFoundError(): void
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListRecordsNoSetsError(): void
public function testGetResponseToRequestListRecordsNonDefaultSetError(): void
{
$processor = new RequestProcessor(
$this->getWriter(),
Expand All @@ -609,7 +646,7 @@ public function testGetResponseToRequestListRecordsNoSetsError(): void
$expected_response = <<<XML
<error_response>
<response_info>base url:ListRecords:metadataPrefix=oai_dc,set=set</response_info>
<error>noSetHierarchy</error>
<error>noRecordsMatch</error>
</error_response>
XML;

Expand All @@ -635,7 +672,7 @@ public function testGetResponseToRequestListRecordsMultipleErrors(): void
<error_response>
<response_info>base url:ListRecords:metadataPrefix=invalid,until=also invalid,from=more invalid,set=set,identifier=id</response_info>
<error>badArgument</error>
<error>noSetHierarchy</error>
<error>noRecordsMatch</error>
<error>cannotDisseminateFormat</error>
<error>badArgument</error>
<error>badArgument</error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public function testGetResponseToRequestListSetsNoSetsError(): void
);

$expected_response = <<<XML
<error_response>
<response>
<response_info>base url:ListSets:</response_info>
<error>noSetHierarchy</error>
</error_response>
<set>default:default</set>
</response>
XML;

$response = $processor->getResponseToRequest($this->getRequest('base url', Verb::LIST_SETS, []));

$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListSetsNoSetsAndAdditionalArgumentError(): void
public function testGetResponseToRequestListSetsAdditionalArgumentError(): void
{
$processor = new RequestProcessor(
$this->getWriter(),
Expand All @@ -59,7 +59,6 @@ public function testGetResponseToRequestListSetsNoSetsAndAdditionalArgumentError
<error_response>
<response_info>base url:ListSets:identifier=some id</response_info>
<error>badArgument</error>
<error>noSetHierarchy</error>
</error_response>
XML;

Expand All @@ -73,7 +72,7 @@ public function testGetResponseToRequestListSetsNoSetsAndAdditionalArgumentError
$this->assertXmlStringEqualsXmlString($expected_response, $response->saveXML());
}

public function testGetResponseToRequestListSetsWithTokenNoSetsError(): void
public function testGetResponseToRequestListSetsWithTokenBadResumptionTokenError(): void
{
$processor = new RequestProcessor(
$this->getWriter(),
Expand All @@ -85,7 +84,7 @@ public function testGetResponseToRequestListSetsWithTokenNoSetsError(): void
$expected_response = <<<XML
<error_response>
<response_info>base url:ListSets:resumptionToken=token</response_info>
<error>noSetHierarchy</error>
<error>badResumptionToken</error>
</error_response>
XML;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ public function writeRecord(
return $doc;
}

public function writeSet(string $spec, string $name): \DOMDocument
{
$doc = new \DOMDocument();
$doc->appendChild($doc->createElement('set', $spec . ':' . $name));
return $doc;
}

public function writeResumptionToken(
string $token,
int $complete_list_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ public function testWriteRecord(): void
$this->assertXmlStringEqualsXmlString($expected_xml, $xml->saveXML());
}

public function testWriteSet(): void
{
$expected_xml = <<<XML
<set>
<setSpec>some spec</setSpec>
<setName>some name</setName>
</set>
XML;

$writer = $this->getWriter();
$xml = $writer->writeSet(
'some spec',
'some name'
);

$this->assertXmlStringEqualsXmlString($expected_xml, $xml->saveXML());
}

public function testWriteResumptionToken(): void
{
$expected_xml = <<<XML
Expand Down

0 comments on commit 7179a33

Please sign in to comment.