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

Commit

Permalink
III-1843 The CopiedCriteriaInterface is the trigger to include the re…
Browse files Browse the repository at this point in the history
…moved saga’s.
  • Loading branch information
Luc Wollants committed Feb 6, 2017
1 parent 7a73e55 commit 07c68bf
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 41 deletions.
10 changes: 1 addition & 9 deletions src/Broadway/Saga/MultipleSagaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Broadway\Saga\SagaInterface;
use Broadway\Saga\SagaManagerInterface;
use Broadway\Saga\State;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\State\Criteria\CopiedCriteriaInterface;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\State\RepositoryInterface;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\State\StateCopierInterface;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\State\StateManagerInterface;
Expand Down Expand Up @@ -95,18 +94,11 @@ public function handle(DomainMessage $domainMessage)
// event with a new state.
$state = $this->stateManager->generateNewState();
$this->handleEventBySagaWithState($sagaType, $saga, $event, $state);
} elseif ($criteria instanceof CopiedCriteriaInterface) {
// For a copy a new state is needed with values from original event.
$states = $this->stateManager->findBy($criteria, $sagaType, false);
foreach ($states as $state) {
// TODO: What if more then one state returned?
$state = $this->stateCopier->copy($state);
$this->handleEventBySagaWithState($sagaType, $saga, $event, $state);
}
} else {
// If actual criteria are given, fetch all matching states and
// update them one by one.
foreach ($this->stateManager->findBy($criteria, $sagaType) as $state) {
// TODO: For CopiedCriteria only one state should be found.
$this->handleEventBySagaWithState($sagaType, $saga, $event, $state);
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/Broadway/Saga/State/Criteria/ExcludeRemovedCriteria.php

This file was deleted.

This file was deleted.

8 changes: 5 additions & 3 deletions src/Broadway/Saga/State/InMemoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Broadway\Saga\State;
use Broadway\Saga\State\Criteria;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\State\Criteria\CopiedCriteriaInterface;

/**
* Copied from Broadway\Saga\State\InMemoryRepository and modified
Expand All @@ -16,7 +17,7 @@ class InMemoryRepository implements RepositoryInterface
/**
* {@inheritDoc}
*/
public function findBy(Criteria $criteria, $sagaId, $excludeRemoved = true)
public function findBy(Criteria $criteria, $sagaId)
{
if (!isset($this->states[$sagaId])) {
$states = [];
Expand All @@ -27,9 +28,10 @@ public function findBy(Criteria $criteria, $sagaId, $excludeRemoved = true)
foreach ($criteria->getComparisons() as $key => $value) {
$states = array_filter(
$states,
function ($elem) use ($key, $value, $excludeRemoved) {
function ($elem) use ($key, $value, $criteria) {
/** @var State $elem */
if ($excludeRemoved && $elem->isDone()) {
if (!($criteria instanceof CopiedCriteriaInterface)
&& $elem->isDone()) {
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Broadway/Saga/State/MongoDBRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Broadway\Saga\State;
use Broadway\Saga\State\Criteria;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\State\Criteria\CopiedCriteriaInterface;
use Doctrine\MongoDB\Collection;
use Doctrine\MongoDB\Query\Query;

Expand All @@ -26,9 +27,9 @@ public function __construct(Collection $collection)
/**
* {@inheritDoc}
*/
public function findBy(Criteria $criteria, $sagaId, $excludeRemoved = true)
public function findBy(Criteria $criteria, $sagaId)
{
$query = $this->createQuery($criteria, $sagaId, $excludeRemoved);
$query = $this->createQuery($criteria, $sagaId);
$results = $query->execute();

foreach ($results as $result) {
Expand All @@ -52,10 +53,9 @@ public function save(State $state, $sagaId)
/**
* @param Criteria $criteria
* @param string $sagaId
* @param bool $excludeRemoved
* @return Query
*/
private function createQuery(Criteria $criteria, $sagaId, $excludeRemoved)
private function createQuery(Criteria $criteria, $sagaId)
{
$comparisons = $criteria->getComparisons();
$wheres = [];
Expand All @@ -68,7 +68,7 @@ private function createQuery(Criteria $criteria, $sagaId, $excludeRemoved)
->addAnd($wheres)
->addAnd(['sagaId' => $sagaId]);

if ($excludeRemoved) {
if (!($criteria instanceof CopiedCriteriaInterface)) {
$queryBuilder->addAnd(['removed' => false]);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Broadway/Saga/State/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ interface RepositoryInterface
/**
* @param Criteria $criteria
* @param string $sagaId
* @param bool $excludeRemoved
* @return State[]|\Generator
*/
public function findBy(Criteria $criteria, $sagaId, $excludeRemoved = true);
public function findBy(Criteria $criteria, $sagaId);

/**
* @param State $state
Expand Down
4 changes: 2 additions & 2 deletions src/Broadway/Saga/State/StateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public function __construct(RepositoryInterface $repository, UuidGeneratorInterf
/**
* {@inheritDoc}
*/
public function findBy($criteria, $sagaId, $excludeRemoved = true)
public function findBy($criteria, $sagaId)
{
// @todo Use "yield from" when minimum requirement is PHP7.
foreach ($this->repository->findBy($criteria, $sagaId, $excludeRemoved) as $state) {
foreach ($this->repository->findBy($criteria, $sagaId) as $state) {
yield $state;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Broadway/Saga/State/StateManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ interface StateManagerInterface
/**
* @param null|Criteria $criteria
* @param string $sagaId
* @param bool $excludeRemoved
* @return State[]|\Generator
*/
public function findBy($criteria, $sagaId, $excludeRemoved = true);
public function findBy($criteria, $sagaId);

/**
* @return State
Expand Down

0 comments on commit 07c68bf

Please sign in to comment.