/**
  * Post metadata to ElasticSearch
  *
  * @param $id
  */
 public function postMetadata($id)
 {
     $contract = $this->contract->find($id);
     $updated_by = ['name' => '', 'email' => ''];
     if (!empty($contract->updated_user)) {
         $updated_by = ['name' => $contract->updated_user->name, 'email' => $contract->updated_user->email];
     }
     $contract->metadata->contract_id = $contract->id;
     $contract->metadata->page_number = $contract->pages()->count();
     $translatedFrom = [];
     $metadataAttr = $contract->metadata;
     if (isset($contract->metadata->translated_from) && !empty($contract->metadata->translated_from)) {
         $translatedFrom = $this->contract->getcontracts((int) $contract->metadata->translated_from);
     }
     $metadataAttr->translated_from = $translatedFrom;
     $contract->metadata = $metadataAttr;
     $metadata = ['id' => $contract->id, 'metadata' => collect($contract->metadata)->toJson(), 'total_pages' => $contract->pages->count(), 'created_by' => json_encode(['name' => $contract->created_user->name, 'email' => $contract->created_user->email]), 'supporting_contracts' => $this->contract->getSupportingDocuments($contract->id), 'updated_by' => json_encode($updated_by), 'created_at' => $contract->created_datetime->format('Y-m-d H:i:s'), 'updated_at' => $contract->last_updated_datetime->format('Y-m-d H:i:s')];
     try {
         $request = $this->http->post($this->apiURL('contract/metadata'), null, $metadata);
         $response = $request->send();
         $this->logger->info('Metadata successfully submitted to Elastic Search.', $response->json());
     } catch (Exception $e) {
         $this->logger->error($e->getMessage());
     }
 }
 /**
  * Display specified contract
  *
  * @return Response
  */
 public function show($id)
 {
     $contract = $this->contract->findWithAnnotations($id);
     if (!$contract) {
         abort('404');
     }
     $translatedFrom = [];
     if (isset($contract->metadata->translated_from) && !empty($contract->metadata->translated_from)) {
         $translatedFrom = $this->contract->getcontracts($contract->metadata->translated_from);
     }
     $supportingDocument = $this->contract->getSupportingDocuments($contract->id);
     $status = $this->contract->getStatus($id);
     $annotationStatus = $this->annotation->getStatus($id);
     $annotations = $contract->annotations;
     $contract->metadata_comment = $this->comment->getLatest($contract->id, Comment::TYPE_METADATA);
     $contract->text_comment = $this->comment->getLatest($contract->id, Comment::TYPE_TEXT);
     $contract->annotation_comment = $this->comment->getLatest($contract->id, Comment::TYPE_ANNOTATION);
     return view('contract.show', compact('contract', 'status', 'annotations', 'annotationStatus', 'translatedFrom', 'supportingDocument'));
 }