Skip to content

Commit

Permalink
Merge branch 'updateNotificationsMessage330' into 'stable-3_3_0'
Browse files Browse the repository at this point in the history
Includes implementations of text and notification improvements

See merge request softwares-pkp/plugins_ojs/OASwitchboard!46
  • Loading branch information
YvesLepidus committed Oct 29, 2024
2 parents 5c01e90 + 53bd06b commit dc4fbe7
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 117 deletions.
1 change: 1 addition & 0 deletions OASwitchboardPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function register($category, $path, $mainContextId = null)
$message = new Message($this);
$resources = new Resources($this);
HookRegistry::register('Publication::publish', [$message, 'sendToOASwitchboard']);
HookRegistry::register('Form::config::before', [$message, 'validateRegister']);
HookRegistry::register('TemplateManager::display', [$resources, 'addWorkflowNotificationsJavaScript']);
HookRegistry::register('NotificationManager::getNotificationMessage', [$resources, 'addMessageToInformationNotification']);
}
Expand Down
84 changes: 70 additions & 14 deletions classes/Message.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import('plugins.generic.OASwitchboard.classes.OASwitchboardService');
import('plugins.generic.OASwitchboard.classes.exceptions.P1PioException');
import('plugins.generic.OASwitchboard.classes.messages.P1Pio');

class Message
{
Expand All @@ -27,33 +28,61 @@ public function sendToOASwitchboard($hookName, $args)
$keyMessage = 'plugins.generic.OASwitchboard.sendMessageWithSuccess';
$this->sendNotification($userId, __($keyMessage), NOTIFICATION_TYPE_SUCCESS);
$this->registerSubmissionEventLog($request, $submission, $keyMessage);
if (!OASwitchboardService::isRorAssociated($submission)) {
$keyMessage = 'plugins.generic.OASwitchboard.rorRecommendation';
$this->sendNotification($userId, __($keyMessage), NOTIFICATION_TYPE_INFORMATION);
$this->registerSubmissionEventLog($request, $submission, $keyMessage);
}
}
} catch (P1PioException $e) {
$this->sendNotification($userId, $e->getMessage(), NOTIFICATION_TYPE_WARNING);
} catch (\Exception $e) {
error_log($e->getMessage());
}
}

public function validateRegister($hookName, $form)
{
if ($form->id !== 'publish' || !empty($form->errors)) {
return;
}

$contextId = Application::get()->getRequest()->getContext()->getId();
$submission = Services::get('submission')->get($form->publication->getData('submissionId'));

try {
OASwitchboardService::validatePluginIsConfigured($this->plugin, $contextId);
} catch (\Exception $e) {
$message = '<div class="pkpNotification pkpNotification--information">' . $e->getMessage() . '</div>';
$form->addField(new \PKP\components\forms\FieldHTML('registerNotice', [
'description' => $message,
'groupId' => 'default',
]));
return false;
}


try {
$p1Pio = new P1Pio($submission);
$successMessage = $this->getSubmissionAlreadyToSendMessage($submission);

$form->addField(new \PKP\components\forms\FieldHTML('registerNotice', [
'description' => $successMessage,
'groupId' => 'default',
]));
} catch (P1PioException $e) {
if ($e->getP1PioErrors()) {
foreach ($e->getP1PioErrors() as $error) {
$this->sendNotification($userId, __($error), NOTIFICATION_TYPE_WARNING);
$this->registerSubmissionEventLog($request, $submission, $error);
}
$errorMessage = $this->getMandatoryDataErrorMessage($e->getP1PioErrors(), $submission);
$form->addField(new \PKP\components\forms\FieldHTML('registerNotice', [
'description' => $errorMessage,
'groupId' => 'default',
]));
}
error_log($e->getMessage());
}

return false;
}

private function registerSubmissionEventLog($request, $submission, $error)
{
$activityLogLocale = $error . '.activityLog';
SubmissionLog::logEvent(
$request,
$submission,
SUBMISSION_LOG_TYPE_DEFAULT,
$activityLogLocale,
$error,
[]
);
}
Expand All @@ -67,4 +96,31 @@ private function sendNotification($userId, $message, $notificationType)
array('contents' => $message)
);
}

private function getMandatoryDataErrorMessage($p1PioErrors, $submission): string
{
$introductionMessage = __('plugins.generic.OASwitchboard.postRequirementsError.introductionText');
$message = '<div class="pkpNotification pkpNotification--information">' . $introductionMessage . '<br><br>';
foreach ($p1PioErrors as $error) {
$noticeMessage = __($error);
$message .= '- ' . $noticeMessage . '<br>';
}
if (!OASwitchboardService::isRorAssociated($submission)) {
$message .= '<br>' . __('plugins.generic.OASwitchboard.rorRecommendation') . '<br>';
}
$message .= '<br>' . __('plugins.generic.OASwitchboard.postRequirementsError.conclusionText');
$message .= '</div>';

return $message;
}

