From 785492583ddefe6572d1937fb3b417868c821e59 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 9 Nov 2022 14:05:37 -0600 Subject: [PATCH 001/117] Formatting date field to match the data dictionary value being imported --- .../Controller/QueryDownloadController.php | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 561d261cf5..9882de763a 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,8 +64,10 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); + //Getting the resource id to be used for getting the data dictionary (DD). + $resource_id = $result->{"$.query.resources.0.id"}; - $response->setCallback(function () use ($result, $datastoreQuery) { + $response->setCallback(function () use ($result, $datastoreQuery,$resource_id) { // Open the stream and send the header. set_time_limit(0); $handle = fopen('php://output', 'wb'); @@ -77,8 +79,28 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + while ($row = $result->fetchAssoc()) { - $this->sendRow($handle, array_values($row)); + //Get the DD definition to get the original date format. + $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); + //Create a new array to place the updated values. + $formated_data = []; + foreach ($row as $key => $value) { + //Get the field definition from the DD. + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + //Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + //Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + //Return the new date in the array. + $formated_data[] = strval($newDate); + }else{ + //It's not a date so return the original value. + $formated_data[] = $value; + } + } + //Send the updated array to the csv file. + $this->sendRow($handle, $formated_data); } } catch (\Exception $e) { @@ -90,6 +112,34 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD return $response; } + /** + * Create initial streamed response object. + * + * @return array + * + */ + private function returnDataDictionaryFields($resource_id) { + //Get data dictionary info. + $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); + $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; + } + + /** + * Create initial streamed response object. + * + * @return array + * + */ + private function returnFieldDefinition($dataDictionaryFields, $field) { + //Get data dictionary info. + foreach ($dataDictionaryFields as $definition) { + if ($field == $definition['name']) { + return $definition; + } + } + } + /** * Create initial streamed response object. * From 1ee3cea081e347896b95fabf5a12c2efbcef4c9c Mon Sep 17 00:00:00 2001 From: B3WM Date: Thu, 10 Nov 2022 07:29:09 -0600 Subject: [PATCH 002/117] adidng a condition for when DD isn't active --- .../Controller/QueryDownloadController.php | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 9882de763a..2b780c7aeb 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -79,28 +79,35 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - - while ($row = $result->fetchAssoc()) { - //Get the DD definition to get the original date format. - $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - //Create a new array to place the updated values. - $formated_data = []; - foreach ($row as $key => $value) { - //Get the field definition from the DD. - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - //Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - //Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - //Return the new date in the array. - $formated_data[] = strval($newDate); - }else{ - //It's not a date so return the original value. - $formated_data[] = $value; + //Get the DD definition to get the original date format. + $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); + + if ($data_dictionary_fields) { + while ($row = $result->fetchAssoc()) { + //Create a new array to place the updated values. + $formated_data = []; + foreach ($row as $key => $value) { + //Get the field definition from the DD. + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + //Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + //Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + //Return the new date in the array. + $formated_data[] = strval($newDate); + }else{ + //It's not a date so return the original value. + $formated_data[] = $value; + } } + //Send the updated array to the csv file. + $this->sendRow($handle, $formated_data); + } + + }else{ + while ($row = $result->fetchAssoc()) { + $this->sendRow($handle, array_values($row)); } - //Send the updated array to the csv file. - $this->sendRow($handle, $formated_data); } } catch (\Exception $e) { @@ -115,14 +122,21 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD /** * Create initial streamed response object. * - * @return array + * {@inheritdoc} * */ private function returnDataDictionaryFields($resource_id) { + //Get DD is mode. + $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); //Get data dictionary info. - $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); - $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; - return $metaData; + if ($dd_mode != "none") { + $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); + $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; + }else{ + return null; + } + } /** From 78a80b9f5b3ae084fce75442ac6181d3e656c465 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 10:44:20 -0600 Subject: [PATCH 003/117] fixing code climate errors --- .../Controller/QueryDownloadController.php | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 2b780c7aeb..3d555198ca 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,7 +64,7 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - //Getting the resource id to be used for getting the data dictionary (DD). + // Getting the resource id to be used for getting the data dictionary (DD). $resource_id = $result->{"$.query.resources.0.id"}; $response->setCallback(function () use ($result, $datastoreQuery,$resource_id) { @@ -79,28 +79,18 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - //Get the DD definition to get the original date format. + // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); if ($data_dictionary_fields) { while ($row = $result->fetchAssoc()) { - //Create a new array to place the updated values. + // Create a new array to place the updated values. $formated_data = []; foreach ($row as $key => $value) { - //Get the field definition from the DD. $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - //Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - //Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - //Return the new date in the array. - $formated_data[] = strval($newDate); - }else{ - //It's not a date so return the original value. - $formated_data[] = $value; - } + $formated_data[] = returnFormattedData($field_definition, $value); } - //Send the updated array to the csv file. + // Send the updated array to the csv file. $this->sendRow($handle, $formated_data); } @@ -120,20 +110,40 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD } /** - * Create initial streamed response object. + * Return formatted date value. * * {@inheritdoc} + */ + private function returnFormattedData($field_definition, $value){ + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + return strval($newDate); + } + else{ + // It's not a date so return the original value. + return $value; + } + } + + /** + * Create initial streamed response object. * + * {@inheritdoc} */ private function returnDataDictionaryFields($resource_id) { - //Get DD is mode. + // Get DD is mode. $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); - //Get data dictionary info. + // Get data dictionary info. if ($dd_mode != "none") { $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; return $metaData; - }else{ + } + else{ return null; } @@ -143,10 +153,9 @@ private function returnDataDictionaryFields($resource_id) { * Create initial streamed response object. * * @return array - * */ private function returnFieldDefinition($dataDictionaryFields, $field) { - //Get data dictionary info. + // Get data dictionary info. foreach ($dataDictionaryFields as $definition) { if ($field == $definition['name']) { return $definition; From 27b2567531d85f2c2f4b5afcc13b39abd8e375c8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 10:54:45 -0600 Subject: [PATCH 004/117] fixing code climate errors p2 --- .../Controller/QueryDownloadController.php | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 3d555198ca..180a06129e 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -67,7 +67,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD // Getting the resource id to be used for getting the data dictionary (DD). $resource_id = $result->{"$.query.resources.0.id"}; - $response->setCallback(function () use ($result, $datastoreQuery,$resource_id) { + $response->setCallback(function () use ($result, $datastoreQuery, $resource_id) { // Open the stream and send the header. set_time_limit(0); $handle = fopen('php://output', 'wb'); @@ -76,25 +76,22 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); - // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - if ($data_dictionary_fields) { while ($row = $result->fetchAssoc()) { - // Create a new array to place the updated values. $formated_data = []; foreach ($row as $key => $value) { $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - $formated_data[] = returnFormattedData($field_definition, $value); + $formated_data[] = $this->returnFormattedData($field_definition, $value); } // Send the updated array to the csv file. $this->sendRow($handle, $formated_data); } - - }else{ + } + else{ while ($row = $result->fetchAssoc()) { $this->sendRow($handle, array_values($row)); } @@ -103,7 +100,6 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); } - fclose($handle); }); return $response; @@ -118,15 +114,15 @@ private function returnFormattedData($field_definition, $value){ // Get the field definition from the DD. // Do something if the field is a date field and isn't empty. if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. + // Format the date. $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); // Return the new date in the array. return strval($newDate); } - else{ - // It's not a date so return the original value. - return $value; - } + else{ + // It's not a date so return the original value. + return $value; + } } /** @@ -144,7 +140,7 @@ private function returnDataDictionaryFields($resource_id) { return $metaData; } else{ - return null; + return NULL; } } @@ -152,7 +148,7 @@ private function returnDataDictionaryFields($resource_id) { /** * Create initial streamed response object. * - * @return array + * @return array $definition */ private function returnFieldDefinition($dataDictionaryFields, $field) { // Get data dictionary info. From 8a086e1b7cc9b91dfd5ca41861276803a3860ae2 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 11:16:44 -0600 Subject: [PATCH 005/117] fixing code climate errors p3 --- .../Controller/QueryDownloadController.php | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 180a06129e..0541eb78de 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -82,16 +82,12 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); if ($data_dictionary_fields) { while ($row = $result->fetchAssoc()) { - $formated_data = []; - foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - $formated_data[] = $this->returnFormattedData($field_definition, $value); - } + $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); // Send the updated array to the csv file. $this->sendRow($handle, $formated_data); } } - else{ + else { while ($row = $result->fetchAssoc()) { $this->sendRow($handle, array_values($row)); } @@ -108,21 +104,28 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD /** * Return formatted date value. * - * {@inheritdoc} + * @return array $definition + * Array of data dictionary definition. */ - private function returnFormattedData($field_definition, $value){ - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - return strval($newDate); - } - else{ + private function returnFormattedData($data_dictionary_fields, $row){ + $formated_data = []; + foreach ($row as $key => $value) { + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + $formated_data[] = strval($newDate); + } + else { // It's not a date so return the original value. - return $value; + $formated_data[] = $value; } + } + return $formated_data; + } /** @@ -135,11 +138,11 @@ private function returnDataDictionaryFields($resource_id) { $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); // Get data dictionary info. if ($dd_mode != "none") { - $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); + $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; return $metaData; } - else{ + else { return NULL; } @@ -149,6 +152,7 @@ private function returnDataDictionaryFields($resource_id) { * Create initial streamed response object. * * @return array $definition + * Array of data dictionary definition */ private function returnFieldDefinition($dataDictionaryFields, $field) { // Get data dictionary info. From bd02972cbbd5eb81c2b3ab57a4b49dabaf6939af Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 12:01:02 -0600 Subject: [PATCH 006/117] fixing code climate errors p4 --- .../Controller/QueryDownloadController.php | 70 +++++++++---------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 0541eb78de..4849238d35 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -76,22 +76,8 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); - // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - // Get the DD definition to get the original date format. - $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - if ($data_dictionary_fields) { - while ($row = $result->fetchAssoc()) { - $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); - // Send the updated array to the csv file. - $this->sendRow($handle, $formated_data); - } - } - else { - while ($row = $result->fetchAssoc()) { - $this->sendRow($handle, array_values($row)); - } - } + $this->getData($handle, $result, $datastoreQuery); + } catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); @@ -104,28 +90,40 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD /** * Return formatted date value. * - * @return array $definition - * Array of data dictionary definition. + * {@inheritdoc} */ - private function returnFormattedData($data_dictionary_fields, $row){ - $formated_data = []; - foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - $formated_data[] = strval($newDate); + private function getData($handle, $result, $datastoreQuery){ + // Get the result pointer and send each row to the stream one by one. + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + // Get the DD definition to get the original date format. + $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); + if ($data_dictionary_fields) { + while ($row = $result->fetchAssoc()) { + $formated_data = []; + foreach ($row as $key => $value) { + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + $formated_data[] = strval($newDate); + } + else { + // It's not a date so return the original value. + $formated_data[] = $value; + } + } + // Send the updated array to the csv file. + $this->sendRow($handle, $formated_data); } - else { - // It's not a date so return the original value. - $formated_data[] = $value; + } + else { + while ($row = $result->fetchAssoc()) { + $this->sendRow($handle, array_values($row)); } } - return $formated_data; - } /** @@ -151,8 +149,8 @@ private function returnDataDictionaryFields($resource_id) { /** * Create initial streamed response object. * - * @return array $definition - * Array of data dictionary definition + * @return array + * Array of data dictionary definition */ private function returnFieldDefinition($dataDictionaryFields, $field) { // Get data dictionary info. From dd10f4b30ccda820b294db8c586d3cfce9152c96 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 12:05:01 -0600 Subject: [PATCH 007/117] fixing code climate errors p5 --- .../src/Controller/QueryDownloadController.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 4849238d35..90fe41a0cf 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,9 +64,6 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - // Getting the resource id to be used for getting the data dictionary (DD). - $resource_id = $result->{"$.query.resources.0.id"}; - $response->setCallback(function () use ($result, $datastoreQuery, $resource_id) { // Open the stream and send the header. set_time_limit(0); @@ -76,7 +73,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); - $this->getData($handle, $result, $datastoreQuery); + $this->getData($handle, $result, $datastoreQuery, $resource_id); } catch (\Exception $e) { @@ -92,7 +89,9 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD * * {@inheritdoc} */ - private function getData($handle, $result, $datastoreQuery){ + private function getData($handle, $result, $datastoreQuery) { + // Getting the resource id to be used for getting the data dictionary (DD). + $resource_id = $result->{"$.query.resources.0.id"}; // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); // Get the DD definition to get the original date format. @@ -115,8 +114,8 @@ private function getData($handle, $result, $datastoreQuery){ $formated_data[] = $value; } } - // Send the updated array to the csv file. - $this->sendRow($handle, $formated_data); + // Send the updated array to the csv file. + $this->sendRow($handle, $formated_data); } } else { From 6e18a2ea5414151218e3a18153fca87aef335190 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 13:11:51 -0600 Subject: [PATCH 008/117] fixing code climate errors p6 --- .../Controller/QueryDownloadController.php | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 90fe41a0cf..0c847fa2f5 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -100,19 +100,7 @@ private function getData($handle, $result, $datastoreQuery) { while ($row = $result->fetchAssoc()) { $formated_data = []; foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - $formated_data[] = strval($newDate); - } - else { - // It's not a date so return the original value. - $formated_data[] = $value; - } + $formated_data = $this->returnFormattedData($field_definition, $value); } // Send the updated array to the csv file. $this->sendRow($handle, $formated_data); @@ -125,6 +113,27 @@ private function getData($handle, $result, $datastoreQuery) { } } + /** + * Return formatted date value. + * + * {@inheritdoc} + * + */ + private function returnFormattedData($field_definition, $value){ + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + return strval($newDate); + } + else{ + //It's not a date so return the original value. + return $value; + } + } + /** * Create initial streamed response object. * From d6d688627eb370aa9283b236329ac94953f0b1fa Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 13:35:04 -0600 Subject: [PATCH 009/117] fixing code climate errors p7 --- .../Controller/QueryDownloadController.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 0c847fa2f5..70f761d5ce 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -96,20 +96,20 @@ private function getData($handle, $result, $datastoreQuery) { $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - if ($data_dictionary_fields) { - while ($row = $result->fetchAssoc()) { + while ($row = $result->fetchAssoc()) { + if ($data_dictionary_fields) { $formated_data = []; foreach ($row as $key => $value) { - $formated_data = $this->returnFormattedData($field_definition, $value); + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + $formated_data = $this->returnFormattedData($field_definition, $value); } // Send the updated array to the csv file. $this->sendRow($handle, $formated_data); } - } - else { - while ($row = $result->fetchAssoc()) { + else { $this->sendRow($handle, array_values($row)); - } + } + } } @@ -117,19 +117,18 @@ private function getData($handle, $result, $datastoreQuery) { * Return formatted date value. * * {@inheritdoc} - * */ - private function returnFormattedData($field_definition, $value){ + private function returnFormattedData($field_definition, $value) { // Get the field definition from the DD. // Do something if the field is a date field and isn't empty. if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. + // Format the date. $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); // Return the new date in the array. return strval($newDate); } else{ - //It's not a date so return the original value. + // It's not a date so return the original value. return $value; } } From 5942488179fed0b24fe6a9491f55129cca41ad89 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 13:43:00 -0600 Subject: [PATCH 010/117] fixing code climate errors p8 --- .../Controller/QueryDownloadController.php | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 70f761d5ce..fa961e54e3 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -98,17 +98,13 @@ private function getData($handle, $result, $datastoreQuery) { $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); while ($row = $result->fetchAssoc()) { if ($data_dictionary_fields) { - $formated_data = []; - foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - $formated_data = $this->returnFormattedData($field_definition, $value); - } + $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); // Send the updated array to the csv file. $this->sendRow($handle, $formated_data); } else { $this->sendRow($handle, array_values($row)); - } + } } } @@ -118,19 +114,25 @@ private function getData($handle, $result, $datastoreQuery) { * * {@inheritdoc} */ - private function returnFormattedData($field_definition, $value) { - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - return strval($newDate); - } - else{ - // It's not a date so return the original value. - return $value; + private function returnFormattedData($data_dictionary_fields, $row) { + $formated_data = []; + foreach ($row as $key => $value) { + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + $formated_data[] = strval($newDate); + } + else { + // It's not a date so return the original value. + $formated_data[] = $value; + } } + return $formated_data; + } /** From 44cc2e189750ad7feb88eac811a2dc3f45ab1eaf Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 13:44:48 -0600 Subject: [PATCH 011/117] fixing code climate errors p9 --- modules/datastore/src/Controller/QueryDownloadController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index fa961e54e3..3204fe5e3c 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -128,7 +128,7 @@ private function returnFormattedData($data_dictionary_fields, $row) { } else { // It's not a date so return the original value. - $formated_data[] = $value; + $formated_data[] = $value; } } return $formated_data; From 03ea121094987bc329c1cf963d237f91092bafa8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 14:23:45 -0600 Subject: [PATCH 012/117] Fixing CircleCI error --- modules/datastore/src/Controller/QueryDownloadController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 3204fe5e3c..f5db5d65ef 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,7 +64,7 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - $response->setCallback(function () use ($result, $datastoreQuery, $resource_id) { + $response->setCallback(function () use ($result, $datastoreQuery) { // Open the stream and send the header. set_time_limit(0); $handle = fopen('php://output', 'wb'); @@ -73,7 +73,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); - $this->getData($handle, $result, $datastoreQuery, $resource_id); + $this->getData($handle, $result, $datastoreQuery); } catch (\Exception $e) { From 85e41eec86f2ccad74ef77ef24a278230d089083 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 14:55:15 -0600 Subject: [PATCH 013/117] reset QueryDownloadController.php --- .../Controller/QueryDownloadController.php | 94 ++----------------- 1 file changed, 7 insertions(+), 87 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index f5db5d65ef..561d261cf5 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,6 +64,7 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); + $response->setCallback(function () use ($result, $datastoreQuery) { // Open the stream and send the header. set_time_limit(0); @@ -73,103 +74,22 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); - $this->getData($handle, $result, $datastoreQuery); + // Get the result pointer and send each row to the stream one by one. + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + while ($row = $result->fetchAssoc()) { + $this->sendRow($handle, array_values($row)); + } } catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); } + fclose($handle); }); return $response; } - /** - * Return formatted date value. - * - * {@inheritdoc} - */ - private function getData($handle, $result, $datastoreQuery) { - // Getting the resource id to be used for getting the data dictionary (DD). - $resource_id = $result->{"$.query.resources.0.id"}; - // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - // Get the DD definition to get the original date format. - $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - while ($row = $result->fetchAssoc()) { - if ($data_dictionary_fields) { - $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); - // Send the updated array to the csv file. - $this->sendRow($handle, $formated_data); - } - else { - $this->sendRow($handle, array_values($row)); - } - - } - } - - /** - * Return formatted date value. - * - * {@inheritdoc} - */ - private function returnFormattedData($data_dictionary_fields, $row) { - $formated_data = []; - foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - $formated_data[] = strval($newDate); - } - else { - // It's not a date so return the original value. - $formated_data[] = $value; - } - } - return $formated_data; - - } - - /** - * Create initial streamed response object. - * - * {@inheritdoc} - */ - private function returnDataDictionaryFields($resource_id) { - // Get DD is mode. - $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); - // Get data dictionary info. - if ($dd_mode != "none") { - $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); - $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; - return $metaData; - } - else { - return NULL; - } - - } - - /** - * Create initial streamed response object. - * - * @return array - * Array of data dictionary definition - */ - private function returnFieldDefinition($dataDictionaryFields, $field) { - // Get data dictionary info. - foreach ($dataDictionaryFields as $definition) { - if ($field == $definition['name']) { - return $definition; - } - } - } - /** * Create initial streamed response object. * From 184257fc459a0fc95c3431ec8ee99e5ef909033b Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 14 Nov 2022 15:02:43 -0600 Subject: [PATCH 014/117] adding back changes to QueryDownloadController.php --- .../Controller/QueryDownloadController.php | 94 +++++++++++++++++-- 1 file changed, 87 insertions(+), 7 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 561d261cf5..f5db5d65ef 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,7 +64,6 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - $response->setCallback(function () use ($result, $datastoreQuery) { // Open the stream and send the header. set_time_limit(0); @@ -74,22 +73,103 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); + $this->getData($handle, $result, $datastoreQuery); - // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - while ($row = $result->fetchAssoc()) { - $this->sendRow($handle, array_values($row)); - } } catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); } - fclose($handle); }); return $response; } + /** + * Return formatted date value. + * + * {@inheritdoc} + */ + private function getData($handle, $result, $datastoreQuery) { + // Getting the resource id to be used for getting the data dictionary (DD). + $resource_id = $result->{"$.query.resources.0.id"}; + // Get the result pointer and send each row to the stream one by one. + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + // Get the DD definition to get the original date format. + $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); + while ($row = $result->fetchAssoc()) { + if ($data_dictionary_fields) { + $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); + // Send the updated array to the csv file. + $this->sendRow($handle, $formated_data); + } + else { + $this->sendRow($handle, array_values($row)); + } + + } + } + + /** + * Return formatted date value. + * + * {@inheritdoc} + */ + private function returnFormattedData($data_dictionary_fields, $row) { + $formated_data = []; + foreach ($row as $key => $value) { + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + $formated_data[] = strval($newDate); + } + else { + // It's not a date so return the original value. + $formated_data[] = $value; + } + } + return $formated_data; + + } + + /** + * Create initial streamed response object. + * + * {@inheritdoc} + */ + private function returnDataDictionaryFields($resource_id) { + // Get DD is mode. + $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); + // Get data dictionary info. + if ($dd_mode != "none") { + $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); + $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; + } + else { + return NULL; + } + + } + + /** + * Create initial streamed response object. + * + * @return array + * Array of data dictionary definition + */ + private function returnFieldDefinition($dataDictionaryFields, $field) { + // Get data dictionary info. + foreach ($dataDictionaryFields as $definition) { + if ($field == $definition['name']) { + return $definition; + } + } + } + /** * Create initial streamed response object. * From eb8c4ce4eae9ae08ec3587d785a524c46731ed15 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 10:05:12 -0600 Subject: [PATCH 015/117] updating circleci config to get around ddev error --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index f3d843d4b8..b794931225 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,6 +11,7 @@ commands: sudo apt-get install ca-certificates curl https://apt.fury.io/drud/gpg.key | sudo apt-key add - echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list + sudo rm -rf /etc/apt/sources.list.d/heroku.list sudo apt update && sudo apt install -y ddev prepare_build: # TODO: Figure out the best way to share this build between the various jobs. From 66aaadc7386ee50d2ee7f1d06cb7af4c9ed37557 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 10:08:46 -0600 Subject: [PATCH 016/117] updating circleci config to get around ddev error --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b794931225..42855d5bc6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,11 +7,11 @@ commands: name: Install DDev command: | set -e + sudo rm -rf /etc/apt/sources.list.d/heroku.list sudo apt-get update sudo apt-get install ca-certificates curl https://apt.fury.io/drud/gpg.key | sudo apt-key add - echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list - sudo rm -rf /etc/apt/sources.list.d/heroku.list sudo apt update && sudo apt install -y ddev prepare_build: # TODO: Figure out the best way to share this build between the various jobs. From 7eda3a5e5e5a0f7c4de6e75f31932529d1ace774 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 10:51:24 -0600 Subject: [PATCH 017/117] resetting QueryDownloadController.php to match 2.x --- .../Controller/QueryDownloadController.php | 94 ++----------------- 1 file changed, 7 insertions(+), 87 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index f5db5d65ef..561d261cf5 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,6 +64,7 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); + $response->setCallback(function () use ($result, $datastoreQuery) { // Open the stream and send the header. set_time_limit(0); @@ -73,103 +74,22 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); - $this->getData($handle, $result, $datastoreQuery); + // Get the result pointer and send each row to the stream one by one. + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + while ($row = $result->fetchAssoc()) { + $this->sendRow($handle, array_values($row)); + } } catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); } + fclose($handle); }); return $response; } - /** - * Return formatted date value. - * - * {@inheritdoc} - */ - private function getData($handle, $result, $datastoreQuery) { - // Getting the resource id to be used for getting the data dictionary (DD). - $resource_id = $result->{"$.query.resources.0.id"}; - // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - // Get the DD definition to get the original date format. - $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - while ($row = $result->fetchAssoc()) { - if ($data_dictionary_fields) { - $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); - // Send the updated array to the csv file. - $this->sendRow($handle, $formated_data); - } - else { - $this->sendRow($handle, array_values($row)); - } - - } - } - - /** - * Return formatted date value. - * - * {@inheritdoc} - */ - private function returnFormattedData($data_dictionary_fields, $row) { - $formated_data = []; - foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - $formated_data[] = strval($newDate); - } - else { - // It's not a date so return the original value. - $formated_data[] = $value; - } - } - return $formated_data; - - } - - /** - * Create initial streamed response object. - * - * {@inheritdoc} - */ - private function returnDataDictionaryFields($resource_id) { - // Get DD is mode. - $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); - // Get data dictionary info. - if ($dd_mode != "none") { - $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); - $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; - return $metaData; - } - else { - return NULL; - } - - } - - /** - * Create initial streamed response object. - * - * @return array - * Array of data dictionary definition - */ - private function returnFieldDefinition($dataDictionaryFields, $field) { - // Get data dictionary info. - foreach ($dataDictionaryFields as $definition) { - if ($field == $definition['name']) { - return $definition; - } - } - } - /** * Create initial streamed response object. * From 2d242e692972e99314e0f669d66a68ac4e891f4a Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 11:01:42 -0600 Subject: [PATCH 018/117] adding back changes to QueryDownloadController.php --- .../Controller/QueryDownloadController.php | 94 +++++++++++++++++-- 1 file changed, 87 insertions(+), 7 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 561d261cf5..f5db5d65ef 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,7 +64,6 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - $response->setCallback(function () use ($result, $datastoreQuery) { // Open the stream and send the header. set_time_limit(0); @@ -74,22 +73,103 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); + $this->getData($handle, $result, $datastoreQuery); - // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - while ($row = $result->fetchAssoc()) { - $this->sendRow($handle, array_values($row)); - } } catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); } - fclose($handle); }); return $response; } + /** + * Return formatted date value. + * + * {@inheritdoc} + */ + private function getData($handle, $result, $datastoreQuery) { + // Getting the resource id to be used for getting the data dictionary (DD). + $resource_id = $result->{"$.query.resources.0.id"}; + // Get the result pointer and send each row to the stream one by one. + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + // Get the DD definition to get the original date format. + $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); + while ($row = $result->fetchAssoc()) { + if ($data_dictionary_fields) { + $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); + // Send the updated array to the csv file. + $this->sendRow($handle, $formated_data); + } + else { + $this->sendRow($handle, array_values($row)); + } + + } + } + + /** + * Return formatted date value. + * + * {@inheritdoc} + */ + private function returnFormattedData($data_dictionary_fields, $row) { + $formated_data = []; + foreach ($row as $key => $value) { + $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); + // Get the field definition from the DD. + // Do something if the field is a date field and isn't empty. + if ($field_definition['type'] == 'date' && !empty($value)) { + // Format the date. + $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); + // Return the new date in the array. + $formated_data[] = strval($newDate); + } + else { + // It's not a date so return the original value. + $formated_data[] = $value; + } + } + return $formated_data; + + } + + /** + * Create initial streamed response object. + * + * {@inheritdoc} + */ + private function returnDataDictionaryFields($resource_id) { + // Get DD is mode. + $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); + // Get data dictionary info. + if ($dd_mode != "none") { + $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); + $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; + } + else { + return NULL; + } + + } + + /** + * Create initial streamed response object. + * + * @return array + * Array of data dictionary definition + */ + private function returnFieldDefinition($dataDictionaryFields, $field) { + // Get data dictionary info. + foreach ($dataDictionaryFields as $definition) { + if ($field == $definition['name']) { + return $definition; + } + } + } + /** * Create initial streamed response object. * From 660c7d803df3bf8e22b2394873619f047c299d3e Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 11:20:08 -0600 Subject: [PATCH 019/117] moving the result varialbe to see if that makes a difference --- modules/datastore/src/Controller/QueryDownloadController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index f5db5d65ef..a7972f084f 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -73,6 +73,8 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); + // Get the result pointer and send each row to the stream one by one. + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); $this->getData($handle, $result, $datastoreQuery); } @@ -92,8 +94,6 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD private function getData($handle, $result, $datastoreQuery) { // Getting the resource id to be used for getting the data dictionary (DD). $resource_id = $result->{"$.query.resources.0.id"}; - // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); while ($row = $result->fetchAssoc()) { From 044debc1ddbd295b85735062356b6553b0fe72f4 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 11:40:40 -0600 Subject: [PATCH 020/117] resource_id varialbe wasn't being set --- .../src/Controller/QueryDownloadController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index a7972f084f..0af6de4e59 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,7 +64,10 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - $response->setCallback(function () use ($result, $datastoreQuery) { + // Getting the resource id to be used for getting the data dictionary (DD). + $resource_id = $result->{"$.query.resources.0.id"}; + + $response->setCallback(function () use ($result, $datastoreQuery, $resource_id) { // Open the stream and send the header. set_time_limit(0); $handle = fopen('php://output', 'wb'); @@ -75,7 +78,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD $this->sendRow($handle, $this->getHeaderRow($result)); // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - $this->getData($handle, $result, $datastoreQuery); + $this->getData($handle, $result, $datastoreQuery, $resource_id); } catch (\Exception $e) { @@ -91,9 +94,8 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD * * {@inheritdoc} */ - private function getData($handle, $result, $datastoreQuery) { - // Getting the resource id to be used for getting the data dictionary (DD). - $resource_id = $result->{"$.query.resources.0.id"}; + private function getData($handle, $result, $datastoreQuery, $resource_id) { + // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); while ($row = $result->fetchAssoc()) { From f0c75bb2054f01f05c3d87bbbc869fec0cb2b964 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 11:54:40 -0600 Subject: [PATCH 021/117] seeing if updating the services included resolves the issue --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 68029886b9..c3a3d5968c 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -340,6 +340,8 @@ public function testStreamedBadSchema() { private function getQueryContainer(int $rowLimit) { $options = (new Options()) ->add("dkan.metastore.storage", DataFactory::class) + ->add("dkan.metastore.data_dictionary_discovery", Service::class) + ->add("dkan.metastore.service", Service::class) ->add("dkan.datastore.service", Service::class) ->add("dkan.datastore.query", Query::class) ->add("dkan.common.dataset_info", DatasetInfo::class) From 828e03d12475b95b26a64aa02aa5166a9fdd5f30 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 12:04:39 -0600 Subject: [PATCH 022/117] resetting Controller/QueryDownloadControllerTest.php --- modules/datastore/src/Controller/QueryDownloadController.php | 4 ++-- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 0af6de4e59..9fe6a9f234 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -78,7 +78,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD $this->sendRow($handle, $this->getHeaderRow($result)); // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - $this->getData($handle, $result, $datastoreQuery, $resource_id); + $this->getData($handle, $result, $resource_id); } catch (\Exception $e) { @@ -94,7 +94,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD * * {@inheritdoc} */ - private function getData($handle, $result, $datastoreQuery, $resource_id) { + private function getData($handle, RootedJsonData $result, $resource_id) { // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index c3a3d5968c..68029886b9 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -340,8 +340,6 @@ public function testStreamedBadSchema() { private function getQueryContainer(int $rowLimit) { $options = (new Options()) ->add("dkan.metastore.storage", DataFactory::class) - ->add("dkan.metastore.data_dictionary_discovery", Service::class) - ->add("dkan.metastore.service", Service::class) ->add("dkan.datastore.service", Service::class) ->add("dkan.datastore.query", Query::class) ->add("dkan.common.dataset_info", DatasetInfo::class) From 6485202e14ab6d37e44278d2ac99e938a5b38f76 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 15 Nov 2022 12:08:39 -0600 Subject: [PATCH 023/117] fixing error from update --- modules/datastore/src/Controller/QueryDownloadController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 9fe6a9f234..29de6b159c 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -94,7 +94,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD * * {@inheritdoc} */ - private function getData($handle, RootedJsonData $result, $resource_id) { + private function getData($handle, $result, $resource_id) { // Get the DD definition to get the original date format. $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); From 4b1d369693909d499c4180de5e312fa38c983b3d Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 12 Dec 2022 10:32:15 -0600 Subject: [PATCH 024/117] adding date formating to AbstractDatabaseTable.php --- .../src/Storage/AbstractDatabaseTable.php | 56 +++++++++++ .../Controller/QueryDownloadController.php | 94 ++----------------- 2 files changed, 62 insertions(+), 88 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 48c1939b1b..10769979f1 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -22,6 +22,13 @@ abstract class AbstractDatabaseTable implements DatabaseTableInterface { */ protected $schema; + /** + * The resource ID if the dataset + * + * @var array + */ + protected $resource_id; + /** * Drupal DB connection object. * @@ -239,8 +246,15 @@ public function count(): int { public function query(Query $query, string $alias = 't', $fetch = TRUE) { $this->setTable(); $query->collection = $this->getTableName(); + $this->resource_id = isset($query->conditions[0]->value) ?? $query->conditions[0]->value ; $selectFactory = new SelectFactory($this->connection, $alias); $db_query = $selectFactory->create($query); + if($query->collection !== 'dkan_metastore_resource_mapper'){ + $fields = $db_query->getFields(); + $resource_id = str_replace("datastore_", "", $query->collection); + $date_fields = $this->returnDataDictionaryDateFields($resource_id); + $this->addDateExpressions($db_query, $fields, $date_fields); + } try { $result = $db_query->execute(); @@ -252,6 +266,48 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { return $fetch ? $result->fetchAll() : $result; } + /** + * Reformatting date fields. + * + * {@inheritdoc} + */ + private function addDateExpressions($db_query, $fields, $date_fields){ + if ($fields && $date_fields) { + foreach ($date_fields as $definition) { + if (isset($fields[$definition['name']])) { + $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); + } + + } + } + } + + /** + * Returning data dictionary fields from schema. + * + * {@inheritdoc} + */ + private function returnDataDictionaryDateFields($resource_id) { + // Get DD is mode. + $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); + // Get data dictionary info. + if ($dd_mode != "none") { + $dateFields = []; + $dict_id = $resource_id ? \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id) : null; + $metaData = $dict_id ? \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"} : null; + foreach ($metaData as $definition) { + if ($definition['type'] == 'date') { + $dateFields[] = $definition; + } + } + return $dateFields; + } + else { + return NULL; + } + + } + /** * Create a minimal error message that does not leak database information. */ diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 29de6b159c..561d261cf5 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -64,10 +64,8 @@ protected function buildDatastoreQuery($request, $identifier = NULL) { */ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonData $result) { $response = $this->initStreamedCsvResponse(); - // Getting the resource id to be used for getting the data dictionary (DD). - $resource_id = $result->{"$.query.resources.0.id"}; - $response->setCallback(function () use ($result, $datastoreQuery, $resource_id) { + $response->setCallback(function () use ($result, $datastoreQuery) { // Open the stream and send the header. set_time_limit(0); $handle = fopen('php://output', 'wb'); @@ -76,102 +74,22 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD try { // Send the header row. $this->sendRow($handle, $this->getHeaderRow($result)); + // Get the result pointer and send each row to the stream one by one. $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); - $this->getData($handle, $result, $resource_id); - + while ($row = $result->fetchAssoc()) { + $this->sendRow($handle, array_values($row)); + } } catch (\Exception $e) { $this->sendRow($handle, [$e->getMessage()]); } + fclose($handle); }); return $response; } - /** - * Return formatted date value. - * - * {@inheritdoc} - */ - private function getData($handle, $result, $resource_id) { - - // Get the DD definition to get the original date format. - $data_dictionary_fields = $this->returnDataDictionaryFields($resource_id); - while ($row = $result->fetchAssoc()) { - if ($data_dictionary_fields) { - $formated_data = $this->returnFormattedData($data_dictionary_fields, $row); - // Send the updated array to the csv file. - $this->sendRow($handle, $formated_data); - } - else { - $this->sendRow($handle, array_values($row)); - } - - } - } - - /** - * Return formatted date value. - * - * {@inheritdoc} - */ - private function returnFormattedData($data_dictionary_fields, $row) { - $formated_data = []; - foreach ($row as $key => $value) { - $field_definition = $this->returnFieldDefinition($data_dictionary_fields, $key); - // Get the field definition from the DD. - // Do something if the field is a date field and isn't empty. - if ($field_definition['type'] == 'date' && !empty($value)) { - // Format the date. - $newDate = str_replace('%', '', date($field_definition['format'], strtotime($value))); - // Return the new date in the array. - $formated_data[] = strval($newDate); - } - else { - // It's not a date so return the original value. - $formated_data[] = $value; - } - } - return $formated_data; - - } - - /** - * Create initial streamed response object. - * - * {@inheritdoc} - */ - private function returnDataDictionaryFields($resource_id) { - // Get DD is mode. - $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); - // Get data dictionary info. - if ($dd_mode != "none") { - $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id); - $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; - return $metaData; - } - else { - return NULL; - } - - } - - /** - * Create initial streamed response object. - * - * @return array - * Array of data dictionary definition - */ - private function returnFieldDefinition($dataDictionaryFields, $field) { - // Get data dictionary info. - foreach ($dataDictionaryFields as $definition) { - if ($field == $definition['name']) { - return $definition; - } - } - } - /** * Create initial streamed response object. * From c057cdc20f02860765ac452d85b0fb3d84debb42 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 12 Dec 2022 10:42:53 -0600 Subject: [PATCH 025/117] Fixing code climate errors --- .../src/Storage/AbstractDatabaseTable.php | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 10769979f1..20a9be313c 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -22,13 +22,6 @@ abstract class AbstractDatabaseTable implements DatabaseTableInterface { */ protected $schema; - /** - * The resource ID if the dataset - * - * @var array - */ - protected $resource_id; - /** * Drupal DB connection object. * @@ -246,12 +239,12 @@ public function count(): int { public function query(Query $query, string $alias = 't', $fetch = TRUE) { $this->setTable(); $query->collection = $this->getTableName(); - $this->resource_id = isset($query->conditions[0]->value) ?? $query->conditions[0]->value ; + $this->resource_id = isset($query->conditions[0]->value) ?? $query->conditions[0]->value; $selectFactory = new SelectFactory($this->connection, $alias); $db_query = $selectFactory->create($query); - if($query->collection !== 'dkan_metastore_resource_mapper'){ + if ($query->collection !== 'dkan_metastore_resource_mapper') { $fields = $db_query->getFields(); - $resource_id = str_replace("datastore_", "", $query->collection); + $resource_id = str_replace("datastore_", "", $query->collection); $date_fields = $this->returnDataDictionaryDateFields($resource_id); $this->addDateExpressions($db_query, $fields, $date_fields); } @@ -271,7 +264,7 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { * * {@inheritdoc} */ - private function addDateExpressions($db_query, $fields, $date_fields){ + private function addDateExpressions ($db_query, $fields, $date_fields) { if ($fields && $date_fields) { foreach ($date_fields as $definition) { if (isset($fields[$definition['name']])) { @@ -287,14 +280,14 @@ private function addDateExpressions($db_query, $fields, $date_fields){ * * {@inheritdoc} */ - private function returnDataDictionaryDateFields($resource_id) { + private function returnDataDictionaryDateFields ($resource_id) { // Get DD is mode. $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); // Get data dictionary info. if ($dd_mode != "none") { $dateFields = []; - $dict_id = $resource_id ? \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id) : null; - $metaData = $dict_id ? \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"} : null; + $dict_id = $resource_id ? \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id) : NULL; + $metaData = $dict_id ? \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"} : NULL; foreach ($metaData as $definition) { if ($definition['type'] == 'date') { $dateFields[] = $definition; From 80a9b4fc8c7b8cae71ac1134a2086df11c5c387f Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 12 Dec 2022 11:08:33 -0600 Subject: [PATCH 026/117] Fixing more code climate errors --- .../src/Storage/AbstractDatabaseTable.php | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 20a9be313c..a7e6202c57 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -246,7 +246,13 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { $fields = $db_query->getFields(); $resource_id = str_replace("datastore_", "", $query->collection); $date_fields = $this->returnDataDictionaryDateFields($resource_id); - $this->addDateExpressions($db_query, $fields, $date_fields); + if ($fields && $date_fields) { + foreach ($date_fields as $definition) { + if (isset($fields[$definition['name']])) { + $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); + } + } + } } try { @@ -264,30 +270,22 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { * * {@inheritdoc} */ - private function addDateExpressions ($db_query, $fields, $date_fields) { - if ($fields && $date_fields) { - foreach ($date_fields as $definition) { - if (isset($fields[$definition['name']])) { - $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); - } + /* private function addDateExpressions($db_query, $fields, $date_fields) { - } - } - } + }*/ /** * Returning data dictionary fields from schema. * * {@inheritdoc} */ - private function returnDataDictionaryDateFields ($resource_id) { + private function returnDataDictionaryDateFields() { // Get DD is mode. $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); // Get data dictionary info. - if ($dd_mode != "none") { - $dateFields = []; - $dict_id = $resource_id ? \Drupal::service('dkan.metastore.data_dictionary_discovery')->dictionaryIdFromResource($resource_id) : NULL; - $metaData = $dict_id ? \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"} : NULL; + if ($dd_mode == "sitewide") { + $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getSitewideDictionaryId(); + $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; foreach ($metaData as $definition) { if ($definition['type'] == 'date') { $dateFields[] = $definition; @@ -295,10 +293,6 @@ private function returnDataDictionaryDateFields ($resource_id) { } return $dateFields; } - else { - return NULL; - } - } /** @@ -466,5 +460,4 @@ public function generateToken(string $field) { $md5 = md5($field); return substr($md5, 0, 4); } - } From 517af212eea58a9611964c29defb8100fda02608 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 12 Dec 2022 11:51:43 -0600 Subject: [PATCH 027/117] Fixing more code climate errors p3 --- .../src/Storage/AbstractDatabaseTable.php | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index a7e6202c57..537916f086 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -245,15 +245,11 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { if ($query->collection !== 'dkan_metastore_resource_mapper') { $fields = $db_query->getFields(); $resource_id = str_replace("datastore_", "", $query->collection); - $date_fields = $this->returnDataDictionaryDateFields($resource_id); - if ($fields && $date_fields) { - foreach ($date_fields as $definition) { - if (isset($fields[$definition['name']])) { - $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); - } + $meta_data = $this->returnDataDictionaryDateFields($resource_id); + if ($meta_data) { + $this->addDateExpressions($db_query, $fields, $meta_data); } } - } try { $result = $db_query->execute(); @@ -270,9 +266,13 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { * * {@inheritdoc} */ - /* private function addDateExpressions($db_query, $fields, $date_fields) { - - }*/ + private function addDateExpressions($db_query, $fields, $meta_data) { + foreach ($meta_data as $definition) { + if (isset($fields[$definition['name']]) && $definition['type'] == 'date') { + $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); + } + } + } /** * Returning data dictionary fields from schema. @@ -285,13 +285,8 @@ private function returnDataDictionaryDateFields() { // Get data dictionary info. if ($dd_mode == "sitewide") { $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getSitewideDictionaryId(); - $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; - foreach ($metaData as $definition) { - if ($definition['type'] == 'date') { - $dateFields[] = $definition; - } - } - return $dateFields; + $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; } } @@ -460,4 +455,5 @@ public function generateToken(string $field) { $md5 = md5($field); return substr($md5, 0, 4); } + } From 3d386997e7fddc03dbe36d88f3365cc47f986b98 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 20 Dec 2022 14:47:53 -0600 Subject: [PATCH 028/117] Moving date formatting back to the select factory --- .../src/Storage/AbstractDatabaseTable.php | 38 ---------- modules/common/src/Storage/SelectFactory.php | 74 ++++++++++++++++++- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 537916f086..48c1939b1b 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -239,17 +239,8 @@ public function count(): int { public function query(Query $query, string $alias = 't', $fetch = TRUE) { $this->setTable(); $query->collection = $this->getTableName(); - $this->resource_id = isset($query->conditions[0]->value) ?? $query->conditions[0]->value; $selectFactory = new SelectFactory($this->connection, $alias); $db_query = $selectFactory->create($query); - if ($query->collection !== 'dkan_metastore_resource_mapper') { - $fields = $db_query->getFields(); - $resource_id = str_replace("datastore_", "", $query->collection); - $meta_data = $this->returnDataDictionaryDateFields($resource_id); - if ($meta_data) { - $this->addDateExpressions($db_query, $fields, $meta_data); - } - } try { $result = $db_query->execute(); @@ -261,35 +252,6 @@ public function query(Query $query, string $alias = 't', $fetch = TRUE) { return $fetch ? $result->fetchAll() : $result; } - /** - * Reformatting date fields. - * - * {@inheritdoc} - */ - private function addDateExpressions($db_query, $fields, $meta_data) { - foreach ($meta_data as $definition) { - if (isset($fields[$definition['name']]) && $definition['type'] == 'date') { - $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); - } - } - } - - /** - * Returning data dictionary fields from schema. - * - * {@inheritdoc} - */ - private function returnDataDictionaryDateFields() { - // Get DD is mode. - $dd_mode = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getDataDictionaryMode(); - // Get data dictionary info. - if ($dd_mode == "sitewide") { - $dict_id = \Drupal::service('dkan.metastore.data_dictionary_discovery')->getSitewideDictionaryId(); - $metaData = \Drupal::service('dkan.metastore.service')->get('data-dictionary', $dict_id)->{"$.data.fields"}; - return $metaData; - } - } - /** * Create a minimal error message that does not leak database information. */ diff --git a/modules/common/src/Storage/SelectFactory.php b/modules/common/src/Storage/SelectFactory.php index b422897a04..e8b0c71c75 100644 --- a/modules/common/src/Storage/SelectFactory.php +++ b/modules/common/src/Storage/SelectFactory.php @@ -4,6 +4,9 @@ use Drupal\Core\Database\Query\Select; use Drupal\Core\Database\Connection; +use Drupal\metastore\DataDictionary\DataDictionaryDiscovery; +use Drupal\metastore\Service; +use Drupal\Core\Config\ConfigFactoryInterface; /** * Class to convert a DKAN Query object into a Drupal DB API Select Object. @@ -24,6 +27,20 @@ class SelectFactory { */ private $alias; + /** + * Data dictionary discovery service. + * + * @var \Drupal\metastore\DataDictionary\DataDictionaryDiscovery + */ + protected $dataDictionaryDiscovery; + + /** + * The metastore service. + * + * @var \Drupal\metastore\Service + */ + protected $metastore; + /** * Our select object. * @@ -45,8 +62,15 @@ class SelectFactory { * A database table object, which includes a database connection. * @param string $alias * Alias for primary table. + * @param \Drupal\metastore\Service $metastore + * The metastore service. + * @param \Drupal\metastore\DataDictionary\DataDictionaryDiscovery $data_dictionary_discovery + * The data-dictionary discovery service. */ - public function __construct(Connection $connection, string $alias = 't') { + public function __construct( + Connection $connection, + string $alias = 't' + ) { $this->connection = $connection; $this->alias = $alias; } @@ -58,8 +82,8 @@ public function __construct(Connection $connection, string $alias = 't') { * DKAN Query object. */ public function create(Query $query): Select { - $this->dbQuery = $this->connection->select($query->collection, $this->alias); + $this->dbQuery = $this->connection->select($query->collection, $this->alias); $this->setQueryProperties($query); $this->setQueryConditions($query); $this->setQueryGroupBy($query); @@ -71,6 +95,16 @@ public function create(Query $query): Select { if ($query->count) { $this->dbQuery = $this->dbQuery->countQuery(); } + + if ($query->collection !== 'dkan_metastore_resource_mapper') { + $fields = $this->dbQuery->getFields(); + $resource_id = str_replace("datastore_", "", $query->collection); + $meta_data = $this->returnDataDictionaryDateFields($resource_id); + if ($meta_data) { + $this->addDateExpressions($this->dbQuery, $fields, $meta_data); + } + } + return $this->dbQuery; } @@ -81,9 +115,12 @@ public function create(Query $query): Select { * A DKAN query object. */ private function setQueryProperties(Query $query) { + + // If properties is empty, just get all from base collection. if (empty($query->properties)) { $this->dbQuery->fields($this->alias); + return; } @@ -92,13 +129,44 @@ private function setQueryProperties(Query $query) { } } + /** + * Reformatting date fields. + * + * {@inheritdoc} + */ + private function addDateExpressions($db_query, $fields, $meta_data) { + foreach ($meta_data as $definition) { + if (isset($fields[$definition['name']]) && $definition['type'] == 'date') { + $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); + } + } + } + + /** + * Returning data dictionary fields from schema. + * + * {@inheritdoc} + */ + private function returnDataDictionaryDateFields() { + //$dataDictionaryDiscovery = new DataDictionaryDiscovery(); + // Get DD is mode. + $dd_mode = DataDictionaryDiscovery::getDataDictionaryMode(); + // Get data dictionary info. + if ($dd_mode == "sitewide") { + $dict_id = $dataDictionaryDiscovery->getSitewideDictionaryId(); + $metaData = Service::get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; + } + } + /** * Set a single property. * * @param mixed $property * One property from a query properties array. */ - private function setQueryProperty($property) { + private function setQueryProperty($property) { + if (isset($property->expression)) { $expressionStr = $this->expressionToString($property->expression); $this->dbQuery->addExpression($expressionStr, $property->alias); From 95e6a7abfae00e06de304d6c60acca4afc7918da Mon Sep 17 00:00:00 2001 From: Janette Day Date: Fri, 30 Dec 2022 15:27:20 -0600 Subject: [PATCH 029/117] hold filefetcher to 4.1.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 926bd0defe..ab5a4187bf 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "fmizzell/maquina": "^1.1.0", "getdkan/contracts": "^1.0.0", "getdkan/csv-parser": "^1.2.3", - "getdkan/file-fetcher" : "^4.1.0", + "getdkan/file-fetcher" : "4.1.0", "getdkan/harvest": "^1.0.0", "getdkan/json-schema-provider": "^0.1.2", "getdkan/locker": "^1.1.0", From 8bdce6e6053e59d35768299ed3b931787300dff1 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 10:24:59 -0600 Subject: [PATCH 030/117] Work done: * Adding a new function called returnDataDictionaryFields to the DictionaryEnforcer service * Adding the DictionaryEnforcer service as an argument in the datastore service * Adding a new function called getDataDictionaryFields to the datastore service * Addig a new variable to the runResultsQuery function that's called by the streamCsvResponse function * When the streamCsvResponse function is called the data dictionary fields are attached to the query variable called dataDictionaryFields in the runResultsQuery function * The SelectFactory function looks for the dataDictionaryFields varialbe and if it's present adds expressions to the sql using the addDateExpressions function --- modules/common/src/Storage/SelectFactory.php | 68 ++++--------------- modules/datastore/datastore.services.yml | 1 + .../Controller/QueryDownloadController.php | 2 +- modules/datastore/src/Service.php | 25 ++++++- modules/datastore/src/Service/Query.php | 18 +++-- .../ResourceProcessor/DictionaryEnforcer.php | 16 +++++ 6 files changed, 70 insertions(+), 60 deletions(-) diff --git a/modules/common/src/Storage/SelectFactory.php b/modules/common/src/Storage/SelectFactory.php index e8b0c71c75..87f349ea30 100644 --- a/modules/common/src/Storage/SelectFactory.php +++ b/modules/common/src/Storage/SelectFactory.php @@ -4,9 +4,7 @@ use Drupal\Core\Database\Query\Select; use Drupal\Core\Database\Connection; -use Drupal\metastore\DataDictionary\DataDictionaryDiscovery; -use Drupal\metastore\Service; -use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\datastore\Service\DatastoreQuery; /** * Class to convert a DKAN Query object into a Drupal DB API Select Object. @@ -28,25 +26,19 @@ class SelectFactory { private $alias; /** - * Data dictionary discovery service. + * Our select object. * - * @var \Drupal\metastore\DataDictionary\DataDictionaryDiscovery + * @var \Drupal\Core\Database\Query\Select */ - protected $dataDictionaryDiscovery; + private $dbQuery; - /** - * The metastore service. - * - * @var \Drupal\metastore\Service - */ - protected $metastore; /** * Our select object. * - * @var \Drupal\Core\Database\Query\Select + * @var \Drupal\datastore\Service\DatastoreQuery */ - private $dbQuery; + private $datastoreQuery; /** * Iterator for "words" named placeholder. @@ -62,15 +54,8 @@ class SelectFactory { * A database table object, which includes a database connection. * @param string $alias * Alias for primary table. - * @param \Drupal\metastore\Service $metastore - * The metastore service. - * @param \Drupal\metastore\DataDictionary\DataDictionaryDiscovery $data_dictionary_discovery - * The data-dictionary discovery service. */ - public function __construct( - Connection $connection, - string $alias = 't' - ) { + public function __construct(Connection $connection, string $alias = 't') { $this->connection = $connection; $this->alias = $alias; } @@ -90,21 +75,15 @@ public function create(Query $query): Select { $this->setQueryOrderBy($query); $this->setQueryLimitAndOffset($query); $this->setQueryJoins($query); - + if (!empty($query->dataDictionaryFields)) { + $meta_data = $query->dataDictionaryFields; + $fields = $this->dbQuery->getFields(); + $this->addDateExpressions($this->dbQuery, $fields, $meta_data); + } // $string = $this->dbQuery->__toString(); if ($query->count) { $this->dbQuery = $this->dbQuery->countQuery(); } - - if ($query->collection !== 'dkan_metastore_resource_mapper') { - $fields = $this->dbQuery->getFields(); - $resource_id = str_replace("datastore_", "", $query->collection); - $meta_data = $this->returnDataDictionaryDateFields($resource_id); - if ($meta_data) { - $this->addDateExpressions($this->dbQuery, $fields, $meta_data); - } - } - return $this->dbQuery; } @@ -115,15 +94,12 @@ public function create(Query $query): Select { * A DKAN query object. */ private function setQueryProperties(Query $query) { - - // If properties is empty, just get all from base collection. if (empty($query->properties)) { $this->dbQuery->fields($this->alias); return; } - foreach ($query->properties as $p) { $this->setQueryProperty($p); } @@ -136,29 +112,13 @@ private function setQueryProperties(Query $query) { */ private function addDateExpressions($db_query, $fields, $meta_data) { foreach ($meta_data as $definition) { - if (isset($fields[$definition['name']]) && $definition['type'] == 'date') { + //Confirm definition name is in the fields list and the definition is a date. + if ($fields[$definition['name']]['field'] && $definition['type'] == 'date') { $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); } } } - /** - * Returning data dictionary fields from schema. - * - * {@inheritdoc} - */ - private function returnDataDictionaryDateFields() { - //$dataDictionaryDiscovery = new DataDictionaryDiscovery(); - // Get DD is mode. - $dd_mode = DataDictionaryDiscovery::getDataDictionaryMode(); - // Get data dictionary info. - if ($dd_mode == "sitewide") { - $dict_id = $dataDictionaryDiscovery->getSitewideDictionaryId(); - $metaData = Service::get('data-dictionary', $dict_id)->{"$.data.fields"}; - return $metaData; - } - } - /** * Set a single property. * diff --git a/modules/datastore/datastore.services.yml b/modules/datastore/datastore.services.yml index 6ff5b2ad1a..6eff203b1b 100644 --- a/modules/datastore/datastore.services.yml +++ b/modules/datastore/datastore.services.yml @@ -7,6 +7,7 @@ services: - '@queue' - '@dkan.common.job_store' - '@dkan.datastore.import_info_list' + - '@dkan.datastore.service.resource_processor.dictionary_enforcer' dkan.datastore.query: class: \Drupal\datastore\Service\Query diff --git a/modules/datastore/src/Controller/QueryDownloadController.php b/modules/datastore/src/Controller/QueryDownloadController.php index 561d261cf5..706fe0dd63 100644 --- a/modules/datastore/src/Controller/QueryDownloadController.php +++ b/modules/datastore/src/Controller/QueryDownloadController.php @@ -76,7 +76,7 @@ protected function streamCsvResponse(DatastoreQuery $datastoreQuery, RootedJsonD $this->sendRow($handle, $this->getHeaderRow($result)); // Get the result pointer and send each row to the stream one by one. - $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE); + $result = $this->queryService->runResultsQuery($datastoreQuery, FALSE, TRUE); while ($row = $result->fetchAssoc()) { $this->sendRow($handle, array_values($row)); } diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index df7df8d778..780d23aee2 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -13,6 +13,7 @@ use Drupal\datastore\Service\Factory\ImportFactoryInterface; use Drupal\datastore\Service\Info\ImportInfoList; use FileFetcher\FileFetcher; +use Drupal\datastore\Service\ResourceProcessor\DictionaryEnforcer; /** * Main services for the datastore. @@ -47,6 +48,13 @@ class Service implements ContainerInjectionInterface { */ private $jobStoreFactory; + /** + * Datastore Query object for conversion. + * + * @var Drupal\datastore\Service\ResourceProcessor\DictionaryEnforcer + */ + private $dictionaryEnforcer; + /** * {@inheritdoc} */ @@ -57,6 +65,7 @@ public static function create(ContainerInterface $container) { $container->get('queue'), $container->get('dkan.common.job_store'), $container->get('dkan.datastore.import_info_list'), + $container->get('dkan.datastore.service.resource_processor.dictionary_enforcer') ); } @@ -73,19 +82,25 @@ public static function create(ContainerInterface $container) { * Jobstore factory service. * @param \Drupal\datastore\Service\Info\ImportInfoList $importInfoList * Import info list service. + * @param \Drupal\datastore\Service\Info\ImportInfoList $importInfoList + * Import info list service. + * @param Drupal\datastore\Service\ResourceProcessor\DictionaryEnforcer $dictionaryEnforcer + * Dictionary Enforcer object. */ public function __construct( ResourceLocalizer $resourceLocalizer, ImportFactoryInterface $importServiceFactory, QueueFactory $queue, JobStoreFactory $jobStoreFactory, - ImportInfoList $importInfoList + ImportInfoList $importInfoList, + DictionaryEnforcer $dictionaryEnforcer ) { $this->queue = $queue; $this->resourceLocalizer = $resourceLocalizer; $this->importServiceFactory = $importServiceFactory; $this->jobStoreFactory = $jobStoreFactory; $this->importInfoList = $importInfoList; + $this->dictionaryEnforcer = $dictionaryEnforcer; } /** @@ -180,6 +195,14 @@ public function getImportService(DataResource $resource) { return $this->importServiceFactory->getInstance($resource->getUniqueIdentifier(), ['resource' => $resource]); } + /** + * Returns the Data Dictionary fields. + * @param string $resource_id + */ + public function getDataDictionaryFields($resource_id) { + return $this->dictionaryEnforcer->returnDataDictionaryFields($resource_id); + } + /** * Drop a resources datastore. * diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 9b62d2579f..928e719a36 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -26,7 +26,7 @@ class Query implements ContainerInjectionInterface { */ public static function create(ContainerInterface $container) { return new static( - $container->get('dkan.datastore.service') + $container->get('dkan.datastore.service'), ); } @@ -123,12 +123,11 @@ public function getQueryStorageMap(DatastoreQuery $datastoreQuery) { * @return array|\Drupal\Core\Database\StatementInterface * Array of result objects or result statement of $fetch is false. */ - public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE) { + public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $csv = FALSE) { $primaryAlias = $datastoreQuery->{"$.resources[0].alias"}; if (!$primaryAlias) { return []; } - $storageMap = $this->getQueryStorageMap($datastoreQuery); $storage = $storageMap[$primaryAlias]; @@ -138,8 +137,17 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE) { $datastoreQuery->{"$.properties"} = array_keys($schema['fields']); } - $query = QueryFactory::create($datastoreQuery, $storageMap); + $query = QueryFactory::create($datastoreQuery, $storageMap); + //If this is a csv download reformat the date fields. + if ($csv) { + $resource_id = $datastoreQuery->{"$.resources.0.id"}; + $meta_data = $this->datastore->getDataDictionaryFields($resource_id); + if ($meta_data) { + //Pass the data dictionary metadata to the query. + $query->dataDictionaryFields = $meta_data; + } + } $result = $storageMap[$primaryAlias]->query($query, $primaryAlias, $fetch); if ($datastoreQuery->{"$.keys"} === FALSE && is_array($result)) { @@ -149,6 +157,8 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE) { } + + /** * Remove the primary key from the schema field list. * diff --git a/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php b/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php index daad76e559..6b97e6f976 100644 --- a/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php +++ b/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php @@ -119,4 +119,20 @@ public function applyDictionary(RootedJsonData $dictionary, string $datastore_ta ->execute(); } + /** + * Returning data dictionary fields from schema. + * + * {@inheritdoc} + */ + public function returnDataDictionaryFields() { + // Get DD is mode. + $dd_mode = $this->dataDictionaryDiscovery->getDataDictionaryMode(); + // Get data dictionary info. + if ($dd_mode == "sitewide") { + $dict_id = $this->dataDictionaryDiscovery->getSitewideDictionaryId(); + $metaData = $this->metastore->get('data-dictionary', $dict_id)->{"$.data.fields"}; + return $metaData; + } + } + } From 8f8719b023f672f7ed7c01b2ae7009868655cd4a Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 10:38:59 -0600 Subject: [PATCH 031/117] Fixing code climate issues --- modules/common/src/Storage/SelectFactory.php | 13 ++---------- modules/datastore/src/Service.php | 4 ++-- modules/datastore/src/Service/Query.php | 20 ++++++++----------- .../ResourceProcessor/DictionaryEnforcer.php | 2 +- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/modules/common/src/Storage/SelectFactory.php b/modules/common/src/Storage/SelectFactory.php index 87f349ea30..ee45b33a72 100644 --- a/modules/common/src/Storage/SelectFactory.php +++ b/modules/common/src/Storage/SelectFactory.php @@ -4,7 +4,6 @@ use Drupal\Core\Database\Query\Select; use Drupal\Core\Database\Connection; -use Drupal\datastore\Service\DatastoreQuery; /** * Class to convert a DKAN Query object into a Drupal DB API Select Object. @@ -32,14 +31,6 @@ class SelectFactory { */ private $dbQuery; - - /** - * Our select object. - * - * @var \Drupal\datastore\Service\DatastoreQuery - */ - private $datastoreQuery; - /** * Iterator for "words" named placeholder. * @@ -112,7 +103,7 @@ private function setQueryProperties(Query $query) { */ private function addDateExpressions($db_query, $fields, $meta_data) { foreach ($meta_data as $definition) { - //Confirm definition name is in the fields list and the definition is a date. + // Confirm definition name is in the fields list. if ($fields[$definition['name']]['field'] && $definition['type'] == 'date') { $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); } @@ -125,7 +116,7 @@ private function addDateExpressions($db_query, $fields, $meta_data) { * @param mixed $property * One property from a query properties array. */ - private function setQueryProperty($property) { + private function setQueryProperty($property) { if (isset($property->expression)) { $expressionStr = $this->expressionToString($property->expression); diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index 780d23aee2..1c2319f2b4 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -82,8 +82,6 @@ public static function create(ContainerInterface $container) { * Jobstore factory service. * @param \Drupal\datastore\Service\Info\ImportInfoList $importInfoList * Import info list service. - * @param \Drupal\datastore\Service\Info\ImportInfoList $importInfoList - * Import info list service. * @param Drupal\datastore\Service\ResourceProcessor\DictionaryEnforcer $dictionaryEnforcer * Dictionary Enforcer object. */ @@ -197,7 +195,9 @@ public function getImportService(DataResource $resource) { /** * Returns the Data Dictionary fields. + * * @param string $resource_id + * Dataset id. */ public function getDataDictionaryFields($resource_id) { return $this->dictionaryEnforcer->returnDataDictionaryFields($resource_id); diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 928e719a36..dd56720a71 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -119,6 +119,8 @@ public function getQueryStorageMap(DatastoreQuery $datastoreQuery) { * DatastoreQuery object. * @param bool $fetch * Perform fetchAll and return array if true, else just statement (cursor). + * @param bool $csv + * Flag for csv downloads. * * @return array|\Drupal\Core\Database\StatementInterface * Array of result objects or result statement of $fetch is false. @@ -136,17 +138,13 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ $schema = $this->filterSchemaFields($storage->getSchema(), $storage->primaryKey()); $datastoreQuery->{"$.properties"} = array_keys($schema['fields']); } - - $query = QueryFactory::create($datastoreQuery, $storageMap); - //If this is a csv download reformat the date fields. - if ($csv) { - $resource_id = $datastoreQuery->{"$.resources.0.id"}; - $meta_data = $this->datastore->getDataDictionaryFields($resource_id); - if ($meta_data) { - //Pass the data dictionary metadata to the query. - $query->dataDictionaryFields = $meta_data; - } + // Get Resource ID and data dictionary fields. + $resource_id = $datastoreQuery->{"$.resources.0.id"}; + $meta_data = $this->datastore->getDataDictionaryFields($resource_id); + if ($csv && $meta_data) { $ + // Pass the data dictionary metadata to the query. + query->dataDictionaryFields = $meta_data; } $result = $storageMap[$primaryAlias]->query($query, $primaryAlias, $fetch); @@ -157,8 +155,6 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ } - - /** * Remove the primary key from the schema field list. * diff --git a/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php b/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php index 6b97e6f976..d7093a71bc 100644 --- a/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php +++ b/modules/datastore/src/Service/ResourceProcessor/DictionaryEnforcer.php @@ -130,7 +130,7 @@ public function returnDataDictionaryFields() { // Get data dictionary info. if ($dd_mode == "sitewide") { $dict_id = $this->dataDictionaryDiscovery->getSitewideDictionaryId(); - $metaData = $this->metastore->get('data-dictionary', $dict_id)->{"$.data.fields"}; + $metaData = $this->metastore->get('data-dictionary', $dict_id)->{"$.data.fields"}; return $metaData; } } From e4647906e52233606e139a7cef0866dfcef70578 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 10:45:11 -0600 Subject: [PATCH 032/117] Fixing code climate issues p2 --- modules/datastore/src/Service.php | 2 +- modules/datastore/src/Service/Query.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index 1c2319f2b4..7d85cc4aef 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -197,7 +197,7 @@ public function getImportService(DataResource $resource) { * Returns the Data Dictionary fields. * * @param string $resource_id - * Dataset id. + * Dataset id. */ public function getDataDictionaryFields($resource_id) { return $this->dictionaryEnforcer->returnDataDictionaryFields($resource_id); diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index dd56720a71..806183e04b 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -142,9 +142,10 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ // Get Resource ID and data dictionary fields. $resource_id = $datastoreQuery->{"$.resources.0.id"}; $meta_data = $this->datastore->getDataDictionaryFields($resource_id); - if ($csv && $meta_data) { $ + if ($csv && $meta_data) { + // Pass the data dictionary metadata to the query. - query->dataDictionaryFields = $meta_data; + $query->dataDictionaryFields = $meta_data; } $result = $storageMap[$primaryAlias]->query($query, $primaryAlias, $fetch); From 62e84ff083d1dbdaa32d03cacd104373a29e40c8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 10:50:09 -0600 Subject: [PATCH 033/117] Fixing code climate issues p3 --- modules/datastore/src/Service/Query.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 806183e04b..f6f8fc47ed 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -142,11 +142,9 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ // Get Resource ID and data dictionary fields. $resource_id = $datastoreQuery->{"$.resources.0.id"}; $meta_data = $this->datastore->getDataDictionaryFields($resource_id); - if ($csv && $meta_data) { + // Pass the data dictionary metadata to the query. + $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; - // Pass the data dictionary metadata to the query. - $query->dataDictionaryFields = $meta_data; - } $result = $storageMap[$primaryAlias]->query($query, $primaryAlias, $fetch); if ($datastoreQuery->{"$.keys"} === FALSE && is_array($result)) { From 3507a344563377bed36938a17b8811e8fb61291b Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 11:01:01 -0600 Subject: [PATCH 034/117] trying to fix failing phpunit tests --- modules/datastore/src/Service/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index f6f8fc47ed..ffea179638 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -141,7 +141,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ $query = QueryFactory::create($datastoreQuery, $storageMap); // Get Resource ID and data dictionary fields. $resource_id = $datastoreQuery->{"$.resources.0.id"}; - $meta_data = $this->datastore->getDataDictionaryFields($resource_id); + $meta_data = $resource_id ? $this->datastore->getDataDictionaryFields($resource_id) : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; From 0423624421840dca64c4ef4d57b1ee3f09a9f1c2 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 11:08:50 -0600 Subject: [PATCH 035/117] more phpunit test fix --- modules/datastore/src/Service.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index 7d85cc4aef..c1551e3fca 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -200,7 +200,9 @@ public function getImportService(DataResource $resource) { * Dataset id. */ public function getDataDictionaryFields($resource_id) { - return $this->dictionaryEnforcer->returnDataDictionaryFields($resource_id); + if ($resource_id) { + return $this->dictionaryEnforcer->returnDataDictionaryFields($resource_id); + } } /** From 996b80f0c5599a6e3b888810532c64f99219cdeb Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 11 Jan 2023 11:58:48 -0600 Subject: [PATCH 036/117] more phpunit test fix pt2 --- modules/datastore/src/Service/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index ffea179638..0b52e0fe74 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -141,7 +141,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ $query = QueryFactory::create($datastoreQuery, $storageMap); // Get Resource ID and data dictionary fields. $resource_id = $datastoreQuery->{"$.resources.0.id"}; - $meta_data = $resource_id ? $this->datastore->getDataDictionaryFields($resource_id) : NULL; + $meta_data = $csv != FALSE ? $this->datastore->getDataDictionaryFields($resource_id) : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; From 16628ad35fd2845670689d695bc688a264108057 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 23 Jan 2023 14:33:36 -0600 Subject: [PATCH 037/117] Updating unit test to add datastore service --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 68029886b9..225fcd9884 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -38,6 +38,7 @@ protected function setUp() { $options = (new Options) ->add('cache_contexts_manager', CacheContextsManager::class) ->add('event_dispatcher', ContainerAwareEventDispatcher::class) + ->add("dkan.datastore.service", Service::class) ->index(0); $chain = (new Chain($this)) ->add(ContainerInterface::class, 'get', $options) From e9a5fa7c90286ab3175dd4dc22f6392dad450b96 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 10:59:59 -0600 Subject: [PATCH 038/117] setting getDataDictionaryFields in mock chain --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 225fcd9884..4b027baff8 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -38,7 +38,6 @@ protected function setUp() { $options = (new Options) ->add('cache_contexts_manager', CacheContextsManager::class) ->add('event_dispatcher', ContainerAwareEventDispatcher::class) - ->add("dkan.datastore.service", Service::class) ->index(0); $chain = (new Chain($this)) ->add(ContainerInterface::class, 'get', $options) @@ -376,6 +375,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Container::class, "get", $options) ->add(DatasetInfo::class, "gather", []) ->add(MetastoreApiResponse::class, 'getMetastoreItemFactory', NodeDataFactory::class) + ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(MetastoreApiResponse::class, 'addReferenceDependencies', NULL) ->add(NodeDataFactory::class, 'getInstance', Data::class) ->add(Data::class, 'getCacheContexts', ['url']) From 4e9bd4bdbea01106f5c45abf5b6460ec3a62ab3c Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 11:10:18 -0600 Subject: [PATCH 039/117] moving the getDataDictionaryFields mock --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 4b027baff8..1f3e6e356f 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -375,7 +375,6 @@ private function getQueryContainer(int $rowLimit) { ->add(Container::class, "get", $options) ->add(DatasetInfo::class, "gather", []) ->add(MetastoreApiResponse::class, 'getMetastoreItemFactory', NodeDataFactory::class) - ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(MetastoreApiResponse::class, 'addReferenceDependencies', NULL) ->add(NodeDataFactory::class, 'getInstance', Data::class) ->add(Data::class, 'getCacheContexts', ['url']) @@ -383,6 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) + ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 37fc18563db3947cc6a976a2ac646253478797a1 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 11:16:49 -0600 Subject: [PATCH 040/117] changing the getDataDictionaryFields mock to Query --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 1f3e6e356f..4aae78525b 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Service::class, 'getDataDictionaryFields', NULL) + ->add(Query::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From cc8b385b9bcfbb031fd704d12157b009fa77feea Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 11:47:40 -0600 Subject: [PATCH 041/117] adding DictionaryEnforcer to mock list --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 4aae78525b..c8a08d7c41 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -346,6 +346,7 @@ private function getQueryContainer(int $rowLimit) { ->add('config.factory', ConfigFactoryInterface::class) ->add('dkan.metastore.metastore_item_factory', NodeDataFactory::class) ->add('dkan.metastore.api_response', MetastoreApiResponse::class) + ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); $connection = new SqliteConnection(new \PDO('sqlite::memory:'), []); @@ -382,7 +383,8 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDataDictionaryFields', NULL) + ->add(Query::class, 'getDataDictionaryFields', Service::getDataDictionaryFields(NULL)) + ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', DictionaryEnforcer::returnDataDictionaryFields()) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 69d951918790f334c64973a8670be92962a4b2e1 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 11:54:00 -0600 Subject: [PATCH 042/117] fixing static class error --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index c8a08d7c41..fcfbf9b515 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -383,8 +383,8 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDataDictionaryFields', Service::getDataDictionaryFields(NULL)) - ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', DictionaryEnforcer::returnDataDictionaryFields()) + ->add(Query::class, 'getDataDictionaryFields', Service::class) + ->add(Service::class, 'getDataDictionaryFields', DictionaryEnforcer::class) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 684fb98228b4efb5c0e249a9e75a0e064e938b3d Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 11:55:13 -0600 Subject: [PATCH 043/117] found service call error --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index fcfbf9b515..e54c13b42e 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -384,7 +384,7 @@ private function getQueryContainer(int $rowLimit) { ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(Query::class, 'getDataDictionaryFields', Service::class) - ->add(Service::class, 'getDataDictionaryFields', DictionaryEnforcer::class) + ->add(Service::class, 'returnDataDictionaryFields', DictionaryEnforcer::class) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From dd01d94ae443cfdc11b8c9c44a990fc64238b58a Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:03:27 -0600 Subject: [PATCH 044/117] fixing getDataDictionaryFields missing error --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index e54c13b42e..75965c54e2 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -383,8 +383,8 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDataDictionaryFields', Service::class) - ->add(Service::class, 'returnDataDictionaryFields', DictionaryEnforcer::class) + ->add(Service::class, 'getDataDictionaryFields', NULL) + ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 9ebec8e069b06d55280de04abc00419e42cafc00 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:22:48 -0600 Subject: [PATCH 045/117] Adding getDatastoreService function to be called in the test --- modules/datastore/src/Service/Query.php | 12 +++++++++++- .../Unit/Controller/QueryDownloadControllerTest.php | 4 +--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 0b52e0fe74..260d736260 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -141,7 +141,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ $query = QueryFactory::create($datastoreQuery, $storageMap); // Get Resource ID and data dictionary fields. $resource_id = $datastoreQuery->{"$.resources.0.id"}; - $meta_data = $csv != FALSE ? $this->datastore->getDataDictionaryFields($resource_id) : NULL; + $meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields($resource_id) : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; @@ -154,6 +154,16 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ } + /** + * Return the datastore service. + * + * @return \Drupal\datastore\Service + * Datastore Service. + */ + protected function getDatastoreService() { + return $this->datastore; + } + /** * Remove the primary key from the schema field list. * diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 75965c54e2..74298f617f 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -346,7 +346,6 @@ private function getQueryContainer(int $rowLimit) { ->add('config.factory', ConfigFactoryInterface::class) ->add('dkan.metastore.metastore_item_factory', NodeDataFactory::class) ->add('dkan.metastore.api_response', MetastoreApiResponse::class) - ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); $connection = new SqliteConnection(new \PDO('sqlite::memory:'), []); @@ -383,8 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Service::class, 'getDataDictionaryFields', NULL) - ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', NULL) + ->add(Query::class, 'getDatastoreService', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From a73a438c81e1ab43e45bfe228364fbdceae0b0b0 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:29:51 -0600 Subject: [PATCH 046/117] more mock work --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 74298f617f..dd61387a4b 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDatastoreService', NULL) + ->add(Query::class, 'getDatastoreService', Service::class) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 0263cce956dca5fbff7d1bb5914eb54389d449fd Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:36:16 -0600 Subject: [PATCH 047/117] adding pack getDataDictionaryFields --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index dd61387a4b..5e24e5b975 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -383,6 +383,7 @@ private function getQueryContainer(int $rowLimit) { ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(Query::class, 'getDatastoreService', Service::class) + ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 1bec98705603f4a362caf81efc85189bd240a51e Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:43:06 -0600 Subject: [PATCH 048/117] adding back dictionary_enforcer --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 5e24e5b975..6c36579097 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -346,6 +346,7 @@ private function getQueryContainer(int $rowLimit) { ->add('config.factory', ConfigFactoryInterface::class) ->add('dkan.metastore.metastore_item_factory', NodeDataFactory::class) ->add('dkan.metastore.api_response', MetastoreApiResponse::class) + ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); $connection = new SqliteConnection(new \PDO('sqlite::memory:'), []); From 78c2553bb3111e162cb09da28948fbe5ee126a6c Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:47:48 -0600 Subject: [PATCH 049/117] fixing error in DatastoreQueryTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 - modules/datastore/tests/src/Unit/Service/DatastoreQueryTest.php | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 6c36579097..5e24e5b975 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -346,7 +346,6 @@ private function getQueryContainer(int $rowLimit) { ->add('config.factory', ConfigFactoryInterface::class) ->add('dkan.metastore.metastore_item_factory', NodeDataFactory::class) ->add('dkan.metastore.api_response', MetastoreApiResponse::class) - ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); $connection = new SqliteConnection(new \PDO('sqlite::memory:'), []); diff --git a/modules/datastore/tests/src/Unit/Service/DatastoreQueryTest.php b/modules/datastore/tests/src/Unit/Service/DatastoreQueryTest.php index 6a42ab5cb5..8f13667f21 100644 --- a/modules/datastore/tests/src/Unit/Service/DatastoreQueryTest.php +++ b/modules/datastore/tests/src/Unit/Service/DatastoreQueryTest.php @@ -24,6 +24,7 @@ use Drupal\metastore\Storage\Data; use Drupal\metastore\Storage\DataFactory; use Drupal\Tests\common\Unit\Storage\QueryDataProvider as QueryData; +use Drupal\datastore\Service\ResourceProcessor\DictionaryEnforcer; /** * @group dkan @@ -195,6 +196,7 @@ public function getCommonMockChain() { ->add('dkan.common.job_store', JobStoreFactory::class) ->add('dkan.metastore.storage', DataFactory::class) ->add('dkan.datastore.import_info_list', ImportInfoList::class) + ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); $resource_metadata = '{"data":{"%Ref:downloadURL":[{"data":{"identifier":"qwerty","version":"uiop"}}]}}'; From 6dbde5be45553a5b54abf05974d11cebb14a3928 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 12:53:44 -0600 Subject: [PATCH 050/117] updating ServiceTest.php --- modules/datastore/tests/src/Unit/ServiceTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/datastore/tests/src/Unit/ServiceTest.php b/modules/datastore/tests/src/Unit/ServiceTest.php index 40ab3e67be..797aa62749 100644 --- a/modules/datastore/tests/src/Unit/ServiceTest.php +++ b/modules/datastore/tests/src/Unit/ServiceTest.php @@ -22,6 +22,7 @@ use Procrastinator\Job\AbstractPersistentJob; use Procrastinator\Result; use Symfony\Component\DependencyInjection\Container; +use Drupal\datastore\Service\ResourceProcessor\DictionaryEnforcer; use TypeError; /** @@ -82,6 +83,7 @@ private function getCommonChain() { ->add('queue', QueueFactory::class) ->add('dkan.common.job_store', JobStoreFactory::class) ->add('dkan.datastore.import_info_list', ImportInfoList::class) + ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); return (new Chain($this)) From b4fd2a58e96594cd79d6ea94c713282551375bba Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 14:01:36 -0600 Subject: [PATCH 051/117] adding additional tests for DictionaryEnforcerTest --- .../DictionaryEnforcerTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index c1d49a7aa2..45e45d9bce 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -143,6 +143,35 @@ public function testProcessItemExecuteException() { $this->assertEquals($errors[0], 'Test Error'); } + /** + * Test getting data dictionary fields. + */ + public function testReturnDataDictionaryFields() { + $resource = new DataResource('test.csv', 'text/csv'); + + $alter_table_query_builder = (new Chain($this)) + ->add(AlterTableQueryBuilderInterface::class, 'getQuery', AlterTableQueryInterface::class) + ->add(AlterTableQueryInterface::class, 'execute') + ->getMock(); + $metastore_service = (new Chain($this)) + ->add(MetastoreService::class, 'get', new RootedJsonData(json_encode(['data' => ['fields' => []]]))) + ->getMock(); + $dictionary_discovery_service = (new Chain($this)) + ->add(DataDictionaryDiscoveryInterface::class, 'dictionaryIdFromResource', 'dictionary-id') + ->getMock(); + $dictionary_enforcer = new DictionaryEnforcer($alter_table_query_builder, $metastore_service, $dictionary_discovery_service); + + $container_chain = $this->getContainerChain($resource->getVersion()) + ->add(AlterTableQueryInterface::class, 'execute') + ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) + ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); + \Drupal::setContainer($container_chain->getMock($resource->getVersion())); + + $result = $dictionary_enforcer->returnDataDictionaryFields(); + var_dump($result); + $this->assertIsArray($result); + } + /** * Get container chain. */ From 0c41f97ed0da1c87a69af24d2455cba17f8d627a Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 14:10:26 -0600 Subject: [PATCH 052/117] updating test --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 45e45d9bce..00cdec4a49 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -167,7 +167,7 @@ public function testReturnDataDictionaryFields() { ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); \Drupal::setContainer($container_chain->getMock($resource->getVersion())); - $result = $dictionary_enforcer->returnDataDictionaryFields(); + $result = $this->returnDataDictionaryFields(); var_dump($result); $this->assertIsArray($result); } From 94cdc4bf17c77f499b4d98429146b572956e5e4c Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 14:39:12 -0600 Subject: [PATCH 053/117] updating test --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 00cdec4a49..7ff331fd0f 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -167,7 +167,7 @@ public function testReturnDataDictionaryFields() { ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); \Drupal::setContainer($container_chain->getMock($resource->getVersion())); - $result = $this->returnDataDictionaryFields(); + $result = $container_chain->returnDataDictionaryFields(); var_dump($result); $this->assertIsArray($result); } From a77c3f5b0f6b28a3e746b6437855d3e9e931fde8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 14:47:15 -0600 Subject: [PATCH 054/117] updating test again --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 7ff331fd0f..b2440c5645 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -165,9 +165,8 @@ public function testReturnDataDictionaryFields() { ->add(AlterTableQueryInterface::class, 'execute') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); - \Drupal::setContainer($container_chain->getMock($resource->getVersion())); - $result = $container_chain->returnDataDictionaryFields(); + $result = $container_chain->getMock($resource->getVersion())->returnDataDictionaryFields(); var_dump($result); $this->assertIsArray($result); } From 0499e3ec3e0df46b8d8223991baaae12126865ba Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 14:54:44 -0600 Subject: [PATCH 055/117] updating test again --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index b2440c5645..65d3f8aaed 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -165,8 +165,10 @@ public function testReturnDataDictionaryFields() { ->add(AlterTableQueryInterface::class, 'execute') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); + ->add(DataDictionaryDiscovery::class, 'getDataDictionaryForResource') + + $result = $containerChain->getMock($resource->getVersion()); - $result = $container_chain->getMock($resource->getVersion())->returnDataDictionaryFields(); var_dump($result); $this->assertIsArray($result); } From e6d1756503799489b5538a6311edcc9820c45deb Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 15:00:08 -0600 Subject: [PATCH 056/117] fixing syntax error --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 65d3f8aaed..69d967daf4 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -165,7 +165,7 @@ public function testReturnDataDictionaryFields() { ->add(AlterTableQueryInterface::class, 'execute') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); - ->add(DataDictionaryDiscovery::class, 'getDataDictionaryForResource') + ->add(DataDictionaryDiscovery::class, 'getDataDictionaryForResource'); $result = $containerChain->getMock($resource->getVersion()); From e6ab227f0faaac66707aef29bcd076a9f442f771 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 15:03:04 -0600 Subject: [PATCH 057/117] fixing syntax error --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 69d967daf4..e9df5d20a8 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -164,7 +164,7 @@ public function testReturnDataDictionaryFields() { $container_chain = $this->getContainerChain($resource->getVersion()) ->add(AlterTableQueryInterface::class, 'execute') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) - ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); + ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]) ->add(DataDictionaryDiscovery::class, 'getDataDictionaryForResource'); $result = $containerChain->getMock($resource->getVersion()); From 0a99acca44c23826c246edd4b2de7cf905fc5cc1 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 15:04:52 -0600 Subject: [PATCH 058/117] changing function being called in mock --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index e9df5d20a8..992d426a64 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -165,7 +165,7 @@ public function testReturnDataDictionaryFields() { ->add(AlterTableQueryInterface::class, 'execute') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]) - ->add(DataDictionaryDiscovery::class, 'getDataDictionaryForResource'); + ->add(DataDictionaryDiscovery::class, 'returnDataDictionaryFields'); $result = $containerChain->getMock($resource->getVersion()); From c9528b6922bc61323db456fd56866f0a21605d8a Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 15:10:40 -0600 Subject: [PATCH 059/117] fixing variable --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 992d426a64..f37bdd616a 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -167,7 +167,7 @@ public function testReturnDataDictionaryFields() { ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]) ->add(DataDictionaryDiscovery::class, 'returnDataDictionaryFields'); - $result = $containerChain->getMock($resource->getVersion()); + $result = $container_chain->getMock($resource->getVersion()); var_dump($result); $this->assertIsArray($result); From 098b664c6043d24e4ea4d3fa56cc8910657ea529 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 15:21:41 -0600 Subject: [PATCH 060/117] removing var_dump --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index f37bdd616a..51f4cda95b 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -169,7 +169,6 @@ public function testReturnDataDictionaryFields() { $result = $container_chain->getMock($resource->getVersion()); - var_dump($result); $this->assertIsArray($result); } From 1f0c0cf56ab21e1846a614f8c09cce12ac741ba7 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 25 Jan 2023 15:39:36 -0600 Subject: [PATCH 061/117] making more changes to the test --- .../Service/ResourceProcessor/DictionaryEnforcerTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 51f4cda95b..f9c93e18ac 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -161,13 +161,7 @@ public function testReturnDataDictionaryFields() { ->getMock(); $dictionary_enforcer = new DictionaryEnforcer($alter_table_query_builder, $metastore_service, $dictionary_discovery_service); - $container_chain = $this->getContainerChain($resource->getVersion()) - ->add(AlterTableQueryInterface::class, 'execute') - ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) - ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]) - ->add(DataDictionaryDiscovery::class, 'returnDataDictionaryFields'); - - $result = $container_chain->getMock($resource->getVersion()); + $result = $dictionary_enforcer->returnDataDictionaryFields(); $this->assertIsArray($result); } From e35cb25676ec7bd05ed477133ef9240e400842a5 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 10:02:25 -0600 Subject: [PATCH 062/117] updating new tests --- .../ResourceProcessor/DictionaryEnforcerTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index f9c93e18ac..9d335d7e1e 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -158,11 +158,19 @@ public function testReturnDataDictionaryFields() { ->getMock(); $dictionary_discovery_service = (new Chain($this)) ->add(DataDictionaryDiscoveryInterface::class, 'dictionaryIdFromResource', 'dictionary-id') + ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) + ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', getSitewideDictionaryId::2) ->getMock(); $dictionary_enforcer = new DictionaryEnforcer($alter_table_query_builder, $metastore_service, $dictionary_discovery_service); - $result = $dictionary_enforcer->returnDataDictionaryFields(); + $container_chain = $this->getContainerChain($resource->getVersion()) + ->add(AlterTableQueryInterface::class, 'execute') + ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) + ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); + ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', ['data' => ['fields' => []]]); + \Drupal::setContainer($container_chain->getMock($resource->getVersion())); + $result = $dictionary_enforcer->returnDataDictionaryFields(); $this->assertIsArray($result); } @@ -180,6 +188,7 @@ protected function getContainerChain(int $resource_version) { ->add('stream_wrapper_manager', StreamWrapperManager::class) ->add('dkan.metastore.resource_mapper', ResourceMapper::class) ->add('dkan.datastore.service.resource_processor_collector', ResourceProcessorCollector::class) + ->add('dkan.datastore.service.resource_processor.dictionary_enforcer', DictionaryEnforcer::class) ->index(0); $json = '{"identifier":"foo","title":"bar","data":{"fields":[]}}'; @@ -192,6 +201,8 @@ protected function getContainerChain(int $resource_version) { ->add(AlterTableQueryBuilderInterface::class, 'setConnectionTimeout', AlterTableQueryBuilderInterface::class) ->add(AlterTableQueryBuilderInterface::class, 'getQuery', AlterTableQueryInterface::class) ->add(DataDictionaryDiscoveryInterface::class, 'dictionaryIdFromResource', 'resource_id') + ->add(DataDictionaryDiscoveryInterface::class, 'getSitewideDictionaryId') + ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields') ->add(PublicStream::class, 'getExternalUrl', self::HOST) ->add(StreamWrapperManager::class, 'getViaUri', PublicStream::class) ->add(ResourceMapper::class, 'get', DataResource::class) From 0fa38c74522a06be16e3b2136aaceb548c56f03c Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 10:13:52 -0600 Subject: [PATCH 063/117] fixing syntax error --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 9d335d7e1e..2a08a1ecb2 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -159,7 +159,7 @@ public function testReturnDataDictionaryFields() { $dictionary_discovery_service = (new Chain($this)) ->add(DataDictionaryDiscoveryInterface::class, 'dictionaryIdFromResource', 'dictionary-id') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) - ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', getSitewideDictionaryId::2) + ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', getSitewideDictionaryId::class,2) ->getMock(); $dictionary_enforcer = new DictionaryEnforcer($alter_table_query_builder, $metastore_service, $dictionary_discovery_service); From 06463f8cc8483db2f6e7e913ee597419736d8f91 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 10:22:13 -0600 Subject: [PATCH 064/117] fixing syntax error p2 --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 2a08a1ecb2..2bbd2e930d 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -159,7 +159,7 @@ public function testReturnDataDictionaryFields() { $dictionary_discovery_service = (new Chain($this)) ->add(DataDictionaryDiscoveryInterface::class, 'dictionaryIdFromResource', 'dictionary-id') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) - ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', getSitewideDictionaryId::class,2) + ->add(DataDictionaryDiscoveryInterface::class, 'getSitewideDictionaryId',2) ->getMock(); $dictionary_enforcer = new DictionaryEnforcer($alter_table_query_builder, $metastore_service, $dictionary_discovery_service); From 26a2b6b5d39c3f49d6206a5ff05e49aaaa6c02cc Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 10:27:09 -0600 Subject: [PATCH 065/117] fixing syntax error p3 --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 2bbd2e930d..8d39c69b2f 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -166,7 +166,7 @@ public function testReturnDataDictionaryFields() { $container_chain = $this->getContainerChain($resource->getVersion()) ->add(AlterTableQueryInterface::class, 'execute') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) - ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]); + ->add(ResourceProcessorCollector::class, 'getResourceProcessors', [$dictionary_enforcer]) ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', ['data' => ['fields' => []]]); \Drupal::setContainer($container_chain->getMock($resource->getVersion())); From f4fc1a321dad84a58a2a3b1baa223b8038f748aa Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 10:37:21 -0600 Subject: [PATCH 066/117] I was returning the wrong type of variable --- .../Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php index 8d39c69b2f..ad7410df5a 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceProcessor/DictionaryEnforcerTest.php @@ -159,7 +159,7 @@ public function testReturnDataDictionaryFields() { $dictionary_discovery_service = (new Chain($this)) ->add(DataDictionaryDiscoveryInterface::class, 'dictionaryIdFromResource', 'dictionary-id') ->add(DataDictionaryDiscoveryInterface::class, 'getDataDictionaryMode', DataDictionaryDiscoveryInterface::MODE_SITEWIDE) - ->add(DataDictionaryDiscoveryInterface::class, 'getSitewideDictionaryId',2) + ->add(DataDictionaryDiscoveryInterface::class, 'getSitewideDictionaryId','2') ->getMock(); $dictionary_enforcer = new DictionaryEnforcer($alter_table_query_builder, $metastore_service, $dictionary_discovery_service); From f09f1e80026f689f611609f2330a0445c378e525 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 14:37:03 -0600 Subject: [PATCH 067/117] removing resrouce_id from DD lookup --- modules/datastore/src/Service.php | 6 ++---- modules/datastore/src/Service/Query.php | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index c1551e3fca..6294e03939 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -199,10 +199,8 @@ public function getImportService(DataResource $resource) { * @param string $resource_id * Dataset id. */ - public function getDataDictionaryFields($resource_id) { - if ($resource_id) { - return $this->dictionaryEnforcer->returnDataDictionaryFields($resource_id); - } + public function getDataDictionaryFields() { + return $this->dictionaryEnforcer->returnDataDictionaryFields(); } /** diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 260d736260..3797cbd8f5 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -139,9 +139,8 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ $datastoreQuery->{"$.properties"} = array_keys($schema['fields']); } $query = QueryFactory::create($datastoreQuery, $storageMap); - // Get Resource ID and data dictionary fields. - $resource_id = $datastoreQuery->{"$.resources.0.id"}; - $meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields($resource_id) : NULL; + // Get data dictionary fields. + $meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields() : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; From b1bd2373d1078295dcf2b8400d2b0bed2270f04f Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 14:41:54 -0600 Subject: [PATCH 068/117] creating test for getDataDictionaryFields --- modules/datastore/tests/src/Unit/ServiceTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/datastore/tests/src/Unit/ServiceTest.php b/modules/datastore/tests/src/Unit/ServiceTest.php index 797aa62749..03e1c0ff72 100644 --- a/modules/datastore/tests/src/Unit/ServiceTest.php +++ b/modules/datastore/tests/src/Unit/ServiceTest.php @@ -76,6 +76,20 @@ public function testDrop() { $actual = $service->drop('foo', NULL, NULL); } + /** + * Testing Get Data Dictionary Fields. + */ + public function testGetDataDictionaryFields() { + $chain = $this->getContainerChainForService('dkan.datastore.service') + ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', ['data' => ['fields' => []]]); + \Drupal::setContainer($chain->getMock()); + + $service = Service::create($chain->getMock()); + $result = $service->returnDataDictionaryFields(); + + $this->assertTrue(is_array($result)); + } + private function getCommonChain() { $options = (new Options()) ->add('dkan.datastore.service.resource_localizer', ResourceLocalizer::class) From f5f79bb9cfaf98785dde0373305696ff8a4945cc Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 14:45:24 -0600 Subject: [PATCH 069/117] fining coding climate errors --- modules/datastore/src/Service.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index 6294e03939..6ff49051c2 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -196,11 +196,9 @@ public function getImportService(DataResource $resource) { /** * Returns the Data Dictionary fields. * - * @param string $resource_id - * Dataset id. */ public function getDataDictionaryFields() { - return $this->dictionaryEnforcer->returnDataDictionaryFields(); + return $this->dictionaryEnforcer->returnDataDictionaryFields(); } /** From 938079d96d14f0d1051304588b9a58288cfda293 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 14:47:42 -0600 Subject: [PATCH 070/117] fixing code climate issue --- modules/datastore/src/Service.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/datastore/src/Service.php b/modules/datastore/src/Service.php index 6ff49051c2..233e3e1ab0 100644 --- a/modules/datastore/src/Service.php +++ b/modules/datastore/src/Service.php @@ -195,7 +195,6 @@ public function getImportService(DataResource $resource) { /** * Returns the Data Dictionary fields. - * */ public function getDataDictionaryFields() { return $this->dictionaryEnforcer->returnDataDictionaryFields(); From ecea581be9f5de6d54ee0a63c24f1b96cb7693f0 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 14:54:13 -0600 Subject: [PATCH 071/117] fixing testing error --- modules/datastore/tests/src/Unit/ServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/ServiceTest.php b/modules/datastore/tests/src/Unit/ServiceTest.php index 03e1c0ff72..1b45762440 100644 --- a/modules/datastore/tests/src/Unit/ServiceTest.php +++ b/modules/datastore/tests/src/Unit/ServiceTest.php @@ -80,7 +80,7 @@ public function testDrop() { * Testing Get Data Dictionary Fields. */ public function testGetDataDictionaryFields() { - $chain = $this->getContainerChainForService('dkan.datastore.service') + $chain = $this->getCommonChain() ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', ['data' => ['fields' => []]]); \Drupal::setContainer($chain->getMock()); From 2407e251b3aee08b2c5bffe20b664ab75928503f Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Feb 2023 15:00:11 -0600 Subject: [PATCH 072/117] fixing testing error --- modules/datastore/tests/src/Unit/ServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/ServiceTest.php b/modules/datastore/tests/src/Unit/ServiceTest.php index 1b45762440..958daac68f 100644 --- a/modules/datastore/tests/src/Unit/ServiceTest.php +++ b/modules/datastore/tests/src/Unit/ServiceTest.php @@ -85,7 +85,7 @@ public function testGetDataDictionaryFields() { \Drupal::setContainer($chain->getMock()); $service = Service::create($chain->getMock()); - $result = $service->returnDataDictionaryFields(); + $result = $service->getDataDictionaryFields(); $this->assertTrue(is_array($result)); } From 4890595a0eeb5ab35f19453271f75e53aee3047c Mon Sep 17 00:00:00 2001 From: B3WM Date: Fri, 3 Feb 2023 08:17:04 -0600 Subject: [PATCH 073/117] Adding a new test called testGetDatastoreService --- .../Unit/Controller/QueryControllerTest.php | 19 +++++++++++++++++++ .../datastore/tests/src/Unit/ServiceTest.php | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index d194a07038..3652217368 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -464,6 +464,25 @@ private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE return $chain; } + /** + * Testing Get Data Dictionary Fields. + */ + public function testGetDatastoreService() { + + $options = (new Options()) + ->add("dkan.datastore.service", Service::class) + ->index(0); + + $chain = (new Chain($this)) + ->add(Container::class, "get", $options) + ->add(Service::class, 'getDatastoreService', NULL); + + $service = Service::create($chain->getMock()); + $result = $service->getDatastoreService(); + $this->assertTrue($result instanceof Service); + + } + /** * We just test POST requests; logic for other methods is tested elsewhere. * diff --git a/modules/datastore/tests/src/Unit/ServiceTest.php b/modules/datastore/tests/src/Unit/ServiceTest.php index 958daac68f..57006aabbf 100644 --- a/modules/datastore/tests/src/Unit/ServiceTest.php +++ b/modules/datastore/tests/src/Unit/ServiceTest.php @@ -81,8 +81,7 @@ public function testDrop() { */ public function testGetDataDictionaryFields() { $chain = $this->getCommonChain() - ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', ['data' => ['fields' => []]]); - \Drupal::setContainer($chain->getMock()); + ->add(DictionaryEnforcer::class, 'getDatastoreService', ['data' => ['fields' => []]]); $service = Service::create($chain->getMock()); $result = $service->getDataDictionaryFields(); From ba7c66ccc0d6e7b6a9d30bdd61f5a3d7c9023d24 Mon Sep 17 00:00:00 2001 From: B3WM Date: Fri, 3 Feb 2023 09:16:55 -0600 Subject: [PATCH 074/117] making additional changes to testGetDatastoreService --- .../Unit/Controller/QueryControllerTest.php | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 3652217368..0c77034bf1 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -433,6 +433,26 @@ public function testQueryCsvCacheHeaders() { $this->assertEmpty($headers->get('last-modified')); } + /** + * Testing Get Data Dictionary Fields. + */ + public function testGetDatastoreService() { + + $options = (new Options()) + ->add("dkan.datastore.service", Service::class) + ->index(0); + + $chain = (new Chain($this)) + ->add(Container::class, "get", $options) + ->add(Service::class, 'getDatastoreService', NULL); + + $service =new Service; + //$service = Service::create($chain->getMock()); + $result = $service->getDatastoreService(); + $this->assertTrue($result instanceof Service); + + } + private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE) { $options = (new Options()) @@ -464,25 +484,6 @@ private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE return $chain; } - /** - * Testing Get Data Dictionary Fields. - */ - public function testGetDatastoreService() { - - $options = (new Options()) - ->add("dkan.datastore.service", Service::class) - ->index(0); - - $chain = (new Chain($this)) - ->add(Container::class, "get", $options) - ->add(Service::class, 'getDatastoreService', NULL); - - $service = Service::create($chain->getMock()); - $result = $service->getDatastoreService(); - $this->assertTrue($result instanceof Service); - - } - /** * We just test POST requests; logic for other methods is tested elsewhere. * From 7bcbc200cbc17de284c51e3623430e8622bf487d Mon Sep 17 00:00:00 2001 From: B3WM Date: Fri, 3 Feb 2023 09:33:52 -0600 Subject: [PATCH 075/117] making changes to testGetDatastoreService --- .../Unit/Controller/QueryControllerTest.php | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 0c77034bf1..abc8dc3332 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -24,6 +24,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Drupal\datastore\Service\ResourceLocalizer; +use FileFetcher\FileFetcher; +use Drupal\datastore\Service\Factory\Import as ImportServiceFactory; +use Drupal\metastore\ResourceMapper; +use Drupal\Core\Queue\QueueFactory; +use Drupal\datastore\Service\Import as ImportService; +use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; /** * @@ -434,21 +441,24 @@ public function testQueryCsvCacheHeaders() { } /** - * Testing Get Data Dictionary Fields. + * Testing Get Data Dictionary Fields. rada */ public function testGetDatastoreService() { + $resource = new DataResource('http://example.org', 'text/csv'); + $chain = $this->getContainerChainForService('dkan.datastore.service') + ->add(ResourceLocalizer::class, 'get', $resource) + ->add(ResourceLocalizer::class, 'getResult', Result::class) + ->add(FileFetcher::class, 'run', Result::class) + ->add(ResourceMapper::class, 'get', $resource) + ->add(ImportServiceFactory::class, "getInstance", ImportService::class) + ->add(ImportService::class, "import", NULL) + ->add(ImportService::class, "getResult", new Result()) + ->add(QueueFactory::class, "get", NULL) + ->add(ContainerAwareEventDispatcher::class, "dispatch", NULL); + + $service = Service::create($chain->getMock()); + $result = $service->getDatastoreService; - $options = (new Options()) - ->add("dkan.datastore.service", Service::class) - ->index(0); - - $chain = (new Chain($this)) - ->add(Container::class, "get", $options) - ->add(Service::class, 'getDatastoreService', NULL); - - $service =new Service; - //$service = Service::create($chain->getMock()); - $result = $service->getDatastoreService(); $this->assertTrue($result instanceof Service); } From 3070910278db94cf93c69de4b913d7b73c24decf Mon Sep 17 00:00:00 2001 From: B3WM Date: Fri, 3 Feb 2023 09:41:47 -0600 Subject: [PATCH 076/117] making changes to testGetDatastoreService --- .../datastore/tests/src/Unit/Controller/QueryControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index abc8dc3332..d92d8552dc 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -31,6 +31,7 @@ use Drupal\Core\Queue\QueueFactory; use Drupal\datastore\Service\Import as ImportService; use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; +use Drupal\common\DataResource; /** * From d80afd0a596e95509925cf9c0d73d1174b84fabe Mon Sep 17 00:00:00 2001 From: B3WM Date: Fri, 3 Feb 2023 09:49:50 -0600 Subject: [PATCH 077/117] making changes to testGetDatastoreService p3 --- .../tests/src/Unit/Controller/QueryControllerTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index d92d8552dc..e381944089 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -464,6 +464,14 @@ public function testGetDatastoreService() { } + /** + * Private. + */ + private function getContainerChainForService($serviceName): Chain { + $options = $this->getContainerOptionsForService($serviceName); + return (new Chain($this))->add(Container::class, 'get', $options); + } + private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE) { $options = (new Options()) From ebdc24cfe7525d982e3b5ae7f9cb8ef9b57600a3 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 08:43:53 -0600 Subject: [PATCH 078/117] adding the rest of the missing functions --- .../Unit/Controller/QueryControllerTest.php | 100 +++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index e381944089..31c96a0e0e 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -467,11 +467,105 @@ public function testGetDatastoreService() { /** * Private. */ - private function getContainerChainForService($serviceName): Chain { - $options = $this->getContainerOptionsForService($serviceName); - return (new Chain($this))->add(Container::class, 'get', $options); + private function getContainerOptionsForService($serviceName): Options { + $options = (new Options())->index(0); + $service = $this->checkService($serviceName); + // Extract services from service arguments. + $arguments = array_filter($service['arguments'], function ($arg) { + return preg_match('/^@[^@]/', $arg, $matches) === 1; + }); + foreach ($arguments as $arg) { + // Extract service name from argument. + $arg = str_replace("@", '', $arg); + $argService = $this->checkService($arg); + $class = $argService['class']; + if ($class[0] == '\\') { + $class = substr($class, 1); + } + $options->add($arg, $class); + } + return $options; } + /** + * Private. + */ + private function checkService($serviceName) { + $dkanModules = [ + 'common', + 'datastore', + 'frontend', + 'harvest', + 'metastore', + ]; + $files = []; + + foreach ($dkanModules as $dkanModule) { + $files[] = $this->getRelativeDkanModulePath($dkanModule) . "/{$dkanModule}.services.yml"; + } + $files[] = $this->getRelativeDrupalPath() . "/core/core.services.yml"; + + foreach ($files as $file) { + $content = Yaml::decode(file_get_contents($file)); + $services = array_keys($content['services']); + if (in_array($serviceName, $services)) { + $this->assertTrue(TRUE, "{$serviceName} exists in {$file}"); + return $content['services'][$serviceName]; + } + } + $this->assertFalse(TRUE, "{$serviceName} does not exist in DKAN or Drupal core."); + } + + /** + * Private. + */ + private function getRelativeDkanModulePath($moduleName, $path = NULL) { + if (!$path) { + $path = $this->getRelativeDkanPath(); + } + + foreach (new \DirectoryIterator($path) as $fileInfo) { + if ($fileInfo->isDir() && !$fileInfo->isDot()) { + if ($fileInfo->getFilename() == $moduleName) { + return $fileInfo->getPathname(); + } + elseif ($fileInfo->getFilename() == "modules") { + return $this->getRelativeDkanModulePath($moduleName, $fileInfo->getPathname()); + } + } + } + } + + /** + * Private. + */ + private function getRelativeDkanPath() { + $path = __DIR__; + + while (TRUE) { + $content = glob($path . "/*"); + $content = array_map(function ($item) use ($path) { + return str_replace($path, "", $item); + }, $content); + + if (in_array("/dkan.info.yml", $content)) { + return $path; + } + + $path .= "/.."; + } + } + + /** + * Private. + */ + private function getRelativeDrupalPath() { + return getenv('DRUPAL_ROOT'); + } + + /** + * Private. + */ private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE) { $options = (new Options()) From 40cbf6753b85b9343d05a9e04aa25ce6132a3944 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 08:49:17 -0600 Subject: [PATCH 079/117] adding another missing function --- .../tests/src/Unit/Controller/QueryControllerTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 31c96a0e0e..e4258f66db 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -464,6 +464,14 @@ public function testGetDatastoreService() { } + /** + * Private. + */ + private function getContainerChainForService($serviceName): Chain { + $options = $this->getContainerOptionsForService($serviceName); + return (new Chain($this))->add(Container::class, 'get', $options); + } + /** * Private. */ From d3885fabb3fa25dde243b103e4ddb91dfe39bb24 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 09:47:13 -0600 Subject: [PATCH 080/117] adding missing Yaml declaration --- .../datastore/tests/src/Unit/Controller/QueryControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index e4258f66db..8696eb2751 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -32,6 +32,7 @@ use Drupal\datastore\Service\Import as ImportService; use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; use Drupal\common\DataResource; +use Drupal\Core\Serialization\Yaml; /** * From adcc319307925a84249a46b10381699eb2bfd719 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 09:56:52 -0600 Subject: [PATCH 081/117] fixing coding error --- .../datastore/tests/src/Unit/Controller/QueryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 8696eb2751..14ceac7093 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -459,7 +459,7 @@ public function testGetDatastoreService() { ->add(ContainerAwareEventDispatcher::class, "dispatch", NULL); $service = Service::create($chain->getMock()); - $result = $service->getDatastoreService; + $result = $service->getDatastoreService(); $this->assertTrue($result instanceof Service); From eb8b405d803edfecef30dd1d87e952baff91832d Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 10:06:42 -0600 Subject: [PATCH 082/117] making changes to the test --- .../tests/src/Unit/Controller/QueryControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 14ceac7093..cf663c4620 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -459,9 +459,9 @@ public function testGetDatastoreService() { ->add(ContainerAwareEventDispatcher::class, "dispatch", NULL); $service = Service::create($chain->getMock()); - $result = $service->getDatastoreService(); + //$result = $service->getDatastoreService(); - $this->assertTrue($result instanceof Service); + $this->assertTrue($service->getDatastoreService() instanceof Service); } From f7dc29a701ec36552a2cc7f9f4a38fded70d5b86 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 10:21:38 -0600 Subject: [PATCH 083/117] resetting the QueryControllerTest.php file --- .../Unit/Controller/QueryControllerTest.php | 143 ++---------------- 1 file changed, 10 insertions(+), 133 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index cf663c4620..57cce97655 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -24,15 +24,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Drupal\datastore\Service\ResourceLocalizer; -use FileFetcher\FileFetcher; -use Drupal\datastore\Service\Factory\Import as ImportServiceFactory; -use Drupal\metastore\ResourceMapper; -use Drupal\Core\Queue\QueueFactory; -use Drupal\datastore\Service\Import as ImportService; -use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; -use Drupal\common\DataResource; -use Drupal\Core\Serialization\Yaml; /** * @@ -443,138 +434,24 @@ public function testQueryCsvCacheHeaders() { } /** - * Testing Get Data Dictionary Fields. rada + * Testing Get Data Dictionary Fields. */ public function testGetDatastoreService() { - $resource = new DataResource('http://example.org', 'text/csv'); - $chain = $this->getContainerChainForService('dkan.datastore.service') - ->add(ResourceLocalizer::class, 'get', $resource) - ->add(ResourceLocalizer::class, 'getResult', Result::class) - ->add(FileFetcher::class, 'run', Result::class) - ->add(ResourceMapper::class, 'get', $resource) - ->add(ImportServiceFactory::class, "getInstance", ImportService::class) - ->add(ImportService::class, "import", NULL) - ->add(ImportService::class, "getResult", new Result()) - ->add(QueueFactory::class, "get", NULL) - ->add(ContainerAwareEventDispatcher::class, "dispatch", NULL); - $service = Service::create($chain->getMock()); - //$result = $service->getDatastoreService(); - - $this->assertTrue($service->getDatastoreService() instanceof Service); - - } - - /** - * Private. - */ - private function getContainerChainForService($serviceName): Chain { - $options = $this->getContainerOptionsForService($serviceName); - return (new Chain($this))->add(Container::class, 'get', $options); - } - - /** - * Private. - */ - private function getContainerOptionsForService($serviceName): Options { - $options = (new Options())->index(0); - $service = $this->checkService($serviceName); - // Extract services from service arguments. - $arguments = array_filter($service['arguments'], function ($arg) { - return preg_match('/^@[^@]/', $arg, $matches) === 1; - }); - foreach ($arguments as $arg) { - // Extract service name from argument. - $arg = str_replace("@", '', $arg); - $argService = $this->checkService($arg); - $class = $argService['class']; - if ($class[0] == '\\') { - $class = substr($class, 1); - } - $options->add($arg, $class); - } - return $options; - } - - /** - * Private. - */ - private function checkService($serviceName) { - $dkanModules = [ - 'common', - 'datastore', - 'frontend', - 'harvest', - 'metastore', - ]; - $files = []; - - foreach ($dkanModules as $dkanModule) { - $files[] = $this->getRelativeDkanModulePath($dkanModule) . "/{$dkanModule}.services.yml"; - } - $files[] = $this->getRelativeDrupalPath() . "/core/core.services.yml"; - - foreach ($files as $file) { - $content = Yaml::decode(file_get_contents($file)); - $services = array_keys($content['services']); - if (in_array($serviceName, $services)) { - $this->assertTrue(TRUE, "{$serviceName} exists in {$file}"); - return $content['services'][$serviceName]; - } - } - $this->assertFalse(TRUE, "{$serviceName} does not exist in DKAN or Drupal core."); - } - - /** - * Private. - */ - private function getRelativeDkanModulePath($moduleName, $path = NULL) { - if (!$path) { - $path = $this->getRelativeDkanPath(); - } - - foreach (new \DirectoryIterator($path) as $fileInfo) { - if ($fileInfo->isDir() && !$fileInfo->isDot()) { - if ($fileInfo->getFilename() == $moduleName) { - return $fileInfo->getPathname(); - } - elseif ($fileInfo->getFilename() == "modules") { - return $this->getRelativeDkanModulePath($moduleName, $fileInfo->getPathname()); - } - } - } - } - - /** - * Private. - */ - private function getRelativeDkanPath() { - $path = __DIR__; - - while (TRUE) { - $content = glob($path . "/*"); - $content = array_map(function ($item) use ($path) { - return str_replace($path, "", $item); - }, $content); + $options = (new Options()) + ->add("dkan.datastore.service", Service::class) + ->index(0); - if (in_array("/dkan.info.yml", $content)) { - return $path; - } + $chain = (new Chain($this)) + ->add(Container::class, "get", $options) + ->add(Service::class, 'getDatastoreService', NULL); - $path .= "/.."; - } - } + $service = Service::create($chain->getMock()); + $result = $service->getDatastoreService(); + $this->assertTrue($result instanceof Service); - /** - * Private. - */ - private function getRelativeDrupalPath() { - return getenv('DRUPAL_ROOT'); } - /** - * Private. - */ private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE) { $options = (new Options()) From dcd71b5b02fbd257f2097cae88ff694d831f91a7 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 10:30:26 -0600 Subject: [PATCH 084/117] reseting QueryControllerTest.php to branch 2.x --- .../Unit/Controller/QueryControllerTest.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 57cce97655..d194a07038 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -433,25 +433,6 @@ public function testQueryCsvCacheHeaders() { $this->assertEmpty($headers->get('last-modified')); } - /** - * Testing Get Data Dictionary Fields. - */ - public function testGetDatastoreService() { - - $options = (new Options()) - ->add("dkan.datastore.service", Service::class) - ->index(0); - - $chain = (new Chain($this)) - ->add(Container::class, "get", $options) - ->add(Service::class, 'getDatastoreService', NULL); - - $service = Service::create($chain->getMock()); - $result = $service->getDatastoreService(); - $this->assertTrue($result instanceof Service); - - } - private function getQueryContainer($data = '', array $info = [], $mockMap = TRUE) { $options = (new Options()) From be69229c9138afe821fb4a7bb0fa3fdbecfbf46d Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 10:41:16 -0600 Subject: [PATCH 085/117] fixing service test --- modules/datastore/tests/src/Unit/ServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/ServiceTest.php b/modules/datastore/tests/src/Unit/ServiceTest.php index 57006aabbf..f4149bb4b7 100644 --- a/modules/datastore/tests/src/Unit/ServiceTest.php +++ b/modules/datastore/tests/src/Unit/ServiceTest.php @@ -81,7 +81,7 @@ public function testDrop() { */ public function testGetDataDictionaryFields() { $chain = $this->getCommonChain() - ->add(DictionaryEnforcer::class, 'getDatastoreService', ['data' => ['fields' => []]]); + ->add(DictionaryEnforcer::class, 'returnDataDictionaryFields', ['data' => ['fields' => []]]); $service = Service::create($chain->getMock()); $result = $service->getDataDictionaryFields(); From 9b9222752261651b29bce7357fe82884067358a6 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 11:04:10 -0600 Subject: [PATCH 086/117] removing get datastore service function --- modules/datastore/src/Service/Query.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 3797cbd8f5..806843ae52 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -140,7 +140,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->datastore()->getDataDictionaryFields() : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; @@ -153,16 +153,6 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ } - /** - * Return the datastore service. - * - * @return \Drupal\datastore\Service - * Datastore Service. - */ - protected function getDatastoreService() { - return $this->datastore; - } - /** * Remove the primary key from the schema field list. * From a5ffecfc33ae059e443197189b4815af6c812f68 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 11:12:34 -0600 Subject: [PATCH 087/117] changing QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 5e24e5b975..1f3e6e356f 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,6 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDatastoreService', Service::class) ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); From 8eb5c2a8d5f1fc52ad3549f4138a0abcd5c8676e Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 11:26:06 -0600 Subject: [PATCH 088/117] changing QueryDownloadControllerTest again --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 1f3e6e356f..a2d6c6ca1c 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,6 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) + ->add(Query::class, 'datastore', Service::class) ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); From 738ce18b827ddccb9ba6499ed132f3723e1b487e Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 11:43:07 -0600 Subject: [PATCH 089/117] changing QueryDownloadControllerTest again --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index a2d6c6ca1c..1f3e6e356f 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,6 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'datastore', Service::class) ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); From f76e5de43a57cd65747a8fa8810ffe146824a18f Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 11:53:24 -0600 Subject: [PATCH 090/117] fixing typo --- modules/datastore/src/Service/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 806843ae52..619e2a97b9 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -140,7 +140,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ } $query = QueryFactory::create($datastoreQuery, $storageMap); // Get data dictionary fields. - $meta_data = $csv != FALSE ? $this->datastore()->getDataDictionaryFields() : NULL; + $meta_data = $csv != FALSE ? $this->datastore->getDataDictionaryFields() : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; From 1c928bb5e724ce120917ccced2a0e5796f4f77af Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 12:00:21 -0600 Subject: [PATCH 091/117] fixing QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 1f3e6e356f..82316f69b7 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Service::class, 'getDataDictionaryFields', NULL) + ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 43e1d8727ace6c6e783c5161409fa8c6636240b3 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 12:08:34 -0600 Subject: [PATCH 092/117] fixing QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 82316f69b7..2deb0a6439 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) + ->add(Query::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 906df3cdcf65db5d05f3cbbc7d64717c3896e488 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 12:20:41 -0600 Subject: [PATCH 093/117] fixing QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 2deb0a6439..383e4ef31c 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,8 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) + ->add(Query::class, 'getDataDictionaryFields', null) + ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 33eaddbbdcd3d693881947a7c7b1ff42a2e99f91 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 12:26:05 -0600 Subject: [PATCH 094/117] fixing QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 383e4ef31c..82316f69b7 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,6 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDataDictionaryFields', null) ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) ->add(ImmutableConfig::class, 'get', $rowLimit); From 62a0ab10a4d42baea2340959a885ba06e5a31c94 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 12:42:29 -0600 Subject: [PATCH 095/117] fixing QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 82316f69b7..9ac7def394 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -381,8 +381,8 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheTags', ['node:1']) ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) - ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) + ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 62212b51e8864cb6ba0fd007fe96eeb285af2e0a Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 13:13:25 -0600 Subject: [PATCH 096/117] adding back getDatastoreService --- modules/datastore/src/Service/Query.php | 12 +++++++++++- .../Unit/Controller/QueryDownloadControllerTest.php | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 619e2a97b9..3797cbd8f5 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -140,7 +140,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ } $query = QueryFactory::create($datastoreQuery, $storageMap); // Get data dictionary fields. - $meta_data = $csv != FALSE ? $this->datastore->getDataDictionaryFields() : NULL; + $meta_data = $csv != FALSE ? $this->getDatastoreService()->getDataDictionaryFields() : NULL; // Pass the data dictionary metadata to the query. $query->dataDictionaryFields = $csv && $meta_data ? $meta_data : NULL; @@ -153,6 +153,16 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ } + /** + * Return the datastore service. + * + * @return \Drupal\datastore\Service + * Datastore Service. + */ + protected function getDatastoreService() { + return $this->datastore; + } + /** * Remove the primary key from the schema field list. * diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 9ac7def394..5e24e5b975 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -381,8 +381,9 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheTags', ['node:1']) ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) - ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) ->add(Query::class, "getQueryStorageMap", $storageMap) + ->add(Query::class, 'getDatastoreService', Service::class) + ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From edd4f90734ef3e2ae1e9576512041264f2f2af63 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 15:17:27 -0600 Subject: [PATCH 097/117] making getDatastoreService private --- modules/datastore/src/Service/Query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index 3797cbd8f5..a1f5798e80 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -159,7 +159,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ * @return \Drupal\datastore\Service * Datastore Service. */ - protected function getDatastoreService() { + private function getDatastoreService() { return $this->datastore; } From 44fa554f9d4f6830308b15645973c6f2d972879f Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 15:31:54 -0600 Subject: [PATCH 098/117] removing getDatastoreService from test --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 5e24e5b975..1f3e6e356f 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,6 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Query::class, 'getDatastoreService', Service::class) ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); From 463d2ce1c3aca9d6329380316ac995a21341b812 Mon Sep 17 00:00:00 2001 From: B3WM Date: Mon, 6 Feb 2023 15:41:19 -0600 Subject: [PATCH 099/117] fixing test error --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 1f3e6e356f..82316f69b7 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,7 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Service::class, 'getDataDictionaryFields', NULL) + ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From a3d9a198f6fc6b16b21bd750e5ed33368aaabddf Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 7 Feb 2023 08:35:42 -0600 Subject: [PATCH 100/117] returning the code back to non private function --- modules/datastore/src/Service/Query.php | 2 +- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/datastore/src/Service/Query.php b/modules/datastore/src/Service/Query.php index a1f5798e80..3797cbd8f5 100644 --- a/modules/datastore/src/Service/Query.php +++ b/modules/datastore/src/Service/Query.php @@ -159,7 +159,7 @@ public function runResultsQuery(DatastoreQuery $datastoreQuery, $fetch = TRUE, $ * @return \Drupal\datastore\Service * Datastore Service. */ - private function getDatastoreService() { + protected function getDatastoreService() { return $this->datastore; } diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 82316f69b7..5e24e5b975 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -382,7 +382,8 @@ private function getQueryContainer(int $rowLimit) { ->add(Data::class, 'getCacheMaxAge', 0) ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) - ->add(Service::class, 'getDataDictionaryFields', ['data' => ['fields' => []]]) + ->add(Query::class, 'getDatastoreService', Service::class) + ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 002234decfd58ce9a53e83db8fdbfaa5530f43a8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 28 Feb 2023 10:24:57 -0600 Subject: [PATCH 101/117] updating QueryDownloadControllerTest --- .../src/Unit/Controller/QueryDownloadControllerTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 5e24e5b975..d3d655cfd6 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -55,12 +55,14 @@ protected function tearDown(): void { */ private function queryResultCompare($data, $resource = NULL) { $request = $this->mockRequest($data); + $dataDictionaryFields = ['date' => ['type' => 'date', 'format '=>'%m/%d/%Y']]; $qController = QueryController::create($this->getQueryContainer(500)); $response = $resource ? $qController->queryResource($resource, $request) : $qController->query($request); $csv = $response->getContent(); $dController = QueryDownloadController::create($this->getQueryContainer(25)); + $dController->dataDictionaryFields = $dataDictionaryFields; ob_start(['self', 'getBuffer']); $streamResponse = $resource ? $dController->queryResource($resource, $request) : $dController->query($request); $streamResponse->sendContent(); @@ -80,6 +82,7 @@ public function testStreamedQueryCsv() { [ "id" => "2", "alias" => "t", + "date" => "2022/06/21", ], ], "format" => "csv", @@ -354,11 +357,13 @@ private function getQueryContainer(int $rowLimit) { 'record_number' => ['type' => 'int', 'not null' => TRUE], 'state' => ['type' => 'text'], 'year' => ['type' => 'int'], + 'date' => ['type' => 'date', 'format '=>'%m/%d/%Y'], ]; $schema3 = [ 'record_number' => ['type' => 'int', 'not null' => TRUE], 'year' => ['type' => 'int'], 'color' => ['type' => 'text'], + 'date' => ['type' => 'date', 'format '=>'%m/%d/%Y'], ]; $storage2 = $this->mockDatastoreTable($connection, "2", 'states_with_dupes.csv', $schema2); @@ -383,7 +388,7 @@ private function getQueryContainer(int $rowLimit) { ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(Query::class, 'getDatastoreService', Service::class) - ->add(Service::class, 'getDataDictionaryFields', NULL) + ->add(Service::class, 'getDataDictionaryFields', $schema2) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 7da506e73b871259b271e050c2ece6c49d303646 Mon Sep 17 00:00:00 2001 From: B3WM Date: Tue, 28 Feb 2023 10:31:19 -0600 Subject: [PATCH 102/117] Forgot to add updated csv files --- .../tests/data/states_with_dupes.csv | 210 +++++++++--------- modules/datastore/tests/data/years_colors.csv | 12 +- 2 files changed, 111 insertions(+), 111 deletions(-) diff --git a/modules/datastore/tests/data/states_with_dupes.csv b/modules/datastore/tests/data/states_with_dupes.csv index 4df2c75aba..bd59d01f63 100644 --- a/modules/datastore/tests/data/states_with_dupes.csv +++ b/modules/datastore/tests/data/states_with_dupes.csv @@ -1,105 +1,105 @@ -1,Alabama,2010 -2,Alaska,2010 -3,Arizona,2010 -4,Arkansas,2010 -5,California,2010 -6,Colorado,2010 -8,Connecticut,2010 -9,Delaware,2010 -10,Florida,2010 -11,Georgia,2010 -12,Hawaii,2010 -13,Idaho,2010 -14,Illinois,2010 -15,Indiana,2010 -16,Iowa,2010 -17,Kansas,2010 -18,Kentucky,2010 -20,Louisiana,2010 -22,Maine,2010 -24,Maryland,2010 -25,Massachusetts,2010 -27,Michigan,2010 -29,Minnesota,2010 -31,Mississippi,2010 -33,Missouri,2010 -35,Montana,2010 -37,Nebraska,2010 -38,Nevada,2010 -39,New Hampshire,2010 -50,New Jersey,2010 -51,New Mexico,2010 -52,New York,2010 -53,North Carolina,2010 -54,North Dakota,2010 -55,Ohio,2010 -56,Oklahoma,2010 -57,Oregon,2010 -58,Pennsylvania,2010 -59,Rhode Island,2010 -60,South Carolina,2010 -61,South Dakota,2010 -62,Tennessee,2010 -105,Texas,2010 -106,Utah,2010 -107,Vermont,2010 -108,Virginia,2010 -109,Washington,2010 -110,West Virginia,2010 -111,Wisconsin,2010 -112,Wyoming,2010 -113,Alabama,2011 -114,Alaska,2011 -115,Arizona,2011 -116,Arkansas,2011 -117,California,2011 -118,Colorado,2011 -119,Connecticut,2011 -120,Delaware,2011 -121,Florida,2011 -122,Georgia,2011 -123,Hawaii,2011 -124,Idaho,2011 -125,Illinois,2011 -126,Indiana,2011 -127,Iowa,2011 -128,Kansas,2011 -129,Kentucky,2011 -130,Louisiana,2011 -131,Maine,2011 -132,Maryland,2011 -133,Massachusetts,2011 -134,Michigan,2011 -135,Minnesota,2011 -136,Mississippi,2011 -137,Missouri,2011 -330,Alabama,2012 -331,Alaska,2012 -332,Arizona,2012 -333,Arkansas,2012 -334,California,2012 -335,Colorado,2012 -336,Connecticut,2012 -337,Delaware,2012 -338,Florida,2012 -339,Georgia,2012 -340,Hawaii,2012 -341,Idaho,2012 -342,Illinois,2012 -343,Alabama,2013 -344,Alaska,2013 -501,Arizona,2013 -502,Arkansas,2013 -503,California,2013 -504,Colorado,2013 -505,Connecticut,2013 -506,Delaware,2013 -507,Florida,2013 -508,Georgia,2013 -509,Hawaii,2013 -510,Idaho,2013 -511,Illinois,2013 -512,Alabama,2014 -513,Alaska,2014 -514,Arizona,2014 -515,Arkansas,2014 \ No newline at end of file +1,Alabama,2010,03/21/1999 +2,Alaska,2010,03/21/1999 +3,Arizona,2010,03/21/1999 +4,Arkansas,2010,03/21/1999 +5,California,2010,03/21/1999 +6,Colorado,2010,03/21/1999 +8,Connecticut,2010,03/21/1999 +9,Delaware,2010,03/21/1999 +10,Florida,2010,03/21/1999 +11,Georgia,2010,03/21/1999 +12,Hawaii,2010,03/21/1999 +13,Idaho,2010,03/21/1999 +14,Illinois,2010,03/21/1999 +15,Indiana,2010,03/21/1999 +16,Iowa,2010,03/21/1999 +17,Kansas,2010,03/21/1999 +18,Kentucky,2010,03/21/1999 +20,Louisiana,2010,03/21/1999 +22,Maine,2010,03/21/1999 +24,Maryland,2010,03/21/1999 +25,Massachusetts,2010,03/21/1999 +27,Michigan,2010,03/21/1999 +29,Minnesota,2010,03/21/1999 +31,Mississippi,2010,03/21/1999 +33,Missouri,2010,03/21/1999 +35,Montana,2010,03/21/1999 +37,Nebraska,2010,03/21/1999 +38,Nevada,2010,03/21/1999 +39,New Hampshire,2010,03/21/1999 +50,New Jersey,2010,03/21/1999 +51,New Mexico,2010,03/21/1999 +52,New York,2010,03/21/1999 +53,North Carolina,2010,03/21/1999 +54,North Dakota,2010,03/21/1999 +55,Ohio,2010,03/21/1999 +56,Oklahoma,2010,03/21/1999 +57,Oregon,2010,03/21/1999 +58,Pennsylvania,2010,03/21/1999 +59,Rhode Island,2010,03/21/1999 +60,South Carolina,2010,03/21/1999 +61,South Dakota,2010,03/21/1999 +62,Tennessee,2010,03/21/1999 +105,Texas,2010,03/21/1999 +106,Utah,2010,03/21/1999 +107,Vermont,2010,03/21/1999 +108,Virginia,2010,03/21/1999 +109,Washington,2010,03/21/1999 +110,West Virginia,2010,03/21/1999 +111,Wisconsin,2010,03/21/1999 +112,Wyoming,2010,03/21/1999 +113,Alabama,2011,03/21/1999 +114,Alaska,2011,03/21/1999 +115,Arizona,2011,03/21/1999 +116,Arkansas,2011,03/21/1999 +117,California,2011,03/21/1999 +118,Colorado,2011,03/21/1999 +119,Connecticut,2011,03/21/1999 +120,Delaware,2011,03/21/1999 +121,Florida,2011,03/21/1999 +122,Georgia,2011,03/21/1999 +123,Hawaii,2011,03/21/1999 +124,Idaho,2011,03/21/1999 +125,Illinois,2011,03/21/1999 +126,Indiana,2011,03/21/1999 +127,Iowa,2011,03/21/1999 +128,Kansas,2011,03/21/1999 +129,Kentucky,2011,03/21/1999 +130,Louisiana,2011,03/21/1999 +131,Maine,2011,03/21/1999 +132,Maryland,2011,03/21/1999 +133,Massachusetts,2011,03/21/1999 +134,Michigan,2011,03/21/1999 +135,Minnesota,2011,03/21/1999 +136,Mississippi,2011,03/21/1999 +137,Missouri,2011,03/21/1999 +330,Alabama,2012,03/21/1999 +331,Alaska,2012,03/21/1999 +332,Arizona,2012,03/21/1999 +333,Arkansas,2012,03/21/1999 +334,California,2012,03/21/1999 +335,Colorado,2012,03/21/1999 +336,Connecticut,2012,03/21/1999 +337,Delaware,2012,03/21/1999 +338,Florida,2012,03/21/1999 +339,Georgia,2012,03/21/1999 +340,Hawaii,2012,03/21/1999 +341,Idaho,2012,03/21/1999 +342,Illinois,2012,03/21/1999 +343,Alabama,2013,03/21/1999 +344,Alaska,2013,03/21/1999 +501,Arizona,2013,03/21/1999 +502,Arkansas,2013,03/21/1999 +503,California,2013,03/21/1999 +504,Colorado,2013,03/21/1999 +505,Connecticut,2013,03/21/1999 +506,Delaware,2013,03/21/1999 +507,Florida,2013,03/21/1999 +508,Georgia,2013,03/21/1999 +509,Hawaii,2013,03/21/1999 +510,Idaho,2013,03/21/1999 +511,Illinois,2013,03/21/1999 +512,Alabama,2014,03/21/1999 +513,Alaska,2014,03/21/1999 +514,Arizona,2014,03/21/1999 +515,Arkansas,2014,03/21/1999 diff --git a/modules/datastore/tests/data/years_colors.csv b/modules/datastore/tests/data/years_colors.csv index d5294bb782..e491bedec4 100644 --- a/modules/datastore/tests/data/years_colors.csv +++ b/modules/datastore/tests/data/years_colors.csv @@ -1,6 +1,6 @@ -1,2010,red -2,2011,green -3,2012,blue -4,2013,indigo -5,2014,violet -6,2015,ultraviolet \ No newline at end of file +1,2010,red,03/21/1999 +2,2011,green,03/21/1999 +3,2012,blue,03/21/1999 +4,2013,indigo,03/21/1999 +5,2014,violet,03/21/1999 +6,2015,ultraviolet,03/21/1999 From 0c243204a7cd20c57ec20cd6f44f48d6a943a422 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 09:28:57 -0600 Subject: [PATCH 103/117] resetting test data --- .../tests/data/states_with_dupes.csv | 210 +++++++++--------- modules/datastore/tests/data/years_colors.csv | 12 +- .../QueryDownloadControllerTest.php | 4 +- 3 files changed, 112 insertions(+), 114 deletions(-) diff --git a/modules/datastore/tests/data/states_with_dupes.csv b/modules/datastore/tests/data/states_with_dupes.csv index bd59d01f63..4df2c75aba 100644 --- a/modules/datastore/tests/data/states_with_dupes.csv +++ b/modules/datastore/tests/data/states_with_dupes.csv @@ -1,105 +1,105 @@ -1,Alabama,2010,03/21/1999 -2,Alaska,2010,03/21/1999 -3,Arizona,2010,03/21/1999 -4,Arkansas,2010,03/21/1999 -5,California,2010,03/21/1999 -6,Colorado,2010,03/21/1999 -8,Connecticut,2010,03/21/1999 -9,Delaware,2010,03/21/1999 -10,Florida,2010,03/21/1999 -11,Georgia,2010,03/21/1999 -12,Hawaii,2010,03/21/1999 -13,Idaho,2010,03/21/1999 -14,Illinois,2010,03/21/1999 -15,Indiana,2010,03/21/1999 -16,Iowa,2010,03/21/1999 -17,Kansas,2010,03/21/1999 -18,Kentucky,2010,03/21/1999 -20,Louisiana,2010,03/21/1999 -22,Maine,2010,03/21/1999 -24,Maryland,2010,03/21/1999 -25,Massachusetts,2010,03/21/1999 -27,Michigan,2010,03/21/1999 -29,Minnesota,2010,03/21/1999 -31,Mississippi,2010,03/21/1999 -33,Missouri,2010,03/21/1999 -35,Montana,2010,03/21/1999 -37,Nebraska,2010,03/21/1999 -38,Nevada,2010,03/21/1999 -39,New Hampshire,2010,03/21/1999 -50,New Jersey,2010,03/21/1999 -51,New Mexico,2010,03/21/1999 -52,New York,2010,03/21/1999 -53,North Carolina,2010,03/21/1999 -54,North Dakota,2010,03/21/1999 -55,Ohio,2010,03/21/1999 -56,Oklahoma,2010,03/21/1999 -57,Oregon,2010,03/21/1999 -58,Pennsylvania,2010,03/21/1999 -59,Rhode Island,2010,03/21/1999 -60,South Carolina,2010,03/21/1999 -61,South Dakota,2010,03/21/1999 -62,Tennessee,2010,03/21/1999 -105,Texas,2010,03/21/1999 -106,Utah,2010,03/21/1999 -107,Vermont,2010,03/21/1999 -108,Virginia,2010,03/21/1999 -109,Washington,2010,03/21/1999 -110,West Virginia,2010,03/21/1999 -111,Wisconsin,2010,03/21/1999 -112,Wyoming,2010,03/21/1999 -113,Alabama,2011,03/21/1999 -114,Alaska,2011,03/21/1999 -115,Arizona,2011,03/21/1999 -116,Arkansas,2011,03/21/1999 -117,California,2011,03/21/1999 -118,Colorado,2011,03/21/1999 -119,Connecticut,2011,03/21/1999 -120,Delaware,2011,03/21/1999 -121,Florida,2011,03/21/1999 -122,Georgia,2011,03/21/1999 -123,Hawaii,2011,03/21/1999 -124,Idaho,2011,03/21/1999 -125,Illinois,2011,03/21/1999 -126,Indiana,2011,03/21/1999 -127,Iowa,2011,03/21/1999 -128,Kansas,2011,03/21/1999 -129,Kentucky,2011,03/21/1999 -130,Louisiana,2011,03/21/1999 -131,Maine,2011,03/21/1999 -132,Maryland,2011,03/21/1999 -133,Massachusetts,2011,03/21/1999 -134,Michigan,2011,03/21/1999 -135,Minnesota,2011,03/21/1999 -136,Mississippi,2011,03/21/1999 -137,Missouri,2011,03/21/1999 -330,Alabama,2012,03/21/1999 -331,Alaska,2012,03/21/1999 -332,Arizona,2012,03/21/1999 -333,Arkansas,2012,03/21/1999 -334,California,2012,03/21/1999 -335,Colorado,2012,03/21/1999 -336,Connecticut,2012,03/21/1999 -337,Delaware,2012,03/21/1999 -338,Florida,2012,03/21/1999 -339,Georgia,2012,03/21/1999 -340,Hawaii,2012,03/21/1999 -341,Idaho,2012,03/21/1999 -342,Illinois,2012,03/21/1999 -343,Alabama,2013,03/21/1999 -344,Alaska,2013,03/21/1999 -501,Arizona,2013,03/21/1999 -502,Arkansas,2013,03/21/1999 -503,California,2013,03/21/1999 -504,Colorado,2013,03/21/1999 -505,Connecticut,2013,03/21/1999 -506,Delaware,2013,03/21/1999 -507,Florida,2013,03/21/1999 -508,Georgia,2013,03/21/1999 -509,Hawaii,2013,03/21/1999 -510,Idaho,2013,03/21/1999 -511,Illinois,2013,03/21/1999 -512,Alabama,2014,03/21/1999 -513,Alaska,2014,03/21/1999 -514,Arizona,2014,03/21/1999 -515,Arkansas,2014,03/21/1999 +1,Alabama,2010 +2,Alaska,2010 +3,Arizona,2010 +4,Arkansas,2010 +5,California,2010 +6,Colorado,2010 +8,Connecticut,2010 +9,Delaware,2010 +10,Florida,2010 +11,Georgia,2010 +12,Hawaii,2010 +13,Idaho,2010 +14,Illinois,2010 +15,Indiana,2010 +16,Iowa,2010 +17,Kansas,2010 +18,Kentucky,2010 +20,Louisiana,2010 +22,Maine,2010 +24,Maryland,2010 +25,Massachusetts,2010 +27,Michigan,2010 +29,Minnesota,2010 +31,Mississippi,2010 +33,Missouri,2010 +35,Montana,2010 +37,Nebraska,2010 +38,Nevada,2010 +39,New Hampshire,2010 +50,New Jersey,2010 +51,New Mexico,2010 +52,New York,2010 +53,North Carolina,2010 +54,North Dakota,2010 +55,Ohio,2010 +56,Oklahoma,2010 +57,Oregon,2010 +58,Pennsylvania,2010 +59,Rhode Island,2010 +60,South Carolina,2010 +61,South Dakota,2010 +62,Tennessee,2010 +105,Texas,2010 +106,Utah,2010 +107,Vermont,2010 +108,Virginia,2010 +109,Washington,2010 +110,West Virginia,2010 +111,Wisconsin,2010 +112,Wyoming,2010 +113,Alabama,2011 +114,Alaska,2011 +115,Arizona,2011 +116,Arkansas,2011 +117,California,2011 +118,Colorado,2011 +119,Connecticut,2011 +120,Delaware,2011 +121,Florida,2011 +122,Georgia,2011 +123,Hawaii,2011 +124,Idaho,2011 +125,Illinois,2011 +126,Indiana,2011 +127,Iowa,2011 +128,Kansas,2011 +129,Kentucky,2011 +130,Louisiana,2011 +131,Maine,2011 +132,Maryland,2011 +133,Massachusetts,2011 +134,Michigan,2011 +135,Minnesota,2011 +136,Mississippi,2011 +137,Missouri,2011 +330,Alabama,2012 +331,Alaska,2012 +332,Arizona,2012 +333,Arkansas,2012 +334,California,2012 +335,Colorado,2012 +336,Connecticut,2012 +337,Delaware,2012 +338,Florida,2012 +339,Georgia,2012 +340,Hawaii,2012 +341,Idaho,2012 +342,Illinois,2012 +343,Alabama,2013 +344,Alaska,2013 +501,Arizona,2013 +502,Arkansas,2013 +503,California,2013 +504,Colorado,2013 +505,Connecticut,2013 +506,Delaware,2013 +507,Florida,2013 +508,Georgia,2013 +509,Hawaii,2013 +510,Idaho,2013 +511,Illinois,2013 +512,Alabama,2014 +513,Alaska,2014 +514,Arizona,2014 +515,Arkansas,2014 \ No newline at end of file diff --git a/modules/datastore/tests/data/years_colors.csv b/modules/datastore/tests/data/years_colors.csv index e491bedec4..d5294bb782 100644 --- a/modules/datastore/tests/data/years_colors.csv +++ b/modules/datastore/tests/data/years_colors.csv @@ -1,6 +1,6 @@ -1,2010,red,03/21/1999 -2,2011,green,03/21/1999 -3,2012,blue,03/21/1999 -4,2013,indigo,03/21/1999 -5,2014,violet,03/21/1999 -6,2015,ultraviolet,03/21/1999 +1,2010,red +2,2011,green +3,2012,blue +4,2013,indigo +5,2014,violet +6,2015,ultraviolet \ No newline at end of file diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index d3d655cfd6..a9a67d473b 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -357,13 +357,11 @@ private function getQueryContainer(int $rowLimit) { 'record_number' => ['type' => 'int', 'not null' => TRUE], 'state' => ['type' => 'text'], 'year' => ['type' => 'int'], - 'date' => ['type' => 'date', 'format '=>'%m/%d/%Y'], ]; $schema3 = [ 'record_number' => ['type' => 'int', 'not null' => TRUE], 'year' => ['type' => 'int'], 'color' => ['type' => 'text'], - 'date' => ['type' => 'date', 'format '=>'%m/%d/%Y'], ]; $storage2 = $this->mockDatastoreTable($connection, "2", 'states_with_dupes.csv', $schema2); @@ -388,7 +386,7 @@ private function getQueryContainer(int $rowLimit) { ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(Query::class, 'getDatastoreService', Service::class) - ->add(Service::class, 'getDataDictionaryFields', $schema2) + ->add(Service::class, 'getDataDictionaryFields', null) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 7a47a12b23d1ed7b1b295d9be70cd59bcd13acd8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 10:39:38 -0600 Subject: [PATCH 104/117] resestting the QueryDownloadControllerTest file and updating the SelectFactoryTest --- modules/common/tests/src/Unit/Storage/SelectFactoryTest.php | 2 ++ .../src/Unit/Controller/QueryDownloadControllerTest.php | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 58a7564630..b85f03e839 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -28,6 +28,8 @@ class SelectFactoryTest extends TestCase { * @dataProvider \Drupal\Tests\common\Unit\Storage\QueryDataProvider::getAllData() */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { + $dataDictionaryFields = ['date' => ['type' => 'date', 'format '=>'%m/%d/%Y']]; + $query->dataDictionaryFields = $dataDictionaryFields; if ($message) { $this->expectExceptionMessage($message); $this->selectFactory->create($query); diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index a9a67d473b..5e24e5b975 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -55,14 +55,12 @@ protected function tearDown(): void { */ private function queryResultCompare($data, $resource = NULL) { $request = $this->mockRequest($data); - $dataDictionaryFields = ['date' => ['type' => 'date', 'format '=>'%m/%d/%Y']]; $qController = QueryController::create($this->getQueryContainer(500)); $response = $resource ? $qController->queryResource($resource, $request) : $qController->query($request); $csv = $response->getContent(); $dController = QueryDownloadController::create($this->getQueryContainer(25)); - $dController->dataDictionaryFields = $dataDictionaryFields; ob_start(['self', 'getBuffer']); $streamResponse = $resource ? $dController->queryResource($resource, $request) : $dController->query($request); $streamResponse->sendContent(); @@ -82,7 +80,6 @@ public function testStreamedQueryCsv() { [ "id" => "2", "alias" => "t", - "date" => "2022/06/21", ], ], "format" => "csv", @@ -386,7 +383,7 @@ private function getQueryContainer(int $rowLimit) { ->add(ConfigFactoryInterface::class, 'get', ImmutableConfig::class) ->add(Query::class, "getQueryStorageMap", $storageMap) ->add(Query::class, 'getDatastoreService', Service::class) - ->add(Service::class, 'getDataDictionaryFields', null) + ->add(Service::class, 'getDataDictionaryFields', NULL) ->add(ImmutableConfig::class, 'get', $rowLimit); return $chain->getMock(); From 2c6792b72a5cc39d516f54e0ca5feb5342157c43 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 10:56:19 -0600 Subject: [PATCH 105/117] updating the array created for DD metadata --- .../common/tests/src/Unit/Storage/SelectFactoryTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index b85f03e839..88e1840fd4 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -28,7 +28,13 @@ class SelectFactoryTest extends TestCase { * @dataProvider \Drupal\Tests\common\Unit\Storage\QueryDataProvider::getAllData() */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { - $dataDictionaryFields = ['date' => ['type' => 'date', 'format '=>'%m/%d/%Y']]; + $dataDictionaryFields = [ + 'name' => [ + 'field' => 'date' + ], + 'type' => 'date', + 'format '=>'%m/%d/%Y', + ]; $query->dataDictionaryFields = $dataDictionaryFields; if ($message) { $this->expectExceptionMessage($message); From 44f041cb80423883512fe598892d77835936c032 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 11:10:25 -0600 Subject: [PATCH 106/117] updating the array created for DD metadata again --- modules/common/tests/src/Unit/Storage/SelectFactoryTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 88e1840fd4..6664e65144 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -29,11 +29,9 @@ class SelectFactoryTest extends TestCase { */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { $dataDictionaryFields = [ - 'name' => [ - 'field' => 'date' - ], + 'name' => 'date', 'type' => 'date', - 'format '=>'%m/%d/%Y', + 'format '=>'%m/%d/%Y' ]; $query->dataDictionaryFields = $dataDictionaryFields; if ($message) { From 31b9230fa5ec07634612149a0b5d6990690de3bd Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 11:31:47 -0600 Subject: [PATCH 107/117] updating the array created for DD metadata again --- .../tests/src/Unit/Storage/SelectFactoryTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 6664e65144..6e547f1937 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -28,11 +28,11 @@ class SelectFactoryTest extends TestCase { * @dataProvider \Drupal\Tests\common\Unit\Storage\QueryDataProvider::getAllData() */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { - $dataDictionaryFields = [ - 'name' => 'date', - 'type' => 'date', - 'format '=>'%m/%d/%Y' - ]; + $dataDictionaryFields = []; + $dataDictionaryFields->name = 'date'; + $dataDictionaryFields->type = 'date'; + $dataDictionaryFields->format = '%m/%d/%Y'; + $query->dataDictionaryFields = $dataDictionaryFields; if ($message) { $this->expectExceptionMessage($message); From f9d3bc80cf542af946a01a788c1fa50b8702a968 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 11:54:49 -0600 Subject: [PATCH 108/117] updating the array created for DD metadata again --- modules/common/tests/src/Unit/Storage/SelectFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 6e547f1937..39a76ee661 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -28,7 +28,7 @@ class SelectFactoryTest extends TestCase { * @dataProvider \Drupal\Tests\common\Unit\Storage\QueryDataProvider::getAllData() */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { - $dataDictionaryFields = []; + $dataDictionaryFields = ['name','type','date']; $dataDictionaryFields->name = 'date'; $dataDictionaryFields->type = 'date'; $dataDictionaryFields->format = '%m/%d/%Y'; From 8ddf965209865ab738e3f6cc3dc8077d5a0eb69e Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 12:00:55 -0600 Subject: [PATCH 109/117] updating the array created for DD metadata again --- modules/common/tests/src/Unit/Storage/SelectFactoryTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 39a76ee661..8c52b21e71 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -29,9 +29,9 @@ class SelectFactoryTest extends TestCase { */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { $dataDictionaryFields = ['name','type','date']; - $dataDictionaryFields->name = 'date'; - $dataDictionaryFields->type = 'date'; - $dataDictionaryFields->format = '%m/%d/%Y'; + $dataDictionaryFields['name'] = 'date'; + $dataDictionaryFieldss['type'] = 'date'; + $dataDictionaryFields['format'] = '%m/%d/%Y'; $query->dataDictionaryFields = $dataDictionaryFields; if ($message) { From c91fe3a4a8b0a99f321510804ffe6287d3bf6109 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 12:32:33 -0600 Subject: [PATCH 110/117] updating the array created for DD metadata again --- .../tests/src/Unit/Storage/SelectFactoryTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 8c52b21e71..565812e127 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -28,18 +28,18 @@ class SelectFactoryTest extends TestCase { * @dataProvider \Drupal\Tests\common\Unit\Storage\QueryDataProvider::getAllData() */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { - $dataDictionaryFields = ['name','type','date']; - $dataDictionaryFields['name'] = 'date'; - $dataDictionaryFieldss['type'] = 'date'; - $dataDictionaryFields['format'] = '%m/%d/%Y'; - - $query->dataDictionaryFields = $dataDictionaryFields; + $dataDictionaryFields = [ + 'name' => 'date', + 'type' => 'date', + 'format '=>'%m/%d/%Y' + ]; if ($message) { $this->expectExceptionMessage($message); $this->selectFactory->create($query); } else { $db_query = $this->selectFactory->create($query); + $db_query->dataDictionaryFields = $dataDictionaryFields; $this->assertStringContainsString($sql, $this->selectToString($db_query)); if (!empty($values)) { From 914f4cfd9412a267a15b2db611445ac974f84774 Mon Sep 17 00:00:00 2001 From: B3WM Date: Wed, 1 Mar 2023 12:48:35 -0600 Subject: [PATCH 111/117] adding some additional logic to QueryDownloadControllerTest --- .../src/Unit/Controller/QueryDownloadControllerTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 5e24e5b975..9bea3f6809 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -55,7 +55,11 @@ protected function tearDown(): void { */ private function queryResultCompare($data, $resource = NULL) { $request = $this->mockRequest($data); - + $dataDictionaryFields = [ + 'name' => 'date', + 'type' => 'date', + 'format '=>'%m/%d/%Y' + ]; $qController = QueryController::create($this->getQueryContainer(500)); $response = $resource ? $qController->queryResource($resource, $request) : $qController->query($request); $csv = $response->getContent(); @@ -63,6 +67,7 @@ private function queryResultCompare($data, $resource = NULL) { $dController = QueryDownloadController::create($this->getQueryContainer(25)); ob_start(['self', 'getBuffer']); $streamResponse = $resource ? $dController->queryResource($resource, $request) : $dController->query($request); + $streamResponse->dataDictionaryFields = $dataDictionaryFields; $streamResponse->sendContent(); $streamedCsv = $this->buffer; ob_get_clean(); @@ -80,6 +85,7 @@ public function testStreamedQueryCsv() { [ "id" => "2", "alias" => "t", + "date" => "06/21/2022", ], ], "format" => "csv", From cc8e699967bae95bfd581659354ef90221361635 Mon Sep 17 00:00:00 2001 From: B3WM Date: Thu, 2 Mar 2023 14:10:25 -0600 Subject: [PATCH 112/117] updating the testing for QueryDownloadControllerTest --- .../QueryDownloadControllerTest.php | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 9bea3f6809..a34f764f42 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -24,6 +24,7 @@ use Drupal\metastore\Storage\DataFactory; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Drupal\common\Storage\SelectFactory; /** * @@ -43,6 +44,8 @@ protected function setUp() { ->add(ContainerInterface::class, 'get', $options) ->add(CacheContextsManager::class, 'assertValidTokens', TRUE); \Drupal::setContainer($chain->getMock()); + $this->selectFactory = $this->getSelectFactory(); + } protected function tearDown(): void { @@ -85,7 +88,6 @@ public function testStreamedQueryCsv() { [ "id" => "2", "alias" => "t", - "date" => "06/21/2022", ], ], "format" => "csv", @@ -94,6 +96,53 @@ public function testStreamedQueryCsv() { $this->queryResultCompare($data); } + /** + * Test streaming of a CSV file from database. + */ + public function testAddDateExpressions() { + $data = [ + "resources" => [ + [ + "id" => "2", + "alias" => "t", + "date" => "06/21/2022", + ], + ], + "format" => "csv", + ]; + // Need 2 json responses which get combined on output. + $this->queryResultReformatted($data); + } + + public function queryResultReformatted($data){ + $request = $this->mockRequest($data); + $dataDictionaryFields = [ + 'name' => 'date', + 'type' => 'date', + 'format '=>'%m/%d/%Y' + ]; + $qController = QueryController::create($this->getQueryContainer(500)); + $response = $resource ? $qController->queryResource($resource, $request) : $qController->query($request); + $csv = $response->getContent(); + + $dController = QueryDownloadController::create($this->getQueryContainer(25)); + ob_start(['self', 'getBuffer']); + $streamResponse = $dController->query($request); + $streamResponse->dataDictionaryFields = $dataDictionaryFields; + //$streamResponse->sendContent(); + $this->selectFactory->create($streamResponse); + + $this->assertEquals(count(explode("\n", $csv)), count(explode("\n", $streamedCsv))); + $this->assertEquals($csv, $streamedCsv); + } + + /** + * + */ + private function getSelectFactory() { + return new SelectFactory($this->getConnection()); + } + /** * Test streaming of a CSV file from database. */ From 239c748a1a6c815e8c5319e9370babbf4b214dd8 Mon Sep 17 00:00:00 2001 From: B3WM Date: Thu, 2 Mar 2023 14:16:34 -0600 Subject: [PATCH 113/117] updating the testing for QueryDownloadControllerTest --- .../Unit/Controller/QueryDownloadControllerTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index a34f764f42..8e2ba2b817 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -143,6 +143,19 @@ private function getSelectFactory() { return new SelectFactory($this->getConnection()); } + /** + * + */ + private function getConnection() { + return (new Chain($this)) + ->add( + Connection::class, + "select", + new Select(new Connection(new \PDO('sqlite::memory:'), []), "table", "t") + ) + ->getMock(); + } + /** * Test streaming of a CSV file from database. */ From da4b69d0fe25cfee853db26acb9373aa7401b78a Mon Sep 17 00:00:00 2001 From: B3WM Date: Thu, 2 Mar 2023 14:44:16 -0600 Subject: [PATCH 114/117] updating the testing for QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 8e2ba2b817..d730856d11 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -25,6 +25,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Drupal\common\Storage\SelectFactory; +use Drupal\Core\Database\Query\Select; /** * From 7bcd4dd623ed5537b5867b2cd91b51756619fdb1 Mon Sep 17 00:00:00 2001 From: B3WM Date: Thu, 2 Mar 2023 15:10:54 -0600 Subject: [PATCH 115/117] updating the testing for QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index d730856d11..0cb38bbcf1 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -26,6 +26,7 @@ use Symfony\Component\HttpFoundation\Request; use Drupal\common\Storage\SelectFactory; use Drupal\Core\Database\Query\Select; +use Drupal\Tests\common\Unit\Connection; /** * From 83c13ce88e89d90ecf6e47384b5616caf2d50b45 Mon Sep 17 00:00:00 2001 From: B3WM Date: Thu, 2 Mar 2023 15:19:54 -0600 Subject: [PATCH 116/117] updating the testing for QueryDownloadControllerTest --- .../tests/src/Unit/Controller/QueryDownloadControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 0cb38bbcf1..466ad0e180 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -124,7 +124,7 @@ public function queryResultReformatted($data){ 'format '=>'%m/%d/%Y' ]; $qController = QueryController::create($this->getQueryContainer(500)); - $response = $resource ? $qController->queryResource($resource, $request) : $qController->query($request); + $response = $qController->query($request); $csv = $response->getContent(); $dController = QueryDownloadController::create($this->getQueryContainer(25)); From 1a3876cb4011807b1385760dc1ff5fa003bcd890 Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Fri, 3 Mar 2023 10:31:49 -0500 Subject: [PATCH 117/117] Fix data dictionary fields test --- modules/common/src/Storage/Query.php | 8 +++++++ modules/common/src/Storage/SelectFactory.php | 2 +- .../src/Unit/Storage/SelectFactoryTest.php | 24 ++++++++++++++----- .../datastore/src/Storage/QueryFactory.php | 2 +- .../QueryDownloadControllerTest.php | 18 -------------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/modules/common/src/Storage/Query.php b/modules/common/src/Storage/Query.php index a977be1b33..a18d330d1b 100644 --- a/modules/common/src/Storage/Query.php +++ b/modules/common/src/Storage/Query.php @@ -16,6 +16,14 @@ class Query implements OffsetterInterface, LimiterInterface { + /** + * The collection of records (usually, a database table) to query against. + * + * @var array + */ + public $dataDictionaryFields; + + /** * The collection of records (usually, a database table) to query against. * diff --git a/modules/common/src/Storage/SelectFactory.php b/modules/common/src/Storage/SelectFactory.php index ee45b33a72..c1aa372051 100644 --- a/modules/common/src/Storage/SelectFactory.php +++ b/modules/common/src/Storage/SelectFactory.php @@ -104,7 +104,7 @@ private function setQueryProperties(Query $query) { private function addDateExpressions($db_query, $fields, $meta_data) { foreach ($meta_data as $definition) { // Confirm definition name is in the fields list. - if ($fields[$definition['name']]['field'] && $definition['type'] == 'date') { + if ($fields[$definition['name']]['field'] ?? FALSE && $definition['type'] == 'date') { $db_query->addExpression("DATE_FORMAT(" . $definition['name'] . ", '" . $definition['format'] . "')", $definition['name']); } } diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 565812e127..45b4da1392 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -28,18 +28,12 @@ class SelectFactoryTest extends TestCase { * @dataProvider \Drupal\Tests\common\Unit\Storage\QueryDataProvider::getAllData() */ public function testQuery(Query $query, string $sql, string $message, array $values = []) { - $dataDictionaryFields = [ - 'name' => 'date', - 'type' => 'date', - 'format '=>'%m/%d/%Y' - ]; if ($message) { $this->expectExceptionMessage($message); $this->selectFactory->create($query); } else { $db_query = $this->selectFactory->create($query); - $db_query->dataDictionaryFields = $dataDictionaryFields; $this->assertStringContainsString($sql, $this->selectToString($db_query)); if (!empty($values)) { @@ -53,6 +47,7 @@ public function testQuery(Query $query, string $sql, string $message, array $val */ public function testConditionByIsEqualTo() { $query = new Query(); + $query->properties = ["field1", "field2"]; $query->conditionByIsEqualTo('prop1', 'value1'); $db_query = $this->selectFactory->create($query); $this->assertStringContainsString('t.prop1 LIKE :db_condition_placeholder_0', $this->selectToString($db_query)); @@ -65,6 +60,23 @@ public function testConditionByIsEqualToCaseInsensitive() { $this->assertStringContainsString('t.prop1 LIKE BINARY :db_condition_placeholder_0', $this->selectToString($db_query)); } + /** + * Test two variations of Query::testConditionByIsEqualTo() + */ + public function testAddDateExpressions() { + $query = new Query(); + $query->dataDictionaryFields = [ + [ + 'name' => 'date', + 'type' => 'date', + 'format'=>'%m/%d/%Y', + ] + ]; + $query->properties = ["date", "field2"]; + $db_query = $this->selectFactory->create($query); + $this->assertStringContainsString("DATE_FORMAT(date, '%m/%d/%Y') AS date", $this->selectToString($db_query)); + } + /** * */ diff --git a/modules/datastore/src/Storage/QueryFactory.php b/modules/datastore/src/Storage/QueryFactory.php index cf49a715dc..acd5aa66e2 100644 --- a/modules/datastore/src/Storage/QueryFactory.php +++ b/modules/datastore/src/Storage/QueryFactory.php @@ -45,7 +45,7 @@ public function __construct(DatastoreQuery $datastoreQuery, array $storageMap) { * @param array $storageMap * Storage map array. * - * @return Drupal\common\Storage\Query + * @return \Drupal\common\Storage\Query * DKAN query object. */ public static function create(DatastoreQuery $datastoreQuery, array $storageMap): Query { diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 466ad0e180..8eaf4fa523 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -98,24 +98,6 @@ public function testStreamedQueryCsv() { $this->queryResultCompare($data); } - /** - * Test streaming of a CSV file from database. - */ - public function testAddDateExpressions() { - $data = [ - "resources" => [ - [ - "id" => "2", - "alias" => "t", - "date" => "06/21/2022", - ], - ], - "format" => "csv", - ]; - // Need 2 json responses which get combined on output. - $this->queryResultReformatted($data); - } - public function queryResultReformatted($data){ $request = $this->mockRequest($data); $dataDictionaryFields = [