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

Move and internalize udb3-uitpas-bridge to udb3-silex #338

Merged
merged 32 commits into from Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cf581a2
III-2935 Move udb3-uitpas-bridge package to lib directory
Jul 25, 2019
2e7cbe2
III-2935 Update udb3-uitpas-bridge composer dependency
Jul 25, 2019
ac54f18
III-2935 Configure udb3-uitpas-bridge phing tasks
Jul 25, 2019
aa13224
III-2753 Add test for case insensitive labels
Jul 25, 2019
ab39f90
III-2753 Add test for case insensitive hidden labels
Jul 25, 2019
0975d85
III-2753 Implement case-insensitive label comparisons
Jul 25, 2019
dcabdd7
Don't pass potential labels to copy as strings
jdrieghe Jul 30, 2019
795c827
Don't pass organizer labels as strings
jdrieghe Jul 30, 2019
517991d
Construct correct label earlier to avoid confusion
jdrieghe Jul 30, 2019
d23aa64
Rename variable to labelsToAdd to better reflect what it is
jdrieghe Jul 30, 2019
437585c
Remove unused labels as strings
jdrieghe Jul 30, 2019
22d46b5
Merge pull request #340 from cultuurnet/feature/III-2753-case-insensi…
Jul 30, 2019
d2b228b
Merge branch 'III-2944-internalize-imports-library' of github.com:cul…
jdrieghe Aug 8, 2019
7cb4b37
Move files from lib folder to src and tests
jdrieghe Aug 8, 2019
cd40c7a
Fix the composer lock file after incorrectly merging it earlier
jdrieghe Aug 8, 2019
224c428
Explicitly add dependencies from uitpas-bridge library
jdrieghe Aug 8, 2019
f972321
Remove dependency on cultuurnet/udb3-uitpas-bridge
jdrieghe Aug 8, 2019
bf5d8bc
Make tests compatible with phpunit 7.x by using namespaced TestCase
jdrieghe Aug 8, 2019
ac56986
Fix code style to comply with stricter udb3-silex rules
jdrieghe Aug 8, 2019
989b377
Remove now unnecessary lib folder
jdrieghe Aug 8, 2019
375ec2b
Merge branch 'master' into feature/III-2935-uitpas-bridge
Aug 8, 2019
c2d6694
III-2268 Make UiTPASLabelsRepositoryInterface return an associative a…
Aug 8, 2019
1235b9c
III-2668 Remove Interface suffix
Aug 8, 2019
067e0b5
III-2668 Apply UiTPAS labels based on active card systems, not organi…
Aug 9, 2019
bb284eb
III-2668 Fix potential issue where the event has active card systems …
Aug 9, 2019
cfdaf8e
III-2668 Document the labelling logic
Aug 9, 2019
d3cf30c
III-2668 Improve structure and readability of UiTPAS event process ma…
Aug 12, 2019
ed467ec
III-2668 Fix casing of property name
Aug 12, 2019
a0c3610
III-2668 Use early returns instead of if/else
Aug 12, 2019
8a91852
Merge pull request #353 from cultuurnet/feature/III-2668
Aug 12, 2019
44d5902
Merge branch 'master' into feature/III-2935-uitpas-bridge
Aug 12, 2019
99dfc53
III-2935 Remove udb3-uitpas-bridge from .lock file again after mergin…
Aug 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion app/UiTPAS/UiTPASIncomingEventServicesProvider.php
Expand Up @@ -84,7 +84,6 @@ function (Application $app) {
$app['uitpas_event_process_manager'] = $app->share(
function (Application $app) {
return new EventProcessManager(
$app['event_jsonld_repository'],
$app['event_command_bus'],
$app['uitpas_label_repository'],
$app['uitpas_logger']
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -11,7 +11,9 @@
"minimum-stability": "dev",
"require": {
"php": "^7.1",
"2dotstwice/collection": "~1.0",
"2dotstwice/silex-feature-toggles-provider": "~0.1",
"broadway/broadway": "~0.10",
"chrisboulton/php-resque": "dev-compat-1-2 as 1.2",
"crell/api-problem": "~1.7",
"cultuurnet/auth": "~1.2",
Expand All @@ -34,7 +36,6 @@
"cultuurnet/udb3-doctrine": "~0.1",
"cultuurnet/udb3-http-foundation": "~0.1",
"cultuurnet/udb3-models": "~0.1",
"cultuurnet/udb3-uitpas-bridge": "~0.1",
"cultuurnet/uitid-credentials": "~0.1",
"cultuurnet/valueobjects": "^3.1",
"deralex/yaml-config-service-provider": "~1.0",
Expand Down
47 changes: 0 additions & 47 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions src/UiTPAS/CardSystem/CardSystem.php
@@ -0,0 +1,47 @@
<?php

namespace CultuurNet\UDB3\UiTPAS\CardSystem;

use CultuurNet\UDB3\UiTPAS\ValueObject\Id;
use ValueObjects\StringLiteral\StringLiteral;

class CardSystem
{
/**
* @var Id
*/
private $id;

/**
* @var StringLiteral
*/
private $name;

/**
* @param Id $id
* @param StringLiteral $name
*/
public function __construct(
Id $id,
StringLiteral $name
) {
$this->id = $id;
$this->name = $name;
}

/**
* @return Id
*/
public function getId()
{
return $this->id;
}

/**
* @return StringLiteral
*/
public function getName()
{
return $this->name;
}
}
13 changes: 13 additions & 0 deletions src/UiTPAS/CardSystem/CardSystems.php
@@ -0,0 +1,13 @@
<?php

namespace CultuurNet\UDB3\UiTPAS\CardSystem;

use TwoDotsTwice\Collection\AbstractCollection;

class CardSystems extends AbstractCollection
{
protected function getValidObjectType()
{
return CardSystem::class;
}
}
@@ -0,0 +1,63 @@
<?php

namespace CultuurNet\UDB3\UiTPAS\Event\CommandHandling\Validation;

use CultuurNet\Broadway\CommandHandling\Validation\CommandValidatorInterface;
use CultuurNet\UDB3\Event\Commands\DeleteOrganizer;
use CultuurNet\UDB3\Event\Commands\UpdateOrganizer;
use CultuurNet\UDB3\Event\Commands\UpdatePriceInfo;
use Psr\Log\LoggerInterface;

class EventHasTicketSalesCommandValidator implements CommandValidatorInterface
{
/**
* @var \CultureFeed_Uitpas
*/
private $uitpas;

/**
* @var LoggerInterface
*/
private $logger;

public function __construct(
\CultureFeed_Uitpas $uitpas,
LoggerInterface $logger
) {
$this->uitpas = $uitpas;
$this->logger = $logger;
}

/**
* @inheritdoc
*/
public function validate($command)
{
if (!($command instanceof UpdateOrganizer) &&
!($command instanceof UpdatePriceInfo) &&
!($command instanceof DeleteOrganizer)) {
return;
}

$eventId = $command->getItemId();

try {
$hasTicketSales = $this->uitpas->eventHasTicketSales($eventId);
} catch (\Exception $exception) {
// By design to catch all exceptions and map an exception to no ticket sales.
// This is done to allow setting price and organizer even when UiTPAS has issues.
// All exceptions will be logged.
$this->logger->warning(
'Ticket call sales failed with exception message "'
. $exception->getMessage() . '" and exception code "' . $exception->getCode() . '". '
. 'Assuming no ticket sales for event ' . $eventId
);

return;
}

if ($hasTicketSales) {
throw new EventHasTicketSalesException($eventId);
}
}
}
@@ -0,0 +1,12 @@
<?php

namespace CultuurNet\UDB3\UiTPAS\Event\CommandHandling\Validation;

class EventHasTicketSalesException extends \Exception
{
public function __construct($eventId)
{
$message = sprintf('Event %s has already had ticket sales in UiTPAS.', $eventId);
parent::__construct($message);
}
}
47 changes: 47 additions & 0 deletions src/UiTPAS/Event/Event/EventCardSystemsUpdated.php
@@ -0,0 +1,47 @@
<?php

namespace CultuurNet\UDB3\UiTPAS\Event\Event;

use CultuurNet\UDB3\UiTPAS\CardSystem\CardSystems;
use CultuurNet\UDB3\UiTPAS\ValueObject\Id;

class EventCardSystemsUpdated
{
/**
* @var Id
*/
private $id;

/**
* @var CardSystems
*/
private $cardSystems;

/**
* @param Id $id
* @param CardSystems $cardSystems
*/
public function __construct(
Id $id,
CardSystems $cardSystems
) {
$this->id = $id;
$this->cardSystems = $cardSystems;
}

/**
* @return Id
*/
public function getId()
{
return $this->id;
}

/**
* @return CardSystems
*/
public function getCardSystems()
{
return $this->cardSystems;
}
}
58 changes: 58 additions & 0 deletions src/UiTPAS/Event/Event/EventCardSystemsUpdatedDeserializer.php
@@ -0,0 +1,58 @@
<?php

namespace CultuurNet\UDB3\UiTPAS\Event\Event;

use CultuurNet\Deserializer\JSONDeserializer;
use CultuurNet\UDB3\UiTPAS\CardSystem\CardSystem;
use CultuurNet\UDB3\UiTPAS\CardSystem\CardSystems;
use CultuurNet\UDB3\UiTPAS\ValueObject\Id;
use ValueObjects\StringLiteral\StringLiteral;

/**
* Deserializes `application/vnd.cultuurnet.uitpas-events.event-card-systems-updated+json` messages
* to typed objects.
*
* Make sure to extract this logic if more (similar) uitpas messages have to be deserialized in the future.
*/
class EventCardSystemsUpdatedDeserializer extends JSONDeserializer
{
public function deserialize(StringLiteral $data)
{
$dto = parent::deserialize($data);

if (!isset($dto->cdbid)) {
throw new \InvalidArgumentException('Missing cdbid property.');
}

$eventId = new Id((string) $dto->cdbid);

if (!isset($dto->cardSystems)) {
throw new \InvalidArgumentException('Missing cardSystems property.');
}

if (!is_array($dto->cardSystems)) {
throw new \InvalidArgumentException('Expected cardSystems property to be an array.');
}

$cardSystems = new CardSystems();
foreach ($dto->cardSystems as $cardSystemDTO) {
if (!isset($cardSystemDTO->id)) {
throw new \InvalidArgumentException('Encountered cardSystems entry without id.');
}

if (!isset($cardSystemDTO->name)) {
throw new \InvalidArgumentException('Encountered cardSystems entry without name.');
}

$cardSystems = $cardSystems->withKey(
$cardSystemDTO->id,
new CardSystem(
new Id((string) $cardSystemDTO->id),
new StringLiteral($cardSystemDTO->name)
)
);
}

return new EventCardSystemsUpdated($eventId, $cardSystems);
}
}