Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refatora upload parte 3 - agrupa em uma tarefa as validações: assets, renditions, conteúdo do XML #398

Merged
Merged
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ minio==7.2
# Upload
# ------------------------------------------------------------------------------
lxml==4.9.3 # https://github.com/lxml/lxml
-e git+https://github.com/scieloorg/[email protected].1#egg=packtools
-e git+https://github.com/scieloorg/[email protected].4#egg=packtools
-e git+https://github.com/scieloorg/scielo_scholarly_data#egg=scielo_scholarly_data

# DSM Publication
Expand Down
2 changes: 1 addition & 1 deletion upload/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, timedelta
from datetime import date, timedelta, datetime

from django.contrib.auth import get_user_model
from django.db import models
Expand Down
76 changes: 75 additions & 1 deletion 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 @@ -485,7 +487,7 @@ def task_validate_content_xml(file_path, xml_path, package_id):
vr.update(
error_category=choices.VE_XML_FORMAT_ERROR,
message=_(message),
data=data,
data=json_validations,
status=status,
)

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