Skip to content

Commit d8743cd

Browse files
Merge branch 'notification-step-by-step' into 'main'
Notification step by step See merge request disi/innovation/aristote/aristoteapi!93
2 parents 799174a + 7830806 commit d8743cd

12 files changed

+146
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250504162143 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE enrichment ADD notification_level VARCHAR(255) DEFAULT NULL');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE enrichment DROP notification_level');
30+
}
31+
}

src/Admin/EnrichmentAdmin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Admin;
44

5+
use App\Constants;
56
use App\Entity\Enrichment;
67
use Sonata\AdminBundle\Admin\AbstractAdmin;
78
use Sonata\AdminBundle\Datagrid\DatagridInterface;
@@ -78,6 +79,11 @@ protected function configureFormFields(FormMapper $form): void
7879
'by_reference' => false,
7980
'entry_type' => TextType::class,
8081
'prototype' => true,
82+
])
83+
->add('notificationWebhookUrl', null, ['label' => 'URL de notification'])
84+
->add('notificationLevel', ChoiceType::class, [
85+
'label' => 'Niveau de notification',
86+
'choices' => Constants::getNotificationLevels(),
8187
]);
8288
}
8389

@@ -112,6 +118,7 @@ protected function configureShowFields(ShowMapper $show): void
112118
->add('failureCause', null, ['label' => "Cause d'erreur"])
113119
->add('mediaUrl', null, ['label' => 'Média URL'])
114120
->add('notificationWebhookUrl', null, ['label' => 'URL de notification'])
121+
->add('notificationLevel', null, ['label' => 'Niveau de notification'])
115122
->add('media.originalFileName', null, ['label' => 'Nom du fichier'])
116123
->add('deleted', null, ['label' => 'Supprimé'])
117124
;

src/Constants.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ final class Constants
2828
public const PARAMETER_AI_ENRICHMENT_WORKER_TIMEOUT_IN_MINUTES = 'AI_ENRICHMENT_WORKER_TIMEOUT_IN_MINUTES';
2929
public const PARAMETER_TRANSLATION_WORKER_TIMEOUT_IN_MINUTES = 'TRANSLATION_WORKER_TIMEOUT_IN_MINUTES';
3030
public const PARAMETER_AI_EVALUATION_WORKER_TIMEOUT_IN_MINUTES = 'AI_EVALUATION_WORKER_TIMEOUT_IN_MINUTES';
31+
public const NOTIFICATION_LEVEL_DEFAULT = 'default';
32+
public const NOTIFICATION_LEVEL_TASK = 'task';
3133

3234
public static function getEvaluators(): array
3335
{
@@ -52,6 +54,14 @@ public static function getMandatoryParameters(): array
5254
];
5355
}
5456

