|
|
@ -25,9 +25,10 @@ class SearchAndDisplaceOriginalDocument |
|
|
|
/** |
|
|
|
* @param $id |
|
|
|
* @param $contents |
|
|
|
* @param $documentFormat |
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
|
|
*/ |
|
|
|
public function applySD($id, $contents) |
|
|
|
public function applySD($id, $contents, $documentFormat) |
|
|
|
{ |
|
|
|
$data = json_decode($contents['document'], true); |
|
|
|
|
|
|
@ -46,6 +47,8 @@ class SearchAndDisplaceOriginalDocument |
|
|
|
$x = $this->applyResultsOnIngestData($data['contents'], $result); |
|
|
|
$data['contents'] = $x; |
|
|
|
|
|
|
|
$data['document_format'] = $documentFormat; |
|
|
|
|
|
|
|
$this->sendDataToIngestToRebuild($id, $data); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
\Illuminate\Support\Facades\Log::info($exception->getMessage()); |
|
|
@ -64,9 +67,16 @@ class SearchAndDisplaceOriginalDocument |
|
|
|
{ |
|
|
|
$storage = Storage::disk('local'); |
|
|
|
$basePath = "contracts/$id"; |
|
|
|
$filePath = $basePath . '-document.docx'; |
|
|
|
|
|
|
|
return ! $storage->exists($basePath) && ! $storage->exists($filePath); |
|
|
|
if ($storage->exists($basePath)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if ($this->findDocumentById($id) !== null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public function isInProgress($id) |
|
|
@ -74,8 +84,7 @@ class SearchAndDisplaceOriginalDocument |
|
|
|
$storage = Storage::disk('local'); |
|
|
|
$basePath = "contracts/$id"; |
|
|
|
|
|
|
|
// @TODO Set document extension.
|
|
|
|
return $storage->exists($basePath) && ! $storage->exists($basePath . '-document.docx'); |
|
|
|
return $storage->exists($basePath) && $this->findDocumentById($id) === null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -87,12 +96,34 @@ class SearchAndDisplaceOriginalDocument |
|
|
|
{ |
|
|
|
$storage = Storage::disk('local'); |
|
|
|
|
|
|
|
if ($this->hasFailed($id) || $this->isInProgress($id)) { |
|
|
|
throw new \Exception('Document is not processed.'); |
|
|
|
// @TODO Improve this. Right now we are calling 'findDocumentById' multiple times.
|
|
|
|
|
|
|
|
if ($this->hasFailed($id)) { |
|
|
|
throw new \Exception('Document has failed.'); |
|
|
|
} |
|
|
|
|
|
|
|
if ($this->isInProgress($id)) { |
|
|
|
throw new \Exception('Document is still processing.'); |
|
|
|
} |
|
|
|
|
|
|
|
return $storage->path($this->findDocumentById($id)); |
|
|
|
} |
|
|
|
|
|
|
|
protected function findDocumentById($id) |
|
|
|
{ |
|
|
|
$storage = Storage::disk('local'); |
|
|
|
|
|
|
|
$documentPartialPath = "contracts/$id-document"; |
|
|
|
|
|
|
|
$contractFiles = $storage->files('contracts'); |
|
|
|
|
|
|
|
foreach ($contractFiles as $contractFile) { |
|
|
|
if (substr($contractFile, 0, strlen($documentPartialPath)) === $documentPartialPath) { |
|
|
|
return $contractFile; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// @TODO Set document extension.
|
|
|
|
return $storage->path('contracts/' . $id . '-document.docx'); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
protected function applyResultsOnIngestData($ingestData, $sdResult) |
|
|
|