From 8cff6a569049b9fc10bb43b24d29c689343cadc1 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 1 Aug 2024 10:55:09 -0400 Subject: [PATCH 1/4] Updates gitlab CI file for 330 version Issue: documentacao-e-tarefas/scielo#688 Signed-off-by: Jhon --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 140515fb..44fbfe7f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,9 +3,9 @@ variables: include: - project: 'documentacao-e-tarefas/modelosparaintegracaocontinua' - ref: main + ref: stable-3_3_0 file: - 'templates/groups/pkp_plugin.yml' - - 'templates/groups/ops_plugins_unit_tests_model.yml' - - 'templates/groups/ojs_plugins_unit_tests_model.yml' - - 'templates/groups/ojs_plugins_cypress_tests_model.yml' + - 'templates/groups/ops/unit_tests.yml' + - 'templates/groups/ojs/unit_tests.yml' + - 'templates/groups/ojs/cypress_tests.yml' From 9997a5765cf89d625a7963abe15b6965940869cc Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 16 Aug 2024 16:44:47 -0400 Subject: [PATCH 2/4] Fixes error caused by offline Dataverse in submission page Issue: documentacao-e-tarefas/scielo#688 Signed-off-by: Jhon --- .../forms/DataStatementForm.inc.php | 31 +++++++------------ classes/services/DataStatementService.inc.php | 10 +++++- dataverseAPI/actions/DataverseActions.inc.php | 8 ++--- .../actions/DataverseActionsTest.php | 26 ++++++++++++++-- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/classes/components/forms/DataStatementForm.inc.php b/classes/components/forms/DataStatementForm.inc.php index 36b67fb0..8de33ae1 100644 --- a/classes/components/forms/DataStatementForm.inc.php +++ b/classes/components/forms/DataStatementForm.inc.php @@ -19,14 +19,9 @@ public function __construct($action, $locales, $publication) $this->action = $action; $this->locales = $locales; - $dataStatementTypes = $this->getDataStatementTypes(); - - $dataStatementOptions = array_map(function ($value, $label) { - return [ - 'value' => $value, - 'label' => $label, - ]; - }, array_keys($dataStatementTypes), array_values($dataStatementTypes)); + $dataStatementService = new DataStatementService(); + $dataStatementOptions = $this->getDataStatementOptions($dataStatementService); + $dataverseName = $dataStatementService->getDataverseName(); $request = Application::get()->getRequest(); $contextPath = $request->getContext()->getPath(); @@ -58,7 +53,7 @@ public function __construct($action, $locales, $publication) [ 'value' => true, 'label' => __('plugins.generic.dataverse.dataStatement.researchDataSubmitted', [ - 'dataverseName' => $this->getDataverseName(), + 'dataverseName' => $dataverseName, ]), 'disabled' => true, ], @@ -67,22 +62,20 @@ public function __construct($action, $locales, $publication) ])); } - private function getDataStatementTypes(): array + private function getDataStatementOptions(): array { $dataStatementService = new DataStatementService(); $dataStatementTypes = $dataStatementService->getDataStatementTypes(); unset($dataStatementTypes[DATA_STATEMENT_TYPE_DATAVERSE_SUBMITTED]); - return $dataStatementTypes; - } - - private function getDataverseName(): string - { - import('plugins.generic.dataverse.dataverseAPI.DataverseClient'); - $dataverseClient = new DataverseClient(); - $dataverseCollection = $dataverseClient->getDataverseCollectionActions()->get(); + $dataStatementOptions = array_map(function ($value, $label) { + return [ + 'value' => $value, + 'label' => $label, + ]; + }, array_keys($dataStatementTypes), array_values($dataStatementTypes)); - return $dataverseCollection->getName(); + return $dataStatementOptions; } private function hasDataset(Publication $publication): bool diff --git a/classes/services/DataStatementService.inc.php b/classes/services/DataStatementService.inc.php index 8df9c0fb..1aef75e0 100644 --- a/classes/services/DataStatementService.inc.php +++ b/classes/services/DataStatementService.inc.php @@ -8,6 +8,8 @@ class DataStatementService { + private $dataverseName; + public function getDataStatementTypes(): array { $dataverseName = $this->getDataverseName(); @@ -27,11 +29,17 @@ public function getDataStatementTypes(): array public function getDataverseName(): ?string { + if ($this->dataverseName) { + return $this->dataverseName; + } + try { import('plugins.generic.dataverse.dataverseAPI.DataverseClient'); $dataverseClient = new DataverseClient(); $dataverseCollection = $dataverseClient->getDataverseCollectionActions()->get(); - return $dataverseCollection->getName(); + $this->dataverseName = $dataverseCollection->getName(); + + return $this->dataverseName; } catch (DataverseException $e) { error_log('Dataverse API error: ' . $e->getMessage()); return null; diff --git a/dataverseAPI/actions/DataverseActions.inc.php b/dataverseAPI/actions/DataverseActions.inc.php index d7073065..0ac1504f 100644 --- a/dataverseAPI/actions/DataverseActions.inc.php +++ b/dataverseAPI/actions/DataverseActions.inc.php @@ -1,6 +1,6 @@ client->request($method, $uri, $options); - } catch (RequestException $e) { + } catch (TransferException $e) { $message = $e->getMessage(); $code = $e->getCode(); - if ($e->hasResponse()) { + if (method_exists($e, 'hasResponse') and $e->hasResponse()) { $response = $e->getResponse(); $code = $response->getStatusCode(); @@ -89,7 +89,7 @@ public function swordAPIRequest(string $method, string $uri, array $options = [] try { $reponse = $this->client->request($method, $uri, $options); - } catch (RequestException $e) { + } catch (TransferException $e) { $message = $e->getMessage(); $code = $e->getCode(); diff --git a/tests/dataverseAPI/actions/DataverseActionsTest.php b/tests/dataverseAPI/actions/DataverseActionsTest.php index 88b28aaf..c5834c89 100644 --- a/tests/dataverseAPI/actions/DataverseActionsTest.php +++ b/tests/dataverseAPI/actions/DataverseActionsTest.php @@ -4,6 +4,7 @@ use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Handler\MockHandler; +use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; import('lib.pkp.tests.PKPTestCase'); @@ -96,7 +97,7 @@ public function testSuccessfulNativeAPIRequest(): void $this->assertEquals('{"foo": "bar"}', $response->getBody()); } - public function testRequestErrorWithoutResponseThrownDataverseException(): void + public function testRequestErrorWithoutResponseThrowsDataverseException(): void { $mockHandler = new MockHandler([ new RequestException( @@ -115,7 +116,26 @@ public function testRequestErrorWithoutResponseThrownDataverseException(): void $actions->nativeAPIRequest('GET', 'test'); } - public function testRequestErrorWithResponseThrownDataverseException(): void + public function testConnectionErrorThrowsDataverseException(): void + { + $mockHandler = new MockHandler([ + new ConnectException( + 'Failed to connect to Dataverse', + new Request('GET', 'test') + ) + ]); + $guzzleClient = new Client(['handler' => $mockHandler]); + + $actions = $this->getMockBuilder(DataverseActions::class) + ->setConstructorArgs([$this->configuration, $guzzleClient]) + ->getMockForAbstractClass(); + + $this->expectException(DataverseException::class); + $this->expectExceptionMessage('Failed to connect to Dataverse'); + $actions->nativeAPIRequest('GET', 'test'); + } + + public function testRequestErrorWithResponseThrowsDataverseException(): void { $mockHandler = new MockHandler([ new RequestException( @@ -136,7 +156,7 @@ public function testRequestErrorWithResponseThrownDataverseException(): void $actions->nativeAPIRequest('GET', 'test'); } - public function testRequestErrorWithResponseBodyEmptyThrownDataverseException(): void + public function testRequestErrorWithResponseBodyEmptyThrowsDataverseException(): void { $mockHandler = new MockHandler([ new RequestException( From 3b424efe21a33bb435de6c6fe376a61426f6a1c9 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 16 Aug 2024 17:03:39 -0400 Subject: [PATCH 3/4] Fixes error of offline Dataverse in create submissions page Issue: documentacao-e-tarefas/scielo#688 Signed-off-by: Jhon --- classes/DataverseMetadata.inc.php | 10 ++++++---- classes/components/forms/DraftDatasetFileForm.inc.php | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/classes/DataverseMetadata.inc.php b/classes/DataverseMetadata.inc.php index e982906e..fa1d245f 100644 --- a/classes/DataverseMetadata.inc.php +++ b/classes/DataverseMetadata.inc.php @@ -66,19 +66,19 @@ public function getDataverseSubjects(): array ]; } - public function getDataverseLicenses(): array + public function getDataverseLicenses(): ?array { $configuration = $this->getDataverseConfiguration(); $licensesUrl = $configuration->getDataverseServerUrl() . '/api/licenses'; $response = json_decode(file_get_contents($licensesUrl), true); - $this->dataverseLicenses = $response['data']; + $this->dataverseLicenses = $response['data'] ?? []; return $this->dataverseLicenses; } - public function getDefaultLicense(): string + public function getDefaultLicense(): ?string { - if(is_null($this->dataverseLicenses)) { + if(empty($this->dataverseLicenses)) { $this->getDataverseLicenses(); } @@ -87,6 +87,8 @@ public function getDefaultLicense(): string return $license['name']; } } + + return null; } private function getDataverseConfiguration(): DataverseConfiguration diff --git a/classes/components/forms/DraftDatasetFileForm.inc.php b/classes/components/forms/DraftDatasetFileForm.inc.php index d3a76518..eda6c25d 100644 --- a/classes/components/forms/DraftDatasetFileForm.inc.php +++ b/classes/components/forms/DraftDatasetFileForm.inc.php @@ -55,8 +55,9 @@ private function getTermsOfUseData($contextId) 'dataverseName' => $dataverseCollection->getName(), 'termsOfUseURL' => $termsOfUse ]; - } catch (\Exception $e) { + } catch (DataverseException $e) { error_log('Dataverse API error: ' . $e->getMessage()); + return []; } } } From 4a2bb18480ccff388f1494ec883ee1d2b2dddb00 Mon Sep 17 00:00:00 2001 From: Jhon Date: Fri, 16 Aug 2024 17:19:43 -0400 Subject: [PATCH 4/4] Updates version.xl Signed-off-by: Jhon --- version.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.xml b/version.xml index 2abfc88d..096dc885 100644 --- a/version.xml +++ b/version.xml @@ -13,8 +13,8 @@ dataverse plugins.generic - 2.5.11.0 - 2024-01-12 + 2.5.12.0 + 2024-08-16 1 DataversePlugin