Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAI Refactoring #1094

Merged
merged 59 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
068bdd0
Separation of the formats regarding the format xslt files and made th…
haogatyp Aug 17, 2023
112b330
#766 Refactor configuration, added options (currently only xslt file…
haogatyp Aug 20, 2023
d7e2477
#766 Including the prefix xslt in the base xslt instead of the other …
haogatyp Aug 23, 2023
83a0a4e
#766 ServerFactory directly reads oai options from configuration and …
haogatyp Aug 25, 2023
84e700e
#766 Fix absolut path for xsltFile
haogatyp Aug 25, 2023
d0fcdcd
#766 Fix some coding style.
haogatyp Aug 25, 2023
5fa63f7
Fix coding style.
haogatyp Aug 28, 2023
32f8269
Adjust visibility of some option getter methods.
haogatyp Aug 29, 2023
b78a459
#766 Add basic option getter tests for the BaseServer.
haogatyp Aug 29, 2023
e92fc9b
#766 Removed usage of getcwd().
haogatyp Aug 29, 2023
ce5004d
#766 Fix method access level
haogatyp Aug 29, 2023
4039c6e
#766 Split ServerFactory test methods.
haogatyp Aug 29, 2023
b167ac2
#766 Merge default and format specific options.
haogatyp Aug 31, 2023
aa07706
#766 Remove unnecessary check on "true".
haogatyp Aug 31, 2023
b9585c9
#766 Removed throwing the exception, as this is already happening at …
haogatyp Aug 31, 2023
97311cc
#766 Set the value for xsltFile so that it can be overwritten again u…
haogatyp Aug 31, 2023
2d24448
#1097 Made ViewHelper configurable.
haogatyp Aug 31, 2023
a711037
#766 Replaced options array with single properties.
haogatyp Sep 1, 2023
9a5da62
#1097 Default and format-specific ViewHelper options are combined add…
haogatyp Sep 1, 2023
098856f
#1097 Check if viewhelpers exist.
haogatyp Sep 1, 2023
88b9275
#766 Replace marker comment with a more technical marker.
haogatyp Sep 1, 2023
2388d8b
#766 Removed some double spaces.
haogatyp Sep 1, 2023
90b25f2
#766 Removed some double blank lines.
haogatyp Sep 1, 2023
a84057c
#766 Remove some hard coded format specific code and reduced oai form…
haogatyp Sep 5, 2023
23621bc
#1101 Generate OAI ListMetadataFormats from configuration.
haogatyp Sep 5, 2023
1b27ea9
#1101 Add xslt viewhelper for generating the OAI ListMetadataFormats.
haogatyp Sep 5, 2023
99c919e
#1101 Made string composition more readable.
haogatyp Sep 6, 2023
a24cf61
#1101 Reworked the behavior of the incremental option merging so that…
haogatyp Sep 6, 2023
f551e13
#1101 Fix option merging.
haogatyp Sep 7, 2023
4963cf7
#1101 Fix coding style.
haogatyp Sep 7, 2023
f8cd379
#1101 Added tests for ListMetadataFormats viewhelper.
haogatyp Sep 7, 2023
52593fc
#1101 Removed deprecated property.
haogatyp Sep 7, 2023
79cac6d
#1101 Fix some coding style.
haogatyp Sep 7, 2023
c4a8ba6
#766 Added comments to OAI config
j3nsch Sep 25, 2023
a8d230c
#766 Rename option "viewHelper"
haogatyp Oct 5, 2023
7967b50
#766 Fixed some typos.
haogatyp Oct 5, 2023
42c37f6
#766 Fix return empty string for integer variables. Renaming maxRecor…
haogatyp Oct 5, 2023
882c038
#766 Now also checking for array.
haogatyp Oct 5, 2023
8c5cec9
#766 Using DocumentInterface instead of Document.
haogatyp Oct 5, 2023
70b7504
#766 Added class comment.
haogatyp Oct 5, 2023
e979a6a
#766 Fix class comment.
haogatyp Oct 6, 2023
6f70e08
#766 Adjust option getters and setters for NULL values.
haogatyp Oct 6, 2023
b773cf1
#766 Using shorter parameter names in setter methods.
haogatyp Oct 6, 2023
111b442
#766 Fix some comments.
haogatyp Oct 6, 2023
c28ecb2
#766 Removed unnecessary ternary operator.
haogatyp Oct 6, 2023
403318e
#766 Removed outdated todo comment.
haogatyp Oct 6, 2023
f25c07a
#766 Renaming the marker for metadata format replacement.
haogatyp Oct 6, 2023
d83ab74
#766 Adjust error message.
haogatyp Oct 6, 2023
bc3f3ac
#766 Renamed OaiConfig to match the class name.
haogatyp Oct 6, 2023
e61c90c
#766 Fixed coding style
j3nsch Oct 9, 2023
f27d9da
#766 Empty line after header (coding style)
j3nsch Oct 9, 2023
719d66b
#766 Shorten class variable comments.
haogatyp Oct 10, 2023
bb48b41
#766 Added a comment to make things hopefully more clear.
haogatyp Oct 10, 2023
43072df
#766 Removed unused method.
haogatyp Oct 10, 2023
1ca259f
#766 Use class name only ones in the function.
haogatyp Oct 10, 2023
01de758
#766 Moved oai server test classes to oai test.
haogatyp Oct 10, 2023
ec8f82d
#766 Updated comment
j3nsch Oct 10, 2023
59b25c3
#766 Removed unnecessary mock test class and moved remaining mock tes…
haogatyp Oct 10, 2023
6527e7b
#766 Added a function to add view helpers to a oai server.
haogatyp Oct 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions application/configs/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ oai.description.eprints.submissionPolicy.text =
oai.description.eprints.comment.url =
oai.description.eprints.comment.text =

; Configuration of the oai formats
; Optional custom oai server class name
; oai.format.[lower cased format identifier].class = [oai server class name]
; The xslt file
; oai.format.[lower cased format identifier ].xsltFile = [xslt file name]
; The format prefix
; oai.format.[lower cased format identifier ].prefix = [prefix]
oai.format.default.class = Oai_Model_BaseServer
oai.format.copy_xml.xsltFile = copy_xml.xslt
oai.format.epicur.xsltFile = epicur.xslt
oai.format.marc21.xsltFile = marc21.xslt
oai.format.oai_dc.xsltFile = oai_dc.xslt
oai.format.oai_pp.xsltFile = oai_pp.xslt
oai.format.xmetadissplus.xsltFile = XMetaDissPlus.xslt

; ERROR CONTROLLER SETTINGS
errorController.showException = 0
errorController.showRequest = 0
Expand Down
11 changes: 10 additions & 1 deletion modules/oai/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ public function indexAction()
unset($parameters[$name]);
}

$server = new Oai_Model_Server(); // TODO needs factory
$serverFactory = new Oai_Model_ServerFactory();

if (isset($parameters['metadataPrefix'])) {
$server = $serverFactory->create($parameters['metadataPrefix']);
} elseif (isset($parameters['resumptionToken'])) {
$server = $serverFactory->createByResumptionToken($parameters['resumptionToken']);
} else {
$server = $serverFactory->create();
}

$server->setScriptPath($this->view->getScriptPath('index'));
$server->setBaseUrl($this->view->fullUrl());
$server->setBaseUri($request->getBaseUrl());
Expand Down
269 changes: 224 additions & 45 deletions modules/oai/models/Server.php → modules/oai/models/BaseServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
use Opus\Model\Xml;
use Opus\Model\Xml\Version1;

