Skip to content

Commit 2ac149e

Browse files
Merge pull request #362 from OP-TED/feature/TED-923
Feature/ted 923
2 parents defed69 + c255e30 commit 2ac149e

13 files changed

Lines changed: 108 additions & 76 deletions

ted_sws/data_manager/adapters/notice_repository.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,6 @@ def write_large_field(large_field: Manifestation):
187187
write_large_field(notice.mets_manifestation)
188188
write_large_field(notice.distilled_rdf_manifestation)
189189
write_large_field(notice.preprocessed_xml_manifestation)
190-
if notice.rdf_manifestation:
191-
for validation_report in notice.rdf_manifestation.shacl_validations:
192-
write_large_field(validation_report)
193-
194-
for validation_report in notice.rdf_manifestation.sparql_validations:
195-
write_large_field(validation_report)
196-
197-
if notice.distilled_rdf_manifestation:
198-
for validation_report in notice.distilled_rdf_manifestation.shacl_validations:
199-
write_large_field(validation_report)
200-
201-
for validation_report in notice.distilled_rdf_manifestation.sparql_validations:
202-
write_large_field(validation_report)
203190

204191
return notice, linked_file_ids, new_linked_file_ids
205192

@@ -219,18 +206,6 @@ def load_large_field(large_field: Manifestation):
219206
load_large_field(large_field=notice.mets_manifestation)
220207
load_large_field(large_field=notice.distilled_rdf_manifestation)
221208
load_large_field(large_field=notice.preprocessed_xml_manifestation)
222-
if notice.rdf_manifestation:
223-
for validation_report in notice.rdf_manifestation.shacl_validations:
224-
load_large_field(validation_report)
225-
for validation_report in notice.rdf_manifestation.sparql_validations:
226-
load_large_field(validation_report)
227-
228-
if notice.distilled_rdf_manifestation:
229-
for validation_report in notice.distilled_rdf_manifestation.shacl_validations:
230-
load_large_field(validation_report)
231-
232-
for validation_report in notice.distilled_rdf_manifestation.sparql_validations:
233-
load_large_field(validation_report)
234209

235210
return notice
236211

ted_sws/notice_validator/entrypoints/cli/cmd_shacl_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535
mappings_path
3636
):
3737
super().__init__(name=CMD_NAME)
38+
self.with_html = True
3839
self.mapping_suite_id = mapping_suite_id
3940
self.notice_ids = self._init_list_input_opts(notice_ids)
4041
self.mappings_path = mappings_path
@@ -65,7 +66,7 @@ def validate(self, rdf_file, base_report_path, notice_ids: List[str] = None):
6566
mapping_suite=self.mapping_suite).execute_test_suite()
6667

6768
report: SHACLTestSuiteValidationReport = generate_shacl_report(
68-
shacl_test_suite_execution=test_suite_execution, notice_ids=notice_ids)
69+
shacl_test_suite_execution=test_suite_execution, notice_ids=notice_ids, with_html=self.with_html)
6970

7071
suite_id = shacl_test_suite.identifier
7172
self.save_report(report_path, HTML_REPORT, suite_id, report.object_data)

ted_sws/notice_validator/entrypoints/cli/cmd_sparql_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
mappings_path
4040
):
4141
super().__init__(name=CMD_NAME)
42+
self.with_html = True
4243
self.mapping_suite_id = mapping_suite_id
4344
self.notice_ids = self._init_list_input_opts(notice_ids)
4445
self.mappings_path = mappings_path
@@ -75,7 +76,7 @@ def validate(self, rdf_file, xpath_report, base_report_path, notice_ids: List[st
7576
mapping_suite=self.mapping_suite).execute_test_suite()
7677

7778
report_builder = SPARQLReportBuilder(sparql_test_suite_execution=test_suite_execution,
78-
notice_ids=notice_ids)
79+
notice_ids=notice_ids, with_html=self.with_html)
7980
report: SPARQLTestSuiteValidationReport = report_builder.generate_report()
8081

8182
suite_id = sparql_test_suite.identifier

ted_sws/notice_validator/entrypoints/cli/cmd_validation_summary_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(
4444
mappings_path
4545
):
4646
super().__init__(name=CMD_NAME)
47+
self.with_html = True
4748
self.mapping_suite_id = mapping_suite_id
4849
self.mappings_path = mappings_path
4950
self.notice_aggregate = notice_aggregate
@@ -121,7 +122,7 @@ def _read_output_notice_ids(self) -> List[str]:
121122
def _generate_report(self, notices: List[Notice], label: str, output_path: Path):
122123
self.log("Generating validation summary report for {label} ... ".format(label=label))
123124

