Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

III-6310 Refactor Language on MainLanguageDefined interface #1801

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected function applyEventCreated(EventCreated $eventCreated): void
$this->typeId = $eventCreated->getEventType()->getId();
$this->themeId = $eventCreated->getTheme() ? $eventCreated->getTheme()->getId() : null;
$this->locationId = $eventCreated->getLocation();
$this->mainLanguage = $eventCreated->getMainLanguage();
$this->mainLanguage = LegacyLanguage::fromUdb3ModelLanguage($eventCreated->getMainLanguage());
$this->workflowStatus = WorkflowStatus::DRAFT();
}

Expand Down
11 changes: 6 additions & 5 deletions src/Event/Events/EventCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
use CultuurNet\UDB3\Event\EventType;
use CultuurNet\UDB3\EventSourcing\ConvertsToGranularEvents;
use CultuurNet\UDB3\EventSourcing\MainLanguageDefined;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Language as LegacyLanguage;
use CultuurNet\UDB3\Event\ValueObjects\LocationId;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use CultuurNet\UDB3\Theme;
use DateTimeImmutable;
use DateTimeInterface;

final class EventCreated extends EventEvent implements ConvertsToGranularEvents, MainLanguageDefined
{
private Language $mainLanguage;
private LegacyLanguage $mainLanguage;
private string $title;
private EventType $eventType;
private ?Theme $theme;
Expand All @@ -28,7 +29,7 @@ final class EventCreated extends EventEvent implements ConvertsToGranularEvents,

public function __construct(
string $eventId,
Language $mainLanguage,
LegacyLanguage $mainLanguage,
string $title,
EventType $eventType,
LocationId $location,
Expand All @@ -49,7 +50,7 @@ public function __construct(

public function getMainLanguage(): Language
{
return $this->mainLanguage;
return $this->mainLanguage->toUdb3ModelLanguage();
}

public function getTitle(): string
Expand Down Expand Up @@ -130,7 +131,7 @@ public static function deserialize(array $data): EventCreated
}
return new self(
$data['event_id'],
new Language($data['main_language']),
new LegacyLanguage($data['main_language']),
$data['title'],
EventType::deserialize($data['event_type']),
new LocationId($data['location']),
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Events/EventImportedFromUDB2.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use CultuurNet\UDB3\EventSourcing\ConvertsToGranularEvents;
use CultuurNet\UDB3\EventSourcing\MainLanguageDefined;
use CultuurNet\UDB3\HasCdbXmlTrait;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;

final class EventImportedFromUDB2 extends EventEvent implements EventCdbXMLInterface, MainLanguageDefined, ConvertsToGranularEvents
{
Expand Down
2 changes: 1 addition & 1 deletion src/EventSourcing/MainLanguageDefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CultuurNet\UDB3\EventSourcing;

use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;

interface MainLanguageDefined
{
Expand Down
11 changes: 6 additions & 5 deletions src/Place/Events/PlaceCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
use CultuurNet\UDB3\Event\EventType;
use CultuurNet\UDB3\EventSourcing\ConvertsToGranularEvents;
use CultuurNet\UDB3\EventSourcing\MainLanguageDefined;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Language as LegacyLanguage;
use CultuurNet\UDB3\Place\PlaceEvent;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use DateTimeImmutable;
use DateTimeInterface;

final class PlaceCreated extends PlaceEvent implements ConvertsToGranularEvents, MainLanguageDefined
{
private Language $mainLanguage;
private LegacyLanguage $mainLanguage;
private string $title;
private EventType $eventType;
private Address $address;
Expand All @@ -26,7 +27,7 @@ final class PlaceCreated extends PlaceEvent implements ConvertsToGranularEvents,

public function __construct(
string $placeId,
Language $mainLanguage,
LegacyLanguage $mainLanguage,
string $title,
EventType $eventType,
Address $address,
Expand All @@ -45,7 +46,7 @@ public function __construct(

public function getMainLanguage(): Language
{
return $this->mainLanguage;
return $this->mainLanguage->toUdb3ModelLanguage();
}

public function getTitle(): string
Expand Down Expand Up @@ -107,7 +108,7 @@ public static function deserialize(array $data): PlaceCreated
}
return new static(
$data['place_id'],
new Language($data['main_language']),
new LegacyLanguage($data['main_language']),
$data['title'],
EventType::deserialize($data['event_type']),
Address::deserialize($data['address']),
Expand Down
2 changes: 1 addition & 1 deletion src/Place/Events/PlaceImportedFromUDB2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use CultuurNet\UDB3\Actor\ActorImportedFromUDB2;
use CultuurNet\UDB3\EventSourcing\ConvertsToGranularEvents;
use CultuurNet\UDB3\EventSourcing\MainLanguageDefined;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;

final class PlaceImportedFromUDB2 extends ActorImportedFromUDB2 implements MainLanguageDefined, ConvertsToGranularEvents
{
Expand Down
16 changes: 8 additions & 8 deletions src/Place/Place.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use CultuurNet\UDB3\Description;
use CultuurNet\UDB3\Event\EventType;
use CultuurNet\UDB3\Geocoding\Coordinate\Coordinates;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Language as LegacyLanguage;
use CultuurNet\UDB3\Media\Image;
use CultuurNet\UDB3\Media\ImageCollection;
use CultuurNet\UDB3\Media\Properties\Description as ImageDescription;
Expand Down Expand Up @@ -110,7 +110,7 @@ public function getAggregateRootId(): string

public static function create(
string $id,
Language $mainLanguage,
LegacyLanguage $mainLanguage,
Title $title,
EventType $eventType,
Address $address,
Expand All @@ -133,7 +133,7 @@ public static function create(

protected function applyPlaceCreated(PlaceCreated $placeCreated): void
{
$this->mainLanguage = $placeCreated->getMainLanguage();
$this->mainLanguage = LegacyLanguage::fromUdb3ModelLanguage($placeCreated->getMainLanguage());
$this->titles[$this->mainLanguage->getCode()] = $placeCreated->getTitle();
$this->calendar = $placeCreated->getCalendar();
$this->contactPoint = new ContactPoint();
Expand Down Expand Up @@ -167,7 +167,7 @@ protected function applyMajorInfoUpdated(MajorInfoUpdated $majorInfoUpdated): vo
$this->calendar = $majorInfoUpdated->getCalendar();
}

public function updateAddress(Address $address, Language $language): void
public function updateAddress(Address $address, LegacyLanguage $language): void
{
if ($language->getCode() === $this->mainLanguage->getCode()) {
$event = new AddressUpdated($this->placeId, $address);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function getDuplicates(): array
return $this->duplicates;
}

private function allowAddressUpdate(Address $address, Language $language): bool
private function allowAddressUpdate(Address $address, LegacyLanguage $language): bool
{
// No current address in the provided language so update with new address is allowed.
if (!isset($this->addresses[$language->getCode()])) {
Expand Down Expand Up @@ -235,7 +235,7 @@ protected function applyPlaceImportedFromUDB2(PlaceImportedFromUDB2 $placeImport
$this->placeId = $placeImported->getActorId();

// When importing from UDB2 the default main language is always 'nl'.
$this->mainLanguage = new Language('nl');
$this->mainLanguage = new LegacyLanguage('nl');

$udb2Actor = ActorItemFactory::createActorFromCdbXml(
$placeImported->getCdbXmlNamespaceUri(),
Expand Down Expand Up @@ -393,7 +393,7 @@ protected function createVideoUpdatedEvent(Video $video): VideoUpdated
return new VideoUpdated($this->placeId, $video);
}

protected function createTitleTranslatedEvent(Language $language, Title $title): TitleTranslated
protected function createTitleTranslatedEvent(LegacyLanguage $language, Title $title): TitleTranslated
{
return new TitleTranslated($this->placeId, $language, $title->toString());
}
Expand All @@ -403,7 +403,7 @@ protected function createTitleUpdatedEvent(Title $title): TitleUpdated
return new TitleUpdated($this->placeId, $title->toString());
}

protected function createDescriptionTranslatedEvent(Language $language, Description $description): DescriptionTranslated
protected function createDescriptionTranslatedEvent(LegacyLanguage $language, Description $description): DescriptionTranslated
{
return new DescriptionTranslated($this->placeId, $language, $description);
}
Expand Down
8 changes: 5 additions & 3 deletions tests/BackwardsCompatiblePayloadSerializerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CultuurNet\UDB3;

use Broadway\Serializer\Serializer;
use CultuurNet\UDB3\Language as LegacyLanguage;
use CultuurNet\UDB3\Event\Events\BookingInfoUpdated;
use CultuurNet\UDB3\Event\Events\DescriptionTranslated;
use CultuurNet\UDB3\Event\Events\EventCreated;
Expand All @@ -29,6 +30,7 @@
use CultuurNet\UDB3\PriceInfo\Tariff;
use CultuurNet\UDB3\Role\Events\ConstraintAdded;
use CultuurNet\UDB3\ValueObject\MultilingualString;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use Money\Currency;
use Money\Money;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -445,7 +447,7 @@ public function it_replaces_deprecated_url_label_on_booking_info_updated(): void
$bookingInfoUpdated = $this->serializer->deserialize($decoded);

$this->assertEquals(
new MultilingualString(new Language('nl'), 'Reserveer plaatsen'),
new MultilingualString(new LegacyLanguage('nl'), 'Reserveer plaatsen'),
$bookingInfoUpdated->getBookingInfo()->getUrlLabel()
);
}
Expand Down Expand Up @@ -615,7 +617,7 @@ public function it_should_replace_string_names_with_translatable_objects_in_pric
->withExtraTariff(
new Tariff(
new MultilingualString(
new Language('nl'),
new LegacyLanguage('nl'),
'Senioren'
),
new Money(1000, new Currency('EUR'))
Expand All @@ -624,7 +626,7 @@ public function it_should_replace_string_names_with_translatable_objects_in_pric
->withExtraTariff(
new Tariff(
new MultilingualString(
new Language('nl'),
new LegacyLanguage('nl'),
'Studenten'
),
new Money(750, new Currency('EUR'))
Expand Down
17 changes: 9 additions & 8 deletions tests/Event/Events/EventCreatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
use CultuurNet\UDB3\Event\EventType;
use CultuurNet\UDB3\EventSourcing\ConvertsToGranularEvents;
use CultuurNet\UDB3\EventSourcing\MainLanguageDefined;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Language as LegacyLanguage;
use CultuurNet\UDB3\Event\ValueObjects\LocationId;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use CultuurNet\UDB3\Theme;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
Expand All @@ -32,7 +33,7 @@ protected function setUp(): void

$this->eventCreated = new EventCreated(
'id',
new Language('es'),
new LegacyLanguage('es'),
'title',
new EventType('id', 'label'),
$this->location,
Expand All @@ -51,7 +52,7 @@ public function it_converts_to_granular_events(): void

$eventWithTheme = new EventCreated(
$eventId,
new Language('nl'),
new LegacyLanguage('nl'),
'Example title',
new EventType('0.50.4.0.0', 'Concert'),
$this->location,
Expand All @@ -61,7 +62,7 @@ public function it_converts_to_granular_events(): void

$eventWithoutTheme = new EventCreated(
$eventId,
new Language('nl'),
new LegacyLanguage('nl'),
'Example title',
new EventType('0.50.4.0.0', 'Concert'),
$this->location,
Expand Down Expand Up @@ -96,7 +97,7 @@ public function it_implements_main_language_defined(): void
{
$event = new EventCreated(
'09994540-289f-4ab4-bf77-b83443d3d0fc',
new Language('fr'),
new LegacyLanguage('fr'),
'Example title',
new EventType('0.50.4.0.0', 'Concert'),
$this->location,
Expand Down Expand Up @@ -218,7 +219,7 @@ public function serializationDataProvider(): array
],
new EventCreated(
'test 456',
new Language('es'),
new LegacyLanguage('es'),
'title',
new EventType('bar_id', 'bar'),
new LocationId('d379187b-7f71-4403-8fff-645a28be8fd0'),
Expand Down Expand Up @@ -256,7 +257,7 @@ public function serializationDataProvider(): array
],
new EventCreated(
'test 456',
new Language('es'),
new LegacyLanguage('es'),
'title',
new EventType('bar_id', 'bar'),
new LocationId('d379187b-7f71-4403-8fff-645a28be8fd0'),
Expand Down Expand Up @@ -291,7 +292,7 @@ public function serializationDataProvider(): array
],
new EventCreated(
'test 456',
new Language('es'),
new LegacyLanguage('es'),
'title',
new EventType('bar_id', 'bar'),
new LocationId('d379187b-7f71-4403-8fff-645a28be8fd0'),
Expand Down
19 changes: 10 additions & 9 deletions tests/Event/Events/EventImportedFromUDB2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use CultuurNet\UDB3\Event\EventType;
use CultuurNet\UDB3\Event\ValueObjects\LocationId;
use CultuurNet\UDB3\EventSourcing\MainLanguageDefined;
use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Language as LegacyLanguage;
use CultuurNet\UDB3\Model\ValueObject\Calendar\OpeningHours\Hour;
use CultuurNet\UDB3\Model\ValueObject\Calendar\OpeningHours\Minute;
use CultuurNet\UDB3\Model\ValueObject\Geography\Address;
Expand All @@ -28,6 +28,7 @@
use CultuurNet\UDB3\Model\ValueObject\Geography\Street;
use CultuurNet\UDB3\Model\ValueObject\Text\Title;
use CultuurNet\UDB3\Calendar\Timestamp;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use CultuurNet\UDB3\SampleFiles;
use DateTimeZone;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -144,8 +145,8 @@ public function it_can_convert_translated_events_to_granular_events(): void
$this->assertEquals(
[
new TitleUpdated($eventId, 'Het evenement!'),
new TitleTranslated($eventId, new Language('fr'), 'L\'événement!'),
new TitleTranslated($eventId, new Language('de'), 'Das Ereignis!'),
new TitleTranslated($eventId, new LegacyLanguage('fr'), 'L\'événement!'),
new TitleTranslated($eventId, new LegacyLanguage('de'), 'Das Ereignis!'),
new TypeUpdated($eventId, new EventType('0.3.1.0.0', 'Cursus of workshop')),
new DummyLocationUpdated(
'0452b4ae-7c18-4b33-a6c6-eba2288c9ac3',
Expand Down Expand Up @@ -194,8 +195,8 @@ public function it_can_convert_events_with_location_id_to_granular_events(): voi
$this->assertEquals(
[
new TitleUpdated($eventId, 'Het evenement!'),
new TitleTranslated($eventId, new Language('fr'), 'L\'événement!'),
new TitleTranslated($eventId, new Language('de'), 'Das Ereignis!'),
new TitleTranslated($eventId, new LegacyLanguage('fr'), 'L\'événement!'),
new TitleTranslated($eventId, new LegacyLanguage('de'), 'Das Ereignis!'),
new TypeUpdated($eventId, new EventType('0.3.1.0.0', 'Cursus of workshop')),
new LocationUpdated($eventId, new LocationId('28d2900d-f784-4d04-8d66-5b93900c6f9c')),
new CalendarUpdated(
Expand Down Expand Up @@ -232,8 +233,8 @@ public function it_can_convert_events_with_external_id_to_granular_events(): voi
$this->assertEquals(
[
new TitleUpdated($eventId, 'Het evenement!'),
new TitleTranslated($eventId, new Language('fr'), 'L\'événement!'),
new TitleTranslated($eventId, new Language('de'), 'Das Ereignis!'),
new TitleTranslated($eventId, new LegacyLanguage('fr'), 'L\'événement!'),
new TitleTranslated($eventId, new LegacyLanguage('de'), 'Das Ereignis!'),
new TypeUpdated($eventId, new EventType('0.3.1.0.0', 'Cursus of workshop')),
new ExternalIdLocationUpdated($eventId, 'SKB:9ccbf9c1-a5c5-4689-9687-9a7dd3c51aee'),
new CalendarUpdated(
Expand Down Expand Up @@ -288,8 +289,8 @@ public function it_can_convert_a_periodic_event_to_granular_events(): void
$this->assertEquals(
[
new TitleUpdated($eventId, 'Oscar et la Dame Rose'),
new TitleTranslated($eventId, new Language('fr'), 'Oscar et la Dame Rose'),
new TitleTranslated($eventId, new Language('en'), 'Oscar et la Dame Rose'),
new TitleTranslated($eventId, new LegacyLanguage('fr'), 'Oscar et la Dame Rose'),
new TitleTranslated($eventId, new LegacyLanguage('en'), 'Oscar et la Dame Rose'),
new TypeUpdated($eventId, new EventType('0.55.0.0.0', 'Theatervoorstelling')),
new DummyLocationUpdated(
'0452b4ae-7c18-4b33-a6c6-eba2288c9ac3',
Expand Down
Loading
Loading