Skip to content

Commit

Permalink
register resource as full url and bump to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
blankdots committed Mar 5, 2021
1 parent 5f113a7 commit e9eadef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sda_orchestrator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""SDA Orchestrator service for coordinating messages and mapping file id to dataset id."""

__title__ = "sda_orchestrator"
__version__ = "0.50"
__version__ = "0.6.0"
__author__ = "NeIC System Developers"
4 changes: 2 additions & 2 deletions sda_orchestrator/complete_consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ async def _process_datasetID(self, user: str, filepath: str) -> str:
doi_obj = await doi_handler.create_draft_doi(user, filepath)
LOG.info(f"Registered dataset {doi_obj}.")
if doi_obj:
await rems.register_resource(doi_obj["fullDOI"])
await rems.register_resource(doi_obj["dataset"])
else:
LOG.error("Registering a DOI was not possible.")
raise Exception("Registering a DOI was not possible.")

datasetID = doi_obj["fullDOI"]
datasetID = doi_obj["dataset"]
await doi_handler.set_doi_state("publish", doi_obj["suffix"])
else:
datasetID = generate_dataset_id(user, filepath)
Expand Down
5 changes: 3 additions & 2 deletions sda_orchestrator/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
}
],
"resourceURL": "http://data-access.sd.neic.no",
"titlePrefix": "Resource"
"titlePrefix": "Resource",
"url": "https://doi.org"
}
}
}
23 changes: 15 additions & 8 deletions sda_orchestrator/utils/id_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def generate_dataset_id(user: str, inbox_path: str, ns: Union[str, None] = None) -> str:
"""Map accession ID to dataset.
"""Generate accession ID for dataset.
Generate dataset id based on folder or user.
We keep the email domain as users might have same name on different domains
Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self) -> None:
self.doi_api = environ.get("DOI_API", "")
self.doi_user = environ.get("DOI_USER", "")
self.doi_key = environ.get("DOI_KEY", "")
self.ns_url = f"https://doi.org/{self.doi_prefix}"
self.ns_url = f"{CONFIG_INFO['datacite']['url'].rstrip('/')}/{self.doi_prefix}"

async def create_draft_doi(self, user: str, inbox_path: str) -> Union[Dict, None]:
"""Create an auto-generated draft DOI.
Expand All @@ -93,11 +93,14 @@ async def create_draft_doi(self, user: str, inbox_path: str) -> Union[Dict, None
doi_data = None
if response.status_code == 201:
draft_resp = response.json()
_doi = draft_resp["data"]["attributes"]["doi"]
_suffix = draft_resp["data"]["attributes"]["suffix"]
LOG.debug(f"DOI draft created and response was: {draft_resp}")
LOG.info(f"DOI draft created with doi: {draft_resp['data']['attributes']['doi']}.")
LOG.info(f"DOI draft created with doi: {_doi}.")
doi_data = {
"suffix": draft_resp["data"]["attributes"]["suffix"],
"fullDOI": draft_resp["data"]["attributes"]["doi"],
"suffix": _suffix,
"fullDOI": _doi,
"dataset": f"{self.ns_url}/{_suffix.lower()}",
}
else:
LOG.error(f"DOI API create draft request failed with code: {response.status_code}")
Expand Down Expand Up @@ -148,11 +151,14 @@ async def set_doi_state(self, state: str, doi_suffix: str) -> Union[Dict, None]:
doi_data = None
if response.status_code == 200:
publish_resp = response.json()
_doi = publish_resp["data"]["attributes"]["doi"]
_suffix = publish_resp["data"]["attributes"]["suffix"]
LOG.debug(f"DOI created with state: {state} and response was: {publish_resp}")
LOG.info(f"DOI created with doi: {publish_resp['data']['attributes']['doi']} with state {state}.")
LOG.info(f"DOI created: {_doi} with state: {state}.")
doi_data = {
"suffix": publish_resp["data"]["attributes"]["suffix"],
"fullDOI": publish_resp["data"]["attributes"]["doi"],
"suffix": _suffix,
"fullDOI": _doi,
"dataset": f"{self.ns_url}/{_suffix.lower()}",
}
else:
LOG.error(f"DOI API request failed with code: {response.status_code}")
Expand All @@ -178,6 +184,7 @@ def _check_errors(self, response: Response, doi_suffix: str) -> Union[Dict, None
doi_data = {
"suffix": doi_suffix,
"fullDOI": f"{self.doi_prefix}/{doi_suffix}",
"dataset": f"{self.ns_url}/{doi_suffix.lower()}",
}
else:
LOG.error(f"Error occurred: {errors_resp}")
Expand Down

0 comments on commit e9eadef

Please sign in to comment.