Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #285 from CSCfi/CSCMETAX-419-add-inscheme-to-refdata
Browse files Browse the repository at this point in the history
Cscmetax 419 add inscheme to refdata
  • Loading branch information
junsk1 authored Jun 14, 2018
2 parents 1fb5cc4 + 03c19e4 commit b976c61
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 924 deletions.
52 changes: 11 additions & 41 deletions src/metax_api/api/rest/base/schemas/att_dataset_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#",
"title":"Metax Research Datasets",
"modified":"Wed, 30 May 2018 12:05:20 GMT",
"modified":"Mon, 11 Jun 2018 10:12:12 GMT",
"$schema":"http://json-schema.org/draft-04/schema#",
"type":"object",
"allOf":[
Expand Down Expand Up @@ -300,40 +300,10 @@
"$ref":"#/definitions/langString"
},
"in_scheme":{
"@id":"http://www.w3.org/2004/02/skos/core#inScheme",
"title":"Is in scheme",
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#inScheme",
"title":"In scheme",
"description":"Relates a resource (for example a concept) to a concept scheme in which it is included.",
"@type":"@id",
"type":"array",
"items":{
"type":"object",
"$ref":"#/definitions/ConceptScheme"
}
}
},
"required":[
"identifier"
]
},
"ConceptScheme":{
"title":"Concept Scheme",
"type":"object",
"@id":"http://www.w3.org/2004/02/skos/core#ConceptScheme",
"description":"A set of concepts, optionally including statements about semantic relationships between those concepts.",
"properties":{
"pref_label":{
"@id":"http://www.w3.org/2004/02/skos/core#prefLabel",
"title":"Preferred label",
"description":"The preferred lexical label for a resource, in a given language. A resource has no more than one value of skos:prefLabel per language tag, and no more than one value of skos:prefLabel without language tag. The range of skos:prefLabel is the class of RDF plain literals. skos:prefLabel, skos:altLabel and skos:hiddenLabel are pairwise\n disjoint properties.",
"@type":"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
"type":"object",
"$ref":"#/definitions/langString"
},
"identifier":{
"@id":"http://purl.org/dc/terms/identifier",
"title":"Identifier",
"description":"URI of the Concept Scheme",
"@type":"@id",
"@type":"http://www.w3.org/2001/XMLSchema#anyURI",
"type":"string",
"format":"uri"
}
Expand Down Expand Up @@ -837,8 +807,8 @@
}
},
"ResearchAgent":{
"type":"object",
"title":"Agent",
"type":"object",
"@id":"http://xmlns.com/foaf/0.1/Agent",
"oneOf":[
{"$ref": "#/definitions/Person"},
Expand Down Expand Up @@ -1397,12 +1367,12 @@
"$ref":"#/definitions/Concept"
},
"representation":{
"@id":"http://rdf-vocabulary.ddialliance.org/discovery#representation",
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#representation",
"title":"Representation",
"description":"Defines the possible values of a variable",
"@type":"@id",
"type":"object",
"$ref":"#/definitions/ConceptScheme"
"description":"Defines reference to a Concept Scheme that includes the possible values of a variable.",
"@type":"http://www.w3.org/2001/XMLSchema#anyURI",
"type":"string",
"format":"uri"
}
},
"required":[
Expand Down Expand Up @@ -1545,4 +1515,4 @@
}
}
}
}
}
48 changes: 9 additions & 39 deletions src/metax_api/api/rest/base/schemas/harvester_dataset_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#",
"title":"Metax Research Datasets",
"modified":"Wed, 30 May 2018 12:05:20 GMT",
"modified":"Mon, 11 Jun 2018 10:12:12 GMT",
"$schema":"http://json-schema.org/draft-04/schema#",
"type":"object",
"allOf":[
Expand Down Expand Up @@ -300,40 +300,10 @@
"$ref":"#/definitions/langString"
},
"in_scheme":{
"@id":"http://www.w3.org/2004/02/skos/core#inScheme",
"title":"Is in scheme",
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#inScheme",
"title":"In scheme",
"description":"Relates a resource (for example a concept) to a concept scheme in which it is included.",
"@type":"@id",
"type":"array",
"items":{
"type":"object",
"$ref":"#/definitions/ConceptScheme"
}
}
},
"required":[
"identifier"
]
},
"ConceptScheme":{
"title":"Concept Scheme",
"type":"object",
"@id":"http://www.w3.org/2004/02/skos/core#ConceptScheme",
"description":"A set of concepts, optionally including statements about semantic relationships between those concepts.",
"properties":{
"pref_label":{
"@id":"http://www.w3.org/2004/02/skos/core#prefLabel",
"title":"Preferred label",
"description":"The preferred lexical label for a resource, in a given language. A resource has no more than one value of skos:prefLabel per language tag, and no more than one value of skos:prefLabel without language tag. The range of skos:prefLabel is the class of RDF plain literals. skos:prefLabel, skos:altLabel and skos:hiddenLabel are pairwise\n disjoint properties.",
"@type":"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
"type":"object",
"$ref":"#/definitions/langString"
},
"identifier":{
"@id":"http://purl.org/dc/terms/identifier",
"title":"Identifier",
"description":"URI of the Concept Scheme",
"@type":"@id",
"@type":"http://www.w3.org/2001/XMLSchema#anyURI",
"type":"string",
"format":"uri"
}
Expand Down Expand Up @@ -1536,12 +1506,12 @@
"$ref":"#/definitions/Concept"
},
"representation":{
"@id":"http://rdf-vocabulary.ddialliance.org/discovery#representation",
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#representation",
"title":"Representation",
"description":"Defines the possible values of a variable",
"@type":"@id",
"type":"object",
"$ref":"#/definitions/ConceptScheme"
"description":"Defines reference to a Concept Scheme that includes the possible values of a variable.",
"@type":"http://www.w3.org/2001/XMLSchema#anyURI",
"type":"string",
"format":"uri"
}
},
"required":[
Expand Down
48 changes: 9 additions & 39 deletions src/metax_api/api/rest/base/schemas/ida_dataset_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#",
"title":"Metax Research Datasets",
"modified":"Wed, 30 May 2018 12:05:20 GMT",
"modified":"Mon, 11 Jun 2018 10:12:12 GMT",
"$schema":"http://json-schema.org/draft-04/schema#",
"type":"object",
"allOf":[
Expand Down Expand Up @@ -274,40 +274,10 @@
"$ref":"#/definitions/langString"
},
"in_scheme":{
"@id":"http://www.w3.org/2004/02/skos/core#inScheme",
"title":"Is in scheme",
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#inScheme",
"title":"In scheme",
"description":"Relates a resource (for example a concept) to a concept scheme in which it is included.",
"@type":"@id",
"type":"array",
"items":{
"type":"object",
"$ref":"#/definitions/ConceptScheme"
}
}
},
"required":[
"identifier"
]
},
"ConceptScheme":{
"title":"Concept Scheme",
"type":"object",
"@id":"http://www.w3.org/2004/02/skos/core#ConceptScheme",
"description":"A set of concepts, optionally including statements about semantic relationships between those concepts.",
"properties":{
"pref_label":{
"@id":"http://www.w3.org/2004/02/skos/core#prefLabel",
"title":"Preferred label",
"description":"The preferred lexical label for a resource, in a given language. A resource has no more than one value of skos:prefLabel per language tag, and no more than one value of skos:prefLabel without language tag. The range of skos:prefLabel is the class of RDF plain literals. skos:prefLabel, skos:altLabel and skos:hiddenLabel are pairwise\n disjoint properties.",
"@type":"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",
"type":"object",
"$ref":"#/definitions/langString"
},
"identifier":{
"@id":"http://purl.org/dc/terms/identifier",
"title":"Identifier",
"description":"URI of the Concept Scheme",
"@type":"@id",
"@type":"http://www.w3.org/2001/XMLSchema#anyURI",
"type":"string",
"format":"uri"
}
Expand Down Expand Up @@ -1456,12 +1426,12 @@
"$ref":"#/definitions/Concept"
},
"representation":{
"@id":"http://rdf-vocabulary.ddialliance.org/discovery#representation",
"@id":"http://uri.suomi.fi/datamodel/ns/mrd#representation",
"title":"Representation",
"description":"Defines the possible values of a variable",
"@type":"@id",
"type":"object",
"$ref":"#/definitions/ConceptScheme"
"description":"Defines reference to a Concept Scheme that includes the possible values of a variable.",
"@type":"http://www.w3.org/2001/XMLSchema#anyURI",
"type":"string",
"format":"uri"
}
},
"required":[
Expand Down
6 changes: 3 additions & 3 deletions src/metax_api/services/data_catalog_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def validate_reference_data(cls, data_catalog, cache):
if access_rights:
for rights_statement_type in access_rights.get('access_type', []):
ref_entry = cls.check_ref_data(refdata['access_type'], rights_statement_type['identifier'],
'data_catalog_json.rights.access_type.identifier', errors)
'data_catalog_json.access_rights.access_type.identifier', errors)
if ref_entry:
cls.populate_from_ref_data(ref_entry, rights_statement_type, label_field='pref_label')

