/**
  * @param $contractId
  * @return bool
  */
 public function execute($contractId)
 {
     $this->contract_id = $contractId;
     $contract = $this->contract->find($contractId);
     $startTime = Carbon::now();
     try {
         $this->logger->info("processing Contract", ['contractId' => $contractId]);
         list($writeFolderPath, $readFilePath) = $this->setup($contract);
         if ($this->process($writeFolderPath, $readFilePath)) {
             $pages = $this->page->buildPages($writeFolderPath);
             $this->page->savePages($contractId, $pages);
             $this->updateContractPdfStructure($contract, $writeFolderPath);
             $contract->text_status = Contract::STATUS_DRAFT;
             $contract->save();
             $this->logger->info("processing contract completed.", ['contractId' => $contractId]);
             $this->mailer->send(['email' => $contract->created_user->email, 'name' => $contract->created_user->name], "{$contract->title} processing contract completed.", 'emails.process_success', ['contract_title' => $contract->title, 'contract_id' => $contract->id, 'contract_detail_url' => route('contract.show', $contract->id), 'start_time' => $startTime->toDayDateTimeString(), 'end_time' => Carbon::now()->toDayDateTimeString()]);
             $this->contract->moveS3File($contract->file, sprintf('%s/%s', $contract->id, $contract->getS3PdfName()));
             $this->contract->updateFileName($contract);
             $this->uploadPdfsToS3($contract->id);
             $this->deleteContractFolder($contract->id);
             $this->contract->updateWordFile($contract->id);
             return true;
         }
     } catch (\Exception $e) {
         $this->processStatus(Contract::PROCESSING_FAILED);
         $this->mailer->send(['email' => $contract->created_user->email, 'name' => $contract->created_user->name], "{$contract->title} processing error.", 'emails.process_error', ['contract_title' => $contract->title, 'contract_id' => $contract->id, 'contract_detail_url' => route('contract.show', $contract->id), 'start_time' => $startTime->toDayDateTimeString(), 'error' => $e->getMessage()]);
         $this->logger->error("error processing contract.{$e->getMessage()}", ['contractId' => $contractId]);
         return false;
     }
     return false;
 }
 /**
  * Generate word file from console command
  *
  * @param $contract_id
  * @return bool
  */
 protected function generateWordFile($contract_id)
 {
     if (is_null($contract_id)) {
         $contracts = $this->contract->getProcessCompleted();
         if (!is_null($contracts)) {
             foreach ($contracts as $contract) {
                 $this->generateWordFile($contract->id);
             }
             return true;
         }
         $this->info('Contract not found');
         return false;
     }
     if ($this->contract->updateWordFile($contract_id)) {
         $this->info(sprintf('Contract %s : completed.', $contract_id));
         return true;
     } else {
         $this->info(sprintf('Contract %s : failed.', $contract_id));
         return false;
     }
 }
 /**
  * Post pdf text
  *
  * @param $id
  */
 public function postText($id)
 {
     $contract = $this->contract->findWithPages($id);
     $pages = ['contract_id' => $contract->id, 'total_pages' => $contract->pages->count(), 'pages' => $contract->pages->toJson(), 'metadata' => $this->getMetadataForES($contract->metadata)];
     try {
         $this->contract->updateWordFile($contract->id);
         $request = $this->http->post($this->apiURL('contract/pdf-text'), null, $pages);
         $response = $request->send();
         $this->logger->info('Pdf Text successfully submitted to Elastic Search.', $response->json());
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
     }
 }