Skip to content

Commit

Permalink
#766 Adjust option getters and setters for NULL values.
Browse files Browse the repository at this point in the history
  • Loading branch information
haogatyp committed Oct 6, 2023
1 parent e979a6a commit 6f70e08
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 40 deletions.
104 changes: 64 additions & 40 deletions modules/oai/models/DefaultServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ protected function handleRequestIntern($oaiRequest, $requestUri)
$this->loadStyleSheet();
$this->setupProcessor();

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

$request = new Oai_Model_Request();

Expand Down Expand Up @@ -703,6 +702,8 @@ private function addSpecInformation(DOMNode $document, $information)
*/
private function addFrontdoorUrlAttribute(DOMNode $document, $docid)
{
$this->checkBaseUrl();

$url = $this->getBaseUrl() . '/frontdoor/index/index/docId/' . $docid;

$owner = $document->ownerDocument;
Expand All @@ -720,6 +721,8 @@ private function addFrontdoorUrlAttribute(DOMNode $document, $docid)
*/
private function addFileUrlAttribute($file, $docid, $filename)
{
$this->checkBaseUrl();

$url = $this->getBaseUrl() . '/files/' . $docid . '/' . rawurlencode($filename);

$owner = $file->ownerDocument;
Expand All @@ -736,6 +739,8 @@ private function addFileUrlAttribute($file, $docid, $filename)
*/
private function addDdbTransferElement(DOMNode $document, $docid)
{
$this->checkBaseUrl();

$url = $this->getBaseUrl() . '/oai/container/index/docId/' . $docid;

$fileElement = $document->ownerDocument->createElement('TransferUrl');
Expand Down Expand Up @@ -876,47 +881,47 @@ public function setOaiConfig($oaiConfig)
}

/**
* @return string
* @return string|false
*/
public function getScriptPath()
{
return $this->scriptPath;
}

/**
* @param string $scriptPath
* @param string|false $scriptPath
*/
public function setScriptPath($scriptPath)
{
$this->scriptPath = $scriptPath;
}

/**
* @return string
* @return string|null
*/
public function getBaseUrl()
{
return $this->baseUrl;
}

/**
* @param string $baseUrl
* @param string|null $baseUrl
*/
public function setBaseUrl($baseUrl)
{
$this->baseUrl = $baseUrl;
}

/**
* @return string
* @return string|null
*/
public function getBaseUri()
{
return $this->baseUri;
}

/**
* @param string $baseUri
* @param string|null $baseUri
*/
public function setBaseUri($baseUri)
{
Expand Down Expand Up @@ -952,7 +957,7 @@ public function getResumptionTokenPath()
/**
* Sets the temporary path for resumption tokens.
*
* @param string $path
* @param string|null $path
*/
public function setResumptionTokenPath($path)
{
Expand All @@ -972,7 +977,7 @@ public function getEmailContact()
/**
* Sets the contact email address.
*
* @param string $email
* @param string|null $email
*/
public function setEmailContact($email)
{
Expand All @@ -999,7 +1004,7 @@ public function getOaiBaseUrl()
/**
* Sets the OAI base url.
*
* @param string $url
* @param string|null $url
*/
public function setOaiBaseUrl($url)
{
Expand All @@ -1019,7 +1024,7 @@ public function getRepositoryName()
/**
* Sets the repository name.
*
* @param string $repoName
* @param string|null $repoName
*/
public function setRepositoryName($repoName)
{
Expand All @@ -1039,7 +1044,7 @@ public function getRepositoryIdentifier()
/**
* Sets the repository identifier.
*
* @param string $repoId
* @param string|null $repoId
*/
public function setRepositoryIdentifier($repoId)
{
Expand All @@ -1059,7 +1064,7 @@ public function getSampleIdentifier()
/**
* Sets the sample identifier.
*
* @param string $sampleId
* @param string|null $sampleId
*/
public function setSampleIdentifier($sampleId)
{
Expand All @@ -1073,7 +1078,7 @@ public function setSampleIdentifier($sampleId)
*/
public function getMaxListIdentifiers()
{
return $this->maxListIdentifiers ?? 0;
return $this->maxListIdentifiers;
}

/**
Expand All @@ -1093,7 +1098,7 @@ public function setMaxListIdentifiers($maxListIds)
*/
public function getMaxListRecords()
{
return $this->maxListRecords ?? 0;
return $this->maxListRecords;
}

/**
Expand All @@ -1109,17 +1114,17 @@ public function setMaxListRecords($maxListRecs)
/**
* Return xslt file name / file path.
*
* @return string
* @return string|null
*/
public function getXsltFile()
{
return $this->xsltFile ?? '';
return $this->xsltFile;
}

/**
* Sets the xslt file name / file path.
*
* @param string $file
* @param string|null $file
*/
public function setXsltFile($file)
{
Expand All @@ -1144,16 +1149,18 @@ public function getViewHelpers()
/**
* Sets the viewHelpers
*
* @param array|string $viewHelpers
* @param array|string|null $viewHelpers
*/
public function setViewHelpers($viewHelpers)
{
if (is_string($viewHelpers)) {
$viewHelpers = array_map('trim', explode(',', $viewHelpers));
$viewHelpers = $viewHelpers !== '' ? array_map('trim', explode(',', $viewHelpers)) : [];
}

// listMetadataFormats ist part of basic OAI functionality.
$viewHelpers = array_values(array_diff($viewHelpers, ['listMetadataFormats']));
if (is_array($viewHelpers)) {
// listMetadataFormats ist part of basic OAI functionality.
$viewHelpers = array_values(array_diff($viewHelpers, ['listMetadataFormats']));
}

$this->viewHelpers = $viewHelpers;
}
Expand Down Expand Up @@ -1185,19 +1192,19 @@ public function setCheckEmbargo($checkEmbargo)
*/
public function getDocumentTypesAllowed()
{
return $this->documentTypesAllowed;
return $this->documentTypesAllowed ?? [];
}

/**
* Sets the allowed document types.
*
* @param array|string $documentTypesAllowed
* @param array|string|null $documentTypesAllowed
*/
public function setDocumentTypesAllowed($documentTypesAllowed)
{
if (is_string($documentTypesAllowed)) {
$this->documentTypesAllowed = [$documentTypesAllowed];
} elseif (is_array($documentTypesAllowed)) {
$this->documentTypesAllowed = $documentTypesAllowed !== '' ? [$documentTypesAllowed] : [];
} elseif (is_array($documentTypesAllowed) || $documentTypesAllowed === null) {
$this->documentTypesAllowed = $documentTypesAllowed;
}
}
Expand All @@ -1209,19 +1216,19 @@ public function setDocumentTypesAllowed($documentTypesAllowed)
*/
public function getDocumentStatesAllowed()
{
return $this->documentStatesAllowed;
return $this->documentStatesAllowed ?? [];
}

/**
* Sets the allowed document states
*
* @param array|string $documentStatesAllowed
* @param array|string|null $documentStatesAllowed
*/
public function setDocumentStatesAllowed($documentStatesAllowed)
{
if (is_string($documentStatesAllowed)) {
$this->documentStatesAllowed = [$documentStatesAllowed];
} elseif (is_array($documentStatesAllowed)) {
$this->documentStatesAllowed = $documentStatesAllowed !== '' ? [$documentStatesAllowed] : [];
} elseif (is_array($documentStatesAllowed) || $documentStatesAllowed === null) {
$this->documentStatesAllowed = $documentStatesAllowed;
}
}
Expand All @@ -1243,15 +1250,15 @@ public function setNotEmbargoedOn($notEmbargoedOn)
}

/**
* @return string
* @return string|null
*/
public function getIdentifierExists()
{
return $this->identifierExists;
}

/**
* @param string $identifierExists
* @param string|null $identifierExists
*/
public function setIdentifierExists($identifierExists)
{
Expand All @@ -1275,47 +1282,47 @@ public function setHasFilesVisibleInOai($hasFilesVisibleInOai)
}

/**
* @return string
* @return string|null
*/
public function getPrefixLabel()
{
return $this->prefixLabel;
}

/**
* @param string $prefixLabel
* @param string|null $prefixLabel
*/
public function setPrefixLabel($prefixLabel)
{
$this->prefixLabel = $prefixLabel;
}

/**
* @return string
* @return string|null
*/
public function getSchemaUrl()
{
return $this->schemaUrl;
}

/**
* @param string $schemaUrl
* @param string|null $schemaUrl
*/
public function setSchemaUrl($schemaUrl)
{
$this->schemaUrl = $schemaUrl;
}

/**
* @return string
* @return string|null
*/
public function getMetadataNamespaceUrl()
{
return $this->metadataNamespaceUrl;
}

/**
* @param string $metadataNamespaceUrl
* @param string|null $metadataNamespaceUrl
*/
public function setMetadataNamespaceUrl($metadataNamespaceUrl)
{
Expand All @@ -1331,7 +1338,7 @@ public function isAdminOnly()
}

/**
* @param mixed $adminOnly
* @param bool|string $adminOnly
*/
public function setAdminOnly($adminOnly)
{
Expand Down Expand Up @@ -1420,4 +1427,21 @@ public function getFinder($metadataPrefix)

return $finder;
}

/**
* Checks if a base url has been set.
*
* @return void
* @throws Zend_Exception
*/
private function checkBaseUrl()
{
$baseUrl = $this->getBaseUrl();

if (empty($baseUrl)) {
$message = 'No base url set.';
Log::get()->err($message);
throw new Exception($message);
}
}
}
13 changes: 13 additions & 0 deletions modules/oai/views/helpers/ListMetaDataFormats.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Common\Log;
use Opus\Common\Security\Realm;

/**
Expand Down Expand Up @@ -60,6 +61,18 @@ public function listMetadataFormats()

if ($server->isVisible() && (! $server->isAdminOnly() || Realm::getInstance()->checkModule('admin'))) {
if ($prefix) {
if (empty($schemaUrl)) {
$message = 'No schema url set.';
Log::get()->err($message);
throw new Exception($message);
}

if (empty($metadataNamespaceUrl)) {
$message = 'No metadata namespace url set.';
Log::get()->err($message);
throw new Exception($message);
}

$output .= '<metadataFormat>'
. "<metadataPrefix><xsl:text>$prefix</xsl:text></metadataPrefix>"
. "<schema><xsl:text>$schemaUrl</xsl:text></schema>"
Expand Down
Loading

0 comments on commit 6f70e08

Please sign in to comment.