Validate a Message instance

@param EntityInterface $entity

@return bool

@throws Exception
358298
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof UserGroup) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Role::class)
            );
        }

        $this->validateName($entity->getName());
        $this->validateDefaultRole($entity->getDefaultRole());
        $errors = $this->getErrors();

        return empty($errors);
    }
1360687
public function objectToRequest(EntityInterface $entity)
    {
        $data = $entity->get();

        $properties = [];
        foreach ($data as $key => $value) {
            $exclude = in_array($key, $entity->excludedProperties());
            $meaning = (isset($entity->meanings()[$key]))
                ? $entity->meanings()[$key]
                : null;

            $properties[$key] = $this->valueObject(
                $value,
                $exclude,
                $meaning
            );
        }

        $key = $entity->key()
            ? $entity->key()->keyObject()
            : null;

        return array_filter([
            'key' => $key,
            'properties' => $properties
        ]);
    }
1143821
public function isNewEntity(EntityInterface $entity)
    {
        $reflection = $this->getEntityClassReflection();
        $metadata = $this->getEntityMetadata();
        $identifier = $metadata->getName($metadata->getIdentifier(), Metadata::CAMILIZED);
        
        return null !== $identifier
            ? ($reflection->getProperty($identifier)->getValue($entity) === null) : true;
    }
292537
protected function formatKeyCondition(EntityInterface $entity)
    {
        $attributes = array(
            $entity::getHashKeyAttribute() => $entity->getHashKey(),
        );

        $rangeKeyAttribute = $entity::getRangeKeyAttribute();
        if ($rangeKeyAttribute !== false) {
            $attributes[$rangeKeyAttribute] = $entity->getRangeKey();
        }

        return $this->formatAttributes(get_class($entity), $attributes);
    }
310461
public function saveEntity(EntityInterface $entity)
    {
        $check = $this->storage->fetchEntityById($entity->getIdentifier());

        if ($check) {
            return $this->storage->updateEntity($entity);
        } else {
            return $this->storage->insertEntity($entity);
        }
    }
1351678
protected function canDecryptField(EntityInterface $entity, string $field): bool
    {
        if (!$this->getTable()->hasField($field)) {
            return false;
        }
        $decryptAll = $this->getConfig('decryptAll');
        if ($decryptAll === true) {
            return true;
        }

        $fields = $this->getFields();
        if (!isset($fields[$field])) {
            return false;
        }

        $decrypt = $fields[$field]['decrypt'];
        if (is_callable($decrypt)) {
            $decrypt = $decrypt($entity, $field);
        }

        return $decrypt;
    }
674219
public function decode(EntityInterface $entity) {
		$idField = $this->_primaryKey;
		$hashid = $entity->get($idField);
		if (!$hashid) {
			return false;
		}

		$field = $this->_config['field'];
		if (!$field) {
			return false;
		}

		$id = $this->decodeHashid($hashid);

		$entity->set($field, $id);
		$entity->setDirty($field, false);

		return true;
	}
306712
protected function removeEntity(EntityInterface $entity)
    {
        Orm::getRepository($this->getEntityClassName())
            ->getIdentityMap()
            ->remove($entity);
    }
461652
public function propertyExists(EntityInterface $entity, $property)
    {
        $visibleProperties = $entity->visibleProperties();

        return in_array($property, $visibleProperties);
    }
124694
public function saveEntity(EntityInterface $entity)
    {
        $checkEntity = $this->getTable()->fetchEntityById($entity->getIdentifier());

        if ($checkEntity) {
            return $this->getTable()->updateEntity($entity);
        } else {
            return $this->getTable()->insertEntity($entity);
        }
    }
871997
public function validate(ValidatorInterface $validator) {
        $validator->validate($this->getEntity());
        $messages = $validator->getMessages();
        if(is_array($messages)) {
            foreach($messages as $message) {
                $this->getEntity()->appendMessage($message);
            }
        }
    }
412538
protected function registerEntity(EntityInterface $entity)
    {
        Orm::getRepository($this->getEntityClassName())
            ->getIdentityMap()
            ->set($entity);
        return $this;
    }
1230987
public function lock(EntityInterface $entity, RepositoryInterface $repository)
    {
        return $this->setStateFor(State::LOCKED, $entity, $repository);
    }
80978
public function load(EntityInterface $entity)
    {
        $adapter = $this->getAdapter();

        $relTable = $this->getParentTableName();
        $relPmk = $this->getParentPrimaryKey();

        $table = $this->getEntityDescriptor()->getTableName();
        $pmk = $this->getEntityDescriptor()->getPrimaryKey();
        $fnk = $this->getForeignKey();

        $onClause = "{$relTable}.{$relPmk} = {$table}.{$fnk}";

        $data = Sql::createSql($adapter)
            ->select($relTable)
            ->join($table, $onClause, null)
            ->where([
                "{$table}.{$pmk->getField()} = :id" => [
                    ':id' => $entity->{$pmk->getName()}
                ]
            ])
            ->first();

        $relEntity = $this->getParentEntityMapper()->createFrom($data);

        return null == $relEntity ? null :$this->registerEntity($relEntity);
    }
514334
public function addEntity(EntityInterface $entity)
    {
        if (!is_a($entity, $this->type)) {
            throw new InvalidArgumentException(
                "Trying to add an entity that is not a {$this->type}."
            );
        }
        $this->data[] = $entity;
        $event = new EntityAdded($entity, ['collection' => $this]);
        $this->getEmitter()->emit($event);
        return $this;
    }
650323
protected function _emailVerification(EntityInterface &$entity, $options) {
		if ($options['emailVerification'] === true) {
			$entity->set($this->_field('emailToken'), $this->generateToken($options['tokenLength']));
			if ($options['verificationExpirationTime'] !== false) {
				$entity->set($this->_field('emailTokenExpires'), $this->expirationTime($options['verificationExpirationTime']));
			}
			$entity->set($this->_field('emailVerified'), false);
		} else {
			$entity->set($this->_field('emailVerified'), true);
		}
	}
383952
public function validate ($entity, Constraint $constraint)
    {
        if (!$entity instanceof ClientBillingAddressInterface) {
            throw new \InvalidArgumentException('Expected instance of ClientBillingAddressInterface');
        }
        
        if (false === $entity->isCompanyAddress()) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            
            if (false === $this->isValidCompanyName($entity)) {
                $this->context->buildViolation('client.company_name_not_valid')->atPath('companyName')->addViolation();
            }
            
            if (false === $this->isValidVatId($entity)) {
                $this->context->buildViolation('client.vatid_not_valid')->atPath('vatId')->addViolation();
            }
        }
    }