Skip to content

Commit ba7f7cd

Browse files
author
Kolea Plesco
committed
Removed object_data from validation reports
1 parent 12be571 commit ba7f7cd

9 files changed

Lines changed: 64 additions & 34 deletions

File tree

ted_sws/data_manager/adapters/notice_repository.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,6 @@ def write_large_field(large_field: Manifestation):
185185
write_large_field(notice.mets_manifestation)
186186
write_large_field(notice.distilled_rdf_manifestation)
187187
write_large_field(notice.preprocessed_xml_manifestation)
188-
if notice.rdf_manifestation:
189-
for validation_report in notice.rdf_manifestation.shacl_validations:
190-
write_large_field(validation_report)
191-
192-
for validation_report in notice.rdf_manifestation.sparql_validations:
193-
write_large_field(validation_report)
194-
195-
if notice.distilled_rdf_manifestation:
196-
for validation_report in notice.distilled_rdf_manifestation.shacl_validations:
197-
write_large_field(validation_report)
198-
199-
for validation_report in notice.distilled_rdf_manifestation.sparql_validations:
200-
write_large_field(validation_report)
201188

202189
return notice, linked_file_ids, new_linked_file_ids
203190

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, with_html=True)
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, with_html=True)
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, with_html=True)
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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def generate_shacl_report(shacl_test_suite_execution: SHACLTestSuiteValidationRe
6363
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:
@@ -76,16 +77,17 @@ def generate_shacl_report(shacl_test_suite_execution: SHACLTestSuiteValidationRe
7677

7778

7879
def validate_notice_with_shacl_suite(notice: Union[Notice, List[Notice]], mapping_suite_package: MappingSuite,
79-
execute_full_validation: bool = True):
80+
execute_full_validation: bool = True, with_html: bool = False):
8081
"""
8182
Validates a notice with a shacl test suites
83+
:param with_html: generate HTML report
8284
:param notice:
8385
:param mapping_suite_package:
8486
:param execute_full_validation:
8587
:return:
8688
"""
8789

88-
def shacl_validation(notice_item: Notice, rdf_manifestation: RDFManifestation) \
90+
def shacl_validation(notice_item: Notice, rdf_manifestation: RDFManifestation, with_html: bool = False) \
8991
-> List[SHACLTestSuiteValidationReport]:
9092
reports = []
9193
shacl_test_suites = mapping_suite_package.shacl_test_suites
@@ -94,26 +96,30 @@ def shacl_validation(notice_item: Notice, rdf_manifestation: RDFManifestation) \
9496
shacl_test_suite=shacl_test_suite,
9597
mapping_suite=mapping_suite_package).execute_test_suite()
9698
reports.append(generate_shacl_report(shacl_test_suite_execution=test_suite_execution,
97-
notice_ids=[notice_item.ted_id]))
99+
notice_ids=[notice_item.ted_id], with_html=with_html))
98100

99101
return sorted(reports, key=lambda x: x.test_suite_identifier)
100102

101103
notices = notice if isinstance(notice, List) else [notice]
102104

103105
for notice in notices:
104106
if execute_full_validation:
105-
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):
106109
notice.set_rdf_validation(rdf_validation=report)
107110

108-
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):
109113
notice.set_distilled_rdf_validation(rdf_validation=report)
110114

111115

