From db9ceb6fa5a5f752b9be0d05ff21b64c2b579ce6 Mon Sep 17 00:00:00 2001 From: Janette Day Date: Thu, 27 Jun 2024 09:22:30 -0500 Subject: [PATCH] Apply dictionary date formats on csv downloads when in reference mode (#4202) --- modules/datastore/src/DatastoreService.php | 7 ++++-- modules/datastore/src/Service/Query.php | 3 ++- .../ResourceProcessor/DictionaryEnforcer.php | 24 ++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/modules/datastore/src/DatastoreService.php b/modules/datastore/src/DatastoreService.php index f1714e875b..4d679e0bfa 100644 --- a/modules/datastore/src/DatastoreService.php +++ b/modules/datastore/src/DatastoreService.php @@ -216,9 +216,12 @@ public function getImportService(DataResource $resource): ImportService { /** * Returns the Data Dictionary fields. + * + * @param string $identifier + * A resource's identifier. Used when in reference mode. */ - public function getDataDictionaryFields() { - return $this->dictionaryEnforcer->returnDataDictionaryFields(); + public function getDataDictionaryFields(string $identifier = NULL) { + return $this->dictionaryEnforcer->returnDataDictionaryFields($identifier); } /** diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index d9c9a6129c..135ad4f5a5 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -129,6 +129,7 @@ public function getQueryStorageMap(DatastoreQuery $datastoreQuery) { */ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $csv = FALSE) { $primaryAlias = $datastoreQuery->{"$.resources[0].alias"}; + $resourceId = $datastoreQuery->{"$.resources[0].id"} ?? ''; if (!$primaryAlias) { return []; } @@ -136,7 +137,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ $query = QueryFactory::create($datastoreQuery, $storageMap); // Get data dictionary fields. - $meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields() : NULL; + $meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields($resourceId) : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; diff --git a/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php b/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php index 30fd3e6677..81a95f9b02 100644 --- a/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php +++ b/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php @@ -122,16 +122,28 @@ public function applyDictionary(RootedJsonData $dictionary, string $datastore_ta /** * Returning data dictionary fields from schema. * - * {@inheritdoc} + * @param string $identifier + * A resource's identifier. Used when in reference mode. */ - public function returnDataDictionaryFields() { - // Get DD is mode. + public function returnDataDictionaryFields($identifier = NULL) { + // Get data dictionary mode. $dd_mode = $this->dataDictionaryDiscovery->getDataDictionaryMode(); // Get data dictionary info. - if ($dd_mode == "sitewide") { - $dict_id = $this->dataDictionaryDiscovery->getSitewideDictionaryId(); - return $this->metastore->get('data-dictionary', $dict_id)->{"$.data.fields"}; + switch ($dd_mode) { + case "sitewide": + $dictionary_id = $this->dataDictionaryDiscovery->getSitewideDictionaryId(); + break; + + case "reference": + $resource = DataResource::getIdentifierAndVersion($identifier); + $dictionary_id = $this->dataDictionaryDiscovery->dictionaryIdFromResource($resource[0]); + break; + + default: + return; } + + return $this->metastore->get('data-dictionary', $dictionary_id)->{"$.data.fields"}; } }