Skip to content

Commit

Permalink
validate inputs (Reason)
Browse files Browse the repository at this point in the history
  • Loading branch information
muddymudskipper committed Jul 25, 2024
1 parent 79e9366 commit 70e4ce5
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions cmem_plugin_reason/plugin_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,27 +333,13 @@ def post_valid_profiles(self, inputs: Sequence[Entities], graphs: dict) -> None:
if self.input_profiles:
values = next(inputs[0].entities).values
paths = [p.path for p in inputs[0].schema.paths]
validated_ontology = values[paths.index("ontology")][0]
valid_profiles = values[paths.index("profile")]
if validated_ontology != self.ontology_graph_iri:
raise ValueError(
"The ontology IRI validated with Validate differs from the input ontology IRI."
)
else:
valid_profiles = validate_profiles(self, graphs)
post_profiles(self, valid_profiles)

def _execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> None:
"""`Execute plugin"""
if self.input_profiles:
if not inputs:
raise OSError(
'Input entities needed if "Process valid OWL profiles from input" is enabled'
)
paths = [p.path for p in inputs[0].schema.paths]
if "profile" not in paths or "ontology" not in paths:
raise ValueError("Invalid input for processing OWL profiles")

setup_cmempy_user_access(context.user)
graphs = get_graphs_tree((self.data_graph_iri, self.ontology_graph_iri))
self.get_graphs(graphs, context)
Expand All @@ -366,6 +352,19 @@ def _execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Non
post_provenance(self, get_provenance(self, context))

def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> None:
"""Remove temp files on error"""
"""Validate input, execute plugin with temporary directory"""
if self.input_profiles:
values = next(inputs[0].entities).values
paths = [p.path for p in inputs[0].schema.paths]
if not inputs:
raise OSError(
'Input entities needed if "Process valid OWL profiles from input" is enabled'
)
if "profile" not in paths or "ontology" not in paths:
raise ValueError("Invalid input for processing OWL profiles")
if values[paths.index("ontology")][0] != self.ontology_graph_iri:
raise ValueError(
"The ontology IRI validated with Validate differs from the input ontology IRI."
)
with TemporaryDirectory() as self.temp:
self._execute(inputs, context)

0 comments on commit 70e4ce5

Please sign in to comment.