Commit da18b44c authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added external id to user metadata.

parent 2a091d61
Pipeline #60796 failed with stages
in 19 minutes and 52 seconds
......@@ -73,7 +73,8 @@ metadata_model = api.model('MetaData', {
calc_metadata_model = api.inherit('CalcMetaData', metadata_model, {
'mainfile': fields.String(description='The calculation main output file is used to identify the calculation in the upload.'),
'_pid': fields.Integer(description='Assign a specific pid. It must be unique.')
'_pid': fields.Integer(description='Assign a specific pid. It must be unique.'),
'external_id': fields.String(description='External user provided id. Does not have to be unique necessarily.')
})
upload_metadata_model = api.inherit('UploadMetaData', metadata_model, {
......
......@@ -99,6 +99,7 @@ class CalcWithMetadata():
self.comment: str = None
self.references: List[utils.POPO] = []
self.datasets: List[utils.POPO] = []
self.external_id: str = None
# parser related general (not domain specific) metadata
self.parser_name = None
......@@ -267,6 +268,7 @@ class Domain:
calc_id=DomainQuantity(description='Search for the calc_id.'),
pid=DomainQuantity(description='Search for the pid.'),
mainfile=DomainQuantity(description='Search for the mainfile.'),
external_id=DomainQuantity(description='External user provided id. Does not have to be unique necessarily.'),
dataset=DomainQuantity(
elastic_field='datasets.name', multi=True, elastic_search_type='match',
description='Search for a particular dataset by name.'),
......
......@@ -130,6 +130,7 @@ class Entry(Document, metaclass=WithDomain):
comment = Text()
references = Keyword()
datasets = Object(Dataset)
external_id = Keyword()
@classmethod
def from_calc_with_metadata(cls, source: datamodel.CalcWithMetadata) -> 'Entry':
......@@ -171,6 +172,7 @@ class Entry(Document, metaclass=WithDomain):
self.comment = source.comment
self.references = [ref.value for ref in source.references]
self.datasets = [Dataset.from_dataset_popo(ds) for ds in source.datasets]
self.external_id = source.external_id
for quantity in datamodel.Domain.instance.domain_quantities.values():
setattr(
......
......@@ -265,7 +265,7 @@ class TestUploads:
assert upload['current_process'] == 'publish_upload'
assert upload['process_running']
additional_keys = ['with_embargo']
additional_keys = ['with_embargo', 'external_id']
if with_coe_repo:
additional_keys.append('pid')
......@@ -662,19 +662,19 @@ class TestRepo():
calc_with_metadata.update(
calc_id='2', uploader=other_test_user.to_popo(), published=True,
with_embargo=False, pid=2, upload_time=today - datetime.timedelta(days=5))
with_embargo=False, pid=2, upload_time=today - datetime.timedelta(days=5), external_id='external_id')
calc_with_metadata.update(
atoms=['Fe'], comment='this is a specific word', formula='AAA', basis_set='zzz')
search.Entry.from_calc_with_metadata(calc_with_metadata).save(refresh=True)
calc_with_metadata.update(
calc_id='3', uploader=other_test_user.to_popo(), published=False,
with_embargo=False, pid=3)
with_embargo=False, pid=3, external_id='external_id')
search.Entry.from_calc_with_metadata(calc_with_metadata).save(refresh=True)
calc_with_metadata.update(
calc_id='4', uploader=other_test_user.to_popo(), published=True,
with_embargo=True, pid=4)
with_embargo=True, pid=4, external_id='external_id')
search.Entry.from_calc_with_metadata(calc_with_metadata).save(refresh=True)
def assert_search(self, rv: Any, number_of_calcs: int) -> dict:
......@@ -789,7 +789,9 @@ class TestRepo():
(2, 'paths', 'mainfile.txt'),
(2, 'paths', 'test'),
(2, 'quantities', ['wyckoff_letters_primitive', 'hall_number']),
(0, 'quantities', 'dos')
(0, 'quantities', 'dos'),
(1, 'external_id', 'external_id'),
(0, 'external_id', 'external')
])
def test_search_parameters(self, api, example_elastic_calcs, no_warn, test_user_auth, calcs, quantity, value):
query_string = urlencode({quantity: value, 'statistics': True}, doseq=True)
......
......@@ -514,7 +514,8 @@ def example_user_metadata(other_test_user, test_user) -> dict:
'_uploader': other_test_user.user_id,
'coauthors': [test_user.user_id],
'_upload_time': datetime.datetime.utcnow(),
'_pid': 256
'_pid': 256,
'external_id': 'external_test_id'
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment