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

[BO - Esabora] Taguer les dossiers comme synchronisés uniquement en cas de succès #2278

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 0 additions & 2 deletions src/Controller/Back/AffectationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ private function dispatchDossier(Affectation $affectation): void
{
$partner = $affectation->getPartner();
if ($partner->canSyncWithEsabora() || $partner->canSyncWithOilhi()) {
$affectation->setIsSynchronized(true);
$this->affectationManager->save($affectation);
$this->interconnectionBus->dispatch($affectation);
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/DataFixtures/Files/Affectation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ affectations:
answered_by: "admin-01@histologe.fr"
affected_by: "admin-01@histologe.fr"
territory: "Pas-de-Calais"
-
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en double

signalement: 2024-01
partner: "partenaire-62-01@histologe.fr"
statut: 0
answered_by: "admin-01@histologe.fr"
affected_by: "admin-01@histologe.fr"
territory: "Pas-de-Calais"
-
signalement: 2023-20
partner: "partenaire-13-01@histologe.fr"
Expand Down
11 changes: 11 additions & 0 deletions src/Manager/AffectationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Entity\Partner;
use App\Entity\Signalement;
use App\Entity\User;
use App\Messenger\Message\DossierMessageInterface;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -104,4 +105,14 @@ function (Affectation $affectation) use ($partner) {
}
}
}

public function flagAsSynchronized(DossierMessageInterface $dossierMessage): void
{
$affectation = $this->getRepository()->findOneBy([
'partner' => $dossierMessage->getPartnerId(),
'signalement' => $dossierMessage->getSignalementId(),
]);
$affectation->setIsSynchronized(true);
$this->save($affectation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Messenger\MessageHandler\Esabora;

use App\Entity\JobEvent;
use App\Manager\AffectationManager;
use App\Manager\JobEventManager;
use App\Messenger\Message\Esabora\DossierMessageSCHS;
use App\Repository\PartnerRepository;
Expand All @@ -23,6 +24,7 @@ public function __construct(
private readonly JobEventManager $jobEventManager,
private readonly SerializerInterface $serializer,
private readonly PartnerRepository $partnerRepository,
private readonly AffectationManager $affectationManager,
) {
}

Expand All @@ -36,17 +38,22 @@ public function __invoke(DossierMessageSCHS $schsDossierMessage): void
{
$response = $this->esaboraService->pushDossier($schsDossierMessage);
$partner = $this->partnerRepository->find($partnerId = $schsDossierMessage->getPartnerId());
$status = 200 === $response->getStatusCode() ? JobEvent::STATUS_SUCCESS : JobEvent::STATUS_FAILED;

$this->jobEventManager->createJobEvent(
service: AbstractEsaboraService::TYPE_SERVICE,
action: AbstractEsaboraService::ACTION_PUSH_DOSSIER,
message: $this->serializer->serialize($schsDossierMessage, 'json'),
response: $response->getContent(throw: false),
status: 200 === $response->getStatusCode() ? JobEvent::STATUS_SUCCESS : JobEvent::STATUS_FAILED,
status: $status,
codeStatus: $response->getStatusCode(),
signalementId: $schsDossierMessage->getSignalementId(),
partnerId: $partnerId,
partnerType: $partner?->getType(),
);

if (JobEvent::STATUS_SUCCESS === $status) {
$this->affectationManager->flagAsSynchronized($schsDossierMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Messenger\MessageHandler\Esabora;

use App\Manager\AffectationManager;
use App\Messenger\Message\Esabora\DossierMessageSISH;
use App\Service\Esabora\Handler\DossierSISHHandlerInterface;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
Expand All @@ -16,7 +17,8 @@ public function __construct(
#[TaggedIterator(
'app.dossier_sish_handler',
defaultPriorityMethod: 'getPriority'
)] iterable $dossierSISHHandlers
)] iterable $dossierSISHHandlers,
private AffectationManager $affectationManager
) {
$this->dossierSISHHandlers = $dossierSISHHandlers;
}
Expand All @@ -26,6 +28,9 @@ public function __invoke(DossierMessageSISH $dossierMessageSISH): void
/** @var DossierSISHHandlerInterface $dossierSISHHandler */
foreach ($this->dossierSISHHandlers as $dossierSISHHandler) {
$dossierSISHHandler->handle($dossierMessageSISH);
if ($dossierSISHHandler->canFlagAsSynchronized()) {
$this->affectationManager->flagAsSynchronized($dossierMessageSISH);
}
}
}
}
6 changes: 6 additions & 0 deletions src/Messenger/MessageHandler/Oilhi/DossierMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Messenger\MessageHandler\Oilhi;

