Skip to content

Commit

Permalink
#1251 Move Sword classes to opus4-sword
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Oct 30, 2024
1 parent 7688a75 commit c6a5cef
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 736 deletions.
99 changes: 0 additions & 99 deletions library/Application/Configuration/MaxUploadSize.php

This file was deleted.

29 changes: 16 additions & 13 deletions modules/sword/controllers/DepositController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Application\Config\MaxUploadSize;
use Opus\Common\Log;
use Opus\Import\AdditionalEnrichments;
use Opus\Import\ImportStatusDocument;
use Opus\Import\Xml\MetadataImportInvalidXmlException;
use Opus\Sword\AtomEntryDocument;
use Opus\Sword\ErrorDocument;

/**
* TODO use OPUS 4 base class?
Expand Down Expand Up @@ -60,15 +63,15 @@ public function postAction()

$userName = Application_Security_BasicAuthProtection::accessAllowed($request, $response);
if (! $userName) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setForbidden();
return;
}

// mediated deposit is currently not supported by OPUS
$mediatedDeposit = $request->getHeader('X-On-Behalf-Of');
if ($mediatedDeposit !== null && $mediatedDeposit !== false) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setMediationNotAllowed();
return;
}
Expand All @@ -78,15 +81,15 @@ public function postAction()
$contentType = $request->getHeader('Content-Type');
$packageHandler = new Sword_Model_PackageHandler($contentType);
} catch (Exception $e) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setErrorContent();
return;
}

// check that package size does not exceed maximum upload size
$payload = $request->getRawBody();
if ($this->maxUploadSizeExceeded($payload)) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setPayloadTooLarge();
return;
}
Expand All @@ -96,7 +99,7 @@ public function postAction()
$additionalEnrichments = $this->getAdditionalEnrichments($userName, $request);
$packageHandler->setAdditionalEnrichments($additionalEnrichments);
} catch (Exception $ex) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setMissingImportEnrichmentKey();
return;
}
Expand All @@ -106,7 +109,7 @@ public function postAction()
if ($checksum !== null) {
$checksumPayload = md5($payload);
if (strcasecmp($checksum, $checksumPayload) !== 0) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setErrorChecksumMismatch($checksum, $checksumPayload);
return;
}
Expand All @@ -126,19 +129,19 @@ public function postAction()
$statusDoc = $packageHandler->handlePackage($payload);
if ($statusDoc === null) {
// im Archiv befindet sich keine Datei opus.xml oder die Datei ist leer
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setMissingXml();
} elseif ($statusDoc->noDocImported()) {
// im Archiv befindet sich zwar ein nicht leeres opus.xml; es
// konnte aber kein Dokument erfolgreich importiert werden
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setInternalFrameworkError();
}
} catch (MetadataImportInvalidXmlException $ex) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
$errorDoc->setInvalidXml();
} catch (Exception $ex) {
$errorDoc = new Sword_Model_ErrorDocument($request, $response);
$errorDoc = new ErrorDocument($request, $response);
}

if ($errorDoc !== null) {
Expand All @@ -165,11 +168,11 @@ private function returnAtomEntryDocument($statusDoc, $request, $response, $userN

/**
* @param ImportStatusDocument $statusDoc
* @return Sword_Model_AtomEntryDocument
* @return AtomEntryDocument
*/
private function createAtomEntryDocument($statusDoc)
{
$atomEntryDoc = new Sword_Model_AtomEntryDocument();
$atomEntryDoc = new AtomEntryDocument();
$atomEntryDoc->setEntries($statusDoc->getDocs());
return $atomEntryDoc;
}
Expand All @@ -184,7 +187,7 @@ private function maxUploadSizeExceeded($payload)
// retrieve number of bytes (not characters) of HTTP payload (SWORD package)
$size = mb_strlen($payload, '8bit');

$maxUploadSize = (new Application_Configuration_MaxUploadSize())->getMaxUploadSizeInByte();
$maxUploadSize = (new MaxUploadSize())->getMaxUploadSizeInByte();
if ($size > $maxUploadSize) {
$log = Log::get();
$log->warn('current package size ' . $size . ' exceeds the maximum upload size ' . $maxUploadSize);
Expand Down
3 changes: 2 additions & 1 deletion modules/sword/controllers/ServicedocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

use Opus\Common\Config;
use Opus\Sword\ServiceDocument;

class Sword_ServicedocumentController extends Zend_Rest_Controller
{
Expand Down Expand Up @@ -83,7 +84,7 @@ private function setErrorDocument($response)
private function setServiceDocument($response)
{
$fullUrl = $this->view->fullUrl();
$serviceDocument = new Sword_Model_ServiceDocument($fullUrl);
$serviceDocument = new ServiceDocument($fullUrl);
$domDocument = $serviceDocument->getDocument();

$config = Config::get();
Expand Down
Loading

0 comments on commit c6a5cef

Please sign in to comment.