Skip to content

Commit

Permalink
adding validation for affiliation identifier
Browse files Browse the repository at this point in the history
adding validation for affiliation identifier
  • Loading branch information
rushirajnenuji committed Dec 16, 2021
1 parent d33a857 commit 9eab353
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
7 changes: 2 additions & 5 deletions impl/datacite_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ def _id_type(str):
"familyName",
"nameIdentifier",
"affiliation",
"affiliationIdentifier",
"affiliationIdentifierScheme",
"affiliationIdentifierSchemeURI",
"dates",
"date",
"language",
Expand Down Expand Up @@ -395,7 +392,7 @@ def temp_mockFormElements():
u'contributors-contributor-0-affiliation': u'',
u'contributors-contributor-0-affiliationIdentifier': u'',
u'contributors-contributor-0-affiliationIdentifierScheme': u'',
u'contributors-contributor-0-affiliationIdentifierSchemeURI': u'',
u'contributors-contributor-0-schemeURI': u'',
u'contributors-contributor-0-contributorName': u'',
u'contributors-contributor-0-contributorType': u'',
u'contributors-contributor-0-familyName': u'',
Expand All @@ -409,7 +406,7 @@ def temp_mockFormElements():
u'creators-creator-0-affiliation': u'',
u'creators-creator-0-affiliationIdentifier': u'',
u'creators-creator-0-affiliationIdentifierScheme': u'',
u'creators-creator-0-affiliationIdentifierSchemeURI': u'',
u'creators-creator-0-schemeURI': u'',
u'creators-creator-0-creatorName': u'test',
u'creators-creator-0-familyName': u'',
u'creators-creator-0-givenName': u'',
Expand Down
54 changes: 44 additions & 10 deletions impl/form_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ def _validateNameIdGrouping(suffix, ni, ni_s, ni_s_uri):
return err


def _validateAffiliationIdGrouping(caff, caffId, caffId_s, caffId_s_uri):
err={}
if caff and not caffId:
err['affiliation-affiliationIdentifier'] = _(
"An Affiliation Identifier must be filled in if you specify an Affiliation."
)
if caff and caffId and not caffId_s:
err['affiliation-affiliationIdentifierScheme'] = _(
"An Affiliation Identifier Scheme must be filled in if you specify an Affiliation Identifier."
)
if caff and caffId and caffId_s and not caffId_s_uri:
err['affiliation-schemeURI'] = _(
"An Affiliation Identifier Scheme URI must be filled in if you specify an Affiliation Identifier."
)
if caffId or caffId_s or caffId_s_uri:
if not caff:
err['affiliation'] = _(
"An Affiliation must be filled in if you specify an Affiliation Identifier / Affiliation Identifier Scheme "
)
return err


def _validate_geolong(n):
m = re.match(REGEX_GEOPOINT, n)
if not m or float(n) < -180 or float(n) > 180:
Expand Down Expand Up @@ -422,13 +444,13 @@ def _construct_form(self, i, **kwargs):
form.fields["affiliation"] = forms.CharField(
required=False, label=_("Affiliation")
)
form.fields["affiliationIdentifier"] = forms.CharField(
form.fields["affiliation-affiliationIdentifier"] = forms.CharField(
required=False, label=_("Affiliation Identifier")
)
form.fields["affiliationIdentifierScheme"] = forms.CharField(
form.fields["affiliation-affiliationIdentifierScheme"] = forms.CharField(
required=False, label=_("Affiliation Identifier Scheme")
)
form.fields["affiliationIdentifierSchemeURI"] = forms.CharField(
form.fields["affiliation-schemeURI"] = forms.CharField(
required=False, label=_("Affiliation Identifier Scheme URI")
)
return form
Expand Down Expand Up @@ -469,6 +491,10 @@ def __init__(self, *args, **kwargs):

def clean(self):
cleaned_data = super(CreatorForm, self).clean()
caff = cleaned_data.get("affiliation")
caffId = cleaned_data.get("affiliation-affiliationIdentifier")
caffId_s = cleaned_data.get("affiliation-affiliationIdentifierScheme")
caffId_s_uri = cleaned_data.get("affiliation-schemeURI")
errs = {}
for i in range(0, len(self.fields) / 3 - 1):
ni = cleaned_data.get(NAME_ID[0].format(str(i)))
Expand All @@ -477,6 +503,10 @@ def clean(self):
err = _validateNameIdGrouping(i, ni, ni_s, ni_s_uri)
if err:
errs.update(err.items())
if caff or caffId or caffId_s or caffId_s_uri:
err = _validateAffiliationIdGrouping(caff, caffId, caffId_s, caffId_s_uri)
if err:
errs.update(err.items())
if errs:
raise ValidationError(errs)
return cleaned_data
Expand Down Expand Up @@ -642,22 +672,26 @@ def clean(self):
cname = cleaned_data.get("contributorName")
cfname = cleaned_data.get("familyName")
cgname = cleaned_data.get("givenName")
err1, err2 = {}, {}
caff = cleaned_data.get("affiliation")
caffId = cleaned_data.get("affiliation-affiliationIdentifier")
caffId_s = cleaned_data.get("affiliation-affiliationIdentifierScheme")
caffId_s_uri = cleaned_data.get("affiliation-schemeURI")
err1, err2, err3 = {}, {}, {}
for i in range(0, len(self.fields) / 3 - 1):
ni = cleaned_data.get(NAME_ID[0].format(str(i)))
ni_s = cleaned_data.get(NAME_ID_SCHEME[0].format(str(i)))
ni_s_uri = cleaned_data.get(NAME_ID_SCHEME_URI[0].format(str(i)))
caff = cleaned_data.get("affiliation")
caffId = cleaned_data.get("affiliationIdentifier")
caffId_s = cleaned_data.get("affiliationIdentifierScheme")
caffId_s_uri = cleaned_data.get("affiliationIdentifierSchemeURI")
""" Use of contributor element requires name and type be populated """
if ctype or cname or cfname or cgname or caff or caffId or caffId_s or caffId_s_uri or ni or ni_s or ni_s_uri:
if ctype or cname or cfname or cgname or ni or ni_s or ni_s_uri:
err1 = _gatherContribErr1(err1, ctype, cname)
err = _validateNameIdGrouping(i, ni, ni_s, ni_s_uri)
if err:
err2.update(err.items())
errs = dict(err1.items() + err2.items())
if caff or caffId or caffId_s or caffId_s_uri:
err = _validateAffiliationIdGrouping(caff, caffId, caffId_s, caffId_s_uri)
if err:
err3.update(err.items())
errs = dict(err1.items() + err2.items() + err3.items())
if errs:
raise ValidationError(errs)
return cleaned_data
Expand Down

0 comments on commit 9eab353

Please sign in to comment.