Skip to content

Commit

Permalink
can possibly create
Browse files Browse the repository at this point in the history
  • Loading branch information
Alzpeta committed Sep 20, 2024
1 parent 1d53674 commit cd57a57
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
16 changes: 8 additions & 8 deletions oarepo_doi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ def edit_doi(service, record, event=None):
"""edit existing draft"""

mapping = obj_or_import_string(service.mapping[record.schema])()
errors = mapping.metadata_check(record)
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} "
)

doi_value = mapping.get_doi(record)

if doi_value:
errors = mapping.metadata_check(record)
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} "
)
if not service.url.endswith("/"):
url = service.url + "/"
else:
Expand Down
9 changes: 9 additions & 0 deletions oarepo_doi/types/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ def can_create(self, identity, data, receiver, topic, creator, *args, **kwargs):
message=f"Could not assigned doi due to validation error: {errors} "
)
super().can_create(identity, data, receiver, topic, creator, *args, **kwargs)

def can_possibly_create(self, identity, record , *args, **kwargs):
mapping_file = current_app.config.get("DATACITE_MAPPING")
mapping = obj_or_import_string(mapping_file[record.schema])()
doi_value = mapping.get_doi(record)
if doi_value:
return False
else:
return super().can_possibly_create(identity, record, *args, **kwargs)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-doi
version = 1.0.8
version = 1.0.9
description =
authors = Alzbeta Pokorna <[email protected]>
readme = README.md
Expand Down

0 comments on commit cd57a57

Please sign in to comment.