diff --git a/cmem_plugin_reason/plugin_reason.py b/cmem_plugin_reason/plugin_reason.py index 63b482f..d2df8ed 100644 --- a/cmem_plugin_reason/plugin_reason.py +++ b/cmem_plugin_reason/plugin_reason.py @@ -343,7 +343,7 @@ def _execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Non create_xml_catalog_file(self.temp, graphs) self.reason(graphs) setup_cmempy_user_access(context.user) - send_result(self.output_graph_iri, Path(self.temp) / "result.ttl") + send_result(self, self.output_graph_iri, Path(self.temp) / "result.ttl") if self.validate_profile: self.post_valid_profiles(inputs, graphs) post_provenance(self, get_provenance(self, context)) diff --git a/cmem_plugin_reason/plugin_validate.py b/cmem_plugin_reason/plugin_validate.py index 6d33bff..f518068 100644 --- a/cmem_plugin_reason/plugin_validate.py +++ b/cmem_plugin_reason/plugin_validate.py @@ -221,7 +221,7 @@ def _execute(self, context: ExecutionContext) -> Entities: if self.produce_graph: setup_cmempy_user_access(context.user) - send_result(self.output_graph_iri, Path(self.temp) / "output.ttl") + send_result(self, self.output_graph_iri, Path(self.temp) / "output.ttl") setup_cmempy_user_access(context.user) post_provenance(self, get_provenance(self, context)) diff --git a/cmem_plugin_reason/utils.py b/cmem_plugin_reason/utils.py index 0cc8b7f..a677cf9 100644 --- a/cmem_plugin_reason/utils.py +++ b/cmem_plugin_reason/utils.py @@ -99,14 +99,16 @@ def get_graphs_tree(graph_iris: tuple) -> dict: return graphs -def send_result(iri: str, filepath: Path) -> None: +def send_result(plugin: WorkflowPlugin, iri: str, filepath: Path) -> None: """Send result""" - post_streamed( + res = post_streamed( iri, str(filepath), replace=True, content_type="text/turtle", ) + if res.status_code != 204: # noqa: PLR2004 + plugin.log.error("Error posting result graph.") def post_provenance(plugin: WorkflowPlugin, prov: dict | None) -> None: @@ -116,7 +118,6 @@ def post_provenance(plugin: WorkflowPlugin, prov: dict | None) -> None: param_sparql = "" for name, iri in prov["parameters"].items(): param_sparql += f'\n<{prov["plugin_iri"]}> <{iri}> "{plugin.__dict__[name]}" .' - insert_query = f""" INSERT DATA {{ GRAPH <{plugin.output_graph_iri}> {{ @@ -130,7 +131,6 @@ def post_provenance(plugin: WorkflowPlugin, prov: dict | None) -> None: }} }} """ - post_update(query=insert_query) @@ -169,13 +169,13 @@ def get_provenance(plugin: WorkflowPlugin, context: ExecutionContext) -> dict | ) parameter_query = f""" - SELECT ?parameter {{ - GRAPH <{project_graph}> {{ - <{plugin_iri}> ?parameter ?o . - FILTER(STRSTARTS(STR(?parameter), "https://vocab.eccenca.com/di/functions/param_")) - }} + SELECT ?parameter {{ + GRAPH <{project_graph}> {{ + <{plugin_iri}> ?parameter ?o . + FILTER(STRSTARTS(STR(?parameter), "https://vocab.eccenca.com/di/functions/param_")) }} - """ + }} + """ new_plugin_iri = f'{"_".join(plugin_iri.split("_")[:-1])}_{token_hex(8)}' result = json.loads(post_select(query=parameter_query))