Skip to content

Commit

Permalink
Refatora upload parte 3 - agrupa em uma tarefa as validações: assets,…
Browse files Browse the repository at this point in the history
… renditions, conteúdo do XML (scieloorg#398)

* Cria a tarefa upload.tasks.task_validate_original_zip_file

* Cria upload.tasks.task_validate_xml_content

* Cria upload.xml_validation

* Anota TODO para inserir parâmetros para as validações

* Atualiza packtools para a versão 3.3.4 que contempla mais validações

* Remove package.tasks

* Adiciona importações faltantes
  • Loading branch information
robertatakenaka committed Mar 31, 2024
1 parent ebb61b5 commit bdcfbf6
Show file tree
Hide file tree
Showing 2 changed files with 651 additions and 0 deletions.
74 changes: 74 additions & 0 deletions upload/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from packtools.sps.validation import article as sps_validation_article
from packtools.sps.validation import journal as sps_validation_journal
from packtools.validator import ValidationReportXML
from packtools.sps.pid_provider.xml_sps_lib import XMLWithPre

from article.choices import AS_CHANGE_SUBMITTED
from article.controller import create_article_from_etree, update_article
Expand All @@ -22,6 +23,7 @@
from .utils import file_utils, package_utils, xml_utils
from upload.models import Package

from upload.xml_validation import validate_xml_content, add_app_data, add_sps_data, add_journal_data

User = get_user_model()

Expand Down Expand Up @@ -539,3 +541,75 @@ def _get_user(request, user_id):
def task_request_pid_for_accepted_packages(self, user_id):
user = _get_user(self.request, user_id)
controller.request_pid_for_accepted_packages(user)


@celery_app.task(bind=True)
def task_validate_original_zip_file(self, package_id, file_path, journal_id, issue_id, article_id):

for xml_with_pre in XMLWithPre.create(file_path=file_path):
xml_path = xml_with_pre.filename
break

if xml_path:
# Aciona validação de Assets
task_validate_assets.apply_async(
kwargs={
"file_path": file_path,
"xml_path": xml_path,
"package_id": package_id,
},
)

# Aciona validação de Renditions
task_validate_renditions.apply_async(
kwargs={
"file_path": file_path,
"xml_path": xml_path,
"package_id": package_id,
},
)

# Aciona validacao do conteudo do XML
task_validate_xml_content.apply_async(
kwargs={
"file_path": file_path,
"xml_path": xml_path,
"package_id": package_id,
"journal_id": journal_id,
"issue_id": issue_id,
"article_id": article_id,
},
)


@celery_app.task(bind=True)
def task_validate_xml_content(self, file_path, xml_path, package_id, journal_id, issue_id, article_id):
# VE_BIBLIOMETRICS_DATA_ERROR = "bibliometrics-data-error"
# VE_SERVICES_DATA_ERROR = "services-data-error"
# VE_DATA_CONSISTENCY_ERROR = "data-consistency-error"
# VE_CRITERIA_ISSUES_ERROR = "criteria-issues-error"

# TODO completar data
data = {}
# add_app_data(data, app_data)
# add_journal_data(data, journal, issue)
# add_sps_data(data, sps_data)

package = Package.objects.get(pk=package_id)
for xml_with_pre in XMLWithPre.create(file_path=file_path):
results = validate_xml_content(xml_with_pre.sps_pkg_name, xml_with_pre.xmltree, data)

for result in results:
# ['xpath', 'advice', 'title', 'expected_value', 'got_value', 'message', 'validation_type', 'response']
if not result["response"] == "ERROR":
continue

message = result["message"]
advice = result["advice"] or ''
message = ". ".join(_(message), _(advice))
package._add_validation_result(
error_category=choices.VE_DATA_CONSISTENCY_ERROR,
status=choices.VS_DISAPPROVED,
message=message,
data=result,
)
Loading

0 comments on commit bdcfbf6

Please sign in to comment.