Skip to content

Commit

Permalink
feat: exploitation des métadonnées taguées bis #301
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Apr 24, 2024
1 parent d6f5291 commit abb2f05
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const DatasheetListItem: FC<DatasheetListItemProps> = ({ datastoreId, datasheet
{/* <div className={fr.cx("fr-col-2")}>{datasheet?.date ? formatDateFromISO(datasheet.date) : ""}</div> */}
<div className={fr.cx("fr-col-2")}>
<Badge noIcon={true} severity="info">
{datasheet?.nb_publications > 0 ? `Publié (${datasheet?.nb_publications})` : "Non Publié"}
{datasheet?.nb_publications > 0
? `Publié (${datasheet?.nb_publications})`
: datasheet.metadata_published === true
? "Publié"
: "Non Publié"}
</Badge>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
/>
<h1 className={fr.cx("fr-m-0")}>{datasheetName}</h1>
<Badge noIcon={true} severity="info" className={fr.cx("fr-ml-2w")}>
{datasheetQuery?.data?.nb_publications && datasheetQuery?.data?.nb_publications > 0
{(datasheetQuery?.data?.nb_publications && datasheetQuery?.data?.nb_publications > 0) ||
datasheetQuery.data?.metadata_published === true
? tCommon("published")
: tCommon("not_published")}
</Badge>
Expand Down
32 changes: 29 additions & 3 deletions src/Controller/Entrepot/DatasheetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ public function getDatasheetList(string $datastoreId): JsonResponse
}
}, $storedDataList);

$uniqueDatasheetNames = array_unique(array_merge($uploadDatasheetNames, $storedDataDatasheetNames));
$metadataList = $this->metadataApiService->getAll($datastoreId);

$metadataDatasheetNames = array_map(function ($apiMetadata) {
if (isset($apiMetadata['tags'][CommonTags::DATASHEET_NAME])) {
return $apiMetadata['tags'][CommonTags::DATASHEET_NAME];
}
}, $metadataList);

$uniqueDatasheetNames = array_unique(array_merge($uploadDatasheetNames, $storedDataDatasheetNames, $metadataDatasheetNames));
$uniqueDatasheetNames = array_filter($uniqueDatasheetNames);
$uniqueDatasheetNames = array_values($uniqueDatasheetNames);

Expand Down Expand Up @@ -100,9 +108,13 @@ public function getDetailed(string $datastoreId, string $datasheetName): JsonRes
],
]);

// TODO récup liste metadata
$metadataList = $this->metadataApiService->getAll($datastoreId, [
'tags' => [
CommonTags::DATASHEET_NAME => $datasheetName,
],
]);

if (0 === count($uploadList) && 0 === count($vectorDbList) && 0 === count($pyramidList)) {
if (0 === count($uploadList) && 0 === count($vectorDbList) && 0 === count($pyramidList) && 0 === count($metadataList)) {
throw new CartesApiException("La fiche de donnée [$datasheetName] n'existe pas", Response::HTTP_NOT_FOUND);
}

Expand Down Expand Up @@ -148,6 +160,14 @@ private function getBasicInfo(string $datastoreId, string $datasheetName): array
]);
$nbPublications = count($configurations);

// recherche de metadata associée
$metadataList = $this->metadataApiService->getAll($datastoreId, [
'tags' => [
CommonTags::DATASHEET_NAME => $datasheetName,
],
]);
$metadataPublished = count($metadataList) > 0;

// recherche de vignette
$annexeUrl = $this->getParameter('annexes_url');
$annexes = $this->annexeApiService->getAll($datastoreId, null, null, ["datasheet_name=$datasheetName", 'type=thumbnail']);
Expand All @@ -164,6 +184,7 @@ private function getBasicInfo(string $datastoreId, string $datasheetName): array
'categories' => [],
'nb_publications' => $nbPublications,
'thumbnail' => $thumbnail,
'metadata_published' => $metadataPublished,
];
}

Expand Down Expand Up @@ -234,6 +255,11 @@ public function delete(string $datastoreId, string $datasheetName): Response

if (count($metadataList) > 0) {
$metadata = $metadataList[0];

foreach ($metadata['endpoints'] as $metadataEndpoint) {
$this->metadataApiService->unpublish($datastoreId, $metadata['file_identifier'], $metadataEndpoint['_id']);
}

$this->metadataApiService->delete($datastoreId, $metadata['_id']);
}

Expand Down

0 comments on commit abb2f05

Please sign in to comment.