Skip to content

Commit

Permalink
Merge branch 'master' into III-6395-ignore-rejected-ownership-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucWollants authored Nov 20, 2024
2 parents aeddb5c + 492a673 commit dc889c2
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 161 deletions.
29 changes: 29 additions & 0 deletions features/history/metadata.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Feature: Test the metadata in the history API

Background:
Given I am using the UDB3 base URL
And I am authorized with an Auth0 client access token for "test_client"
And I create a minimal place and save the "url" as "placeUrl"
And I wait for the place with url "%{placeUrl}" to be indexed
And I create a minimal permanent event and save the "url" as "eventUrl"
And I wait for the event with url "%{eventUrl}" to be indexed

Scenario: test metaData place
Given I am using an UiTID v1 API key of consumer "uitdatabank"
And I am authorized as JWT provider v1 user "centraal_beheerder"
And I send and accept "application/json"
And I send a GET request to "%{placeUrl}/history"
And the JSON response at "0/author" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc@clients"
And the JSON response at "0/auth0ClientId" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc"
And the JSON response at "0/auth0ClientName" should be "UiTdatabank Acceptance Tests"
And the JSON response at "0/api" should be "JSON-LD API"

Scenario: test metaData event
Given I am using an UiTID v1 API key of consumer "uitdatabank"
And I am authorized as JWT provider v1 user "centraal_beheerder"
And I send and accept "application/json"
And I send a GET request to "%{eventUrl}/history"
And the JSON response at "0/author" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc@clients"
And the JSON response at "0/auth0ClientId" should be "pjeOqgEYI0Y4gmr8DWMpUrpTMXrvjgpc"
And the JSON response at "0/auth0ClientName" should be "UiTdatabank Acceptance Tests"
And the JSON response at "0/api" should be "JSON-LD API"
9 changes: 5 additions & 4 deletions src/Cdb/CdbXmlPriceInfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

use CultureFeed_Cdb_Data_Detail;
use CultureFeed_Cdb_Data_Price;
use CultuurNet\UDB3\Model\ValueObject\Price\Tariff;
use CultuurNet\UDB3\Model\ValueObject\Price\TariffName;
use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName;
use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use CultuurNet\UDB3\MoneyFactory;
use CultuurNet\UDB3\PriceInfo\BasePrice;
use CultuurNet\UDB3\PriceInfo\PriceInfo;
use CultuurNet\UDB3\PriceInfo\Tariff;
use CultuurNet\UDB3\ValueObject\MultilingualString;
use Money\Currency;