for license in access_rights.get('license', []):
license_url = license.get('license', None)

ref_entry = cls.check_ref_data(refdata['license'], license['identifier'],
'data_catalog_json.rights.license.identifier', errors)
'data_catalog_json.access_rights.license.identifier', errors)
if ref_entry:
cls.populate_from_ref_data(ref_entry, license, label_field='title')

Expand All @@ -67,7 +67,7 @@ def validate_reference_data(cls, data_catalog, cache):
if 'has_rights_related_agent' in access_rights:
for agent in access_rights.get('has_rights_related_agent', []):
cls.process_org_obj_against_ref_data(orgdata['organization'], agent,
'data_catalog_json.rights.has_rights_related_agent')
'data_catalog_json.access_rights.has_rights_related_agent')

publisher = data_catalog.get('publisher', None)
if publisher:
Expand Down
2 changes: 2 additions & 0 deletions src/metax_api/services/reference_data_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def populate_from_ref_data(ref_entry, obj, uri_field='identifier', label_field=N
obj[uri_field] = ref_entry['uri']
if label_field and 'label' in ref_entry:
obj[label_field] = ref_entry['label']
if 'scheme' in ref_entry:
obj['in_scheme'] = ref_entry['scheme']

def _raise_reference_data_reload_error(error):
"""
Expand Down
28 changes: 26 additions & 2 deletions src/metax_api/tests/api/rest/base/views/datasets/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,13 +956,14 @@ def test_create_catalog_record_populate_fields_from_reference_data(self):
'code': entry['code'],
'uri': entry['uri'],
'label': entry.get('label', None),
'wkt': entry.get('wkt', None)
'wkt': entry.get('wkt', None),
'scheme': entry.get('scheme', None)
}

refs['organization'] = {
'uri': orgdata['organization'][0]['uri'],
'code': orgdata['organization'][0]['code'],
'label': orgdata['organization'][0]['label'],
'label': orgdata['organization'][0]['label']
}

# replace the relations with objects that have only the identifier set with code as value,
Expand Down Expand Up @@ -1074,6 +1075,29 @@ def _assert_uri_copied_to_identifier(self, refs, new_rd):
self.assertEqual(refs['lifecycle_event']['uri'], new_rd['provenance'][0]['lifecycle_event']['identifier'])
self.assertEqual(refs['preservation_event']['uri'], new_rd['provenance'][1]['preservation_event']['identifier'])

def _assert_scheme_copied_to_in_scheme(self, refs, new_rd):
self.assertEqual(refs['keyword']['scheme'], new_rd['theme'][0]['in_scheme'])
self.assertEqual(refs['field_of_science']['scheme'], new_rd['field_of_science'][0]['in_scheme'])
self.assertEqual(refs['language']['scheme'], new_rd['language'][0]['in_scheme'])
self.assertEqual(refs['access_type']['scheme'], new_rd['access_rights']['access_type']['in_scheme'])
self.assertEqual(refs['restriction_grounds']['scheme'],
new_rd['access_rights']['restriction_grounds']['in_scheme'])
self.assertEqual(refs['license']['scheme'], new_rd['access_rights']['license'][0]['in_scheme'])
self.assertEqual(refs['identifier_type']['scheme'], new_rd['other_identifier'][0]['type']['in_scheme'])
self.assertEqual(refs['location']['scheme'], new_rd['spatial'][0]['place_uri']['in_scheme'])
self.assertEqual(refs['file_type']['scheme'], new_rd['files'][0]['file_type']['in_scheme'])
self.assertEqual(refs['use_category']['scheme'], new_rd['files'][0]['use_category']['in_scheme'])

self.assertEqual(refs['use_category']['scheme'], new_rd['directories'][0]['use_category']['in_scheme'])
self.assertEqual(refs['research_infra']['scheme'], new_rd['infrastructure'][0]['in_scheme'])
self.assertEqual(refs['contributor_role']['scheme'], new_rd['creator'][0]['contributor_role']['in_scheme'])
self.assertEqual(refs['funder_type']['scheme'], new_rd['is_output_of'][0]['funder_type']['in_scheme'])
self.assertEqual(refs['relation_type']['scheme'], new_rd['relation'][0]['relation_type']['in_scheme'])
self.assertEqual(refs['resource_type']['scheme'], new_rd['relation'][0]['entity']['type']['in_scheme'])
self.assertEqual(refs['lifecycle_event']['scheme'], new_rd['provenance'][0]['lifecycle_event']['in_scheme'])
self.assertEqual(refs['preservation_event']['scheme'],
new_rd['provenance'][1]['preservation_event']['in_scheme'])

def _assert_label_copied_to_pref_label(self, refs, new_rd):
self.assertEqual(refs['keyword']['label'], new_rd['theme'][0].get('pref_label', None))
self.assertEqual(refs['field_of_science']['label'], new_rd['field_of_science'][0].get('pref_label', None))
Expand Down
Loading

0 comments on commit b976c61

Please sign in to comment.