Orzu Ionut
3 years ago
7 changed files with 186 additions and 33 deletions
-
2.idea/vcs.xml
-
3app/Http/Controllers/SearchAndDisplaceOriginalDocumentController.php
-
42app/SearchDisplace/Ingest/HandleReceivedDocument.php
-
73app/SearchDisplace/Ingest/SendDataToRecreateDocument.php
-
68app/SearchDisplace/SearchAndDisplaceOriginalDocument.php
-
16public/js/app.js
-
15resources/js/components/ProcessFile/ProcessFile.ts
@ -1,6 +1,6 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="VcsDirectoryMappings"> |
|||
<mapping directory="$PROJECT_DIR$" vcs="Git" /> |
|||
<mapping directory="" vcs="Git" /> |
|||
</component> |
|||
</project> |
@ -0,0 +1,73 @@ |
|||
<?php |
|||
|
|||
namespace App\SearchDisplace\Ingest; |
|||
|
|||
use GuzzleHttp\Client; |
|||
use GuzzleHttp\Exception\ClientException; |
|||
|
|||
class SendDataToRecreateDocument |
|||
{ |
|||
protected $url; |
|||
|
|||
public function __construct() |
|||
{ |
|||
$this->url = env('SD_INGEST_URL') . '/recreate-document'; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param $id |
|||
* @param $data |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
* @throws \Exception |
|||
*/ |
|||
public function execute($id, $data) |
|||
{ |
|||
$response = $this->sendRequest($id, $data); |
|||
|
|||
if ( ! array_key_exists('status', $response)) { |
|||
throw new \Exception('Something went wrong.'); |
|||
} |
|||
|
|||
if ($response['status'] === 'fail') { |
|||
$message = array_key_exists('message', $response) |
|||
? $response['message'] |
|||
: 'Something went wrong.'; |
|||
|
|||
throw new \Exception($message); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Send request to Ingest to recreate document. |
|||
* |
|||
* @param $id |
|||
* @param $data |
|||
* @return mixed |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
* @throws \Exception |
|||
*/ |
|||
public function sendRequest($id, $data) |
|||
{ |
|||
$client = new Client(); |
|||
|
|||
try { |
|||
$response = $client->request('post', $this->url, [ |
|||
'headers' => [ |
|||
'Accept' => 'application/json', |
|||
], |
|||
|
|||
'form_params' => [ |
|||
'id' => $id, |
|||
'data' => json_encode($data), |
|||
], |
|||
]); |
|||
|
|||
return json_decode($response->getBody()->getContents(), true); |
|||
} catch (ClientException $clientException) { |
|||
$error = json_decode($clientException->getResponse()->getBody()->getContents(), true); |
|||
|
|||
throw new \Exception($error['message']); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue