diff --git a/osf/metadata/osf_gathering.py b/osf/metadata/osf_gathering.py index 268fb6cc733e..23ead91f3672 100644 --- a/osf/metadata/osf_gathering.py +++ b/osf/metadata/osf_gathering.py @@ -147,10 +147,12 @@ def osfmap_for_type(rdftype_iri: str): OSF.Project: { **OSF_OBJECT, OSF.supplements: OSF_OBJECT_REFERENCE, + OSF.usesCedarTemplate: None, }, OSF.ProjectComponent: { **OSF_OBJECT, OSF.supplements: OSF_OBJECT_REFERENCE, + OSF.usesCedarTemplate: None, }, OSF.Registration: { **OSF_OBJECT, @@ -161,6 +163,7 @@ def osfmap_for_type(rdftype_iri: str): OSF.hasMaterialsResource: OSF_OBJECT_REFERENCE, OSF.hasPapersResource: OSF_OBJECT_REFERENCE, OSF.hasSupplementalResource: OSF_OBJECT_REFERENCE, + OSF.usesCedarTemplate: None, }, OSF.RegistrationComponent: { **OSF_OBJECT, @@ -171,6 +174,7 @@ def osfmap_for_type(rdftype_iri: str): OSF.hasMaterialsResource: OSF_OBJECT_REFERENCE, OSF.hasPapersResource: OSF_OBJECT_REFERENCE, OSF.hasSupplementalResource: OSF_OBJECT_REFERENCE, + OSF.usesCedarTemplate: None, }, OSF.Preprint: { **OSF_OBJECT, @@ -195,6 +199,7 @@ def osfmap_for_type(rdftype_iri: str): OSF.filePath: None, OSF.funding: None, OSF.hasFunding: None, + OSF.usesCedarTemplate: None, OWL.sameAs: None, }, DCTERMS.Agent: { @@ -1010,3 +1015,15 @@ def _omitted_metadata(focus, omitted_property_set, description): for property_iri in omitted_property_set: yield (bnode, OSF.omittedMetadataProperty, property_iri) yield (bnode, DCTERMS.description, _language_text(focus, description)) + +@gather.er(OSF.usesCedarTemplate) +def gather_cedar_templates(focus): + try: + _guids = focus.dbmodel.guids.all() + except AttributeError: + return # no guids + records = osfdb.CedarMetadataRecord.objects.filter(guid__in=_guids, public=True) + for record in records: + template_iri = rdflib.URIRef(record.get_template_semantic_iri()) + yield (OSF.usesCedarTemplate, template_iri) + yield (template_iri, DCTERMS.title, record.get_template_name()) diff --git a/osf/models/cedar_metadata.py b/osf/models/cedar_metadata.py index 68378d233124..dd7e6f10683e 100644 --- a/osf/models/cedar_metadata.py +++ b/osf/models/cedar_metadata.py @@ -17,6 +17,9 @@ class Meta: def __unicode__(self): return f'(name=[{self.schema_name}], version=[{self.template_version}], id=[{self.cedar_id}])' + def get_semantic_iri(self): + return self.template['@id'] + class CedarMetadataRecord(ObjectIDMixin, BaseModel): @@ -30,3 +33,9 @@ class Meta: def __unicode__(self): return f'(guid=[{self.guid._id}], template=[{self.template._id}])' + + def get_template_semantic_iri(self): + return self.template.get_semantic_iri() + + def get_template_name(self): + return self.template.name