Skip to content

Commit 5e0147b

Browse files
committed
fix: make datasets.Creator a subclass of Person
addresses #793
1 parent cfda873 commit 5e0147b

File tree

2 files changed

+20
-46
lines changed

2 files changed

+20
-46
lines changed

renku/core/models/datasets.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from attr.validators import instance_of
3232

3333
from renku.core import errors
34+
from renku.core.models.provenance.agents import Person
3435
from renku.core.models.provenance.entities import Entity
3536
from renku.core.utils.datetime8601 import parse_date
3637
from renku.core.utils.doi import extract_doi, is_doi
@@ -53,35 +54,17 @@ def _extract_doi(value):
5354
return value
5455

5556

56-
@jsonld.s(
57-
type='schema:Person',
58-
context={'schema': 'http://schema.org/'},
59-
slots=True,
60-
)
61-
class Creator(object):
57+
class Creator(Person):
6258
"""Represent the creator of a resource."""
6359

64-
client = attr.ib(default=None, kw_only=True)
65-
6660
affiliation = jsonld.ib(
6761
default=None, kw_only=True, context='schema:affiliation'
6862
)
6963

70-
email = jsonld.ib(default=None, kw_only=True, context='schema:email')
71-
7264
alternate_name = jsonld.ib(
7365
default=None, kw_only=True, context='schema:alternateName'
7466
)
7567

76-
name = jsonld.ib(
77-
default=None,
78-
kw_only=True,
79-
validator=instance_of(str),
80-
context='schema:name'
81-
)
82-
83-
_id = jsonld.ib(kw_only=True, context='@id')
84-
8568
@property
8669
def short_name(self):
8770
"""Gives full name in short form."""
@@ -95,14 +78,6 @@ def short_name(self):
9578

9679
return '{0}.{1}'.format('.'.join(initials), last_name)
9780

98-
@email.validator
99-
def check_email(self, attribute, value):
100-
"""Check that the email is valid."""
101-
if self.email and not (
102-
isinstance(value, str) and re.match(r'[^@]+@[^@]+\.[^@]+', value)
103-
):
104-
raise ValueError('Email address is invalid.')
105-
10681
@classmethod
10782
def from_git(cls, git):
10883
"""Create an instance from a Git repo."""
@@ -129,18 +104,6 @@ def from_git(cls, git):
129104

130105
return cls(name=name, email=email)
131106

132-
@classmethod
133-
def from_commit(cls, commit):
134-
"""Create an instance from a Git commit."""
135-
return cls(name=commit.author.name, email=commit.author.email)
136-
137-
@_id.default
138-
def default_id(self):
139-
"""Set the default id."""
140-
if self.email:
141-
return 'mailto:{email}'.format(email=self.email)
142-
return '_:{}'.format(str(uuid.uuid4()))
143-
144107
def __attrs_post_init__(self):
145108
"""Finish object initialization."""
146109
# handle the case where ids were improperly set

renku/core/models/provenance/agents.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""Represent provenance agents."""
1919

2020
import re
21+
import uuid
2122

2223
from renku.core.models import jsonld as jsonld
2324
from renku.version import __version__, version_url
@@ -38,21 +39,31 @@
3839
class Person:
3940
"""Represent a person."""
4041

41-
name = jsonld.ib(context='rdfs:label')
42-
email = jsonld.ib(context='schema:email')
42+
name = jsonld.ib(context='schema:name')
43+
email = jsonld.ib(context='schema:email', default=None, kw_only=True)
44+
label = jsonld.ib(context='rdfs:label', kw_only=True)
4345

44-
_id = jsonld.ib(context='@id', init=False, kw_only=True)
46+
_id = jsonld.ib(context='@id', kw_only=True)
4547

4648
@_id.default
4749
def default_id(self):
48-
"""Configure calculated ID."""
49-
return 'mailto:{0}'.format(self.email)
50+
"""Set the default id."""
51+
if self.email:
52+
return 'mailto:{email}'.format(email=self.email)
53+
return '_:{}'.format(str(uuid.uuid4()))
5054

5155
@email.validator
5256
def check_email(self, attribute, value):
5357
"""Check that the email is valid."""
54-
if not (isinstance(value, str) and re.match(r'[^@]+@[^@]+', value)):
55-
raise ValueError('Email address "{0}" is invalid.'.format(value))
58+
if self.email and not (
59+
isinstance(value, str) and re.match(r'[^@]+@[^@]+\.[^@]+', value)
60+
):
61+
raise ValueError('Email address is invalid.')
62+
63+
@label.default
64+
def default_label(self):
65+
"""Set the default label."""
66+
return self.name
5667

5768
@classmethod
5869
def from_commit(cls, commit):

0 commit comments

Comments
 (0)