use App\Entity\JobEvent;
use App\Manager\AffectationManager;
use App\Manager\JobEventManager;
use App\Messenger\Message\Oilhi\DossierMessage;
use App\Repository\PartnerRepository;
Expand All @@ -19,6 +20,7 @@ public function __construct(
private JobEventManager $jobEventManager,
private HookZapierService $hookZapierService,
private PartnerRepository $partnerRepository,
private AffectationManager $affectationManager,
) {
}

Expand All @@ -40,5 +42,9 @@ public function __invoke(DossierMessage $dossierMessage): void
partnerId: $partnerId,
partnerType: $partner?->getType(),
);

if (JobEvent::STATUS_SUCCESS === $status) {
$this->affectationManager->flagAsSynchronized($dossierMessage);
}
}
}
10 changes: 9 additions & 1 deletion src/Service/Esabora/Handler/AbstractDossierSISHHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class AbstractDossierSISHHandler implements DossierSISHHandlerInterface
protected mixed $response = null;
protected ?int $sasAdresseId = null;
protected ?int $sasDossierId = null;
protected string $status = JobEvent::STATUS_FAILED;

public function __construct(
private readonly SerializerInterface $serializer,
Expand All @@ -29,18 +30,25 @@ public function handle(DossierMessageSISH $dossierMessageSISH): void
{
$this->sasAdresseId = $dossierMessageSISH->getSasAdresse();
$this->sasDossierId = $dossierMessageSISH->getSasDossierId();
$this->status = 200 === $this->response->getStatusCode() ? JobEvent::STATUS_SUCCESS : JobEvent::STATUS_FAILED;

$this->partner = $this->partnerRepository->find($dossierMessageSISH->getPartnerId());
$this->jobEventManager->createJobEvent(
service: AbstractEsaboraService::TYPE_SERVICE,
action: $this->action,
message: $this->serializer->serialize($dossierMessageSISH, 'json'),
response: $this->serializer->serialize($this->response, 'json'),
status: 200 === $this->response->getStatusCode() ? JobEvent::STATUS_SUCCESS : JobEvent::STATUS_FAILED,
status: $this->status,
codeStatus: $this->response->getStatusCode(),
signalementId: $dossierMessageSISH->getSignalementId(),
partnerId: $this->partner?->getId(),
partnerType: $this->partner?->getType(),
);
}

public function canFlagAsSynchronized(): bool
{
return AbstractEsaboraService::ACTION_PUSH_DOSSIER_PERSONNE === $this->action
&& JobEvent::STATUS_SUCCESS === $this->status;
}
Copy link
Collaborator Author

@sfinx13 sfinx13 Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour rappel un envoi de dossier SISH c'est 3 appels de WS dans cet ordre la

  1. adresse
  2. signalement
  3. personne

Donc si le service personne répond OK (c'est que signalement et adresses ont répondu OK également) alors le dossier est complet et doit être tagué comme synchronisé

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

génial

}
2 changes: 2 additions & 0 deletions src/Service/Esabora/Handler/DossierSISHHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ interface DossierSISHHandlerInterface
{
public function handle(DossierMessageSISH $dossierMessageSISH): void;

public function canFlagAsSynchronized(): bool;

public static function getPriority(): int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Tests\Unit\Messenger\MessageHandler\Esabora;

use App\Entity\Partner;
use App\Manager\AffectationManager;
use App\Manager\JobEventManager;
use App\Messenger\MessageHandler\Esabora\DossierMessageSCHSHandler;
use App\Repository\PartnerRepository;
Expand Down Expand Up @@ -53,11 +54,18 @@ public function testProcessDossierMessage(): void
->with($dossierMessage->getPartnerId())
->willReturn(new Partner());

$affectationManagerMock = $this->createMock(AffectationManager::class);
$affectationManagerMock
->expects($this->once())
->method('flagAsSynchronized')
->with($dossierMessage);

$dossierMessageHandler = new DossierMessageSCHSHandler(
$esaboraServiceMock,
$jobEventManagerMock,
$serializerMock,
$partnerRepositoryMock,
$affectationManagerMock
);

$dossierMessageHandler($dossierMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Tests\Unit\Messenger\MessageHandler\Oilhi;

use App\Entity\Partner;
use App\Manager\AffectationManager;
use App\Manager\JobEventManager;
use App\Messenger\Message\Oilhi\DossierMessage;
use App\Messenger\MessageHandler\Oilhi\DossierMessageHandler;
Expand Down Expand Up @@ -61,11 +62,18 @@ public function testProcessDossierMessage(): void
->with($dossierMessage->getPartnerId())
->willReturn(new Partner());

$affectationManagerMock = $this->createMock(AffectationManager::class);
$affectationManagerMock
->expects($this->once())
->method('flagAsSynchronized')
->with($dossierMessage);

$dossierMessageHandler = new DossierMessageHandler(
$serializerMock,
$jobEventManagerMock,
$hookZapierServiceMock,
$partnerRepositoryMock,
$affectationManagerMock
);

$dossierMessageHandler($dossierMessage);
Expand Down
Loading