|
32 | 32 | use App\Models\ToolHasTypeCategory; |
33 | 33 | use App\Models\TypeCategory; |
34 | 34 | use App\Services\DatasetService; |
| 35 | +use App\Services\Gwdm\GwdmHandlerFactory; |
35 | 36 | use ElasticClientController as ECC; |
36 | 37 |
|
37 | 38 | trait IndexElastic |
@@ -85,6 +86,18 @@ private function reconstructedLatestEnvelope(Dataset $dataset): array |
85 | 86 | ); |
86 | 87 | } |
87 | 88 |
|
| 89 | + // Whether this envelope's GWDM version should be indexed into Elasticsearch. |
| 90 | + private function isElasticIndexable(array $envelope): bool |
| 91 | + { |
| 92 | + $version = $envelope['gwdmVersion'] ?? null; |
| 93 | + |
| 94 | + if ($version === null) { |
| 95 | + return true; // no version info available — preserve current behaviour |
| 96 | + } |
| 97 | + |
| 98 | + return app(GwdmHandlerFactory::class)->resolve($version)->supportsElasticIndexing(); |
| 99 | + } |
| 100 | + |
88 | 101 | /** |
89 | 102 | * Calls a re-indexing of Elastic search when a dataset is created, updated or added to a collection. |
90 | 103 | * |
@@ -114,6 +127,12 @@ public function reindexElastic(string $datasetId, bool $returnParams = false, bo |
114 | 127 | } |
115 | 128 |
|
116 | 129 | $metadata = $this->reconstructedLatestEnvelope($datasetMatch); |
| 130 | + |
| 131 | + if (!$this->isElasticIndexable($metadata)) { |
| 132 | + $this->deleteDatasetFromElastic($datasetId); |
| 133 | + return null; |
| 134 | + } |
| 135 | + |
117 | 136 | $latestVersion = $datasetMatch->latestVersion(); |
118 | 137 |
|
119 | 138 | // inject relationships via Local functions |
@@ -333,13 +352,16 @@ public function reindexElasticDataProvider(string $teamId, bool $returnParams = |
333 | 352 |
|
334 | 353 | $latestVersion = $dataset->latestVersion(); |
335 | 354 | if ($latestVersion) { |
336 | | - $datasetVersionIds[] = $latestVersion->id; |
337 | | - $metadata = $latestVersion->metadata; |
338 | | - $datasetTitles[] = $latestVersion->short_title ?? ($metadata['metadata']['summary']['shortTitle'] ?? ''); |
339 | | - $types = explode(';,;', $metadata['metadata']['summary']['datasetType']); |
340 | | - foreach ($types as $t) { |
341 | | - if (!in_array($t, $dataTypes)) { |
342 | | - $dataTypes[] = $t; |
| 355 | + $metadata = $this->reconstructedLatestEnvelope($dataset); |
| 356 | + |
| 357 | + if ($this->isElasticIndexable($metadata)) { |
| 358 | + $datasetVersionIds[] = $latestVersion->id; |
| 359 | + $datasetTitles[] = $latestVersion->short_title ?? $this->getValueByPossibleKeys($metadata, ['metadata.summary.shortTitle'], ''); |
| 360 | + $types = $this->normalizeDelimitedList($this->getValueByPossibleKeys($metadata, ['metadata.summary.datasetType'], '')); |
| 361 | + foreach ($types as $t) { |
| 362 | + if (!in_array($t, $dataTypes)) { |
| 363 | + $dataTypes[] = $t; |
| 364 | + } |
343 | 365 | } |
344 | 366 | } |
345 | 367 | } |
@@ -505,10 +527,19 @@ public function indexElasticCollections(int $collectionId, bool $returnParams = |
505 | 527 | $datasetTitles = array(); |
506 | 528 | $datasetAbstracts = array(); |
507 | 529 | foreach ($datasetIds as $d) { |
508 | | - $latestVersion = Dataset::where(['id' => $d])->first()->latestVersion(); |
509 | | - $metadata = $latestVersion->metadata; |
510 | | - $datasetTitles[] = $latestVersion->short_title ?? ($metadata['metadata']['summary']['shortTitle'] ?? ''); |
511 | | - $datasetAbstracts[] = $metadata['metadata']['summary']['abstract']; |
| 530 | + $datasetRow = Dataset::where(['id' => $d])->first(); |
| 531 | + $latestVersion = $datasetRow?->latestVersion(); |
| 532 | + if (!$latestVersion) { |
| 533 | + continue; |
| 534 | + } |
| 535 | + |
| 536 | + $metadata = $this->reconstructedLatestEnvelope($datasetRow); |
| 537 | + if (!$this->isElasticIndexable($metadata)) { |
| 538 | + continue; |
| 539 | + } |
| 540 | + |
| 541 | + $datasetTitles[] = $latestVersion->short_title ?? $this->getValueByPossibleKeys($metadata, ['metadata.summary.shortTitle'], ''); |
| 542 | + $datasetAbstracts[] = $this->getValueByPossibleKeys($metadata, ['metadata.summary.abstract'], ''); |
512 | 543 | } |
513 | 544 |
|
514 | 545 | $keywords = array(); |
@@ -1009,7 +1040,10 @@ public function deleteDataProviderCollFromElastic(string $id) |
1009 | 1040 | public function getMaterialTypes(array $metadata): array|null |
1010 | 1041 | { |
1011 | 1042 | $materialTypes = null; |
1012 | | - if (version_compare(Config::get('metadata.GWDM.version'), "2.0", "<")) { |
| 1043 | + // Check the reconstructed envelope's own gwdmVersion, not the global config |
| 1044 | + // default — a dataset's actual version can diverge from that default. |
| 1045 | + $rowGwdmVersion = $metadata['gwdmVersion'] ?? Config::get('metadata.GWDM.version'); |
| 1046 | + if (version_compare($rowGwdmVersion, "2.0", "<")) { |
1013 | 1047 | $containsTissue = !empty($this->getValueByPossibleKeys($metadata, [ |
1014 | 1048 | 'metadata.coverage.biologicalsamples', |
1015 | 1049 | 'metadata.coverage.physicalSampleAvailability', |
|
0 commit comments