Skip to content

Commit

Permalink
Merge branch 'adaptReport340-669' into 'adaptTo340'
Browse files Browse the repository at this point in the history
Adapta relatório e últimos ajustes da adaptação pro 3.4.0

See merge request softwares-pkp/plugins_ojs/dataverse!162
  • Loading branch information
JhonathanLepidus committed Jun 21, 2024
2 parents 00a4658 + 86dbe45 commit e86d6b0
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 1,221 deletions.
5 changes: 3 additions & 2 deletions DataversePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace APP\plugins\generic\dataverse;

use PKP\plugins\GenericPlugin;
use PKP\plugins\PluginRegistry;
use APP\core\Application;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
Expand All @@ -24,6 +25,7 @@
use APP\plugins\generic\dataverse\classes\migrations\DataverseMigration;
use APP\plugins\generic\dataverse\classes\dataverseConfiguration\DataverseConfigurationDAO;
use APP\plugins\generic\dataverse\DataverseSettingsForm;
use APP\plugins\generic\dataverse\report\DataverseReportPlugin;

class DataversePlugin extends GenericPlugin
{
Expand All @@ -42,7 +44,7 @@ public function register($category, $path, $mainContextId = null)

if(!is_null($context) and $dataverseConfigurationDAO->hasConfiguration($context->getId())) {
$this->loadDispatcherClasses();
//PluginRegistry::register('reports', $this->getReportPlugin(), $this->getPluginPath());
PluginRegistry::register('reports', $this->getReportPlugin(), $this->getPluginPath());
}

return $success;
Expand Down Expand Up @@ -79,7 +81,6 @@ public function getDescription()

public function getReportPlugin()
{
$this->import('report.DataverseReportPlugin');
return new DataverseReportPlugin();
}

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ It is a work in progress, the current version is a MVP for OPS and OJS.

The latest release of this plugin is compatible with the following PKP applications:

* OPS 3.3.0
* OJS 3.3.0
* OPS 3.4.0
* OJS 3.4.0

Using PHP between 7.3 and 8.1.
Using PHP 8.1 or later.

## Plugin Download

Expand Down Expand Up @@ -49,7 +49,7 @@ After filling in the fields, just confirm the action by clicking `Save`. The plu

### Use

A "Research Data" deposit dialog is shown in step 2 of the Submission proccess.
A "Research Data" deposit dialog is shown in the "Files" step of the Submission proccess.

Authors, moderators, editors or managers can also edit the dataset, before publication, on the Research Data tab of the submission.

Expand Down Expand Up @@ -92,19 +92,19 @@ Creates a `cypress.env.json` file in root of the PKP Application directory, with

Next, to execute the Cypress tests run the following command from root of the PKP Appplication directory:
```
npx cypress run --config integrationFolder=plugins/generic/dataverse/cypress/tests
npx cypress run --config specPattern=plugins/generic/dataverse/cypress/tests
```

For execute the tests with the Cypress UI, run:
```
npx cypress open --config integrationFolder=plugins/generic/dataverse/cypress/tests
npx cypress open --config specPattern=plugins/generic/dataverse/cypress/tests
```
Important: Cypress search for elements with expected strings. The locale of your operating system and PKP Application must be `en_US` for passing into the tests.
Important: Cypress search for elements with expected strings. The locale of your operating system and PKP Application must be `en` for passing into the tests.

# License

__This plugin is licensed under the GNU General Public License v3.0__

__Copyright (c) 2021-2023 Lepidus Tecnologia__
__Copyright (c) 2021-2024 Lepidus Tecnologia__

__Copyright (c) 2021-2023 SciELO__
__Copyright (c) 2021-2024 SciELO__
8 changes: 6 additions & 2 deletions classes/APACitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use APP\submission\Submission;
use APP\publication\Publication;
use APP\author\Author;
use PKP\db\DAORegistry;
use APP\plugins\generic\dataverse\classes\dataverseStudy\DataverseStudy;
Expand All @@ -18,12 +19,15 @@ public function getCitationAsMarkupByStudy(DataverseStudy $study): string
return str_replace($study->getPersistentUri(), $href, strip_tags($study->getDataCitation()));
}

