/**
  * Updates $location in the content repository
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to update this location
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException   if if set the remoteId exists already
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param \eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct $locationUpdateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location the updated Location
  */
 public function updateLocation(APILocation $location, LocationUpdateStruct $locationUpdateStruct)
 {
     if ($locationUpdateStruct->priority !== null && !is_int($locationUpdateStruct->priority)) {
         throw new InvalidArgumentValue("priority", $locationUpdateStruct->priority, "LocationUpdateStruct");
     }
     if ($locationUpdateStruct->remoteId !== null && (!is_string($locationUpdateStruct->remoteId) || empty($locationUpdateStruct->remoteId))) {
         throw new InvalidArgumentValue("remoteId", $locationUpdateStruct->remoteId, "LocationUpdateStruct");
     }
     if ($locationUpdateStruct->sortField !== null && !$this->domainMapper->isValidLocationSortField($locationUpdateStruct->sortField)) {
         throw new InvalidArgumentValue("sortField", $locationUpdateStruct->sortField, "LocationUpdateStruct");
     }
     if ($locationUpdateStruct->sortOrder !== null && !$this->domainMapper->isValidLocationSortOrder($locationUpdateStruct->sortOrder)) {
         throw new InvalidArgumentValue("sortOrder", $locationUpdateStruct->sortOrder, "LocationUpdateStruct");
     }
     $loadedLocation = $this->loadLocation($location->id);
     if ($locationUpdateStruct->remoteId !== null) {
         try {
             $existingLocation = $this->loadLocationByRemoteId($locationUpdateStruct->remoteId);
             if ($existingLocation !== null) {
                 throw new InvalidArgumentException("locationUpdateStruct", "location with provided remote ID already exists");
             }
         } catch (APINotFoundException $e) {
         }
     }
     if (!$this->repository->canUser('content', 'edit', $loadedLocation->getContentInfo(), $loadedLocation)) {
         throw new UnauthorizedException('content', 'edit');
     }
     $updateStruct = new UpdateStruct();
     $updateStruct->priority = $locationUpdateStruct->priority !== null ? $locationUpdateStruct->priority : $loadedLocation->priority;
     $updateStruct->remoteId = $locationUpdateStruct->remoteId !== null ? trim($locationUpdateStruct->remoteId) : $loadedLocation->remoteId;
     $updateStruct->sortField = $locationUpdateStruct->sortField !== null ? $locationUpdateStruct->sortField : $loadedLocation->sortField;
     $updateStruct->sortOrder = $locationUpdateStruct->sortOrder !== null ? $locationUpdateStruct->sortOrder : $loadedLocation->sortOrder;
     $this->repository->beginTransaction();
     try {
         $this->persistenceHandler->locationHandler()->update($updateStruct, $loadedLocation->id);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->loadLocation($loadedLocation->id);
 }
 /**
  * Validates input ContentType create struct.
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeCreateStruct $contentTypeCreateStruct
  *
  * @return void
  */
 protected function validateInputContentTypeCreateStruct(APIContentTypeCreateStruct $contentTypeCreateStruct)
 {
     // Required properties
     if ($contentTypeCreateStruct->identifier === null) {
         throw new InvalidArgumentException("\$contentTypeCreateStruct", "Property 'identifier' is required");
     }
     if (!is_string($contentTypeCreateStruct->identifier)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->identifier", "string", $contentTypeCreateStruct->identifier);
     }
     if ($contentTypeCreateStruct->identifier === "") {
         throw new InvalidArgumentValue("\$contentTypeCreateStruct->identifier", $contentTypeCreateStruct->identifier);
     }
     if ($contentTypeCreateStruct->mainLanguageCode === null) {
         throw new InvalidArgumentException("\$contentTypeCreateStruct", "Property 'mainLanguageCode' is required");
     }
     if (!is_string($contentTypeCreateStruct->mainLanguageCode)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->mainLanguageCode", "string", $contentTypeCreateStruct->mainLanguageCode);
     }
     if ($contentTypeCreateStruct->mainLanguageCode === "") {
         throw new InvalidArgumentValue("\$contentTypeCreateStruct->mainLanguageCode", $contentTypeCreateStruct->mainLanguageCode);
     }
     if ($contentTypeCreateStruct->names !== null) {
         $this->domainMapper->validateTranslatedList($contentTypeCreateStruct->names, "\$contentTypeCreateStruct->names");
     }
     if (!isset($contentTypeCreateStruct->names[$contentTypeCreateStruct->mainLanguageCode]) || $contentTypeCreateStruct->names[$contentTypeCreateStruct->mainLanguageCode] === "") {
         throw new InvalidArgumentException("\$contentTypeCreateStruct->names", "At least one name in the main language is required");
     }
     // Optional properties
     if ($contentTypeCreateStruct->descriptions !== null) {
         $this->domainMapper->validateTranslatedList($contentTypeCreateStruct->descriptions, "\$contentTypeCreateStruct->descriptions");
     }
     if ($contentTypeCreateStruct->defaultSortField !== null && !$this->domainMapper->isValidLocationSortField($contentTypeCreateStruct->defaultSortField)) {
         throw new InvalidArgumentValue("\$contentTypeCreateStruct->defaultSortField", $contentTypeCreateStruct->defaultSortField);
     }
     if ($contentTypeCreateStruct->defaultSortOrder !== null && !$this->domainMapper->isValidLocationSortOrder($contentTypeCreateStruct->defaultSortOrder)) {
         throw new InvalidArgumentValue("\$contentTypeCreateStruct->defaultSortOrder", $contentTypeCreateStruct->defaultSortOrder);
     }
     if ($contentTypeCreateStruct->creatorId !== null) {
         $this->repository->getUserService()->loadUser($contentTypeCreateStruct->creatorId);
     }
     if ($contentTypeCreateStruct->creationDate !== null && !$contentTypeCreateStruct->creationDate instanceof DateTime) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->creationDate", "DateTime", $contentTypeCreateStruct->creationDate);
     }
     if ($contentTypeCreateStruct->defaultAlwaysAvailable !== null && !is_bool($contentTypeCreateStruct->defaultAlwaysAvailable)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->defaultAlwaysAvailable", "boolean", $contentTypeCreateStruct->defaultAlwaysAvailable);
     }
     if ($contentTypeCreateStruct->isContainer !== null && !is_bool($contentTypeCreateStruct->isContainer)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->isContainer", "boolean", $contentTypeCreateStruct->isContainer);
     }
     if ($contentTypeCreateStruct->remoteId !== null && !is_string($contentTypeCreateStruct->remoteId)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->remoteId", "string", $contentTypeCreateStruct->remoteId);
     }
     if ($contentTypeCreateStruct->nameSchema !== null && !is_string($contentTypeCreateStruct->nameSchema)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->nameSchema", "string", $contentTypeCreateStruct->nameSchema);
     }
     if ($contentTypeCreateStruct->urlAliasSchema !== null && !is_string($contentTypeCreateStruct->urlAliasSchema)) {
         throw new InvalidArgumentType("\$contentTypeCreateStruct->urlAliasSchema", "string", $contentTypeCreateStruct->urlAliasSchema);
     }
     if (empty($contentTypeCreateStruct->fieldDefinitions)) {
         throw new InvalidArgumentException("\$contentTypeCreateStruct", "Argument must contain at least one FieldDefinitionCreateStruct");
     }
     foreach ($contentTypeCreateStruct->fieldDefinitions as $key => $fieldDefinitionCreateStruct) {
         if (!$fieldDefinitionCreateStruct instanceof FieldDefinitionCreateStruct) {
             throw new InvalidArgumentType("\$contentTypeCreateStruct->fieldDefinitions[{$key}]", "eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinitionCreateStruct", $fieldDefinitionCreateStruct);
         }
         $this->validateInputFieldDefinitionCreateStruct($fieldDefinitionCreateStruct, "\$contentTypeCreateStruct->fieldDefinitions[{$key}]");
     }
 }