class _PIDMSClient:
def __init__(self):
self.pid_ms_url = f"https://{settings.PID_MS_BASEURL}"
self.pid_ms_apikey = settings.PID_MS_APIKEY
self.etsin_url = settings.ETSIN_URL
def create_urn(self, dataset_id):
payload = {
"url": f"https://{self.etsin_url}/dataset/{dataset_id}",
"type": "URN",
"persist": 0,
}
headers = {"apikey": self.pid_ms_apikey}
try:
response = requests.post(
f"https://{settings.PID_MS_BASEURL}/v1/pid", json=payload, headers=headers
)
response.raise_for_status()
return response.text
except Exception as e:
_logger.error(f"Exception in PIDMSClient: {e}")
raise ServiceUnavailableError
def create_doi(self, dataset_id):
from apps.common.datacitedata import Datacitedata
payload = Datacitedata().get_datacite_json(dataset_id)
payload["data"]["attributes"]["event"] = "publish"
payload["data"]["attributes"]["url"] = f"https://{self.etsin_url}/dataset/{dataset_id}"
headers = {"apikey": self.pid_ms_apikey, "Content-Type": "application/json"}
try:
response = requests.post(
f"https://{settings.PID_MS_BASEURL}/v1/pid/doi", json=payload, headers=headers
)
response.raise_for_status()
return response.text
except Exception as e:
_logger.error(f"Exception in PIDMSClient: {e}")
raise ServiceUnavailableError