Skip to content

Commit

Permalink
Update Result public interface to support new schema
Browse files Browse the repository at this point in the history
Signed-off-by: patrickpa <[email protected]>
  • Loading branch information
patrickpa committed Jun 10, 2024
1 parent 74ffe0c commit e8e56e8
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions qc_baselib/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ def register_checker_bundle(
self._report_results.checker_bundles.append(bundle)

def register_checker(
self, checker_bundle_name: str, checker_id: str, description: str, summary: str
self,
checker_bundle_name: str,
checker_id: str,
description: str,
summary: str,
) -> None:

checker = result.CheckerType(
Expand All @@ -181,12 +185,40 @@ def register_checker(

bundle.checkers.append(checker)

def register_rule(
self,
checker_bundle_name: str,
checker_id: str,
emanating_entity: str,
standard: str,
definition_setting: str,
rule_full_name: str,
) -> str:
"""
Rule will be registered to checker and the generated rule uid will be
returned.
"""

rule = result.RuleType(
emanating_entity=emanating_entity,
standard=standard,
definition_setting=definition_setting,
rule_full_name=rule_full_name,
)

bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name)
checker = self._get_checker(bundle=bundle, checker_id=checker_id)
checker.addressed_rule.append(rule)

return rule.rule_uid

def register_issue(
self,
checker_bundle_name: str,
checker_id: str,
description: str,
level: IssueSeverity,
rule_uid: str,
) -> int:
"""
Issue will be registered to checker and the generated issue id will be
Expand All @@ -195,7 +227,7 @@ def register_issue(
issue_id = self._id_manager.get_next_free_id()

issue = result.IssueType(
issue_id=issue_id, description=description, level=level
issue_id=issue_id, description=description, level=level, rule_uid=rule_uid
)

bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name)
Expand All @@ -204,6 +236,10 @@ def register_issue(

checker.issues.append(issue)

# Validation need to be triggered to check if no schema relation was
# violated by the new issue addition.
result.CheckerType.model_validate(checker)

return issue_id

def add_file_location(
Expand Down Expand Up @@ -250,6 +286,13 @@ def add_xml_location(
result.LocationType(xml_location=[xml_location], description=description)
)

def set_checker_status(
self, checker_bundle_name: str, checker_id: str, status: result.StatusType
) -> None:
bundle = self._get_checker_bundle(checker_bundle_name=checker_bundle_name)
checker = self._get_checker(bundle=bundle, checker_id=checker_id)
checker.status = status

def get_result_version(self) -> str:
return self._report_results.version

Expand Down

0 comments on commit e8e56e8

Please sign in to comment.