57+
public static function getNotificationLevels(): array
58+
{
59+
return [
60+
self::NOTIFICATION_LEVEL_DEFAULT => self::NOTIFICATION_LEVEL_DEFAULT,
61+
self::NOTIFICATION_LEVEL_TASK => self::NOTIFICATION_LEVEL_TASK,
62+
];
63+
}
64+
5565
public static function getAvailableScopes(): array
5666
{
5767
return [

src/Controller/Api/AiEnrichmentsWorkerController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ public function completeInitialEnrichmentVersionsByEnrichmentVersionID(
220220

221221
if (Enrichment::STATUS_SUCCESS === $targetStatus) {
222222
$this->enrichmentUtils->sendNotification($enrichment);
223+
} elseif (Constants::NOTIFICATION_LEVEL_TASK === $enrichment->getNotificationLevel()) {
224+
$this->enrichmentUtils->sendNotification($enrichment, Enrichment::STATUS_AI_ENRICHING);
223225
}
224226
$enrichment->getAiProcessedBy()->setJobLastSuccessAt(new DateTime());
225227
$entityManager->flush();

src/Controller/Api/EnrichmentsController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ public function createEnrichmentFromUrl(
11731173
->setLatestEnrichmentRequestedAt(new DateTime())
11741174
->setMediaUrl($enrichmentCreationUrlRequestPayload->getUrl())
11751175
->setNotificationWebhookUrl($enrichmentCreationUrlRequestPayload->getNotificationWebhookUrl())
1176+
->setNotificationLevel($enrichmentCreationUrlRequestPayload->getNotificationLevel())
11761177
->setDisciplines($enrichmentCreationUrlRequestPayload->getEnrichmentParameters()->getDisciplines())
11771178
->setMediaTypes($enrichmentCreationUrlRequestPayload->getEnrichmentParameters()->getMediaTypes())
11781179
->setAiEvaluation($enrichmentCreationUrlRequestPayload->getEnrichmentParameters()->getAiEvaluation())
@@ -1288,6 +1289,7 @@ public function createEnrichmentFromUploadedFile(
12881289
$enrichmentCreationFileUploadRequestPayload = (new EnrichmentCreationFileUploadRequestPayload())
12891290
->setFile($file)
12901291
->setNotificationWebhookUrl($request->request->get('notificationWebhookUrl'))
1292+
->setNotificationLevel($request->request->get('notificationLevel'))
12911293
->setEndUserIdentifier(null === $endUserIdentifier || '' === $endUserIdentifier ? null : $endUserIdentifier)
12921294
->setEnrichmentParameters((new EnrichmentParameters())
12931295
->setDisciplines($inputEnrichmentParameters['disciplines'] ?? [])
@@ -1335,6 +1337,7 @@ public function createEnrichmentFromUploadedFile(
13351337
->setCreatedBy($clientEntity)
13361338
->setLatestEnrichmentRequestedAt(new DateTime())
13371339
->setNotificationWebhookUrl($enrichmentCreationFileUploadRequestPayload->getNotificationWebhookUrl())
1340+
->setNotificationLevel($enrichmentCreationFileUploadRequestPayload->getNotificationLevel())
13381341
->setDisciplines($enrichmentCreationFileUploadRequestPayload->getEnrichmentParameters()->getDisciplines())
13391342
->setMediaTypes($enrichmentCreationFileUploadRequestPayload->getEnrichmentParameters()->getMediaTypes())
13401343
->setAiEvaluation($enrichmentCreationFileUploadRequestPayload->getEnrichmentParameters()->getAiEvaluation())
@@ -1499,6 +1502,7 @@ public function createNewAiEnrichment(
14991502
->setTranslationRetries(0)
15001503
->setEvaluationRetries(0)
15011504
->setNotificationWebhookUrl($enrichmentCreationRequestPayload->getNotificationWebhookUrl())
1505+
->setNotificationLevel($enrichmentCreationRequestPayload->getNotificationLevel())
15021506
->setDisciplines($enrichmentCreationRequestPayload->getEnrichmentParameters()->getDisciplines())
15031507
->setMediaTypes($enrichmentCreationRequestPayload->getEnrichmentParameters()->getMediaTypes())
15041508
->setAiEvaluation($enrichmentCreationRequestPayload->getEnrichmentParameters()->getAiEvaluation())

src/Controller/Api/TranscribingWorkerController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ public function createInitialEnrichmentVersionsByEnrichmentID(
253253

254254
if (Enrichment::STATUS_SUCCESS === $targetStatus) {
255255
$this->enrichmentUtils->sendNotification($enrichment);
256+
} elseif (Constants::NOTIFICATION_LEVEL_TASK === $enrichment->getNotificationLevel()) {
257+
$this->enrichmentUtils->sendNotification($enrichment, Enrichment::STATUS_TRANSCRIBING_MEDIA);
256258
}
257259

258260
return $this->json(['status' => 'OK', 'id' => $enrichmentVersion->getId()]);

src/Controller/Api/TranslationWorkerController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ public function translateEnrichmentVersion(
295295

296296
if (Enrichment::STATUS_SUCCESS === $targetStatus) {
297297
$this->enrichmentUtils->sendNotification($enrichment);
298+
} elseif (Constants::NOTIFICATION_LEVEL_TASK === $enrichment->getNotificationLevel()) {
299+
$this->enrichmentUtils->sendNotification($enrichment, Enrichment::STATUS_TRANSLATING);
298300
}
299301
$enrichment->getTranslatedBy()->setJobLastSuccessAt(new DateTime());
300302
$entityManager->flush();

src/Entity/Enrichment.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Entity;
44

5+
use App\Constants;
56
use App\Repository\EnrichmentRepository;
67
use App\Validator\Constraints as AppAssert;
78
use DateTimeInterface;
@@ -53,6 +54,15 @@ public static function getPossibleStatuses(): array
5354
];
5455
}
5556

57+
public static function getPossibleCompletedSteps(): array
58+
{
59+
return [
60+
self::STATUS_TRANSCRIBING_MEDIA => self::STATUS_TRANSCRIBING_MEDIA,
61+
self::STATUS_AI_ENRICHING => self::STATUS_AI_ENRICHING,
62+
self::STATUS_TRANSLATING => self::STATUS_TRANSLATING,
63+
];
64+
}
65+
5666
final public const LANGUAGE_FR = 'fr';
5767
final public const LANGUAGE_EN = 'en';
5868

@@ -320,6 +330,10 @@ public static function getSortFields(): array
320330
#[Groups(groups: ['enrichments'])]
321331
private ?int $mediaDurationInSeconds = null;
322332

333+
#[ORM\Column(type: 'string', nullable: true)]
334+
#[Assert\Choice(callback: [Constants::class, 'getNotificationLevels'], multiple: false, message: 'Invalid notificationLevel value')]
335+
private ?string $notificationLevel = null;
336+
323337
#[Groups(groups: ['enrichments'])]
324338
#[OA\Property(property: 'initialVersionId', description: "Enrichment's initial version ID", type: 'string')]
325339
public function getInitialVersionId(): ?Uuid
@@ -1010,4 +1024,16 @@ public function setMediaDurationInSeconds(?int $mediaDurationInSeconds): self
10101024

10111025
return $this;
10121026
}
1027+
1028+
public function getNotificationLevel(): ?string
1029+
{
1030+
return $this->notificationLevel;
1031+
}
1032+
1033+
public function setNotificationLevel(?string $notificationLevel): self
1034+
{
1035+
$this->notificationLevel = $notificationLevel;
1036+
1037+
return $this;
1038+
}
10131039
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Exception;
4+
5+
use Exception;
6+
7+
class EnrichmentWebhookPayloadValidationException extends Exception
8+
{
9+
}

src/Model/EnrichmentCreationRequestPayload.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Model;
44

5+
use App\Constants;
56
use Nelmio\ApiDocBundle\Annotation\Model;
67
use OpenApi\Attributes as OA;
78
use Symfony\Component\Serializer\Annotation\Groups;
@@ -16,6 +17,11 @@ class EnrichmentCreationRequestPayload
1617
#[Groups(['Default'])]
1718
private ?string $notificationWebhookUrl = null;
1819

20+
#[OA\Property(property: 'notificationLevel', description: 'Choose to receive notifications only at the end of the enrichment or at each step of the process', type: 'string', required: false)]
21+
#[Assert\Choice(callback: [Constants::class, 'getNotificationLevels'], multiple: false, message: 'Invalid notificationLevel value')]
22+
#[Groups(['Default'])]
23+
private ?string $notificationLevel = null;
24+
1925
#[OA\Property(property: 'enrichmentParameters', type: 'object', ref: new Model(type: EnrichmentParameters::class))]
2026
#[Assert\Valid]
2127
#[Groups(['Default'])]
@@ -37,6 +43,18 @@ public function setNotificationWebhookUrl(?string $notificationWebhookUrl): stat
3743
return $this;
3844
}
3945

46+
public function getNotificationLevel(): ?string
47+
{
48+
return $this->notificationLevel;
49+
}
50+
51+
public function setNotificationLevel(?string $notificationLevel): static
52+
{
53+
$this->notificationLevel = $notificationLevel;
54+
55+
return $this;
56+
}
57+
4058
public function getEnrichmentParameters(): ?EnrichmentParameters
4159
{
4260
return $this->enrichmentParameters;

0 commit comments

Comments
 (0)