Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ted 690 #267

Merged
merged 4 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions ted_sws/core/model/manifestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ class ManifestationMimeType(Enum):
TURTLE = "text/turtle"


class SPARQLQueryRefinedResultType(Enum):
"""
The aggregated SPARQL Query result
"""
VALID = "valid"
INVALID = "invalid"
ERROR = "error"
WARNING = "warning"


class Manifestation(PropertyBaseModel):
"""
A manifestation that embodies a FRBR Work/Expression.
Expand Down Expand Up @@ -136,13 +146,16 @@ class SPARQLQueryResult(PropertyBaseModel):
Stores SPARQL query execution result
"""
query: SPARQLQuery
result: Optional[str]
result: Optional[SPARQLQueryRefinedResultType]
query_result: Optional[str]
fields_covered: Optional[bool] = True
missing_fields: Optional[List[str]] = []
error: Optional[str]
identifier: Optional[str]

class Config:
use_enum_values = True


class SPARQLTestSuiteValidationReport(RDFValidationManifestation):
"""
Expand Down Expand Up @@ -207,8 +220,9 @@ class XMLManifestationValidationSummaryReport(PropertyBaseModel):


class SPARQLSummaryCountReport(PropertyBaseModel):
success: Optional[int] = 0
fail: Optional[int] = 0
valid: Optional[int] = 0
invalid: Optional[int] = 0
warning: Optional[int] = 0
error: Optional[int] = 0


Expand Down
24 changes: 15 additions & 9 deletions ted_sws/notice_validator/adapters/validation_summary_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from ted_sws.core.model.manifestation import ValidationSummaryReport, XMLManifestationValidationSummaryReport, \
RDFManifestationValidationSummaryReport, XPATHCoverageSummaryReport, XPATHCoverageSummaryResult, \
SPARQLSummaryCountReport, SHACLSummarySeverityCountReport, SPARQLQueryResult, SPARQLTestSuiteValidationReport, \
SHACLTestSuiteValidationReport, RDFManifestation, SPARQLSummaryResult, SHACLSummaryResult
SHACLTestSuiteValidationReport, RDFManifestation, SPARQLSummaryResult, SHACLSummaryResult, \
SPARQLQueryRefinedResultType
from ted_sws.core.model.notice import Notice

TEMPLATES = Environment(loader=PackageLoader("ted_sws.notice_validator.resources", "templates"))
Expand Down Expand Up @@ -52,13 +53,16 @@ def notice_sparql_summary(self, notice: Notice, report: RDFManifestationValidati
result_count: SPARQLSummaryCountReport = result_validation.aggregate
if validation_results:
for validation in validation_results:
if validation.result == 'True':
report_count.success += 1
result_count.success += 1
else:
report_count.fail += 1
result_count.fail += 1
if validation.error:
if validation.result == SPARQLQueryRefinedResultType.VALID.value:
report_count.valid += 1
result_count.valid += 1
elif validation.result == SPARQLQueryRefinedResultType.INVALID.value:
report_count.invalid += 1
result_count.invalid += 1
elif validation.result == SPARQLQueryRefinedResultType.WARNING.value:
report_count.warning += 1
result_count.warning += 1
elif validation.result == SPARQLQueryRefinedResultType.ERROR.value:
report_count.error += 1
result_count.error += 1

Expand Down Expand Up @@ -162,7 +166,9 @@ class ValidationSummaryRunner:
"""

def __init__(self):
pass
"""

"""

@classmethod
def validation_summary(cls, notices: List[Notice]) -> ValidationSummaryReport:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def run_cmd(self):
self.validate(rdf_file=f, xpath_report=xpath_report, base_report_path=base_report_path)
except Exception as e:
error = e

