Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
III-1491: Cleaned up structure of commands & command handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed Nov 2, 2016
1 parent 189aa24 commit 2145b2e
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 75 deletions.
6 changes: 3 additions & 3 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
use CultuurNet\UDB3\EventSourcing\ExecutionContextMetadataEnricher;
use CultuurNet\UDB3\LabelCollection;
use CultuurNet\UDB3\SimpleEventBus;
use CultuurNet\UDB3\UiTPASService\Command\RemotelySyncUiTPASCommandHandler;
use CultuurNet\UDB3\UiTPASService\Sync\SyncCommandHandler;
use CultuurNet\UDB3\UiTPASService\EventStoreSchemaConfigurator;
use CultuurNet\UDB3\UiTPASService\Specification\IsUiTPASOrganizerAccordingToJSONLD;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregateRepository;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\UiTPASAggregateRepository;
use CultuurNet\UDB3\UiTPASService\UiTPASEventSaga;
use DerAlex\Silex\YamlConfigServiceProvider;
use Monolog\Handler\StreamHandler;
Expand Down Expand Up @@ -376,7 +376,7 @@ function (Application $app) {

$app['uitpas_sync_command_handler'] = $app->share(
function (Application $app) {
return new RemotelySyncUiTPASCommandHandler(
return new SyncCommandHandler(
$app['culturefeed_uitpas_client']
);
}
Expand Down
7 changes: 0 additions & 7 deletions src/Command/RemotelyRegisterUiTPASEvent.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Command/RemotelyUpdateUiTPASEvent.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/Sync/Command/RegisterUiTPASEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Sync\Command;

class RegisterUiTPASEvent extends SyncUiTPASEvent
{
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Command;
namespace CultuurNet\UDB3\UiTPASService\Sync\Command;

use CultuurNet\UDB3\PriceInfo\PriceInfo;

abstract class RemotelySyncUiTPASEvent
abstract class SyncUiTPASEvent
{
/**
* @var string
Expand Down
7 changes: 7 additions & 0 deletions src/Sync/Command/UpdateUiTPASEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Sync\Command;

class UpdateUiTPASEvent extends SyncUiTPASEvent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
* @file
*/

namespace CultuurNet\UDB3\UiTPASService\Command;
namespace CultuurNet\UDB3\UiTPASService\Sync;

use Broadway\CommandHandling\CommandHandler;
use CultureFeed_Uitpas;
use CultureFeed_Uitpas_DistributionKey;
use CultureFeed_Uitpas_Event_CultureEvent;
use CultuurNet\UDB3\UiTPASService\Sync\Command\RegisterUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Sync\Command\SyncUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Sync\Command\UpdateUiTPASEvent;
use Exception;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;

class RemotelySyncUiTPASCommandHandler extends CommandHandler implements LoggerAwareInterface
class SyncCommandHandler extends CommandHandler implements LoggerAwareInterface
{
use LoggerAwareTrait;

Expand All @@ -30,31 +33,31 @@ public function __construct(CultureFeed_Uitpas $culturefeedClient)
}

/**
* @param RemotelyRegisterUiTPASEvent $command
* @param RegisterUiTPASEvent $command
*/
protected function handleRemotelyRegisterUiTPASEvent(
RemotelyRegisterUiTPASEvent $command
RegisterUiTPASEvent $command
) {
$event = $this->buildEvent($command);
$this->syncEvent($event, ['registerEvent', 'updateEvent']);
}

/**
* @param RemotelyUpdateUiTPASEvent $command
* @param UpdateUiTPASEvent $command
*/
protected function handleRemotelyUpdateUiTPASEvent(
RemotelyUpdateUiTPASEvent $command
UpdateUiTPASEvent $command
) {
$event = $this->buildEvent($command);
$this->syncEvent($event, ['updateEvent', 'registerEvent']);
}

/**
* @var RemotelySyncUiTPASEvent $command
* @var SyncUiTPASEvent $command
*
* @return CultureFeed_Uitpas_Event_CultureEvent
*/
private function buildEvent(RemotelySyncUiTPASEvent $command)
private function buildEvent(SyncUiTPASEvent $command)
{
$event = new CultureFeed_Uitpas_Event_CultureEvent();
$event->cdbid = $command->getEventId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Command;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command;

class ClearDistributionKeys
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Command;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command;

class CreateUiTPASAggregate
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Command;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command;

class UpdateDistributionKeys
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Event;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event;

abstract class AbstractUiTPASAggregateEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Event;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event;

class DistributionKeysCleared extends AbstractUiTPASAggregateEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Event;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event;

class DistributionKeysUpdated extends AbstractUiTPASAggregateEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Event;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event;

class UiTPASAggregateCreated extends AbstractUiTPASAggregateEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace CultuurNet\UDB3\UiTPASService;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate;

use Broadway\EventSourcing\EventSourcedAggregateRoot;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\Event\UiTPASAggregateCreated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\UiTPASAggregateCreated;

class UiTPASAggregate extends EventSourcedAggregateRoot
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace CultuurNet\UDB3\UiTPASService;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate;

use Broadway\CommandHandling\CommandHandlerInterface;
use Broadway\Repository\RepositoryInterface;
use CultuurNet\UDB3\UiTPASService\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Command\UpdateDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\UpdateDistributionKeys;

class UiTPASAggregateCommandHandler implements CommandHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CultuurNet\UDB3\UiTPASService;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate;

use Broadway\EventHandling\EventBusInterface;
use Broadway\EventSourcing\AggregateFactory\PublicConstructorAggregateFactory;
Expand Down
20 changes: 10 additions & 10 deletions src/UiTPASEventSaga.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
use CultuurNet\UDB3\Event\Events\PriceInfoUpdated;
use CultuurNet\UDB3\Offer\Events\AbstractEvent;
use CultuurNet\UDB3\PriceInfo\PriceInfo;
use CultuurNet\UDB3\UiTPASService\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Command\RemotelyRegisterUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Command\RemotelyUpdateUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Event\AbstractUiTPASAggregateEvent;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\Event\UiTPASAggregateCreated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Sync\Command\RegisterUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Sync\Command\UpdateUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\AbstractUiTPASAggregateEvent;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\UiTPASAggregateCreated;
use CultuurNet\UDB3\UiTPASService\Specification\OrganizerSpecificationInterface;

class UiTPASEventSaga extends Saga implements StaticallyConfiguredSagaInterface
Expand Down Expand Up @@ -207,14 +207,14 @@ private function triggerSyncWhenConditionsAreMet(State $state)
new CreateUiTPASAggregate($aggregateId, $distributionKeyIds)
);

$syncCommand = new RemotelyRegisterUiTPASEvent(
$syncCommand = new RegisterUiTPASEvent(
$aggregateId,
$organizerId,
$priceInfo,
$distributionKeyIds
);
} else {
$syncCommand = new RemotelyUpdateUiTPASEvent(
$syncCommand = new UpdateUiTPASEvent(
$aggregateId,
$organizerId,
$priceInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php

namespace CultuurNet\UDB3\UiTPASService;
namespace CultuurNet\UDB3\UiTPASService\UiTPASAggregate;

use Broadway\CommandHandling\CommandHandlerInterface;
use Broadway\CommandHandling\Testing\CommandHandlerScenarioTestCase;
use Broadway\EventHandling\EventBusInterface;
use Broadway\EventStore\EventStoreInterface;
use CultuurNet\UDB3\UiTPASService\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Command\UpdateDistributionKeys;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\Event\UiTPASAggregateCreated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\UpdateDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\UiTPASAggregateCreated;

class UiTPASAggregateCommandHandlerTest extends CommandHandlerScenarioTestCase
{
Expand Down
30 changes: 15 additions & 15 deletions tests/UiTPASEventSagaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
use CultuurNet\UDB3\PriceInfo\PriceInfo;
use CultuurNet\UDB3\PriceInfo\Tariff;
use CultuurNet\UDB3\Title;
use CultuurNet\UDB3\UiTPASService\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Command\RemotelyRegisterUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Command\RemotelyUpdateUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\Event\UiTPASAggregateCreated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Sync\Command\RegisterUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\Sync\Command\UpdateUiTPASEvent;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysCleared;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\DistributionKeysUpdated;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Event\UiTPASAggregateCreated;
use CultuurNet\UDB3\UiTPASService\Specification\OrganizerSpecificationInterface;
use ValueObjects\Geography\Country;
use ValueObjects\Money\Currency;
Expand Down Expand Up @@ -202,7 +202,7 @@ public function it_creates_an_uitpas_aggregate_and_registers_an_uitpas_event_whe
->then(
[
new CreateUiTPASAggregate($this->eventId, []),
new RemotelyRegisterUiTPASEvent(
new RegisterUiTPASEvent(
new StringLiteral($this->eventId),
new StringLiteral($this->uitpasOrganizerId),
$this->priceInfo
Expand All @@ -227,7 +227,7 @@ public function it_creates_an_uitpas_aggregate_and_registers_an_uitpas_event_whe
->then(
[
new CreateUiTPASAggregate($this->eventId, []),
new RemotelyRegisterUiTPASEvent(
new RegisterUiTPASEvent(
new StringLiteral($this->eventId),
new StringLiteral($this->uitpasOrganizerId),
$this->priceInfo
Expand Down Expand Up @@ -284,7 +284,7 @@ public function it_updates_an_uitpas_event_when_it_has_a_new_uitpas_organizer()
->when(new OrganizerUpdated($this->eventId, $this->updatedUitpasOrganizerId))
->then(
[
new RemotelyUpdateUiTPASEvent(
new UpdateUiTPASEvent(
$this->eventId,
$this->updatedUitpasOrganizerId,
$this->priceInfo
Expand Down Expand Up @@ -318,7 +318,7 @@ public function it_updates_an_uitpas_event_when_it_has_new_price_info()
->when(new PriceInfoUpdated($this->eventId, $updatedPriceInfo))
->then(
[
new RemotelyUpdateUiTPASEvent(
new UpdateUiTPASEvent(
$this->eventId,
$this->uitpasOrganizerId,
$updatedPriceInfo
Expand Down Expand Up @@ -373,7 +373,7 @@ public function it_updates_the_uitpas_event_with_distribution_keys_when_the_uitp
)
->then(
[
new RemotelyUpdateUiTPASEvent(
new UpdateUiTPASEvent(
$this->eventId,
$this->uitpasOrganizerId,
$this->priceInfo,
Expand Down Expand Up @@ -405,7 +405,7 @@ public function it_updates_the_uitpas_event_when_the_distribution_keys_on_the_ui
)
->then(
[
new RemotelyUpdateUiTPASEvent(
new UpdateUiTPASEvent(
$this->eventId,
$this->uitpasOrganizerId,
$this->priceInfo,
Expand Down Expand Up @@ -434,7 +434,7 @@ public function it_updates_the_uitpas_event_when_the_distribution_keys_on_the_ui
)
->then(
[
new RemotelyUpdateUiTPASEvent(
new UpdateUiTPASEvent(
$this->eventId,
$this->uitpasOrganizerId,
$this->priceInfo,
Expand Down Expand Up @@ -466,7 +466,7 @@ public function it_clears_the_distribution_keys_if_the_organizer_is_changed()
)
->then(
[
new RemotelyUpdateUiTPASEvent(
new UpdateUiTPASEvent(
$this->eventId,
$this->updatedUitpasOrganizerId,
$this->priceInfo,
Expand Down

0 comments on commit 2145b2e

Please sign in to comment.