Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ yarn-error.log
/.vscode
/.docker
.DS_Store
config/app.php
28 changes: 14 additions & 14 deletions app/Livewire/Conducting/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

use App\Utils\CheckProjectDataPlanning;
use App\Traits\ProjectPermissions;
use App\Traits\LivewireExceptionHandler;

class FileUpload extends Component
{

use ProjectPermissions;
use WithFileUploads;
use LivewireExceptionHandler;

private $translationPath = 'project/conducting.import-studies.livewire';
private $toastMessages = 'project/conducting.import-studies.livewire.toasts';
Expand Down Expand Up @@ -192,11 +194,13 @@ public function save()
$errorMessage = $e->getMessage();
FacadesLog::error('Erro ao salvar o arquivo ou processar BibUpload.', ['error' => $errorMessage]);

$toastMessage = __($this->toastMessages . '.file_upload_error', ['message' => $errorMessage]);
$this->toast(
message: $toastMessage,
type: 'error'
);
// Deleta o bibUpload se houver erro
if (isset($bibUpload) && $bibUpload->exists()) {
$bibUpload->delete();
FacadesLog::info('Registro BibUpload deletado após falha no processamento.', ['id_bib' => $bibUpload->id_bib]);
}

$this->handleException($e);
}

} else {
Expand All @@ -214,11 +218,7 @@ public function save()
$errorMessage = $e->getMessage();
FacadesLog::error('Erro geral ao tentar salvar o arquivo.', ['error' => $errorMessage]);

$toastMessage = __($this->toastMessages . '.file_upload_error', ['message' => $errorMessage]);
$this->toast(
message: $toastMessage,
type: 'error'
);
$this->handleException($e);
}
}

Expand Down Expand Up @@ -262,15 +262,15 @@ private function mapCsvFields($csvRow)
return [
'type' => $csvRow['Content Type'] ?? '',
'citation-key' => '',
'title' => $csvRow['Item Title'] ?? '',
'author' => $csvRow['Authors'] ?? '',
'title' => !empty($csvRow['Item Title']) ? $csvRow['Item Title'] : null,
'author' =>!empty($csvRow['Authors']) ? $csvRow['Authors'] : null,
'booktitle' => $csvRow['Book Series Title'] ?? '',
'volume' => $csvRow['Journal Volume'] ?? '',
'pages' => '',
'numpages' => '',
'abstract' => '',
'keywords' => '',
'doi' => $csvRow['Item DOI'] ?? '',
'doi' => !empty($csvRow['Item DOI']) ? $csvRow['Item DOI'] : null,
'journal' => $csvRow['Publication Title'] ?? '',
'issn' => '',
'location' => '',
Expand All @@ -288,7 +288,7 @@ public function deleteFile($id)
if (!$this->checkEditPermission($this->toastMessages . '.denied')) {
return;
}

$file = BibUpload::findOrFail($id);

try {
Expand Down
27 changes: 9 additions & 18 deletions app/Livewire/Planning/Criteria/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use App\Utils\ActivityLogHelper as Log;
use App\Utils\ToastHelper;
use App\Traits\ProjectPermissions;
use App\Traits\LivewireExceptionHandler;

class Criteria extends Component
{

use ProjectPermissions;
use LivewireExceptionHandler;

private $toastMessages = 'project/planning.criteria.livewire.toasts';

Expand Down Expand Up @@ -46,8 +48,7 @@ protected function rules()
'currentProject' => 'required',
'criteriaId' => 'required|string|max:20|regex:/^[a-zA-Z0-9]+$/',
'description' => 'required|string|max:255',
'type' => 'required|array',
'type.*.value' => 'string'
'type.value' => 'required|in:Inclusion,Exclusion'
];
}

Expand All @@ -63,7 +64,8 @@ protected function messages()
'description.required' => __($tpath . '.description.required'),
'criteriaId.required' => __($tpath . '.criteriaId.required'),
'criteriaId.regex' => __($tpath . '.criteriaId.regex'),
'type.required' => __($tpath . '.type.required'),
'type.value.required' => __($tpath . '.type.required'),
'type.value.in' => __($tpath . '.type.in'),
];
}