private function getSubmissionAlreadyToSendMessage($submission): string
{
$hasRorAssociated = OASwitchboardService::isRorAssociated($submission);
$messageType = $hasRorAssociated ? 'success' : 'information';
$successMessage = __('plugins.generic.OASwitchboard.postRequirementsSuccess');
$rorRecommendationMessage = $hasRorAssociated ? '' : '<br><br>' . __('plugins.generic.OASwitchboard.rorRecommendation');

return '<div class="pkpNotification pkpNotification--' . $messageType . '">' . $successMessage . $rorRecommendationMessage . '</div>';
}
}
10 changes: 5 additions & 5 deletions classes/OASwitchboardService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($plugin, $contextId, $submission)
$this->plugin = $plugin;
$this->contextId = $contextId;
$this->submission = $submission;
$this->validatePluginIsConfigured($this->plugin);
self::validatePluginIsConfigured($this->plugin, $this->contextId);

$httpClient = Application::get()->getHttpClient();
$useSandboxApi = $this->plugin->getSetting($this->contextId, 'isSandBoxAPI');
Expand Down Expand Up @@ -60,11 +60,11 @@ private function getAuthTokenByCredentials()
);
}

private function validatePluginIsConfigured($plugin)
public static function validatePluginIsConfigured($plugin, $contextId)
{
$username = $this->plugin->getSetting($this->contextId, 'username');
$password = $this->plugin->getSetting($this->contextId, 'password');
$useSandboxApi = $this->plugin->getSetting($this->contextId, 'isSandBoxAPI');
$username = $plugin->getSetting($contextId, 'username');
$password = $plugin->getSetting($contextId, 'password');
$useSandboxApi = $plugin->getSetting($contextId, 'isSandBoxAPI');
if (is_null($username) || is_null($password) || is_null($useSandboxApi)) {
throw new Exception(__("plugins.generic.OASwitchboard.pluginIsNotConfigured"));
}
Expand Down
7 changes: 5 additions & 2 deletions classes/messages/P1Pio.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function getAuthorsData(): array
{
$authors = $this->submission->getAuthors();
$authorsData = [];
$listingOrder = 0;
foreach ($authors as $author) {
$listingOrder++;
$lastNameRetrieved = $author->getLocalizedFamilyName();
$lastName = is_array($lastNameRetrieved) ? reset($lastNameRetrieved) : $lastNameRetrieved;
$firstName = $author->getLocalizedGivenName();
Expand Down Expand Up @@ -61,8 +63,7 @@ public function getAuthorsData(): array
$primaryContactId = $this->submission->getCurrentPublication()->getData('primaryContactId');
$authorsData[$lastAuthorIndex]['isCorrespondingAuthor'] = $primaryContactId === $author->getId();

$contributorSequence = $author->getData('seq') + 1;
$authorsData[$lastAuthorIndex]['listingorder'] = $contributorSequence;
$authorsData[$lastAuthorIndex]['listingorder'] = $listingOrder;
}
return $authorsData;
}
Expand Down Expand Up @@ -246,6 +247,8 @@ public function validateHasMinimumSubmissionData(): array
$missingDataMessages[] = 'plugins.generic.OASwitchboard.postRequirementsError.issn';
}

$missingDataMessages = array_unique($missingDataMessages);

return $missingDataMessages;
}
}
2 changes: 1 addition & 1 deletion cypress/tests/Test1_settingsFormInvalidAuth.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ describe('Setup OASwitchboard invalid credentials', function () {
cy.get('input[name=OASUsername]').type('username');
cy.get('input[name=OASPassword]').type('password');
cy.get('form#OASwitchboardSettingsForm button:contains("Save")').click();
cy.get('form#OASwitchboardSettingsForm').should('contain', 'Failed to authenticate, please check the OA Switchboard API credentials again');
cy.get('form#OASwitchboardSettingsForm').should('contain', 'Authentication failed, please check the OA Switchboard API credentials.');
})
})
3 changes: 0 additions & 3 deletions cypress/tests/Test3_sendMessageError.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ describe('Error when submission is published', function () {
cy.get('.modal__content button:contains("Unpublish")').click();
cy.get('.pkpPublication > .pkpHeader button:contains("Publish")').click();
cy.get('.pkpFormPage__footer button:contains("Publish")').click();

cy.get('.app__notifications').contains("We don't have the mandatory data for sending the message to the OA Switchboard, please check the submission activity log to understand the pending requirements.");
cy.get('.app__notifications').contains("The article must have a DOI associated.");
})
})
3 changes: 1 addition & 2 deletions cypress/tests/Test4_sendMessageSuccess.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('Send P1-PIO message with success', function () {
cy.get('.pkpPublication > .pkpHeader > .pkpHeader__actions > button.pkpButton').contains("Schedule For Publication").click();
cy.get('.pkpFormPage__footer button:contains("Publish")').click();

cy.get('.app__notifications').contains("At least one author should have a ROR ID linked to their affiliation (requires the ROR plugin) for the message to be sent to the affiliation.");
cy.get('.app__notifications').contains("The message was successfully sent to the OA Switchboard");
cy.get('.app__notifications').contains("The P1 message was successfully sent to the OA Switchboard.");
})
})
48 changes: 17 additions & 31 deletions locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,40 @@ msgid "plugins.generic.OASwitchboard.settings.password"
msgstr "Password:"

