Skip to content

Commit db9ceb6

Browse files
authored
Apply dictionary date formats on csv downloads when in reference mode (#4202)
1 parent 4193da7 commit db9ceb6

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

modules/datastore/src/DatastoreService.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,12 @@ public function getImportService(DataResource $resource): ImportService {
216216

217217
/**
218218
* Returns the Data Dictionary fields.
219+
*
220+
* @param string $identifier
221+
* A resource's identifier. Used when in reference mode.
219222
*/
220-
public function getDataDictionaryFields() {
221-
return $this->dictionaryEnforcer->returnDataDictionaryFields();
223+
public function getDataDictionaryFields(string $identifier = NULL) {
224+
return $this->dictionaryEnforcer->returnDataDictionaryFields($identifier);
222225
}
223226

224227
/**

modules/datastore/src/Service/Query.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,15 @@ public function getQueryStorageMap(DatastoreQuery $datastoreQuery) {
129129
*/
130130
public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $csv = FALSE) {
131131
$primaryAlias = $datastoreQuery->{"$.resources[0].alias"};
132+
$resourceId = $datastoreQuery->{"$.resources[0].id"} ?? '';
132133
if (!$primaryAlias) {
133134
return [];
134135
}
135136
$storageMap = $this->getQueryStorageMap($datastoreQuery);
136137

137138
$query = QueryFactory::create($datastoreQuery, $storageMap);
138139
// Get data dictionary fields.
139-
$meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields() : NULL;
140+
$meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields($resourceId) : NULL;
140141
// Pass the data dictionary metadata to the query.
141142
$query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL;
142143

modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,28 @@ public function applyDictionary(RootedJsonData $dictionary, string $datastore_ta
122122
/**
123123
* Returning data dictionary fields from schema.
124124
*
125-
* {@inheritdoc}
125+
* @param string $identifier
126+
* A resource's identifier. Used when in reference mode.
126127
*/
127-
public function returnDataDictionaryFields() {
128-
// Get DD is mode.
128+
public function returnDataDictionaryFields($identifier = NULL) {
129+
// Get data dictionary mode.
129130
$dd_mode = $this->dataDictionaryDiscovery->getDataDictionaryMode();
130131
// Get data dictionary info.
131-
if ($dd_mode == "sitewide") {
132-
$dict_id = $this->dataDictionaryDiscovery->getSitewideDictionaryId();
133-
return $this->metastore->get('data-dictionary', $dict_id)->{"$.data.fields"};
132+
switch ($dd_mode) {
133+
case "sitewide":
134+
$dictionary_id = $this->dataDictionaryDiscovery->getSitewideDictionaryId();
135+
break;
136+
137+
case "reference":
138+
$resource = DataResource::getIdentifierAndVersion($identifier);
139+
$dictionary_id = $this->dataDictionaryDiscovery->dictionaryIdFromResource($resource[0]);
140+
break;
141+
142+
default:
143+
return;
134144
}
145+
146+
return $this->metastore->get('data-dictionary', $dictionary_id)->{"$.data.fields"};
135147
}
136148

137149
}

0 commit comments

Comments
 (0)