124-
report: ValidationSummaryReport = generate_validation_summary_report_notices(notices)
125+
report: ValidationSummaryReport = generate_validation_summary_report_notices(notices, with_html=self.with_html)
125126

126127
self.save_html_report(output_path, report.object_data)
127128
del report.object_data

ted_sws/notice_validator/entrypoints/cli/cmd_xpath_coverage_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
mappings_path
4444
):
4545
super().__init__(name=CMD_NAME)
46+
self.with_html = True
4647
self.mapping_suite_id = mapping_suite_id
4748
self.notice_ids = self._init_list_input_opts(notice_ids)
4849
self.mappings_path = mappings_path
@@ -82,7 +83,8 @@ def coverage_report(self, notices: List[Notice], output_path: Path, label: str):
8283
self.conceptual_mappings_file_path,
8384
self.coverage_runner)
8485
self.save_json_report(Path(str(output_path) + ".json"), xpath_coverage_json_report(report))
85-
self.save_html_report(Path(str(output_path) + ".html"), xpath_coverage_html_report(report))
86+
if self.with_html:
87+
self.save_html_report(Path(str(output_path) + ".html"), xpath_coverage_html_report(report))
8688

8789
def run_cmd(self):
8890
super().run_cmd()

ted_sws/notice_validator/services/shacl_test_suite_runner.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,34 @@ def execute_test_suite(self) -> SHACLTestSuiteValidationReport:
6060

6161

6262
def generate_shacl_report(shacl_test_suite_execution: SHACLTestSuiteValidationReport,
63-
notice_ids: List[str] = None) -> SHACLTestSuiteValidationReport:
63+
notice_ids: List[str] = None, with_html: bool = False) -> SHACLTestSuiteValidationReport:
6464
"""
6565
This function generate html report after SHACL test execution.
66+
:param with_html: generate HTML report
6667
:param notice_ids:
6768
:param shacl_test_suite_execution:
6869
:return:
6970
"""
70-
template_data: dict = shacl_test_suite_execution.dict()
71-
template_data[NOTICE_IDS_FIELD] = notice_ids
72-
html_report = TEMPLATES.get_template(SHACL_TEST_SUITE_EXECUTION_HTML_REPORT_TEMPLATE).render(template_data)
73-
shacl_test_suite_execution.object_data = html_report
71+
if with_html:
72+
template_data: dict = shacl_test_suite_execution.dict()
73+
template_data[NOTICE_IDS_FIELD] = notice_ids
74+
html_report = TEMPLATES.get_template(SHACL_TEST_SUITE_EXECUTION_HTML_REPORT_TEMPLATE).render(template_data)
75+
shacl_test_suite_execution.object_data = html_report
7476
return shacl_test_suite_execution
7577

7678

7779
def validate_notice_with_shacl_suite(notice: Union[Notice, List[Notice]], mapping_suite_package: MappingSuite,
78-
execute_full_validation: bool = True):
80+
execute_full_validation: bool = True, with_html: bool = False):
7981
"""
8082
Validates a notice with a shacl test suites
83+
:param with_html: generate HTML report
8184
:param notice:
8285
:param mapping_suite_package:
8386
:param execute_full_validation:
8487
:return:
8588
"""
8689

87-
def shacl_validation(notice_item: Notice, rdf_manifestation: RDFManifestation) \
90+
def shacl_validation(notice_item: Notice, rdf_manifestation: RDFManifestation, with_html: bool = False) \
8891
-> List[SHACLTestSuiteValidationReport]:
8992
reports = []
9093
shacl_test_suites = mapping_suite_package.shacl_test_suites
@@ -93,26 +96,30 @@ def shacl_validation(notice_item: Notice, rdf_manifestation: RDFManifestation) \
9396
shacl_test_suite=shacl_test_suite,
9497
mapping_suite=mapping_suite_package).execute_test_suite()
9598
reports.append(generate_shacl_report(shacl_test_suite_execution=test_suite_execution,
96-
notice_ids=[notice_item.ted_id]))
99+
notice_ids=[notice_item.ted_id], with_html=with_html))
97100

98101
return sorted(reports, key=lambda x: x.test_suite_identifier)
99102

100103
notices = notice if isinstance(notice, List) else [notice]
101104