msgid "plugins.generic.OASwitchboard.settings.apiAuthenticatorFailed"
msgstr "Failed to authenticate, please check the OA Switchboard API credentials again"
msgstr "Authentication failed, please check the OA Switchboard API credentials."

msgid "plugins.generic.OASwitchboard.pluginIsNotConfigured"
msgstr "The OA Switchboard plugin needs to be configured to successfully send the message."
msgstr "The OA Switchboard plugin is not configured."

msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess"
msgstr "The message was successfully sent to the OA Switchboard"
msgstr "The P1 message was successfully sent to the OA Switchboard."

msgid "plugins.generic.OASwitchboard.postRequirements"
msgstr "Client error when sending message to OA Switchboard API server, more information in the system log."
msgstr "Error while attempting to send message via OA Switchboard API. More information can be found in the server logs."

msgid "plugins.generic.OASwitchboard.serverError"
msgstr "Server error when sending message. The OA Switchboard API server encountered an internal error."

msgid "plugins.generic.OASwitchboard.postRequirementsError"
msgstr "We don't have the mandatory data for sending the message to the OA Switchboard, please check the submission activity log to understand the pending requirements."
msgstr "Error sending the message. The OA Switchboard API returned an internal server error."

msgid "plugins.generic.OASwitchboard.rorRecommendation"
msgstr "At least one author should have a ROR ID linked to their affiliation (requires the ROR plugin) for the message to be sent to the affiliation."
msgstr "It is recommended that at least one author has a ROR ID linked to their affiliation (requires the ROR plugin) to send the message to the author's institution."

msgid "plugins.generic.OASwitchboard.postRequirementsError.introductionText"
msgstr "OA Switchboard: it will not be possible to send the P1 message as the submission does not meet the following requirements."

msgid "plugins.generic.OASwitchboard.postRequirementsError.familyName"
msgstr "The family name of an author must be present."
msgstr "The family name of all authors must be present."

msgid "plugins.generic.OASwitchboard.postRequirementsError.affiliation"
msgstr "Affiliation of an author must be set."
msgstr "All authors must have their affiliation filled in."

msgid "plugins.generic.OASwitchboard.postRequirementsError.doi"
msgstr "The article must have a DOI associated."
msgstr "The article must have an associated DOI."

msgid "plugins.generic.OASwitchboard.postRequirementsError.issn"
msgstr "The journal must have a ISSN or eISSN assigned."


msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess.activityLog"
msgstr "Successfully sent a message to the OA Switchboard."

msgid "plugins.generic.OASwitchboard.rorRecommendation.activityLog"
msgstr "Received a notification from the OA Switchboard: At least one author must have a ROR ID linked to their affiliation (requires ROR plugin) for the message to be sent to the affiliation."

msgid "plugins.generic.OASwitchboard.postRequirementsError.familyName.activityLog"
msgstr "Tried to deposit with OA Switchboard, which returned: The family name of an author must be present."

msgid "plugins.generic.OASwitchboard.postRequirementsError.affiliation.activityLog"
msgstr "Tried to deposit with OA Switchboard, which returned: Affiliation of an author must be set."

msgid "plugins.generic.OASwitchboard.postRequirementsError.doi.activityLog"
msgstr "Tried to deposit with OA Switchboard, which returned: The article must have a DOI associated."
msgstr "The journal must have an assigned ISSN."

msgid "plugins.generic.OASwitchboard.postRequirementsError.issn.activityLog"
msgstr "Tried to deposit with OA Switchboard, which returned: The journal must have an ISSN or eISSN assigned."
msgid "plugins.generic.OASwitchboard.postRequirementsError.conclusionText"
msgstr "You may review these metadata, or proceed with the publication without sending the message to the OA Switchboard."

msgid "plugins.generic.OASwitchboard.postRequirementsSuccess"
msgstr "OA Switchboard: the requirements have been met and the P1 message will be sent to the OA Switchboard upon publishing the submission."
44 changes: 16 additions & 28 deletions locale/es_ES/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,40 @@ msgid "plugins.generic.OASwitchboard.settings.password"
msgstr "Contraseña:"