class Oai_Model_Server extends Application_Model_Abstract
class Oai_Model_BaseServer extends Application_Model_Abstract
{
use Oai_Model_OptionsTrait;

/**
* Holds xml representation of document information to be processed.
*
Expand Down Expand Up @@ -75,13 +77,6 @@ class Oai_Model_Server extends Application_Model_Abstract
*/
private $xMetaDissRestriction = ['doctoralthesis', 'habilitation'];

/**
* Hold oai module configuration model.
*
* @var Oai_Model_Configuration
*/
protected $configuration;

/** @var Oai_Model_XmlFactory */
private $xmlFactory;

Expand All @@ -104,10 +99,9 @@ public function init()
{
$config = $this->getConfig();

$this->xml = new DOMDocument();
$this->proc = new XSLTProcessor();
$this->configuration = new Oai_Model_Configuration($config);
$this->xmlFactory = new Oai_Model_XmlFactory();
$this->xml = new DOMDocument();
$this->proc = new XSLTProcessor();
$this->xmlFactory = new Oai_Model_XmlFactory();
}

/**
Expand All @@ -120,7 +114,7 @@ public function init()
*/
public function handleRequest($parameters, $requestUri)
{
// TODO move error handling into Oai_Model_Server
// TODO move error handling into Oai_Model_BaseServer
try {
// handle request
return $this->handleRequestIntern($parameters, $requestUri);
Expand Down Expand Up @@ -162,14 +156,11 @@ public function handleRequest($parameters, $requestUri)
protected function handleRequestIntern($oaiRequest, $requestUri)
{
$this->init();

// Setup stylesheet
$this->loadStyleSheet($this->getScriptPath() . '/oai-pmh.xslt');

$this->loadStyleSheet();
$this->setupProcessor();

$metadataPrefixPath = $this->getScriptPath() . DIRECTORY_SEPARATOR . 'prefixes';
$resumptionPath = $this->configuration->getResumptionTokenPath();
$resumptionPath = $this->getResumptionTokenPath();

$request = new Oai_Model_Request();
$request->setPathToMetadataPrefixFiles($metadataPrefixPath);
Expand Down Expand Up @@ -350,10 +341,10 @@ protected function handleGetRecord(array &$oaiRequest)
*/
protected function handleIdentify()
{
$email = $this->configuration->getEmailContact();
$repName = $this->configuration->getRepositoryName();
$repIdentifier = $this->configuration->getRepositoryIdentifier();
$sampleIdentifier = $this->configuration->getSampleIdentifier();
$email = $this->getEmailContact();
$repName = $this->getRepositoryName();
$repIdentifier = $this->getRepositoryIdentifier();
$sampleIdentifier = $this->getSampleIdentifier();

// Set backup date if database query does not return a date.
$earliestDate = DateTime::createFromFormat("Y-m-d", '1970-01-01');
Expand Down Expand Up @@ -385,7 +376,7 @@ protected function handleIdentify()
*/
protected function handleListIdentifiers(array &$oaiRequest)
{
$maxIdentifier = $this->configuration->getMaxListIdentifiers();
$maxIdentifier = $this->getMaxListIdentifiers();
$this->handlingOfLists($oaiRequest, $maxIdentifier);
}

Expand Down Expand Up @@ -424,7 +415,7 @@ protected function handleListMetadataFormats($oaiRequest)
*/
protected function handleListRecords(array &$oaiRequest)
{
$maxRecords = $this->configuration->getMaxListRecords();
$maxRecords = $this->getMaxListRecords();
$this->handlingOfLists($oaiRequest, $maxRecords);
}

Expand All @@ -433,7 +424,7 @@ protected function handleListRecords(array &$oaiRequest)
*/
protected function handleListSets()
{
$repIdentifier = $this->configuration->getRepositoryIdentifier();
$repIdentifier = $this->getRepositoryIdentifier();

$this->proc->setParameter('', 'repIdentifier', $repIdentifier);
$this->xml->appendChild($this->xml->createElement('Documents'));
Expand Down Expand Up @@ -467,8 +458,8 @@ private function handlingOfLists(array &$oaiRequest, $maxRecords)
$maxRecords = 100;
}

$repIdentifier = $this->configuration->getRepositoryIdentifier();
$tempPath = $this->configuration->getResumptionTokenPath();
$repIdentifier = $this->getRepositoryIdentifier();
$tempPath = $this->getResumptionTokenPath();

$this->proc->setParameter('', 'repIdentifier', $repIdentifier);
$this->xml->appendChild($this->xml->createElement('Documents'));
Expand Down Expand Up @@ -782,29 +773,30 @@ private function getDocumentXmlDomNode($document)
}

/**
* @return string
* Load an xslt stylesheet.
*/
private function getOaiBaseUrl()
protected function loadStyleSheet()
{
$oaiBaseUrl = $this->configuration->getOaiBaseUrl();
$this->xslt = new DOMDocument();
$this->xslt->load($this->getScriptPath() . '/oai-pmh.xslt');

// if no OAI base url is set, use local information as base url
if (true === empty($oaiBaseUrl)) {
$oaiBaseUrl = $this->getBaseUrl() . '/oai'; // TODO . $module;
}
// Replace import comment with prefix import
$prefixXsltFile = $this->getXsltFile();

return $oaiBaseUrl;
}
if ($prefixXsltFile) {
if (! file_exists($prefixXsltFile)) {
$prefixXsltFile = $this->getScriptPath() . '/prefixes/' . $prefixXsltFile;
}
$xsltXml = $this->xslt->saveXML();
$xsltXml = preg_replace(
'/<!-- add include here for each new metadata format -->/u',
'<xsl:include href="' . $prefixXsltFile . '"/>',
$xsltXml
);

$this->xslt->loadXML($xsltXml);
}

/**
* Load an xslt stylesheet.
*
* @param string $stylesheet
*/
protected function loadStyleSheet($stylesheet)
{
$this->xslt = new DOMDocument();
$this->xslt->load($stylesheet);
$this->proc->importStyleSheet($this->xslt);
if (isset($_SERVER['HTTP_HOST'])) {
$this->proc->setParameter('', 'host', $_SERVER['HTTP_HOST']);
Expand Down Expand Up @@ -875,4 +867,191 @@ public function getResponse()
{
return $this->response;
}

/**
* Return temporary path for resumption tokens.
*
* @return string Path.
*/
public function getResumptionTokenPath()
{
return $this->options['resumptionTokenPath'] ?? '';
}

/**
* Sets the temporary path for resumption tokens.
*
* @param string $path
*/
public function setResumptionTokenPath($path)
{
$this->options['resumptionTokenPath'] = $path;
}

/**
* Return contact email address.
*
* @return string Email address.
*/
public function getEmailContact()
{
return $this->options['emailContact'] ?? '';
}

/**
* Sets the contact email address.
*
* @param string $email
*/
public function setEmailContact($email)
{
$this->options['emailContact'] = $email;
}

/**
* Return OAI base url.
*
* @return string Oai base url.
*/
private function getOaiBaseUrl()
{
$oaiBaseUrl = $this->options['oaiBaseUrl'] ?? '';

// if no OAI base url is set, use local information as base url
if (true === empty($oaiBaseUrl)) {
$oaiBaseUrl = $this->getBaseUrl() . '/oai'; // TODO . $module;
}

return $oaiBaseUrl;
}

/**
* Sets the OAI base url.
*
* @param string $url
*/
public function setOaiBaseUrl($url)
{
$this->options['oaiBaseUrl'] = $url;
}

/**
* Return repository name.
*
* @return string Repository name.
*/
private function getRepositoryName()
{
return $this->options['repositoryName'] ?? '';
}

/**
* Sets the repository name.
*
* @param string $repoName
*/
public function setRepositoryName($repoName)
{
$this->options['repositoryName'] = $repoName;
}

/**
* Return repository identifier.
*
* @return string Repository identifier.
*/
private function getRepositoryIdentifier()
{
return $this->options['repositoryIdentifier'] ?? '';
}

/**
* Sets the repository identifier.
*
* @param string $repoId
*/
public function setRepositoryIdentifier($repoId)
{
$this->options['repositoryIdentifier'] = $repoId;
}

/**
* Return sample identifier.
*
* @return string Sample identifier.
*/
private function getSampleIdentifier()
{
return $this->options['sampleIdentifier'] ?? '';
}

/**
* Sets the sample identifier.
*
* @param string $sampleId
*/
public function setSampleIdentifier($sampleId)
{
$this->options['sampleIdentifier'] = $sampleId;
}

/**
* Return maximum number of listable identifiers per request.
*
* @return int Maximum number of listable identifiers per request.
*/
private function getMaxListIdentifiers()
{
return $this->options['maxListIdentifiers'] ?? '';
}

/**
* Sets the maximum number of listable identifiers per request.
*
* @param int $maxListIds
*/
public function setMaxListIdentifiers($maxListIds)
{
$this->options['maxListIdentifiers'] = $maxListIds;
}

/**
* Return maximum number of listable records per request.
*
* @return int Maximum number of listable records per request.
*/
private function getMaxListRecords()
{
return $this->options['maxListRecords'] ?? '';
}

/**
* Sets the maximum number of listable records per request.
*
* @param int $maxListRecs
*/
public function setMaxListRecords($maxListRecs)
{
$this->options['maxListRecords'] = $maxListRecs;
}

/**
* Return xlst file name / file path.
*
* @return string
*/
protected function getXsltFile()
{
return $this->options['xsltFile'] ?? '';
}

/**
* Sets the xlst file name / file path.
*
* @param string $file
*/
public function setXsltFile($file)
{
$this->options['xsltFile'] = $file;
}
}
Loading