112116
def validate_notice_by_id_with_shacl_suite(notice_id: str, mapping_suite_identifier: str,
113117
notice_repository: NoticeRepositoryABC,
114-
mapping_suite_repository: MappingSuiteRepositoryABC):
118+
mapping_suite_repository: MappingSuiteRepositoryABC,
119+
with_html: bool = False):
115120
"""
116121
Validates a notice by id with a shacl test suites
122+
:param with_html: generate HTML report
117123
:param notice_id:
118124
:param mapping_suite_identifier:
119125
:param notice_repository:
@@ -127,5 +133,5 @@ def validate_notice_by_id_with_shacl_suite(notice_id: str, mapping_suite_identif
127133
mapping_suite_package = mapping_suite_repository.get(reference=mapping_suite_identifier)
128134
if mapping_suite_package is None:
129135
raise ValueError(f'Mapping suite package, with {mapping_suite_identifier} id, was not found')
130-
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)
131137
notice_repository.update(notice=notice)

ted_sws/notice_validator/services/sparql_test_suite_runner.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ class SPARQLReportBuilder:
128128

129129
def __init__(self, sparql_test_suite_execution: SPARQLTestSuiteValidationReport, notice_ids: List[str] = None,
130130
with_html: bool = False):
131+
"""
132+
:param sparql_test_suite_execution:
133+
:param notice_ids:
134+
:param with_html:
135+
"""
131136
self.sparql_test_suite_execution = sparql_test_suite_execution
132137
self.notice_ids = notice_ids
133138
self.with_html = with_html
@@ -142,16 +147,17 @@ def generate_report(self) -> SPARQLTestSuiteValidationReport:
142147

143148

144149
def validate_notice_with_sparql_suite(notice: Union[Notice, List[Notice]], mapping_suite_package: MappingSuite,
145-
execute_full_validation: bool = True):
150+
execute_full_validation: bool = True, with_html: bool = False):
146151
"""
147152
Validates a notice with a sparql test suites
153+
:param with_html: generate HTML report
148154
:param notice:
149155
:param mapping_suite_package:
150156
:param execute_full_validation:
151157
:return:
152158
"""
153159

154-
def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation) \
160+
def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation, with_html: bool = False) \
155161
-> List[SPARQLTestSuiteValidationReport]:
156162
reports = []
157163
sparql_test_suites = mapping_suite_package.sparql_test_suites
@@ -162,26 +168,30 @@ def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation)
162168
mapping_suite=mapping_suite_package
163169
).execute_test_suite()
164170
report_builder = SPARQLReportBuilder(sparql_test_suite_execution=test_suite_execution,
165-
notice_ids=[notice_item.ted_id])
171+
notice_ids=[notice_item.ted_id], with_html=with_html)
166172
reports.append(report_builder.generate_report())
167173
return sorted(reports, key=lambda x: x.test_suite_identifier)
168174

169175
notices = notice if isinstance(notice, List) else [notice]
170176

171177
for notice in notices:
172178
if execute_full_validation:
173-
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):
174181
notice.set_rdf_validation(rdf_validation=report)
175182

176-
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):
177185
notice.set_distilled_rdf_validation(rdf_validation=report)
178186

179187

180188
def validate_notice_by_id_with_sparql_suite(notice_id: str, mapping_suite_identifier: str,
181189
notice_repository: NoticeRepositoryABC,
182-
mapping_suite_repository: MappingSuiteRepositoryABC):
190+
mapping_suite_repository: MappingSuiteRepositoryABC,
191+
with_html: bool = False):
183192
"""
184193
Validates a notice by id with a sparql test suites
194+
:param with_html: generate HTML report
185195
:param notice_id:
186196
:param mapping_suite_identifier:
187197
:param notice_repository:
@@ -195,7 +205,7 @@ def validate_notice_by_id_with_sparql_suite(notice_id: str, mapping_suite_identi
195205
mapping_suite_package = mapping_suite_repository.get(reference=mapping_suite_identifier)
196206
if mapping_suite_package is None:
197207
raise ValueError(f'Mapping suite package, with {mapping_suite_identifier} id, was not found')
198-
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)
199209
notice_repository.update(notice=notice)
200210

201211

ted_sws/notice_validator/services/xpath_coverage_runner.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class XPATHCoverageReportBuilder:
1515
"""
1616

1717
def __init__(self, xpath_coverage_report: XPATHCoverageValidationReport, with_html: bool = False):
18+
"""
19+
20+
:param xpath_coverage_report:
21+
:param with_html: generate HTML report
22+
"""
1823
self.xpath_coverage_report = xpath_coverage_report
1924
self.with_html = with_html
2025

@@ -45,6 +50,14 @@ def xpath_coverage_html_report(report: XPATHCoverageValidationReport) -> str:
4550

4651
def validate_xpath_coverage_notice(notice: Notice, mapping_suite: MappingSuite, mongodb_client: MongoClient,
4752
with_html: bool = False):
53+
"""
54+
55+
:param notice:
56+
:param mapping_suite:
57+
:param mongodb_client:
58+
:param with_html: generate HTML report
59+
:return:
60+
"""
4861
xpath_coverage_report = coverage_notice_xpath_report(notices=[notice],
4962
mapping_suite_id=mapping_suite.get_mongodb_id(),
5063
mongodb_client=mongodb_client)
@@ -55,6 +68,15 @@ def validate_xpath_coverage_notice(notice: Notice, mapping_suite: MappingSuite,
5568
def validate_xpath_coverage_notice_by_id(notice_id: str, mapping_suite_identifier: str,
5669
mapping_suite_repository: MappingSuiteRepositoryABC,
5770
mongodb_client: MongoClient, with_html: bool = False):
71+
"""
72+
73+
:param notice_id:
74+
:param mapping_suite_identifier:
75+
:param mapping_suite_repository:
76+
:param mongodb_client:
77+
:param with_html: generate HTML report
78+
:return:
79+
"""
5880
notice_repository = NoticeRepository(mongodb_client=mongodb_client)
5981
notice = notice_repository.get(reference=notice_id)
6082
if notice is None:

tests/unit/notice_validator/test_xpath_coverage_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
def test_xpath_coverage_runner(fake_notice_F03, fake_conceptual_mappings_F03_path,
1313
fake_mapping_suite_F03_id, fake_mapping_suite_F03_id_with_version, mongodb_client,
14-
fake_mapping_suite_F03_path,
15-
invalid_mapping_suite_id):
14+
fake_mapping_suite_F03_path, invalid_mapping_suite_id):
1615
report = coverage_notice_xpath_report([fake_notice_F03], fake_mapping_suite_F03_id,
1716
fake_conceptual_mappings_F03_path, None)
1817
json_report = xpath_coverage_json_report(report)
@@ -51,7 +50,8 @@ def test_validate_xpath_coverage_notice_by_id(fake_notice_id, fake_mapping_suite
5150
notice_id=fake_notice_id,
5251
mapping_suite_identifier=fake_mapping_suite_F03_id,
5352
mapping_suite_repository=mapping_suite_repository_db,
54-
mongodb_client=mongodb_client)
53+
mongodb_client=mongodb_client,
54+
with_html=True)
5555

5656
notice_repository.add(fake_notice_F03)
5757

0 commit comments

Comments
 (0)