Since: 5.11.18 (5.03.2016)
Author: Andrii Penchuk (a.penchuk@scalr.com)
Inheritance: extends Scalr\Model\AbstractEntity
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  * @see ApiEntityAdapter::validateEntity()
  */
 public function validateEntity($entity)
 {
     if (!$entity instanceof Team) {
         throw new InvalidArgumentException(sprintf("First argument must be instance of %s", Team::class));
     }
     if (empty($entity->name)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property name");
     }
     if (Team::findOne([['accountId' => $entity->accountId], ['name' => $entity->name], ['id' => ['$ne' => $entity->id]]])) {
         throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, "Team with name '{$entity->name}' already exists in this account");
     }
     $this->validateTeamName($entity->name);
     if (empty($entity->accountRoleId)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property defaultAclRole");
     }
     if (!(is_string($entity->accountRoleId) && preg_match('/^' . AclRole::ACL_ROLE_ID_REGEXP . '$/', $entity->accountRoleId))) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid identifier of the ACL Role");
     }
     if (empty(AclRole::findOne([['accountRoleId' => $entity->accountRoleId], ['accountId' => $entity->accountId]]))) {
         throw new ApiErrorException(404, ErrorMessage::ERR_INVALID_VALUE, "ACL Role with ID: '{$entity->accountRoleId}' is not found in this account.");
     }
 }