From 18b55695d45fcb2fe016ff77ef5e08fc1eb2a31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20M=C2=AA=20Fern=C3=A1ndez?= Date: Thu, 31 Aug 2023 04:31:03 +0200 Subject: [PATCH] Guessing the workflow repository from RO-Crate fixed from regression. In the future, all the method must be completely rewritten in order to query JSON-LD through rdflib and SPARQL. But for now, the code uses the trick of parsing it as JSON and finding the linked data within it. --- wfexs_backend/wfexs_backend.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/wfexs_backend/wfexs_backend.py b/wfexs_backend/wfexs_backend.py index 07609e65..cc9e2fb2 100644 --- a/wfexs_backend/wfexs_backend.py +++ b/wfexs_backend/wfexs_backend.py @@ -2061,6 +2061,7 @@ def getWorkflowRepoFromROCrateFile( mainEntityId = None workflowPID = None workflowUploadURL = None + workflowRepoURL = None workflowTypeId = None for e in roCrateObj.get_entities(): if ( @@ -2072,6 +2073,7 @@ def getWorkflowRepoFromROCrateFile( elif e["@id"] == mainEntityIdHolder: eAsLD = e.as_jsonld() mainEntityId = eAsLD["mainEntity"]["@id"] + workflowRepoURL = eAsLD.get("isBasedOn") workflowPID = eAsLD.get("identifier") elif e["@id"] == mainEntityId: eAsLD = e.as_jsonld() @@ -2140,14 +2142,24 @@ def getWorkflowRepoFromROCrateFile( # Some RO-Crates might have this value missing or ill-built remote_repo: "Optional[RemoteRepo]" = None if workflowUploadURL is not None: - remote_repo = self.guess_repo_params(workflowUploadURL, fail_ok=True) + try: + remote_repo = self.guess_repo_params(workflowUploadURL, fail_ok=True) + except: + self.logger.exception( + f"Unable to use RO-Crate derived {workflowUploadURL} as workflow source" + ) - if remote_repo is None: - remote_repo = self.guess_repo_params( - roCrateObj.root_dataset["isBasedOn"], fail_ok=True - ) + if workflowRepoURL is not None and ( + remote_repo is None or remote_repo.repo_type is None + ): + try: + remote_repo = self.guess_repo_params(workflowRepoURL, fail_ok=True) + except: + self.logger.exception( + f"Unable to use RO-Crate derived {workflowRepoURL} as workflow source" + ) - if remote_repo is None: + if remote_repo is None or remote_repo.repo_type is None: raise WfExSBackendException( "Unable to guess repository from RO-Crate manifest" )