return self.run_cmd_result(error)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
table thead th {
text-align: left;
}
.success {
.success, .valid {
color: #3c763d;
}
.info {
Expand All @@ -32,7 +32,7 @@
.warning {
color: #8a6d3b;
}
.danger {
.danger, .invalid, .error {
color: #a94442;
}
.strong {
Expand All @@ -48,7 +48,7 @@
display: none;
}
.dialog li {
margin-bottom: 5px;
margin-bottom: 8px;
}

</style>
Expand All @@ -72,7 +72,6 @@
<th>Query content</th>
<th>Result</th>
<th>Details</th>
<th>Error</th>
</tr>
</thead>
<tbody>
Expand All @@ -91,7 +90,7 @@
</div>
</td>
<td>{{ result.query.query | e | replace('\n', '<br>') }}</td>
<td{% if result.result == "True" and result.fields_covered %} class="strong success" {% elif result.result == "True" and not result.fields_covered %} class="strong warning" {% else %} class="strong danger" {% endif %}>{{ result.result }}</td>
<td class="strong {{ result.result }}">{{ result.result }}</td>
<td>
<button class="open-dialog">Details</button>
<div class="dialog" title="{{ result.query.title }}">
Expand Down Expand Up @@ -121,12 +120,17 @@
</ol>
</li>
{% endif %}
{% if result.error and (result.error|length > 0) %}
<li>
<h4 class="danger strong">ERROR:</h4>
{{ result.error }}
</li>
{% endif %}
</ul>
</div>
</td>
<td>{{ result.error }}</td>
</tr>
{% if result.result == "True" %}
{% if result.query_result == "True" %}
{{ increment(counter, 'true_executions') }}
{% elif result.error %}
{{ increment(counter, 'error_executions') }}
Expand Down Expand Up @@ -199,7 +203,7 @@
$(document).on('click', '.open-dialog', function () {
$dialog = $(this).next('.dialog');
$dialog.dialog({
width: 600,
width: 800,
modal: true,
buttons: {
"Close": function(event, ui) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@
<h3>SPARQL Summary</h3>
<h4>Report details: </h4>
<ul>
<li>Success: {{ manifestation.sparql_summary.aggregate.success }}</li>
<li>Fail: {{ manifestation.sparql_summary.aggregate.fail }}</li>
<li>Valid: {{ manifestation.sparql_summary.aggregate.valid }}</li>
<li>Invalid: {{ manifestation.sparql_summary.aggregate.invalid }}</li>
<li>Warning: {{ manifestation.sparql_summary.aggregate.warning }}</li>
<li>Error: {{ manifestation.sparql_summary.aggregate.error }}</li>
</ul>
<p>-----</p>
<h4>Validation results: </h4>
{% for result in rdf_manifestation.sparql_summary.validation_results %}
{% set result_total = result.aggregate.success + result.aggregate.fail + result.aggregate.error %}
{% set result_total = result.aggregate.valid + result.aggregate.invalid + result.aggregate.warning + result.aggregate.error %}
<p>---</p>
<ul>
<li>Mapping suite identifier: {{ result.mapping_suite_identifier }}</li>
Expand All @@ -121,14 +122,19 @@
</thead>
<tbody>
<tr>
<td>Success</td>
<td>{{ result.aggregate.success }}</td>
<td>{{ (result.aggregate.success / result_total * 100) | round(2) }}%</td>
<td>Valid</td>
<td>{{ result.aggregate.valid }}</td>
<td>{{ (result.aggregate.valid / result_total * 100) | round(2) }}%</td>
</tr>
<tr>
<td>Fail</td>
<td>{{ result.aggregate.fail }}</td>
<td>{{ (result.aggregate.fail / result_total * 100) | round(2) }}%</td>
<td>Invalid</td>
<td>{{ result.aggregate.invalid }}</td>
<td>{{ (result.aggregate.invalid / result_total * 100) | round(2) }}%</td>
</tr>
<tr>
<td>Warning</td>
<td>{{ result.aggregate.warning }}</td>
<td>{{ (result.aggregate.warning / result_total * 100) | round(2) }}%</td>
</tr>
<tr>
<td>Error</td>
Expand Down Expand Up @@ -194,14 +200,15 @@
<h3>SPARQL Summary</h3>
<h4>Report details: </h4>
<ul>
<li>Success: {{ manifestation.sparql_summary.aggregate.success }}</li>
<li>Fail: {{ manifestation.sparql_summary.aggregate.fail }}</li>
<li>Valid: {{ manifestation.sparql_summary.aggregate.valid }}</li>
<li>Invalid: {{ manifestation.sparql_summary.aggregate.invalid }}</li>
<li>Warning: {{ manifestation.sparql_summary.aggregate.warning }}</li>
<li>Error: {{ manifestation.sparql_summary.aggregate.error }}</li>
</ul>
<p>-----</p>
<h4>Validation results: </h4>
{% for result in rdf_manifestation.sparql_summary.validation_results %}
{% set result_total = result.aggregate.success + result.aggregate.fail + result.aggregate.error %}
{% set result_total = result.aggregate.valid + result.aggregate.invalid + result.aggregate.warning + result.aggregate.error %}
<p>---</p>
<ul>
<li>Mapping suite identifier: {{ result.mapping_suite_identifier }}</li>
Expand All @@ -218,14 +225,19 @@
</thead>
<tbody>
<tr>
<td>Success</td>
<td>{{ result.aggregate.success }}</td>
<td>{{ (result.aggregate.success / result_total * 100) | round(2) }}%</td>
<td>Valid</td>
<td>{{ result.aggregate.valid }}</td>
<td>{{ (result.aggregate.valid / result_total * 100) | round(2) }}%</td>
</tr>
<tr>
<td>Invalid</td>
<td>{{ result.aggregate.invalid }}</td>
<td>{{ (result.aggregate.invalid / result_total * 100) | round(2) }}%</td>
</tr>
<tr>
<td>Fail</td>
<td>{{ result.aggregate.fail }}</td>
<td>{{ (result.aggregate.fail / result_total * 100) | round(2) }}%</td>
<td>Warning</td>
<td>{{ result.aggregate.warning }}</td>
<td>{{ (result.aggregate.warning / result_total * 100) | round(2) }}%</td>
</tr>
<tr>
<td>Error</td>
Expand Down
18 changes: 12 additions & 6 deletions ted_sws/notice_validator/services/sparql_test_suite_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from jinja2 import Environment, PackageLoader

from ted_sws.core.model.manifestation import RDFManifestation, SPARQLQueryResult, \
SPARQLTestSuiteValidationReport, SPARQLQuery, XMLManifestation
SPARQLTestSuiteValidationReport, SPARQLQuery, XMLManifestation, SPARQLQueryRefinedResultType
from ted_sws.core.model.notice import Notice
from ted_sws.core.model.transform import SPARQLTestSuite, MappingSuite, FileResource
from ted_sws.data_manager.adapters.repository_abc import NoticeRepositoryABC, MappingSuiteRepositoryABC
Expand Down Expand Up @@ -62,7 +62,9 @@ def _process_sparql_ask_result(self, query_result, sparql_query: SPARQLQuery,
ask_answer = query_result.askAnswer
sparql_query_result.query_result = str(ask_answer)

result = ask_answer
# Initial result
result: SPARQLQueryRefinedResultType = \
SPARQLQueryRefinedResultType.VALID if ask_answer else SPARQLQueryRefinedResultType.INVALID

xpath_coverage_validation = None
if self.xml_manifestation:
Expand All @@ -78,13 +80,16 @@ def _process_sparql_ask_result(self, query_result, sparql_query: SPARQLQuery,
if len(xpaths_in_notice) < len(sparql_query_xpath):
sparql_query_result.missing_fields = list(sparql_query_xpath - xpaths_in_notice)

if not ask_answer and not sparql_query_result.fields_covered:
result = True
# Refined result
if ask_answer and sparql_query_result.fields_covered:
result = SPARQLQueryRefinedResultType.VALID
elif not ask_answer and not sparql_query_result.fields_covered:
result = SPARQLQueryRefinedResultType.WARNING
elif (not ask_answer and sparql_query_result.fields_covered) or (
ask_answer and not sparql_query_result.fields_covered):
result = False
result = SPARQLQueryRefinedResultType.INVALID

sparql_query_result.result = str(result)
sparql_query_result.result = result

def execute_test_suite(self) -> SPARQLTestSuiteValidationReport:
"""
Expand All @@ -108,6 +113,7 @@ def execute_test_suite(self) -> SPARQLTestSuiteValidationReport:
sparql_query_result.query_result = query_result.serialize(format="json")
except Exception as e:
sparql_query_result.error = str(e)[:100]
sparql_query_result.result = SPARQLQueryRefinedResultType.ERROR
test_suite_executions.validation_results.append(sparql_query_result)
return test_suite_executions

Expand Down
Loading