102105
for notice in notices:
103106
if execute_full_validation:
104-
for report in shacl_validation(notice_item=notice, rdf_manifestation=notice.rdf_manifestation):
107+
for report in shacl_validation(notice_item=notice, rdf_manifestation=notice.rdf_manifestation,
108+
with_html=with_html):
105109
notice.set_rdf_validation(rdf_validation=report)
106110

107-
for report in shacl_validation(notice_item=notice, rdf_manifestation=notice.distilled_rdf_manifestation):
111+
for report in shacl_validation(notice_item=notice, rdf_manifestation=notice.distilled_rdf_manifestation,
112+
with_html=with_html):
108113
notice.set_distilled_rdf_validation(rdf_validation=report)
109114

110115

111116
def validate_notice_by_id_with_shacl_suite(notice_id: str, mapping_suite_identifier: str,
112117
notice_repository: NoticeRepositoryABC,
113-
mapping_suite_repository: MappingSuiteRepositoryABC):
118+
mapping_suite_repository: MappingSuiteRepositoryABC,
119+
with_html: bool = False):
114120
"""
115121
Validates a notice by id with a shacl test suites
122+
:param with_html: generate HTML report
116123
:param notice_id:
117124
:param mapping_suite_identifier:
118125
:param notice_repository:
@@ -126,5 +133,5 @@ def validate_notice_by_id_with_shacl_suite(notice_id: str, mapping_suite_identif
126133
mapping_suite_package = mapping_suite_repository.get(reference=mapping_suite_identifier)
127134
if mapping_suite_package is None:
128135
raise ValueError(f'Mapping suite package, with {mapping_suite_identifier} id, was not found')
129-
validate_notice_with_shacl_suite(notice=notice, mapping_suite_package=mapping_suite_package)
136+
validate_notice_with_shacl_suite(notice=notice, mapping_suite_package=mapping_suite_package, with_html=with_html)
130137
notice_repository.update(notice=notice)

ted_sws/notice_validator/services/sparql_test_suite_runner.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,38 @@ class SPARQLReportBuilder:
126126
Given a SPARQLQueryResult, generates JSON and HTML reports.
127127
"""
128128

129-
def __init__(self, sparql_test_suite_execution: SPARQLTestSuiteValidationReport, notice_ids: List[str] = None):
129+
def __init__(self, sparql_test_suite_execution: SPARQLTestSuiteValidationReport, notice_ids: List[str] = None,
130+
with_html: bool = False):
131+
"""
132+
:param sparql_test_suite_execution:
133+
:param notice_ids:
134+
:param with_html: generate HTML report
135+
"""
130136
self.sparql_test_suite_execution = sparql_test_suite_execution
131137
self.notice_ids = notice_ids
138+
self.with_html = with_html
132139

133140
def generate_report(self) -> SPARQLTestSuiteValidationReport:
134-
template_data: dict = self.sparql_test_suite_execution.dict()
135-
template_data[NOTICE_IDS_FIELD] = self.notice_ids
136-
html_report = TEMPLATES.get_template(SPARQL_TEST_SUITE_EXECUTION_HTML_REPORT_TEMPLATE).render(template_data)
137-
self.sparql_test_suite_execution.object_data = html_report
141+
if self.with_html:
142+
template_data: dict = self.sparql_test_suite_execution.dict()
143+
template_data[NOTICE_IDS_FIELD] = self.notice_ids
144+
html_report = TEMPLATES.get_template(SPARQL_TEST_SUITE_EXECUTION_HTML_REPORT_TEMPLATE).render(template_data)
145+
self.sparql_test_suite_execution.object_data = html_report
138146
return self.sparql_test_suite_execution
139147

140148

141149
def validate_notice_with_sparql_suite(notice: Union[Notice, List[Notice]], mapping_suite_package: MappingSuite,
142-
execute_full_validation: bool = True):
150+
execute_full_validation: bool = True, with_html: bool = False):
143151
"""
144152
Validates a notice with a sparql test suites
153+
:param with_html: generate HTML report
145154
:param notice:
146155
:param mapping_suite_package:
147156
:param execute_full_validation:
148157
:return:
149158
"""
150159

151-
def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation) \
160+
def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation, with_html: bool = False) \
152161
-> List[SPARQLTestSuiteValidationReport]:
153162
reports = []
154163
sparql_test_suites = mapping_suite_package.sparql_test_suites
@@ -159,26 +168,30 @@ def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation)
159168
mapping_suite=mapping_suite_package
160169
).execute_test_suite()
161170
report_builder = SPARQLReportBuilder(sparql_test_suite_execution=test_suite_execution,
162-
notice_ids=[notice_item.ted_id])
171+
notice_ids=[notice_item.ted_id], with_html=with_html)
163172
reports.append(report_builder.generate_report())
164173
return sorted(reports, key=lambda x: x.test_suite_identifier)
165174

