@param JsonApiResource $entity
@param string          $field
@param object          $item

@return mixed
@throws RestException
970164
protected function removeRelationItem(JsonApiResource $entity, $field, $item)
    {
        $remover = 'remove' . ucfirst($field);

        if (!method_exists($entity, $remover)) {
            throw RestException::missingRemover($entity, $field, $remover);
        }

        return $entity->$remover($item);
    }
762759
protected function collectIdsFromField($item, $field)
    {
        $ids = Arr::get($item, $field, []);

        return is_object($ids) && method_exists($ids, 'toArray') ? $ids->toArray() : (array) $ids;
    }
763511
protected function getRefillAttr($field, ItemEntity $item = null)
    {
        // item exists and can be refilled
        if ($item instanceof ItemEntity && $item->getName() &&
            ($plugins = $this->chain->getPluginsThatCanFillItem($item, $field))
        ) {
            /* @var $plugin RefillerInterface */
            foreach ($plugins as $key => $plugin) {
                $plugins[$key] = [
                    'name' => $plugin->getName(),
                    'title' => $plugin->getTitle(),
                    'can_refill' => $plugin->isCanRefill($item, $field), // can refill or can search
                ];
            }

            return [
                'data-type' => 'refill',
                'data-plugins' => $this->templating->render(
                    'AnimeDbCatalogBundle:Form:refillers.html.twig',
                    [
                        'item' => $item,
                        'field' => $field,
                        'plugins' => $plugins,
                    ]
                ),
            ];
        }

        return [];
    }
102408
private function processItem($item) : JsonRpcResponse
    {
        try {
            if ($item instanceof \Exception) {
                // Exception will be caught just below and converted to response
                throw $item;
            }

            return $this->jsonRpcRequestHandler->processJsonRpcRequest($item);
        } catch (\Exception $exception) {
            return $this->exceptionHandler->getJsonRpcResponseFromException(
                $exception,
                $item instanceof JsonRpcRequest ? $item : null
            );
        }
    }
1310185
public static function updateItemAsync($item_id, $item)
    {
        return self::updateItemAsyncWithHttpInfo($item_id, $item)
            ->then(
                function ($response) {
                    return $response[0];
            }
        );
    }
924319
public function isCanRefill(Item $item, $field)
    {
        return in_array($field, $this->supported_fields) && $this->getSourceForFill($item);
    }
1128458
private function getComparisonField(array $item, string $field)
    {
        if (! isset($item[$field])) {
            throw new InvalidArgumentException(sprintf('Unable to find comparison field %s', $field));
        }

        $value = $item[$field];

        return is_string($value) ? strtolower($value) : $value;
    }
466297
public function get($entity)
    {
        $key = $this->mapping['fieldname'];
        $valueMethod = 'get' . ucfirst($key);
        $value = $entity->$valueMethod();

        return $value;
    }
1339596
protected function setProperty(JsonApiResource $entity, $property, $value)
    {
        $setter = 'set' . ucfirst($property);

        if (!method_exists($entity, $setter)) {
            throw RestException::missingSetter($entity, $property, $setter);
        }

        return $entity->$setter($value);
    }
1138584
public function toResource(EntityInterface $entity, FetchRequestInterface $request, ResourceInterface $resource)
    {
        if ($request->requestedResourceBody()) {
            $this->mapAttributesToResource($entity, $request, $resource->attributes());
        }

        if ($request->requestedRelationships()) {
            $this->mapRelationshipsToResource($entity, $request, $resource->relationships());
        }

        $this->mapMetaInformationToResource($entity, $request, $resource->metaInformation());
    }
1153130
protected function indexItem(Item $item, TypoScriptConfiguration $configuration)
    {
        $indexer = $this->getIndexerByItem($item->getIndexingConfigurationName(), $configuration);

        // Remember original http host value
        $originalHttpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;

        $itemChangedDate = $item->getChanged();
        $itemChangedDateAfterIndex = 0;

        try {
            $this->initializeHttpServerEnvironment($item);
            $itemIndexed = $indexer->index($item);

            // update IQ item so that the IQ can determine what's been indexed already
            if ($itemIndexed) {
                $this->indexQueue->updateIndexTimeByItem($item);
                $itemChangedDateAfterIndex = $item->getChanged();
            }

            if ($itemChangedDateAfterIndex > $itemChangedDate && $itemChangedDateAfterIndex > time()) {
                $this->indexQueue->setForcedChangeTimeByItem($item, $itemChangedDateAfterIndex);
            }
        } catch (\Exception $e) {
            $this->restoreOriginalHttpHost($originalHttpHost);
            throw $e;
        }

        $this->restoreOriginalHttpHost($originalHttpHost);

        return $itemIndexed;
    }
