/**
  * Handle individual entity
  *
  * @param Transaction         $transaction Transaction
  * @param CrudEntityInterface $entity      Entity
  *
  * @return void
  */
 private function handleEntity($transaction, CrudEntityInterface $entity)
 {
     $transaction->setRequestSource(Transaction::SOURCE_SERVICE);
     $transaction->setId(UUID::generate());
     $transaction->setRequestId(microtime());
     $transaction->setRelatedIds($entity->getIds());
     $errors = $this->errorBuilder->getEntityErrors($entity->getPrimaryKey());
     $messages = new ArrayCollection();
     $success = $errors->isEmpty();
     $status = $success ? Transaction::STATUS_CREATED : Transaction::STATUS_CONFLICT;
     $transaction->setStatus($status);
     $transaction->setSuccess($success);
     if ($success) {
         $this->noticeBuilder->addSuccess();
     } else {
         $messages->set('errors', $errors);
         $this->noticeBuilder->addFail();
     }
     $transaction->setMessages($messages);
     $em = $this->registry->getManagerForClass(get_class($transaction));
     $em->persist($transaction);
     $entity->setTransaction($transaction);
 }
 /**
  * Building transaction
  *
  * @return Transaction
  */
 public function build()
 {
     $datetime = new \DateTime();
     $transaction = new Transaction();
     $transaction->setMethod($this->requestMethod)->setRelatedRoute($this->relatedRoute)->setRelatedIds($this->relatedIds)->setRequestId(microtime())->setId(UUID::generate())->setRequestSource($this->requestSource)->setModel($this->model)->setCreatedAt($datetime)->setUpdatedAt($datetime);
     return $transaction;
 }