Skip to content

Commit 31aaf7f

Browse files
committed
First basic validation
Validation on empty config that does nothing.
1 parent 2127c5a commit 31aaf7f

1 file changed

Lines changed: 48 additions & 2 deletions

File tree

src/hermes_plugin_software_card/curate.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,58 @@
55

66
"""Module containing the Software CaRD curation plugin for HERMES."""
77

8+
import json
9+
from pathlib import Path
10+
811
from hermes.commands.curate.base import BaseCuratePlugin
12+
from software_card_policies.config import Config
13+
from software_card_policies.data_model import (
14+
make_shacl_graph,
15+
read_rdf_resource,
16+
validate_graph,
17+
)
18+
from software_card_policies.report import create_report
919

1020

1121
class SoftwareCaRDCuratePlugin(BaseCuratePlugin):
1222
"""Software CaRD curation plugin."""
1323

14-
def is_publication_approved(self):
24+
def __init__(self, command, ctx):
25+
"""Initialize the plugin."""
26+
super().__init__(command, ctx)
27+
self._data_graph = None
28+
self._shacl_graph = None
29+
self._conforms = False
30+
self._validation_graph = None
31+
self._report = None
32+
33+
def prepare(self):
34+
"""Prepare the validation.
35+
36+
The metadata given in the context is parsed as an RDF graph. The configuration
37+
for the Software CaRD validation process is left empty.
38+
"""
39+
text = json.dumps(self.ctx.get_data()["curate"])
40+
self._data_graph = read_rdf_resource(format="json-ld", data=text)
41+
self._shacl_graph = make_shacl_graph(Config.from_dict({"policies": {}}))
42+
43+
def validate(self):
44+
"""Run Software CaRD validation."""
45+
conforms, validation_graph = validate_graph(self._data_graph, self._shacl_graph)
46+
self._conforms = conforms
47+
self._validation_graph = validation_graph
48+
49+
def create_report(self):
50+
"""Create basic text report."""
51+
self._report = create_report(self._validation_graph)
52+
53+
def is_publication_approved(self) -> bool:
1554
"""Decide whether the publication of the software is approved."""
16-
return False
55+
return self._conforms
56+
57+
def process_decision_positive(self):
58+
"""Write the given metadata into the curate directory."""
59+
curate_output = Path(self.ctx.get_cache("curate", self.ctx.hermes_name))
60+
Path.mkdir(curate_output.parent)
61+
with open(curate_output, "w") as curate_output_fh:
62+
json.dump(self.ctx.get_data(), curate_output_fh)

0 commit comments

Comments
 (0)