/**
  * @param AlmEntity $entity
  * @return AlmEntity
  * @throws AlmEntityManagerException
  * @throws Exception\AlmCurlException
  * @throws Exception\AlmException
  */
 public function save(AlmEntity $entity)
 {
     $headers = array('Accept: application/xml', 'Content-Type: application/xml');
     if ($entity->isNew()) {
         $entityXml = $this->entityExtractor->pack($entity);
         array_push($headers, 'POST /HTTP/1.1');
         $this->curl->setHeaders($headers)->setPost($entityXml->asXML())->exec($this->routes->getEntityUrl($entity->getTypePluralized()));
         $xml = simplexml_load_string($this->curl->getResult());
     } else {
         $entityXml = $this->entityExtractor->pack($entity, $this->parametersManager->getEntityEditableParameters($entity));
         if ($this->entityLocker->isEntityLocked($entity)) {
             if (!$this->entityLocker->isEntityLockedByMe($entity)) {
                 throw new AlmEntityManagerException('Entity is locked by someone');
             }
         } else {
             $this->entityLocker->lockEntity($entity);
         }
         if ($this->isEntityVersioning($entity)) {
             $this->getEntityLocker()->checkOutEntity($entity);
         }
         array_push($headers, 'PUT /HTTP/1.1');
         $this->curl->setHeaders($headers)->setPut($entityXml->asXML())->exec($this->routes->getEntityUrl($entity->getTypePluralized(), $entity->id));
         $xml = simplexml_load_string($this->curl->getResult());
         if ($this->isEntityVersioning($entity)) {
             $this->getEntityLocker()->checkInEntity($entity);
         }
         $this->entityLocker->unlockEntity($entity);
     }
     return $this->entityExtractor->extract($xml);
 }