166175
notices = notice if isinstance(notice, List) else [notice]
167176

168177
for notice in notices:
169178
if execute_full_validation:
170-
for report in sparql_validation(notice_item=notice, rdf_manifestation=notice.rdf_manifestation):
179+
for report in sparql_validation(notice_item=notice, rdf_manifestation=notice.rdf_manifestation,
180+
with_html=with_html):
171181
notice.set_rdf_validation(rdf_validation=report)
172182

173-
for report in sparql_validation(notice_item=notice, rdf_manifestation=notice.distilled_rdf_manifestation):
183+
for report in sparql_validation(notice_item=notice, rdf_manifestation=notice.distilled_rdf_manifestation,
184+
with_html=with_html):
174185
notice.set_distilled_rdf_validation(rdf_validation=report)
175186

176187

177188
def validate_notice_by_id_with_sparql_suite(notice_id: str, mapping_suite_identifier: str,
178189
notice_repository: NoticeRepositoryABC,
179-
mapping_suite_repository: MappingSuiteRepositoryABC):
190+
mapping_suite_repository: MappingSuiteRepositoryABC,
191+
with_html: bool = False):
180192
"""
181193
Validates a notice by id with a sparql test suites
194+
:param with_html: generate HTML report
182195
:param notice_id:
183196
:param mapping_suite_identifier:
184197
:param notice_repository:
@@ -192,7 +205,7 @@ def validate_notice_by_id_with_sparql_suite(notice_id: str, mapping_suite_identi
192205
mapping_suite_package = mapping_suite_repository.get(reference=mapping_suite_identifier)
193206
if mapping_suite_package is None:
194207
raise ValueError(f'Mapping suite package, with {mapping_suite_identifier} id, was not found')
195-
validate_notice_with_sparql_suite(notice=notice, mapping_suite_package=mapping_suite_package)
208+
validate_notice_with_sparql_suite(notice=notice, mapping_suite_package=mapping_suite_package, with_html=with_html)
196209
notice_repository.update(notice=notice)
197210

198211

ted_sws/notice_validator/services/validation_summary_runner.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,34 @@ class ValidationSummaryReportBuilder:
1212

1313
report: ValidationSummaryReport
1414

15-
def __init__(self, report: ValidationSummaryReport):
15+
def __init__(self, report: ValidationSummaryReport, with_html: bool = False):
1616
self.report = report
17+
self.with_html = with_html
1718

1819
def generate_report(self) -> ValidationSummaryReport:
19-
html_report = ValidationSummaryRunner.html_report(self.report)
20-
self.report.object_data = html_report
20+
if self.with_html:
21+
html_report = ValidationSummaryRunner.html_report(self.report)
22+
self.report.object_data = html_report
2123
return self.report
2224

2325

24-
def generate_validation_summary_report_notices(notices: List[Notice]) -> ValidationSummaryReport:
26+
def generate_validation_summary_report_notices(notices: List[Notice],
27+
with_html: bool = False) -> ValidationSummaryReport:
2528
validation_summary_report = ValidationSummaryRunner()
26-
report_builder = ValidationSummaryReportBuilder(validation_summary_report.validation_summary(notices))
29+
report_builder = ValidationSummaryReportBuilder(validation_summary_report.validation_summary(notices),
30+
with_html=with_html)
2731
return report_builder.generate_report()
2832

2933

30-
def validation_summary_report_notice(notice: Notice):
31-
notice.validation_summary = generate_validation_summary_report_notices([notice])
34+
def validation_summary_report_notice(notice: Notice, with_html: bool = False):
35+
notice.validation_summary = generate_validation_summary_report_notices([notice], with_html=with_html)
3236

3337

34-
def validation_summary_report_notice_by_id(notice_id: str, notice_repository: NoticeRepository):
38+
def validation_summary_report_notice_by_id(notice_id: str, notice_repository: NoticeRepository,
39+
with_html: bool = False):
3540
notice = notice_repository.get(reference=notice_id)
3641
if notice is None:
3742
raise ValueError(f'Notice, with {notice_id} id, was not found')
3843

39-
validation_summary_report_notice(notice=notice)
44+
validation_summary_report_notice(notice=notice, with_html=with_html)
4045
notice_repository.update(notice=notice)

0 commit comments

Comments
 (0)