/**
  * Parse input structure.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     $contentType = null;
     if (array_key_exists('ContentType', $data) && is_array($data['ContentType'])) {
         if (!array_key_exists('_href', $data['ContentType'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for ContentType element in UserCreate.");
         }
         $contentType = $this->contentTypeService->loadContentType($this->requestParser->parseHref($data['ContentType']['_href'], 'contentTypeId'));
     }
     if (!array_key_exists('mainLanguageCode', $data)) {
         throw new Exceptions\Parser("Missing 'mainLanguageCode' element for UserCreate.");
     }
     if (!array_key_exists('login', $data)) {
         throw new Exceptions\Parser("Missing 'login' element for UserCreate.");
     }
     if (!array_key_exists('email', $data)) {
         throw new Exceptions\Parser("Missing 'email' element for UserCreate.");
     }
     if (!array_key_exists('password', $data)) {
         throw new Exceptions\Parser("Missing 'password' element for UserCreate.");
     }
     $userCreateStruct = $this->userService->newUserCreateStruct($data['login'], $data['email'], $data['password'], $data['mainLanguageCode'], $contentType);
     if (array_key_exists('Section', $data) && is_array($data['Section'])) {
         if (!array_key_exists('_href', $data['Section'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for Section element in UserCreate.");
         }
         $userCreateStruct->sectionId = $this->requestParser->parseHref($data['Section']['_href'], 'sectionId');
     }
     if (array_key_exists('remoteId', $data)) {
         $userCreateStruct->remoteId = $data['remoteId'];
     }
     if (array_key_exists('enabled', $data)) {
         $userCreateStruct->enabled = $this->parserTools->parseBooleanValue($data['enabled']);
     }
     if (!array_key_exists('fields', $data) || !is_array($data['fields']) || !is_array($data['fields']['field'])) {
         throw new Exceptions\Parser("Missing or invalid 'fields' element for UserCreate.");
     }
     foreach ($data['fields']['field'] as $fieldData) {
         if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
             throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for UserCreate.");
         }
         $fieldDefinition = $userCreateStruct->contentType->getFieldDefinition($fieldData['fieldDefinitionIdentifier']);
         if (!$fieldDefinition) {
             throw new Exceptions\Parser("'{$fieldData['fieldDefinitionIdentifier']}' is invalid field definition identifier for '{$userCreateStruct->contentType->identifier}' content type in UserCreate.");
         }
         if (!array_key_exists('fieldValue', $fieldData)) {
             throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in UserCreate.");
         }
         $fieldValue = $this->fieldTypeParser->parseValue($fieldDefinition->fieldTypeIdentifier, $fieldData['fieldValue']);
         $languageCode = null;
         if (array_key_exists('languageCode', $fieldData)) {
             $languageCode = $fieldData['languageCode'];
         }
         $userCreateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
     }
     return $userCreateStruct;
 }
 /**
  * @Given /^there is a User Content$/
  */
 public function thereIsAUserContent()
 {
     $login = '******' . microtime(true);
     $email = $login . '@example.com';
     $struct = $this->userService->newUserCreateStruct($login, $email, 'publish', 'eng-GB');
     $struct->setField('first_name', 'John');
     $struct->setField('last_name', 'Doe');
     $parentGroup = $this->userService->loadUserGroup(11);
     $user = $this->userService->createUser($struct, [$parentGroup]);
     $this->currentContent = $this->contentService->loadContentByContentInfo($user->contentInfo);
 }
 /**
  * Create user inside given User Group; DELETES existing User if login already exists!
  *
  * @param $username username of the user to create
  * @param $email email address of user to create
  * @param $password account password for user to create
  * @param $parentGroup pathstring wherein to create user
  *
  * @return eZ\Publish\API\Repository\Values\User\User
  */
 protected function createUser($username, $email, $password, $parentGroup = null, $fields = array())
 {
     $userCreateStruct = $this->userService->newUserCreateStruct($username, $email, $password, self::DEFAULT_LANGUAGE);
     $userCreateStruct->setField('first_name', $username);
     $userCreateStruct->setField('last_name', $username);
     foreach ($fields as $fieldName => $fieldValue) {
         $userCreateStruct->setField($fieldName, $fieldValue);
     }
     try {
         $existingUser = $this->userService->loadUserByLogin($username);
         $this->userService->deleteUser($existingUser);
     } catch (NotFoundException $e) {
         // do nothing
     }
     if (!$parentGroup) {
         $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID);
     }
     $user = $this->userService->createUser($userCreateStruct, array($parentGroup));
     return $user;
 }
 /**
  * Instantiate a user create class
  *
  * @param string $login the login of the new user
  * @param string $email the email of the new user
  * @param string $password the plain password of the new user
  * @param string $mainLanguageCode the main language for the underlying content object
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
  */
 public function newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType = null)
 {
     return $this->service->newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType);
 }
 /**
  * Creates and prepares user structure
  *
  * @param array $data
  * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
  */
 private function getUserStruct(array &$data)
 {
     $struct = $this->userService->newUserCreateStruct('', '', '', '');
     $this->fillValueObject($struct, $data, ['content_type']);
     return $struct;
 }