final class CdbXmlPriceInfoParser
Expand Down Expand Up @@ -100,13 +101,13 @@ function (\CultureFeed_Cdb_Data_Detail $detail) use ($mainLanguage) {
foreach ($translatedTariffs as $tariffName => $tariffPrice) {
if (!isset($tariffs[$tariffIndex])) {
$tariff = new Tariff(
new MultilingualString(new Language($language), (string) $tariffName),
new TranslatedTariffName(new Language($language), new TariffName((string) $tariffName)),
MoneyFactory::create($tariffPrice, new Currency('EUR'))
);
} else {
$tariff = $tariffs[$tariffIndex];
$name = $tariff->getName();
$name = $name->withTranslation(new Language($language), (string) $tariffName);
$name = $name->withTranslation(new Language($language), new TariffName($tariffName));
$tariff = new Tariff(
$name,
$tariff->getPrice()
Expand Down
3 changes: 1 addition & 2 deletions src/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
use CultuurNet\UDB3\Offer\Offer;
use CultuurNet\UDB3\Offer\OfferType;
use CultuurNet\UDB3\PriceInfo\PriceInfo;
use CultuurNet\UDB3\PriceInfo\Tariff;
use CultuurNet\UDB3\Theme;
use CultuurNet\UDB3\Model\ValueObject\Text\Title;
use DateTimeImmutable;
Expand Down Expand Up @@ -506,7 +505,7 @@ public function updateUiTPASPrices(Tariffs $tariffs): void

$legacyUiTPASTariffs = [];
foreach ($tariffs as $tariff) {
$legacyUiTPASTariffs[] = Tariff::fromUdb3ModelTariff($tariff);
$legacyUiTPASTariffs[] = $tariff;
}
$newPriceInfo = $this->priceInfo->withUiTPASTariffs($legacyUiTPASTariffs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public function denormalize($data, $class, $format = null, array $context = []):

public function supportsDenormalization($data, $type, $format = null)
{
return $data === AudienceType::class;
return $type === AudienceType::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function denormalize($data, $class, $format = null, array $context = []):

public function supportsDenormalization($data, $type, $format = null): bool
{
return $data === OpeningHour::class;
return $type === OpeningHour::class;
}
}
33 changes: 33 additions & 0 deletions src/Model/Serializer/ValueObject/Price/TariffDenormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Price;

use CultuurNet\UDB3\Model\ValueObject\Price\Tariff;
use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName;
use CultuurNet\UDB3\MoneyFactory;
use Money\Currency;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

final class TariffDenormalizer implements DenormalizerInterface
{
public function denormalize($data, $class, $format = null, array $context = []): Tariff
{
/** @var TranslatedTariffName $tariffName */
$tariffName = (new TranslatedTariffNameDenormalizer())->denormalize(
$data['name'],
TranslatedTariffName::class
);

return new Tariff(
$tariffName,
MoneyFactory::createFromCents($data['price'], new Currency($data['currency']))
);
}

public function supportsDenormalization($data, $type, $format = null): bool
{
return $type === Tariff::class;
}
}
28 changes: 28 additions & 0 deletions src/Model/Serializer/ValueObject/Price/TariffNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Price;

use CultuurNet\UDB3\Model\ValueObject\Price\Tariff;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

final class TariffNormalizer implements NormalizerInterface
{
/**
* @param Tariff $tariff
*/
public function normalize($tariff, $format = null, array $context = []): array
{
return [
'name' => (new TranslatedTariffNameNormalizer())->normalize($tariff->getName()),
'price' => $tariff->getPrice()->getAmount(),
'currency' => $tariff->getPrice()->getCurrency()->getName(),
];
}

public function supportsNormalization($data, $format = null): bool
{
return $data === Tariff::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Price;

use CultuurNet\UDB3\Model\Serializer\ValueObject\Translation\TranslatedValueObjectNormalizer;
use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName;

final class TranslatedTariffNameNormalizer extends TranslatedValueObjectNormalizer
{
public function supportsNormalization($data, $format = null): bool
{
return $data === TranslatedTariffName::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Translation;

use CultuurNet\UDB3\Model\ValueObject\Translation\Language;
use CultuurNet\UDB3\Model\ValueObject\Translation\TranslatedValueObject;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

abstract class TranslatedValueObjectNormalizer implements NormalizerInterface
{
/**
* @param TranslatedValueObject $object
*/
public function normalize($object, $format = null, array $context = []): array
{
$data = [];

/** @var Language $language */
foreach ($object->getLanguages() as $language) {
$data[$language->toString()] = $object->getTranslation($language)->toString();
}

return $data;
}
}
5 changes: 3 additions & 2 deletions src/Offer/ReadModel/JSONLD/CdbXMLItemBaseImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use CultureFeed_Cdb_Item_Base;
use CultuurNet\UDB3\Cdb\CdbXmlPriceInfoParser;
use CultuurNet\UDB3\DateTimeFactory;
use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TranslatedTariffNameNormalizer;
use CultuurNet\UDB3\Model\ValueObject\Moderation\WorkflowStatus;
use CultuurNet\UDB3\ReadModel\MultilingualJsonLDProjectorTrait;

Expand Down Expand Up @@ -140,9 +141,9 @@ public function importPriceInfo(
foreach ($priceInfo->getTariffs() as $tariff) {
$jsonLD->priceInfo[] = [
'category' => 'tariff',
'name' => $tariff->getName()->serialize(),
'name' => (new TranslatedTariffNameNormalizer())->normalize($tariff->getName()),
'price' => $tariff->getPrice()->getAmount() / 100,
'priceCurrency' => $tariff->getCurrency()->getName(),
'priceCurrency' => $tariff->getPrice()->getCurrency()->getName(),
];
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/Offer/ReadModel/JSONLD/OfferLDProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CultuurNet\UDB3\Media\Serialization\MediaObjectSerializer;
use CultuurNet\UDB3\Model\Serializer\ValueObject\Contact\ContactPointNormalizer;
use CultuurNet\UDB3\Model\Serializer\ValueObject\MediaObject\VideoNormalizer;
use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TranslatedTariffNameNormalizer;
use CultuurNet\UDB3\Model\ValueObject\Identity\UUID;
use CultuurNet\UDB3\Model\ValueObject\Moderation\WorkflowStatus;
use CultuurNet\UDB3\Offer\AvailableTo;
Expand Down Expand Up @@ -668,21 +669,23 @@ protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpda
'priceCurrency' => $basePrice->getCurrency()->getName(),
];

$translatedTariffNameNormalizer = new TranslatedTariffNameNormalizer();

foreach ($priceInfoUpdated->getPriceInfo()->getTariffs() as $tariff) {
$offerLd->priceInfo[] = [
'category' => 'tariff',
'name' => $tariff->getName()->serialize(),
'name' => $translatedTariffNameNormalizer->normalize($tariff->getName()),
'price' => $tariff->getPrice()->getAmount() / 100,
'priceCurrency' => $tariff->getCurrency()->getName(),
'priceCurrency' => $tariff->getPrice()->getCurrency()->getName(),
];
}

foreach ($priceInfoUpdated->getPriceInfo()->getUiTPASTariffs() as $tariff) {
$offerLd->priceInfo[] = [
'category' => 'uitpas',
'name' => $tariff->getName()->serialize(),
'name' => $translatedTariffNameNormalizer->normalize($tariff->getName()),
'price' => $tariff->getPrice()->getAmount() / 100,
'priceCurrency' => $tariff->getCurrency()->getName(),
'priceCurrency' => $tariff->getPrice()->getCurrency()->getName(),
];
}

Expand Down
18 changes: 12 additions & 6 deletions src/PriceInfo/PriceInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
namespace CultuurNet\UDB3\PriceInfo;

use Broadway\Serializer\Serializable;
use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TariffDenormalizer;
use CultuurNet\UDB3\Model\Serializer\ValueObject\Price\TariffNormalizer;
use CultuurNet\UDB3\Model\ValueObject\Price\PriceInfo as Udb3ModelPriceInfo;
use CultuurNet\UDB3\Model\ValueObject\Price\Tariff;

/**
* @deprecated
Expand Down Expand Up @@ -86,12 +89,14 @@ public function serialize(): array
'uitpas_tariffs' => [],
];

$tariffNormalizer = new TariffNormalizer();

foreach ($this->tariffs as $tariff) {
$serialized['tariffs'][] = $tariff->serialize();
$serialized['tariffs'][] = $tariffNormalizer->normalize($tariff);
}

foreach ($this->uitpasTariffs as $uitpasTariff) {
$serialized['uitpas_tariffs'][] = $uitpasTariff->serialize();
$serialized['uitpas_tariffs'][] = $tariffNormalizer->normalize($uitpasTariff);
}

return $serialized;
Expand All @@ -103,16 +108,18 @@ public static function deserialize(array $data): PriceInfo

$priceInfo = new PriceInfo($basePriceInfo);

$tariffDenormalizer = new TariffDenormalizer();

foreach ($data['tariffs'] as $tariffData) {
$priceInfo = $priceInfo->withExtraTariff(
Tariff::deserialize($tariffData)
$tariffDenormalizer->denormalize($tariffData, Tariff::class)
);
}

if (isset($data['uitpas_tariffs'])) {
foreach ($data['uitpas_tariffs'] as $uitpasTariffData) {
$priceInfo = $priceInfo->withExtraUiTPASTariff(
Tariff::deserialize($uitpasTariffData)
$tariffDenormalizer->denormalize($uitpasTariffData, Tariff::class)
);
}
}
Expand All @@ -126,8 +133,7 @@ public static function fromUdb3ModelPriceInfo(Udb3ModelPriceInfo $udb3ModelPrice
$priceInfo = new PriceInfo($basePrice);

foreach ($udb3ModelPriceInfo->getTariffs() as $udb3ModelTariff) {
$tariff = Tariff::fromUdb3ModelTariff($udb3ModelTariff);
$priceInfo = $priceInfo->withExtraTariff($tariff);
$priceInfo = $priceInfo->withExtraTariff($udb3ModelTariff);
}

return $priceInfo;
Expand Down
71 changes: 0 additions & 71 deletions src/PriceInfo/Tariff.php

This file was deleted.

Loading

0 comments on commit dc889c2

Please sign in to comment.