Skip to content

Commit

Permalink
Merge pull request #73 from CommonGateway/feature/PC173-5/sync-zaak-o…
Browse files Browse the repository at this point in the history
…p-trigger

Synchronize cases on trigger, trigger from sync command
  • Loading branch information
rjzondervan authored Feb 8, 2024
2 parents 8f8215f + 7d51fc0 commit 53e0e48
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Installation/installation.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
{
"reference": "https://development.zaaksysteem.nl/action/xxllnc.Zaak.action.json",
"actionHandler": "CommonGateway\\XxllncZGWBundle\\ActionHandler\\ZaakHandler",
"listens": ["xxllnc.cronjob.trigger"]
"listens": ["xxllnc.cronjob.trigger", "xxllnc.case.received"],
"async": true
},
{
"reference": "https://development.zaaksysteem.nl/action/xxllnc.ZaakType.action.json",
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ZaakCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->zaakService->setStyle($style);
$zaakId = $input->getArgument('id');

$action = $this->entityManager->getRepository('App:Action')->findOneBy(['reference' => 'https://development.zaaksysteem.nl/action/xxllnc.Zaak.action.json']);
$action = $this->entityManager->getRepository(Action::class)->findOneBy(['reference' => 'https://development.zaaksysteem.nl/action/xxllnc.Zaak.action.json']);
if ($action instanceof Action === null) {
$style->error('Action with reference https://development.zaaksysteem.nl/action/xxllnc.Zaak.action.json not found');

Check warning on line 97 in src/Command/ZaakCommand.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 127 characters

Expand Down
54 changes: 37 additions & 17 deletions src/Service/ZaakService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Entity\Gateway as Source;
use App\Entity\ObjectEntity;
use App\Event\ActionEvent;
use App\Service\SynchronizationService;
use CommonGateway\CoreBundle\Service\GatewayResourceService;
use CommonGateway\CoreBundle\Service\MappingService;
Expand All @@ -23,6 +24,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Console\Style\SymfonyStyle;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;

class ZaakService
Expand Down Expand Up @@ -88,6 +90,11 @@ class ZaakService
*/
private LoggerInterface $logger;

/**
* @var EventDispatcherInterface The event dispatcher.
*/
private EventDispatcherInterface $eventDispatcher;


/**
* __construct.
Expand All @@ -100,7 +107,8 @@ public function __construct(
ZaakTypeService $zaakTypeService,
GatewayResourceService $resourceService,
MappingService $mappingService,
LoggerInterface $pluginLogger
LoggerInterface $pluginLogger,
EventDispatcherInterface $eventDispatcher
) {
$this->entityManager = $entityManager;
$this->synchronizationService = $synchronizationService;
Expand All @@ -110,6 +118,7 @@ public function __construct(
$this->resourceService = $resourceService;
$this->mappingService = $mappingService;
$this->logger = $pluginLogger;
$this->eventDispatcher = $eventDispatcher;

}//end __construct()

Expand Down Expand Up @@ -329,7 +338,7 @@ private function createFileEndpoints(ObjectEntity $zaak): void
*
* @return ObjectEntity The resulting zaak object.
*/
public function syncCase(array $case, bool $flush = true): ObjectEntity
public function syncCase(array $case, bool $flush = true): ?ObjectEntity
{
// 0. Get required config objects.
$zaakSchema = $this->resourceService->getSchema(
Expand Down Expand Up @@ -473,6 +482,10 @@ public function zaakHandler(?array $data = [], ?array $configuration = [])
return null;
}

if (isset($data['caseId']) === true) {
$this->getZaak($configuration, $data['caseId']);
}

isset($this->style) === true && $this->zaakTypeService->setStyle($this->style);

// Fetch the xxllnc cases.
Expand Down Expand Up @@ -500,22 +513,29 @@ public function zaakHandler(?array $data = [], ?array $configuration = [])
$createdZaakCount = 0;
$flushCount = 0;
foreach ($xxllncCases as $case) {
if ($this->syncCase($case) instanceof ObjectEntity === false) {
isset($this->style) === true && $this->style->error("Could not sync a case");
$this->logger->error("Could not sync a case");

continue;
}

$createdZaakCount = ($createdZaakCount + 1);
$flushCount = ($flushCount + 1);

$event = new ActionEvent(
'commongateway.action.event',
['caseId' => $case['reference']],
'xxllnc.case.received'
);
$this->eventDispatcher->dispatch($event, 'commongateway.action.event');

// if ($this->syncCase($case) instanceof ObjectEntity === false) {
// isset($this->style) === true && $this->style->error("Could not sync a case");
// $this->logger->error("Could not sync a case");
//
// continue;
// }
//
// $createdZaakCount = ($createdZaakCount + 1);
// $flushCount = ($flushCount + 1);
//
// Flush every 20
if ($flushCount == 20) {
$this->entityManager->flush();
$this->entityManager->flush();
$flushCount = 0;
}//end if
// if ($flushCount == 20) {
// $this->entityManager->flush();
// $this->entityManager->flush();
// $flushCount = 0;
// }//end if
}//end foreach

isset($this->style) === true && $this->style->success("Created $createdZaakCount zaken from the $caseCount fetched cases");
Expand Down

0 comments on commit 53e0e48

Please sign in to comment.