Skip to content

Commit

Permalink
Merge pull request #153 from michamos/acquisition_sources
Browse files Browse the repository at this point in the history
schemas: promote acquisition_source to array
  • Loading branch information
michamos authored Jun 13, 2017
2 parents d9509d9 + 670bc3e commit 0bc9bc1
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 40 deletions.
20 changes: 16 additions & 4 deletions inspire_schemas/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, source, record=None):
def _append_to(self, field, element):
"""Append the ``element`` to the ``field`` of the record.
This method is smart: it does nothing if ``field`` is empty and
This method is smart: it does nothing if ``element`` is empty and
creates ``field`` if it does not exit yet.
:param field: the name of the field of the record to append to
Expand All @@ -119,6 +119,20 @@ def _append_to(self, field, element):
self.record.setdefault(field, [])
self.record.get(field).append(element)

def _prepend_to(self, field, element):
"""Prepend the ``element`` to the ``field`` of the record.
This method is smart: it does nothing if ``element`` is empty and
creates ``field`` if it does not exit yet.
:param field: the name of the field of the record to prepend to
:type field: string
:param element: the element to prepend
"""
if element not in EMPTIES:
self.record.setdefault(field, [])
self.record.get(field).insert(0, element)

def __str__(self):
"""Print the current record."""
return str(self.record)
Expand Down Expand Up @@ -651,8 +665,6 @@ def add_acquisition_source(
warnings.warn("Use 'datetime', not 'date'", DeprecationWarning)
datetime = date

self.record.setdefault('acquisition_source', {})

acquisition_source = {}

acquisition_source['submission_number'] = str(submission_number)
Expand All @@ -661,7 +673,7 @@ def add_acquisition_source(
if locals()[key] is not None:
acquisition_source[key] = locals()[key]

self.record['acquisition_source'] = acquisition_source
self._prepend_to('acquisition_sources', acquisition_source)

@filter_empty_parameters
def add_document_type(self, document_type):
Expand Down
12 changes: 10 additions & 2 deletions inspire_schemas/records/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ properties:
$ref: elements/sourced_value.json
type: array
uniqueItems: true
acquisition_source:
$ref: elements/acquisition_source.json
acquisition_sources:
description: |-
:MARC: ``541`` (only the earliest source was stored)
Sources of the metadata in the record, in inverse chronological
order (i.e. the first element is the latest one).
items:
$ref: elements/acquisition_source.json
type: array
uniqueItems: true
advisors:
items:
additionalProperties: false
Expand Down
6 changes: 0 additions & 6 deletions inspire_schemas/records/elements/acquisition_source.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
$schema: http://json-schema.org/schema#
additionalProperties: false
description: |-
:MARC: ``541``
Only the first source is stored: if the record later gets enriched with
metadata coming from a second source, the `acquisition_source` is not
updated.
properties:
datetime:
description: |-
Expand Down
12 changes: 10 additions & 2 deletions inspire_schemas/records/hep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,16 @@ properties:
title: List of related accelerators/experiments
type: array
uniqueItems: true
acquisition_source:
$ref: elements/acquisition_source.json
acquisition_sources:
description: |-
:MARC: ``541`` (only the earliest source was stored)
Sources of the metadata in the record, in inverse chronological
order (i.e. the first element is the latest one).
items:
$ref: elements/acquisition_source.json
type: array
uniqueItems: true
arxiv_eprints:
items:
additionalProperties: false
Expand Down
20 changes: 11 additions & 9 deletions tests/integration/fixtures/authors_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
"value": "nulla com"
}
],
"acquisition_source": {
"datetime": "2234-06-08T05:46:05.263Z",
"email": "[email protected]",
"internal_uid": 76120453,
"method": "submitter",
"orcid": "8351-4483-7418-2367",
"source": "voluptate qui fugiat nulla",
"submission_number": "voluptate reprehenderit nisi nostrud elit"
},
"acquisition_sources": [
{
"datetime": "2234-06-08T05:46:05.263Z",
"email": "[email protected]",
"internal_uid": 76120453,
"method": "submitter",
"orcid": "8351-4483-7418-2367",
"source": "voluptate qui fugiat nulla",
"submission_number": "voluptate reprehenderit nisi nostrud elit"
}
],
"advisors": [
{
"curated_relation": false,
Expand Down
23 changes: 15 additions & 8 deletions tests/integration/fixtures/expected_data_hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,21 @@
"value":"7892"
}
],
"acquisition_source":{
"email":"[email protected]",
"source":"submitter",
"internal_uid":1,
"submission_number":"12",
"orcid":"0000-0001-8528-2091",
"method":"batchuploader"
},
"acquisition_sources":[
{
"submission_number":"13",
"source":"submitter",
"method":"hepcrawl"
},
{
"email":"[email protected]",
"source":"submitter",
"internal_uid":1,
"submission_number":"12",
"orcid":"0000-0001-8528-2091",
"method":"batchuploader"
}
],
"license":[
{
"url":"https://opensource.org/licenses/MIT",
Expand Down
20 changes: 11 additions & 9 deletions tests/integration/fixtures/hep_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@
}
}
],
"acquisition_source": {
"datetime": "4655-08-10T13:24:39.377Z",
"email": "[email protected]",
"internal_uid": 33119180,
"method": "submitter",
"orcid": "7517-2459-3361-8685",
"source": "do occaecat voluptate elit veniam",
"submission_number": "Lorem ad reprehenderit sed esse"
},
"acquisition_sources": [
{
"datetime": "4655-08-10T13:24:39.377Z",
"email": "[email protected]",
"internal_uid": 33119180,
"method": "submitter",
"orcid": "7517-2459-3361-8685",
"source": "do occaecat voluptate elit veniam",
"submission_number": "Lorem ad reprehenderit sed esse"
}
],
"arxiv_eprints": [
{
"categories": [
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/fixtures/input_data_hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"internal_uid":1,
"email":"[email protected]",
"orcid":"0000-0001-8528-2091",
"method2":"hepcrawl",
"submission_number2":"13",
"document_type":"report",
"material":"visual production",
"holder":"cern",
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def test_literature_builder_valid_record(input_data_hep, expected_data_hep):
email=input_data_hep['email'],
orcid=input_data_hep['orcid']
)
builder.add_acquisition_source(
method=input_data_hep['method2'],
submission_number=input_data_hep['submission_number2'],
)
builder.add_document_type(document_type=input_data_hep['document_type'])
builder.add_copyright(
material=input_data_hep['material'],
Expand Down

0 comments on commit 0bc9bc1

Please sign in to comment.