public function getFormattedCitationBySubmission(Submission $submission): string
public function getFormattedCitationBySubmission(Submission $submission, ?Publication $publication = null): string
{
if (is_null($publication)) {
$publication = $submission->getCurrentPublication();
}

$this->locale = $submission->getData('locale');
$journalDao = DAORegistry::getDAO('JournalDAO');
$journal = $journalDao->getById($submission->getData('contextId'));
$publication = $submission->getCurrentPublication();
$authors = $publication->getData('authors')->toArray();
$submittedDate = new DateTime($submission->getData('dateSubmitted'));

Expand Down
62 changes: 0 additions & 62 deletions classes/dispatchers/DataStatementDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,68 +145,6 @@ public function addDataStatementToPublicationSchema(string $hookName, array $arg
return false;
}

private function isValidStepForm(int $step, &$stepForm): bool
{
if ($step !== 1 || !$stepForm->validate()) {
return false;
}

if (empty($stepForm->getData('dataStatementTypes'))) {
$stepForm->addError(
'dataStatementTypes',
__('plugins.generic.dataverse.dataStatement.required')
);
$stepForm->addErrorField('dataStatementTypes');
return false;
}

if (in_array(DATA_STATEMENT_TYPE_REPO_AVAILABLE, $stepForm->getData('dataStatementTypes'))) {
if(empty($stepForm->getData('keywords')['dataStatementUrls'])) {
$stepForm->addError(
'dataStatementUrls',
__('plugins.generic.dataverse.dataStatement.repoAvailable.urls.required')
);
$stepForm->addErrorField('dataStatementUrls');
return false;
} else {
foreach($stepForm->getData('keywords')['dataStatementUrls'] as $dataStatementUrl) {
if(!$this->inputIsURL($dataStatementUrl)) {
$stepForm->addError(
'dataStatementUrls',
__('plugins.generic.dataverse.dataStatement.repoAvailable.urls.urlFormat')
);
$stepForm->addErrorField('dataStatementUrls');
$stepForm->setData('keywords', null);
return false;
}
}
}
}

return true;
}

private function createDataStatementParams($stepForm): array
{
$dataStatementTypes = $stepForm->getData('dataStatementTypes');
$dataStatementUrls = null;
$dataStatementReason = null;

if (in_array(DATA_STATEMENT_TYPE_REPO_AVAILABLE, $dataStatementTypes)) {
$dataStatementUrls = $stepForm->getData('keywords')['dataStatementUrls'];
}

if (in_array(DATA_STATEMENT_TYPE_PUBLICLY_UNAVAILABLE, $dataStatementTypes)) {
$dataStatementReason = $stepForm->getData('dataStatementReason');
}

return [
'dataStatementTypes' => $dataStatementTypes,
'dataStatementUrls' => $dataStatementUrls,
'dataStatementReason' => $dataStatementReason
];
}

public function dataStatementEditingCheck(string $hookName, array $params): bool
{
$publication = &$params[0];
Expand Down
5 changes: 4 additions & 1 deletion classes/dispatchers/DatasetMetadataDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public function validateSubmissionFields(string $hookName, array $params)

$dataStatementTypes = $publication->getData('dataStatementTypes');

if (in_array(DataStatementService::DATA_STATEMENT_TYPE_DATAVERSE_SUBMITTED, $dataStatementTypes)) {
if (
!empty($dataStatementTypes)
&& in_array(DataStatementService::DATA_STATEMENT_TYPE_DATAVERSE_SUBMITTED, $dataStatementTypes)
) {
if (!$submission->getData('datasetSubject')) {
$errors['datasetSubject'] = [__('plugins.generic.dataverse.error.datasetSubject.required')];
}
Expand Down
48 changes: 7 additions & 41 deletions classes/dispatchers/DataverseEventsDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Facades\Event;
use APP\plugins\generic\dataverse\api\v1\datasets\DatasetHandler;
use APP\plugins\generic\dataverse\api\v1\draftDatasetFiles\DraftDatasetFileHandler;
use APP\plugins\generic\dataverse\classes\APACitation;
use APP\plugins\generic\dataverse\classes\components\forms\SelectDataFilesForReviewForm;
use APP\plugins\generic\dataverse\classes\dataverseConfiguration\DataverseConfiguration;
use APP\plugins\generic\dataverse\classes\dispatchers\DataverseDispatcher;
Expand All @@ -36,8 +37,7 @@ protected function registerHooks(): void
Hook::add('Publication::publish', [$this, 'publishDeposit'], Hook::SEQUENCE_CORE);
Hook::add('TemplateManager::display', [$this, 'editDecisions']);
Hook::add('LoadComponentHandler', [$this, 'setupDataverseComponentHandlers']);

// HookRegistry::register('Publication::edit', array($this, 'updateDatasetOnPublicationUpdate'));
Hook::add('Publication::edit', [$this, 'updateDatasetOnPublicationUpdate']);
}

public function modifySubmissionSchema(string $hookName, array $params): bool
Expand Down Expand Up @@ -250,61 +250,27 @@ private function editAcceptDecision($templateMgr, $study, $contextId)
$templateMgr->setState(['steps' => $decisionSteps]);
}

public function updateDatasetOnPublicationUpdate(string $hookName, array $args): bool
public function updateDatasetOnPublicationUpdate(string $hookName, array $params): bool
{
$publication = &$args[0];
$publication = &$params[0];
$submission = Repo::submission()->get($publication->getData('submissionId'));
$data = [];

$publicationDAO = DAORegistry::getDAO('PublicationDAO');
$publicationDAO->updateObject($publication);

$submission = Services::get('submission')->get($publication->getData('submissionId'));

$studyDAO = DAORegistry::getDAO('DataverseStudyDAO');
$study = $studyDAO->getStudyBySubmissionId($submission->getId());

$study = Repo::dataverseStudy()->getBySubmissionId($submission->getId());
if (!$study) {
return false;
}

import('plugins.generic.dataverse.classes.APACitation');
$apaCitation = new APACitation();

$data['persistentId'] = $study->getPersistentId();
$data['pubCitation'] = $apaCitation->getFormattedCitationBySubmission($submission);
$data['pubCitation'] = $apaCitation->getFormattedCitationBySubmission($submission, $publication);

$datasetService = new DatasetService();
$datasetService->update($data);

return false;
}

private function prepareFormToDisplay($templateMgr, $form, $request): string
{
$context = $request->getContext();
$templateMgr->setCacheability(CACHEABILITY_NO_STORE);

$fbv = $templateMgr->getFBV();
$fbv->setForm($form);

$templateMgr->assign(array_merge($form->_data, [
'isError' => !$form->isValid(),
'errors' => $form->getErrorsArray(),
'formLocales' => $form->supportedLocales,
'formLocale' => $form->getDefaultFormLocale(),
]));

if (!$templateMgr->getTemplateVars('primaryLocale')) {
$templateMgr->assign([
'primaryLocale' => $context
? $context->getPrimaryLocale()
: (Config::getVar('general', 'installed') ? $request->getSite()->getPrimaryLocale() : null),
]);
}

return $templateMgr->fetch($form->_template);
}

public function setupDataverseAPIHandlers(string $hookname, array $params): void
{
$request = $params[0];
Expand Down
5 changes: 4 additions & 1 deletion classes/dispatchers/DraftDatasetFilesDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ public function validateSubmissionFields(string $hookName, array $params)

$dataStatementTypes = $publication->getData('dataStatementTypes');

if (in_array(DataStatementService::DATA_STATEMENT_TYPE_DATAVERSE_SUBMITTED, $dataStatementTypes)) {
if (
!empty($dataStatementTypes)
&& in_array(DataStatementService::DATA_STATEMENT_TYPE_DATAVERSE_SUBMITTED, $dataStatementTypes)
) {
$draftDatasetFiles = Repo::draftDatasetFile()->getBySubmissionId($submission->getId())->toArray();

if (empty($draftDatasetFiles)) {
Expand Down
4 changes: 4 additions & 0 deletions classes/services/DatasetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public function update(array $data): void
$dataverseClient = new DataverseClient();
$dataset = $dataverseClient->getDatasetActions()->get($data['persistentId']);

if ($dataset->isPublished()) {
return;
}

foreach($data as $name => $value) {
$dataset->setData($name, $value);
}
Expand Down
Loading

0 comments on commit e86d6b0

Please sign in to comment.