Skip to content

Commit

Permalink
Merge pull request #313 from effective-webwork/issue-1947
Browse files Browse the repository at this point in the history
#1947: Differentiate the answer depending on the workflow status (for…
  • Loading branch information
Erikmitk authored Dec 17, 2024
2 parents ba72997 + b98204e commit 278dba1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 27 deletions.
13 changes: 13 additions & 0 deletions Classes/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ public function showAction($document, $token) {
/** @var Document $doc */
$doc = $this->documentManager->read($document);

if ($doc->getState() === DocumentWorkflow::STATE_NEW_NONE) {
return '{"error": "workflowState: \'new\' - No data is provided for documents in this workflowState."}';
}

if ($doc->getLocalState() === DocumentWorkflow::LOCAL_STATE_IN_PROGRESS) {
if ($doc->getRemoteState() === DocumentWorkflow::REMOTE_STATE_NONE) {
return '{"error": "workflowState: \'in_progress\' - No data is provided for documents in this workflowState."}';
}

// Return the remote document instead of the local working copy.
$doc = $this->documentManager->readRemoteData($document);
}

if ($doc) {
$this->security->getUser()->getUid();

Expand Down
32 changes: 32 additions & 0 deletions Classes/Services/Document/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,38 @@ public function read($identifier)
return $document;
}


/**
* Returns a document specified by repository object identifier, no local copy will be created.
* Due to FIS-Api requirement for released documents with state in_progress (local working copy exists).
*
* @param string $identifier
* @return Document|null
*/
public function readRemoteData($identifier)
{
if (!$identifier) {
return null;
}

$query = $this->queryBuilder->buildQuery(
1, [], 0,
[], [], [], null, null,
'identifier:"' . $identifier . '"'
);
$results = $this->elasticSearch->search($query, 'object');
if (is_array($results) && $results['hits']['total']['value'] > 0) {
$remoteIdentifier = $results['hits']['hits'][0]['_id'];
}

if ($remoteIdentifier) {
$document = $this->documentStorage->retrieve($identifier, false);
return $document;
}

return null;
}

/**
* Updates a document locally or remotely.
*
Expand Down
60 changes: 33 additions & 27 deletions Classes/Services/Storage/DocumentStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,13 @@ public function update(Document $document, string $state = null)

/**
* @param string $documentIdentifier
* @param bool $createLocalCopy
* @return Document|null
* @throws ConnectionException
* @throws IllegalObjectTypeException
* @throws RetrieveDocumentException
*/
public function retrieve(string $documentIdentifier) : ?Document
public function retrieve(string $documentIdentifier, bool $createLocalCopy = true) : ?Document
{
try {

Expand Down Expand Up @@ -451,35 +452,40 @@ public function retrieve(string $documentIdentifier) : ?Document

$document->setTemporary(true);

$this->documentRepository->add($document);
$this->persistenceManager->persistAll();

foreach ($internalFormat->getFiles() as $attachment) {

/** @var File $file */
$file = $this->objectManager->get(File::class);
$file->setContentType($attachment['mimetype']);
$file->setDatastreamIdentifier($attachment['id']);
$file->setFileIdentifier($attachment['id']);
$file->setLink($attachment['href']);
$file->setTitle($attachment['title']);
$file->setLabel($attachment['title']);
$file->setDownload($attachment['download']);
$file->setArchive($attachment['archive']);
$file->setFileGroupDeleted($attachment['deleted']);

if ($attachment['id'] == \EWW\Dpf\Domain\Model\File::PRIMARY_DATASTREAM_IDENTIFIER) {
$file->setPrimaryFile(true);
}
// $createLocalCopy = false is needed for the Fis api to be able to return only the
// remote version of the document metadata in case of a local workingcopy.
if ($createLocalCopy) {
$this->documentRepository->add($document);
$this->persistenceManager->persistAll();


foreach ($internalFormat->getFiles() as $attachment) {

/** @var File $file */
$file = $this->objectManager->get(File::class);
$file->setContentType($attachment['mimetype']);
$file->setDatastreamIdentifier($attachment['id']);
$file->setFileIdentifier($attachment['id']);
$file->setLink($attachment['href']);
$file->setTitle($attachment['title']);
$file->setLabel($attachment['title']);
$file->setDownload($attachment['download']);
$file->setArchive($attachment['archive']);
$file->setFileGroupDeleted($attachment['deleted']);

if ($attachment['id'] == \EWW\Dpf\Domain\Model\File::PRIMARY_DATASTREAM_IDENTIFIER) {
$file->setPrimaryFile(true);
}

$file->setDocument($document);
$file->setDocument($document);

$this->fileRepository->add($file);
$document->addFile($file);
}
$this->fileRepository->add($file);
$document->addFile($file);
}

$this->documentRepository->update($document);
$this->persistenceManager->persistAll();
$this->documentRepository->update($document);
$this->persistenceManager->persistAll();
}

return $document;

Expand Down

0 comments on commit 278dba1

Please sign in to comment.