Skip to content

Commit

Permalink
Adjusted to use const for name, fitted multilines to single where pla…
Browse files Browse the repository at this point in the history
…usible
  • Loading branch information
LuomaJuha committed Dec 20, 2024
1 parent dc65675 commit 0e02534
Showing 1 changed file with 21 additions and 35 deletions.
56 changes: 21 additions & 35 deletions module/Finna/src/Finna/OAI/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class Server extends \VuFind\OAI\Server
*/
protected array $finnaApiFields = [];

/**
* Finna metadata prefix
*
* @var string
*/
protected const OAI_FINNA_JSON = 'oai_finna_json';

/**
* Does the current configuration support the Finna metadata format (using
* the API's record formatter.
Expand Down Expand Up @@ -90,7 +97,7 @@ protected function initializeMetadataFormats()
'schema' => $qdc,
'namespace' => 'urn:dc:qdc:container'];
if ($this->supportsFinnaMetadata()) {
$this->metadataFormats['oai_finna_json'] = [
$this->metadataFormats[self::OAI_FINNA_JSON] = [
'schema' => 'https://vufind.org/xsd/oai_vufind_json-1.0.xsd',
'namespace' => 'http://vufind.org/oai_vufind_json-1.0',
];
Expand All @@ -107,7 +114,7 @@ protected function initializeMetadataFormats()
*/
protected function getRecordAsXML(AbstractRecordDriver $record, string $format): string|false
{
if ('oai_json_finna' === 'format' && $this->supportsFinnaMetadata()) {
if (self::OAI_FINNA_JSON === $format && $this->supportsFinnaMetadata()) {
return $this->getFinnaMetadata($record);
}
return parent::getRecordAsXml($record, $format);
Expand All @@ -116,7 +123,7 @@ protected function getRecordAsXML(AbstractRecordDriver $record, string $format):
/**
* Respond to a ListMetadataFormats request.
*
* @return string
* @return string|false
*/
protected function listMetadataFormats()
{
Expand All @@ -141,7 +148,7 @@ protected function listMetadataFormats()
$record === false
|| $record->getXML($prefix) !== false
|| ('oai_vufind_json' === $prefix && $this->supportsVuFindMetadata())
|| ('oai_finna_json' === $prefix && $this->supportsFinnaMetadata())
|| (self::OAI_FINNA_JSON === $prefix && $this->supportsFinnaMetadata())
) {
$node = $xml->addChild('metadataFormat');
$node->metadataPrefix = $prefix;
Expand Down Expand Up @@ -191,43 +198,22 @@ protected function getFinnaMetadata($record)
{
// Root node
$recordDoc = new \DOMDocument();
$vufindFormat = $this->getMetadataFormats()['oai_finna_json'];
$rootNode = $recordDoc->createElementNS(
$vufindFormat['namespace'],
'oai_finna_json:record'
);
$rootNode->setAttribute(
'xmlns:xsi',
'http://www.w3.org/2001/XMLSchema-instance'
);
$rootNode->setAttribute(
'xsi:schemaLocation',
$vufindFormat['namespace'] . ' ' . $vufindFormat['schema']
);
$finnaFormat = $this->getMetadataFormats()[self::OAI_FINNA_JSON];
$rootNode = $recordDoc->createElementNS($finnaFormat['namespace'], self::OAI_FINNA_JSON . ':record');
$rootNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootNode->setAttribute('xsi:schemaLocation', $finnaFormat['namespace'] . ' ' . $finnaFormat['schema']);
$recordDoc->appendChild($rootNode);

// Add oai_dc part
$oaiDc = new \DOMDocument();
$oaiDc->loadXML(
$record->getXML('oai_dc', $this->baseHostURL, $this->recordLinkerHelper)
);
$rootNode->appendChild(
$recordDoc->importNode($oaiDc->documentElement, true)
);
$oaiDc->loadXML($record->getXML('oai_dc', $this->baseHostURL, $this->recordLinkerHelper));
$rootNode->appendChild($recordDoc->importNode($oaiDc->documentElement, true));

// Add VuFind metadata
$records = $this->recordFormatter->format(
[$record],
$this->finnaApiFields
);
$metadataNode = $recordDoc->createElementNS(
$vufindFormat['namespace'],
'oai_finna_json:metadata'
);
// Add Finna specific metadata
$records = $this->recordFormatter->format([$record], $this->finnaApiFields);
$metadataNode = $recordDoc->createElementNS($finnaFormat['namespace'], self::OAI_FINNA_JSON . ':metadata');
$metadataNode->setAttribute('type', 'application/json');
$metadataNode->appendChild(
$recordDoc->createCDATASection(json_encode($records[0]))
);
$metadataNode->appendChild($recordDoc->createCDATASection(json_encode($records[0])));
$rootNode->appendChild($metadataNode);

return $recordDoc->saveXML();
Expand Down

0 comments on commit 0e02534

Please sign in to comment.