Expand All @@ -88,16 +90,16 @@ public function mount()
'id_project',
$this->currentProject->id_project
)->where('type', 'Exclusion')->first()->rule ?? 'ANY';
$this->type['value'] = 'NONE';
$this->type['value'] = null;
}

/**
* Reset the fields to the default values.
*/
public function resetFields()
{
$this->criteriaId = '';
$this->description = '';
$this->criteriaId = null;
$this->description = null;
$this->type['value'] = null;
$this->currentCriteria = null;
$this->form['isEditing'] = false;
Expand Down Expand Up @@ -253,14 +255,6 @@ public function submit()

$this->validate();

if (strcmp($this->type['value'], 'NONE') === 0) {
$this->toast(
message: $this->translate('type.required'),
type: 'info'
);
return;
}

$updateIf = [
'id_criteria' => $this->currentCriteria?->id_criteria,
];
Expand Down Expand Up @@ -311,10 +305,7 @@ public function submit()
type: 'success'
);
} catch (\Exception $e) {
$this->toast(
message: $e->getMessage(),
type: 'error'
);
$this->handleException($e);
} finally {
$this->resetFields();
}
Expand Down
28 changes: 14 additions & 14 deletions app/Models/BibUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ public function importPapers(array $papers, $database, int $id_project, int $id_
'id_bib' => $id_bib,
'type' => $p['type'] ?? '',
'bib_key' => $p['citation-key'] ?? '',
'title' => $p['title'] ?? '',
'author' => $p['author'] ?? '',
'book_title' => $p['booktitle'] ?? null,
'volume' => $p['volume'] ?? null,
'pages' => $p['pages'] ?? null,
'num_pages' => $p['numpages'] ?? null,
'abstract' => $p['abstract'] ?? null,
'keywords' => $p['keywords'] ?? null,
'doi' => $p['doi'] ?? '',
'title' => $p['title'] ?? null,
'author' => $p['author'] ?? null,
'book_title' => $p['booktitle'] ?? '',
'volume' => $p['volume'] ?? '',
'pages' => $p['pages'] ?? '',
'num_pages' => $p['numpages'] ?? '',
'abstract' => $p['abstract'] ?? '',
'keywords' => $p['keywords'] ?? '',
'doi' => $p['doi'] ?? null,
'journal' => $p['journal'] ?? '',
'issn' => $p['issn'] ?? null,
'location' =>$p['location'] ?? null,
'isbn' => $p['isbn'] ?? null,
'address' =>$p['address'] ?? null,
'issn' => $p['issn'] ?? '',
'location' =>$p['location'] ?? '',
'isbn' => $p['isbn'] ?? '',
'address' =>$p['address'] ?? '',
'url' => $p['url'] ?? '',
'publisher' => $p['series'] ?? null,
'publisher' => $p['publisher'] ?? '',
'year' => $p['year'] ?? '',
'score' => 0,
'status_qa' => 3,
Expand Down
81 changes: 81 additions & 0 deletions app/Traits/LivewireExceptionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Traits;

use Exception;
use Illuminate\Database\QueryException;
use Illuminate\Validation\ValidationException;

trait LivewireExceptionHandler
{
/**
* Handle exceptions and display appropriate error messages.
* @param \Exception $e
* @return void
*/
public function handleException(Exception $e): void
{
/**
* ----------------------------------------------------------------
* Query Exceptions
* ----------------------------------------------------------------
*/
if ($e instanceof QueryException) {
$errorCode = $e->errorInfo[1] ?? null; // https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html

switch ($errorCode){
case 1048:
$column = $this->extractColumnFromMessage($e->getMessage());
$this->toast(
message: $column
? __("errors.database.column_cannot_be_null", ['column' => $column])
: __("errors.database.missing_required_field"),
type: 'error'
);
break;

default:
$this->toast(
message: __('errors.database.generic'),
type: 'error'
);
}
return;
}
// ----------------------------------------------------------------

/**
* ----------------------------------------------------------------
* Validation Exceptions
* ----------------------------------------------------------------
*/
if ($e instanceof ValidationException) {
$errors = $e->validator->errors()->all();
$this->toast(
message: implode(' ', $errors),
type: 'error'
);
return;
}
// ----------------------------------------------------------------

$this->toast(
message: __('errors.generic'),
type: 'error'
);
}

/**
* Extract the column name from the error message.
* @param string $message
* @return string|null
*/
protected function extractColumnFromMessage(string $message): ?string
{
if (preg_match("/Column '(.+?)' cannot be null/", $message, $matches)) {
return $matches[1];
}

return null;
}
}
10 changes: 10 additions & 0 deletions lang/en/errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'generic' => 'Something went wrong. Please try again or contact support.',
'database' => [
'generic' => 'There was a problem with the database. Please try again.',
'column_cannot_be_null' => "The ':column' field cannot be null.",
'missing_required_field' => 'A required field was not filled in.',
],
];
16 changes: 15 additions & 1 deletion lang/en/project/conducting.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,21 @@
<ul>
<li><b>Note:</b> If you want to conduct <b>"Peer Review"</b>, it is necessary to invite the researchers and add them to the project before importing the studies (papers).</li>
<li>To add researchers, navigate to <b>"My Projects->Team"</b></li>
</ul>'
</ul>
<br>
<b>CSV Format Guidelines:</b><br>
Your CSV file must include the following column headers:<br>
<ul>
<li>"<b>Item Title</b>" – used as the paper title</li>
<li>"<b>Authors</b>" – list of authors</li>
<li>"<b>Item DOI</b>" – Digital Object Identifier</li>
<li>"URL" – link to the paper</li>
<li>"Publication Year" – publication year</li>
<li>"Book Series Title" – optional book series name</li>
<li>"Journal Volume" – optional journal volume</li>
<li>"Publication Title" – optional journal or publication name</li>
</ul>
<b>Important:</b> If any of the fields in <b>bold</b> are missing or empty, the import will <b>not</b> occur.'
],
'table' => [
'database' => 'Database',
Expand Down
1 change: 1 addition & 0 deletions lang/en/project/planning.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@
],
'type' => [
'required' => 'The type field is required.',
'in' => 'Select a valid type.'
],
'logs' => [
'added' => 'Criteria added',
Expand Down
10 changes: 10 additions & 0 deletions lang/pt_BR/errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'generic' => 'Algo deu errado. Tente novamente ou entre em contato com o suporte.',
'database' => [
'generic' => 'Problemas com o banco de dados. Tente novamente.',
'column_cannot_be_null' => "O campo ':column' não pode ser nulo.",
'missing_required_field' => 'Um campo obrigatório não foi preenchido.',
],
];
16 changes: 15 additions & 1 deletion lang/pt_BR/project/conducting.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,21 @@
<ul>
<li><b>Obs.:</b> Se você deseja realizar <b>"Avaliação por Pares"</b>, é necessário convidar os pesquisadores e adicionar ao projeto antes de importar os estudos (papers)</li>
<li>Para adicionar pesquisadores, navegue até <b>"Meus Projetos->Colaboradores"</b></li>
</ul>'
</ul>
<br>
<b>Orientações para o formato CSV:</b><br>
O arquivo CSV deve conter os seguintes cabeçalhos de coluna:<br>
<ul>
<li>"<b>Item Title</b>" – usado como o título do estudo</li>
<li>"<b>Authors</b>" – lista de autores</li>
<li>"<b>Item DOI</b>" – identificador digital do objeto</li>
<li>"URL" – link opcional para o estudo</li>
<li>"Publication Year" – ano de publicação</li>
<li>"Book Series Title" – nome da série de livros</li>
<li>"Journal Volume" – volume do periódico</li>
<li>"Publication Title" – nome do periódico ou publicação</li>
</ul>
<b>Atenção:</b> Se algum dos campos em <b>negrito</b> estiver ausente ou vazio, a importação <b>não será realizada</b>.'
],
'table' => [
'database' => 'Base de dados',
Expand Down
1 change: 1 addition & 0 deletions lang/pt_BR/project/planning.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@
],
'type' => [
'required' => 'Selecionar um tipo é obrigatório.',
'in' => 'Selecione um tipo válido.',
],
'logs' => [
'added' => 'Critério adicionado',
Expand Down
Loading
Loading