-
Notifications
You must be signed in to change notification settings - Fork 13
/
epic.py
56 lines (38 loc) · 1.65 KB
/
epic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Functions for communicating with EPIC and some utilities."""
__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__license__ = 'GPLv3, see LICENSE'
import uuid
from typing import Dict
import publication
from util import *
__all__ = ['rule_generate_uuid']
def generate_uuid(ctx: rule.Context) -> str:
"""Generate random ID for DOI."""
randomuuid = str(uuid.uuid4())
return randomuuid.upper()
rule_generate_uuid = rule.make(inputs=[], outputs=[0])(generate_uuid)
def register_epic_pid(ctx: rule.Context, target: str) -> Dict:
"""Create and try to register an EPIC PID.
:param ctx: Combined type of a callback and rei struct
:param target: Target to register EPIC PID on
:return: Dict with url, PID and http status.
"""
config = publication.get_publication_config(ctx)
host = config['davrodsVHost']
parts = target.split('/')
subpath = '/'.join(parts[2:]) # only user part without /tempZone/home
url = "https://" + host + "/" + subpath
pid = generate_uuid(ctx)
ret = msi.register_epic_pid(ctx, url, pid, '')
return {'url': ret['arguments'][0],
'pid': ret['arguments'][1],
'httpCode': ret['arguments'][2]}
def save_epic_pid(ctx: rule.Context, target: str, url: str, pid: str) -> None:
"""Save persistent EPIC ID.
:param ctx: Combined type of a callback and rei struct
:param target: Target to register EPIC PID on
:param url: URL of EPIC PID
:param pid: PID of EPIC PID
"""
avu.set_on_coll(ctx, target, constants.UUORGMETADATAPREFIX + "epic_url", url)
avu.set_on_coll(ctx, target, constants.UUORGMETADATAPREFIX + "epic_pid", pid)