Skip to content

Commit

Permalink
doi validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Alzpeta committed Oct 2, 2024
1 parent 437dc13 commit 3cd7ed8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 3 additions & 2 deletions oarepo_doi/actions/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from invenio_base.utils import obj_or_import_string
from marshmallow.exceptions import ValidationError
from oarepo_requests.actions.generic import OARepoAcceptAction, OARepoSubmitAction
from ..exceptions import DoiValidationError

from oarepo_doi.api import community_slug_for_credentials, create_doi

Expand Down Expand Up @@ -65,8 +66,8 @@ def execute(self, identity, uow, *args, **kwargs):
mapping = obj_or_import_string(self.mapping[topic.schema])()
errors = mapping.metadata_check(topic)
if len(errors) > 0:
raise ValidationError(
message=f"Could not assigned doi due to validation error: {errors} "
raise DoiValidationError(
data=errors
)

super().execute(identity, uow)
10 changes: 5 additions & 5 deletions oarepo_doi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from invenio_search.engine import dsl
from marshmallow.exceptions import ValidationError
from oarepo_runtime.datastreams.utils import get_record_service_for_record

from .exceptions import DoiValidationError

def create_doi(service, record, data, event=None):
"""if event = None, doi will be created as a draft."""
Expand All @@ -19,8 +19,8 @@ def create_doi(service, record, data, event=None):
record["links"] = record_service.links_item_tpl.expand(system_identity, record)

if len(errors) > 0 and event:
raise ValidationError(
message=f"Could not assigned doi due to validation error: {errors} "
raise DoiValidationError(
data=errors
)
request_metadata = {"data": {"type": "dois", "attributes": {}}}

Expand Down Expand Up @@ -63,8 +63,8 @@ def edit_doi(service, record, event=None):
record_service = get_record_service_for_record(record)
record["links"] = record_service.links_item_tpl.expand(system_identity, record)
if len(errors) > 0 and event:
raise ValidationError(
message=f"Could not assigned doi due to validation error: {errors} "
raise DoiValidationError(
data=errors
)
if not service.url.endswith("/"):
url = service.url + "/"
Expand Down
8 changes: 8 additions & 0 deletions oarepo_doi/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from marshmallow.exceptions import ValidationError

class DoiValidationError(ValidationError):

def validation_error_to_list_errors(exception):

errors = exception.data
return errors
6 changes: 3 additions & 3 deletions oarepo_doi/types/doi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import current_app
from invenio_base.utils import obj_or_import_string
from marshmallow.exceptions import ValidationError
from ..exceptions import DoiValidationError
from oarepo_requests.types.generic import NonDuplicableOARepoRequestType
from oarepo_requests.types.ref_types import ModelRefTypes
from oarepo_runtime.i18n import lazy_gettext as _
Expand Down Expand Up @@ -29,8 +29,8 @@ def can_create(self, identity, data, receiver, topic, creator, *args, **kwargs):
mapping = obj_or_import_string(mapping_file[topic.schema])()
errors = mapping.metadata_check(topic)
if len(errors) > 0:
raise ValidationError(
message=f"Could not assigned doi due to validation error: {errors} "
raise DoiValidationError(
data=errors
)
super().can_create(identity, data, receiver, topic, creator, *args, **kwargs)

Expand Down

0 comments on commit 3cd7ed8

Please sign in to comment.