diff --git a/api/share/utils.py b/api/share/utils.py index 34c9be4609c..2619905ac5e 100644 --- a/api/share/utils.py +++ b/api/share/utils.py @@ -70,14 +70,14 @@ def _enqueue_update_share(osfresource): @celery_app.task(bind=True, max_retries=4, acks_late=True) -def task__update_share(self, guid: str, is_backfill=False): +def task__update_share(self, guid: str, is_backfill=False, is_supplementary=False): """ This function updates share takes Preprints, Projects and Registrations. :param self: :param guid: :return: """ - resp = _do_update_share(guid, is_backfill=is_backfill) + resp = _do_update_share(guid, is_backfill=is_backfill, is_supplementary=is_supplementary) try: resp.raise_for_status() except Exception as e: @@ -97,18 +97,22 @@ def task__update_share(self, guid: str, is_backfill=False): return resp -def pls_send_trove_indexcard(osf_item, *, is_backfill=False): +def pls_send_trove_indexcard(osf_item, *, is_backfill=False, is_supplementary=False): try: _iri = osf_item.get_semantic_iri() except (AttributeError, ValueError): raise ValueError(f'could not get iri for {osf_item}') - _metadata_record = pls_gather_metadata_file(osf_item, 'turtle') + _metadata_record = pls_gather_metadata_file(osf_item, 'turtle', { + 'is_supplementary': is_supplementary, + }) _queryparams = { 'focus_iri': _iri, - 'record_identifier': _shtrove_record_identifier(osf_item), + 'record_identifier': _shtrove_record_identifier(osf_item, is_supplementary=is_supplementary), } if is_backfill: _queryparams['nonurgent'] = True + if is_supplementary: + _queryparams['is_supplementary'] = True return requests.post( shtrove_ingest_url(), params=_queryparams, @@ -130,7 +134,7 @@ def pls_delete_trove_indexcard(osf_item): ) -def _do_update_share(osfguid: str, *, is_backfill=False): +def _do_update_share(osfguid: str, *, is_backfill=False, is_supplementary=False): logger.debug('%s._do_update_share("%s", is_backfill=%s)', __name__, osfguid, is_backfill) _guid_instance = apps.get_model('osf.Guid').load(osfguid) if _guid_instance is None: @@ -139,13 +143,18 @@ def _do_update_share(osfguid: str, *, is_backfill=False): _response = ( pls_delete_trove_indexcard(_resource) if _should_delete_indexcard(_resource) - else pls_send_trove_indexcard(_resource, is_backfill=is_backfill) + else pls_send_trove_indexcard( + _resource, + is_backfill=is_backfill, + is_supplementary=is_supplementary, + ) ) return _response -def _shtrove_record_identifier(osf_item): - return osf_item.guids.values_list('_id', flat=True).first() +def _shtrove_record_identifier(osf_item, *, is_supplementary=False): + _id = osf_item.guids.values_list('_id', flat=True).first() + return (f'{_id}/supplement' if is_supplementary else _id) def _shtrove_auth_headers(osf_item): diff --git a/osf/metadata/osf_gathering.py b/osf/metadata/osf_gathering.py index 9a93f7214fe..9d97782dfff 100644 --- a/osf/metadata/osf_gathering.py +++ b/osf/metadata/osf_gathering.py @@ -54,6 +54,13 @@ def osfmap_for_type(rdftype_iri: str): raise ValueError(f'invalid OSFMAP type! expected one of {set(OSFMAP.keys())}, got {rdftype_iri}') +def osfmap_supplement_for_type(rdftype_iri: str): + try: + return OSFMAP_SUPPLEMENT[rdftype_iri] + except KeyError: + return {} + + ##### END "public" api ##### @@ -211,6 +218,21 @@ def osfmap_for_type(rdftype_iri: str): }, } +OSFMAP_SUPPLEMENT = { + OSF.Project: { + }, + OSF.ProjectComponent: { + }, + OSF.Registration: { + }, + OSF.RegistrationComponent: { + }, + OSF.Preprint: { + }, + OSF.File: { + }, +} + OSF_ARTIFACT_PREDICATES = { ArtifactTypes.ANALYTIC_CODE: OSF.hasAnalyticCodeResource, ArtifactTypes.DATA: OSF.hasDataResource, diff --git a/osf/metadata/serializers/turtle.py b/osf/metadata/serializers/turtle.py index 649614b0bfa..4f24b1e2828 100644 --- a/osf/metadata/serializers/turtle.py +++ b/osf/metadata/serializers/turtle.py @@ -1,4 +1,4 @@ -from osf.metadata.osf_gathering import osfmap_for_type +from osf.metadata.osf_gathering import osfmap_for_type, osfmap_supplement_for_type from osf.metadata.serializers import _base @@ -9,5 +9,8 @@ def filename_for_itemid(self, itemid: str): return f'{itemid}-metadata.ttl' def serialize(self) -> str: - self.basket.pls_gather(osfmap_for_type(self.basket.focus.rdftype)) + if self.serializer_config.get('is_supplementary', False): + self.basket.pls_gather(osfmap_supplement_for_type(self.basket.focus.rdftype)) + else: + self.basket.pls_gather(osfmap_for_type(self.basket.focus.rdftype)) return self.basket.gathered_metadata.serialize(format='turtle')