886073
protected function validateEntity($entity)
    {
        $errors = Validation::createValidatorBuilder()
            ->enableAnnotationMapping()
            ->getValidator()
            ->validate($entity);

        if ($errors->count() > 0) {
            throw RestException::createFromConstraintViolationList($errors);
        }

        return $entity;
    }
626393
private function hydrateAttributes($entity, array $attributes, $scope = '')
    {
        $metadata = $this->repository()->getEntityManager()->getClassMetadata(ClassUtils::getClass($entity));

        foreach ($attributes as $name => $value) {
            if (!isset($metadata->reflFields[$name])) {
                throw RestException::unknownAttribute($scope.$name);
            }

            $this->setObjectProperty($entity, $name, $value);
        }

        return $entity;
    }
108345
private function processAttributes($data, ApiItemInterface $item)
    {
        $result = true;
        try {
            if (isset($data['attributes']) && is_array($data['attributes'])) {
                /** @var ItemAttribute $itemAttribute */
                $get = function ($itemAttribute) {
                    return $itemAttribute->getId();
                };

                $delete = function ($itemAttribute) use ($item) {
                    // Delete item.
                    $this->em->remove($itemAttribute);
                };

                /** @var ItemAttribute $itemAttribute */
                $update = function ($itemAttribute, $matchedEntry) use ($item) {
                    $itemAttribute->setAttribute($matchedEntry['attribute']);
                    $itemAttribute->setValue($matchedEntry['value']);

                    return $itemAttribute ? true : false;
                };

                $add = function ($itemData) use ($item) {
                    $itemAttribute = new ItemAttribute();
                    $itemAttribute->setAttribute($itemData['attribute']);
                    $itemAttribute->setValue($itemData['value']);
                    $itemAttribute->setItem($item->getEntity());
                    $this->em->persist($itemAttribute);

                    return $item->addAttribute($itemAttribute);
                };

                $result = $this->processSubEntities(
                    $item->getAttributes(),
                    isset($data['attributes']) ? $data['attributes'] : [],
                    $get,
                    $add,
                    $update,
                    $delete
                );
            }
        } catch (\Exception $e) {
            throw new ItemException('Error while creating attributes: ' . $e->getMessage());
        }

        return $result;
    }
604076
protected function manageFieldIndex($entity, $field)
    {
        if ($entity == null || $field == null || $this->has($this->route_name.'_'.$field.'_datatable') == false) {
            throw new \Exception('All the parameters are not correctly set');
        }
        $postDatatable = $this->get($this->route_name.'_'.$field.'_datatable');
        $postDatatable->buildDatatable(['entity' => $entity]);

        return $this->render($this->getIndexTemplate(strtolower($field)), array(
            'datatable' => $postDatatable,
            'entity' => $entity,
        ));
    }
861127
protected function generateRequiredFieldException(Entity $entity, FieldDescriptorProto $field)
    {
        $name = $field->getName();
        $tag  = $field->getNumber();

        $class   = $entity->getNamespacedName();
        $format  = 'Field "%s" (tag %s) is required but has no value.';
        $message = var_export(sprintf($format, $name, $tag), true);

        $body[] = 'if ( ! isset($values[\'' . $name . '\'])) {';
        $body[] = '    throw new \InvalidArgumentException(' . $message . ');';
        $body[] = '}';

        return $body;
    }
66954
public Response invokePost(String resourcePath, Entity<?> entity) {
		logger.debug("POST {}, entity: {}", getFullPath(resourcePath), entity);
		return invokeSignedRequest(getApiClient(), accessKey, key(true), POST,
				getEndpoint(), getFullPath(resourcePath), null, null, entity);
	}