<commit_before><?php

/**
 * @file
 * Contains \Cultuurnet\UDB3\LocalEntityService.
 */

namespace CultuurNet\UDB3;

use Broadway\Repository\AggregateNotFoundException;
use Broadway\Repository\RepositoryInterface;
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface;
use CultuurNet\UDB3\Event\ReadModel\JsonDocument;
use CultuurNet\UDB3\Iri\IriGeneratorInterface;

abstract class LocalEntityService implements EntityServiceInterface
{
    /**
     * @var DocumentRepositoryInterface
     */
    protected $documentRepository;

    /**
     * @var RepositoryInterface
     */
    protected $entityRepository;

    /**
     * @var IriGeneratorInterface
     */
    protected $iriGenerator;

    /**
     * Constructs the local entity service.
     *
     * @param DocumentRepositoryInterface $documentRepository
     * @param RepositoryInterface $entityRepository
     */
    public function __construct(
        DocumentRepositoryInterface $documentRepository,
        RepositoryInterface $entityRepository,
        IriGeneratorInterface $iriGenerator
    ) {
        $this->documentRepository = $documentRepository;
        $this->entityRepository = $entityRepository;
        $this->iriGenerator = $iriGenerator;
    }

    /**
     * {@inheritdoc}
     */
    public function getEntity($id)
    {
        /** @var JsonDocument $document */
        $document = $this->documentRepository->get($id);

        if (!$document) {
            // If the read model is not initialized yet, try to load
            // the entity, which will initialize the read model.
            try {
                $this->entityRepository->load($id);
            } catch (AggregateNotFoundException $e) {
                throw new EntityNotFoundException(
                    sprintf('Entity with id: %s not found.', $id)
                );
            }

            /** @var JsonDocument $document */
            $document = $this->documentRepository->get($id);
        }

        return $document->getRawBody();
    }

    public function iri($id)
    {
        return $this->iriGenerator->iri($id);
    }
}<commit_msg>Fix fatal error occurring when organizer/place can not be found<commit_after><?php

/**
 * @file
 * Contains \Cultuurnet\UDB3\LocalEntityService.
 */

namespace CultuurNet\UDB3;

use Broadway\Repository\AggregateNotFoundException;
use Broadway\Repository\RepositoryInterface;
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface;
use CultuurNet\UDB3\Event\ReadModel\JsonDocument;
use CultuurNet\UDB3\Iri\IriGeneratorInterface;

abstract class LocalEntityService implements EntityServiceInterface
{
    /**
     * @var DocumentRepositoryInterface
     */
    protected $documentRepository;

    /**
     * @var RepositoryInterface
     */
    protected $entityRepository;

    /**
     * @var IriGeneratorInterface
     */
    protected $iriGenerator;

    /**
     * Constructs the local entity service.
     *
     * @param DocumentRepositoryInterface $documentRepository
     * @param RepositoryInterface $entityRepository
     */
    public function __construct(
        DocumentRepositoryInterface $documentRepository,
        RepositoryInterface $entityRepository,
        IriGeneratorInterface $iriGenerator
    ) {
        $this->documentRepository = $documentRepository;
        $this->entityRepository = $entityRepository;
        $this->iriGenerator = $iriGenerator;
    }

    /**
     * {@inheritdoc}
     */
    public function getEntity($id)
    {
        /** @var JsonDocument $document */
        $document = $this->documentRepository->get($id);

        if (!$document) {
            // If the read model is not initialized yet, try to load
            // the entity, which will initialize the read model.
            try {
                $this->entityRepository->load($id);
            } catch (AggregateNotFoundException $e) {
                throw new EntityNotFoundException(
                    sprintf('Entity with id: %s not found.', $id)
                );
            }

            /** @var JsonDocument $document */
            $document = $this->documentRepository->get($id);

            if (!$document) {
                throw new EntityNotFoundException(
                    sprintf('Entity with id: %s not found.', $id)
                );
            }
        }

        return $document->getRawBody();
    }

    public function iri($id)
    {
        return $this->iriGenerator->iri($id);
    }
}
{'fraction_non_alphanumeric': 0.10298407000224366, 'fraction_numerical': 0.002243661655822302, 'mean_word_length': 2.341829085457271, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1330771', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1133, 'n_words': 253}