msgid "plugins.generic.OASwitchboard.settings.apiAuthenticatorFailed"
msgstr "No se pudo autenticar, por favor, comprueba las credenciales de API de OA Switchboard nuevamente"
msgstr "No se pudo autenticar, por favor, verifique las credenciales de la API de OA Switchboard."

msgid "plugins.generic.OASwitchboard.pluginIsNotConfigured"
msgstr "El módulo OA Switchboard debe configurarse para enviar correctamente el mensaje."
msgstr "El plugin OA Switchboard no está configurado."

msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess"
msgstr "El mensaje se envió correctamente al OA Switchboard"
msgstr "El mensaje P1 fue enviado con éxito al OA Switchboard."

msgid "plugins.generic.OASwitchboard.postRequirements"
msgstr "Error del cliente al enviar un mensaje al servidor de la API de OA Switchboard, más información en el registro del sistema."
msgstr "Error al intentar enviar un mensaje a través de la API de OA Switchboard. Puede encontrar más información en los registros del servidor."

msgid "plugins.generic.OASwitchboard.serverError"
msgstr "Error del servidor al enviar el mensaje. El servidor de la API de OA Switchboard encontró un error interno."

msgid "plugins.generic.OASwitchboard.postRequirementsError"
msgstr "No tenemos los datos obligatorios para enviar el mensaje al OA Switchboard, por favor revise el Registro de actividad de lo envío para entender los requisitos pendientes."
msgstr "Error al enviar el mensaje. La API de OA Switchboard devolvió un error interno."

msgid "plugins.generic.OASwitchboard.rorRecommendation"
msgstr "Al menos un autor debe tener un ID ROR vinculado a su afiliación (requiere el plugin ROR) para que el mensaje sea enviado a la afiliación."
msgstr "Se recomienda que al menos un autor tenga un ID ROR vinculado a su afiliación (requiere el plugin ROR) para enviar el mensaje a la institución del autor."

msgid "plugins.generic.OASwitchboard.postRequirementsError.introductionText"
msgstr "OA Switchboard: no será posible enviar el mensaje P1, ya que la presentación no cumple con los requisitos a continuación."

msgid "plugins.generic.OASwitchboard.postRequirementsError.familyName"
msgstr "El apellido de un autor debe estar presente."
msgstr "El apellido de todos los autores debe estar presente."

msgid "plugins.generic.OASwitchboard.postRequirementsError.affiliation"
msgstr "La afiliación de un autor debe estar establecida."
msgstr "Todos los autores deben tener su afiliación completada."

msgid "plugins.generic.OASwitchboard.postRequirementsError.doi"
msgstr "El artículo debe tener un DOI asociado."

msgid "plugins.generic.OASwitchboard.postRequirementsError.issn"
msgstr "La revista debe tener un ISSN o eISSN asignado."

msgid "plugins.generic.OASwitchboard.sendMessageWithSuccess.activityLog"
msgstr "Mensaje enviado con éxito al OA Switchboard."

msgid "plugins.generic.OASwitchboard.rorRecommendation.activityLog"
msgstr "Recibió una notificación del OA Switchboard: Al menos un autor debe tener un ID ROR vinculado a su afiliación (requiere el plugin ROR) para que el mensaje sea enviado a la afiliación."

msgid "plugins.generic.OASwitchboard.postRequirementsError.familyName.activityLog"
msgstr "Intentó depositar en la OA Switchboard, lo que devolvió: El apellido de un autor debe estar presente."

msgid "plugins.generic.OASwitchboard.postRequirementsError.affiliation.activityLog"
msgstr "Intentó depositar en la OA Switchboard, lo que devolvió: La afiliación de un autor debe establecerse."
msgstr "La revista debe tener un ISSN asignado."

msgid "plugins.generic.OASwitchboard.postRequirementsError.doi.activityLog"
msgstr "Intentó depositar en la OA Switchboard, lo que devolvió: El artículo debe tener un DOI asociado."
msgid "plugins.generic.OASwitchboard.postRequirementsError.conclusionText"
msgstr "Puede revisar estos metadatos o continuar con la publicación sin enviar el mensaje al OA Switchboard."

msgid "plugins.generic.OASwitchboard.postRequirementsError.issn.activityLog"
msgstr "Intentó depositar en la OA Switchboard, lo que devolvió: La revista debe tener un ISSN o eISSN asignado."
msgid "plugins.generic.OASwitchboard.postRequirementsSuccess"
msgstr "OA Switchboard: se han cumplido los requisitos y el mensaje P1 será enviado al OA Switchboard al publicar la publicacíon."
Loading

0 comments on commit dc4fbe7

Please sign in to comment.