Skip to content

Commit

Permalink
signposting RDF pref_mime_type added to handle JSON regradless the se…
Browse files Browse the repository at this point in the history
…rver reports to be the content type see #544
  • Loading branch information
huberrob committed Nov 11, 2024
1 parent f5e35bc commit 5c3d88e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion fuji_server/harvester/metadata_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,10 @@ def retrieve_metadata_external_linked_metadata(self):
else:
source = MetadataSources.RDF_TYPED_LINKS
typed_rdf_collector = MetaDataCollectorRdf(
loggerinst=self.logger, target_url=metadata_link["url"], source=source
loggerinst=self.logger,
target_url=metadata_link["url"],
source=source,
pref_mime_type=metadata_link["type"],
)
if typed_rdf_collector is not None:
source_rdf, rdf_dict = typed_rdf_collector.parse_metadata()
Expand Down
8 changes: 6 additions & 2 deletions fuji_server/helper/metadata_collector_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MetaDataCollectorRdf(MetaDataCollector):
SCHEMA_ORG_CONTEXT = Preprocessor.get_schema_org_context()
SCHEMA_ORG_CREATIVEWORKS = Preprocessor.get_schema_org_creativeworks()

def __init__(self, loggerinst, target_url=None, source=None, json_ld_content=None):
def __init__(self, loggerinst, target_url=None, source=None, json_ld_content=None, pref_mime_type=None):
"""
Parameters
----------
Expand All @@ -90,6 +90,7 @@ def __init__(self, loggerinst, target_url=None, source=None, json_ld_content=Non
self.json_ld_content = json_ld_content
# self.rdf_graph = rdf_graph
self.accept_type = AcceptTypes.rdf
self.pref_mime_type = pref_mime_type

def getAllURIS(self, graph):
founduris = []
Expand Down Expand Up @@ -212,6 +213,8 @@ def parse_metadata(self):
requestHelper: RequestHelper = RequestHelper(self.target_url, self.logger)
requestHelper.setAcceptType(self.accept_type)
requestHelper.setAuthToken(self.auth_token, self.auth_token_type)
if self.pref_mime_type:
requestHelper.addAcceptType(self.pref_mime_type)
neg_format, rdf_response = requestHelper.content_negotiate("FsF-F2-01M")
self.metadata_format = neg_format
if requestHelper.checked_content_hash:
Expand All @@ -230,7 +233,8 @@ def parse_metadata(self):
if self.content_type is not None:
self.content_type = self.content_type.split(";", 1)[0]
# handle JSON-LD
if self.content_type in ["application/ld+json", "application/json", "application/vnd.schemaorg.ld+json"]:
json_types = ["application/ld+json", "application/json", "application/vnd.schemaorg.ld+json"]
if self.content_type in json_types or self.pref_mime_type in json_types:
if self.target_url:
jsonld_source_url = self.resolved_url
else:
Expand Down

0 comments on commit 5c3d88e

Please sign in to comment.