Skip to content

Commit

Permalink
Apply dictionary date formats on csv downloads when in reference mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
janette authored Jun 27, 2024
1 parent 4193da7 commit db9ceb6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
7 changes: 5 additions & 2 deletions modules/datastore/src/DatastoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/datastore/src/Service/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,15 @@ 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 [];
}
$storageMap = $this->getQueryStorageMap($datastoreQuery);

$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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}

}

0 comments on commit db9ceb6

Please sign in to comment.