Skip to content

artifact_problem_type_validator

Validator for the problem type field of an artifact.

ArtifactProblemTypeValidator

Bases: CrossValidator

Implementation of a CrossValidator to validate an artifacts problem type against the custom list store.

Source code in mlte/store/validators/cross_validators/artifact_problem_type_validator.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class ArtifactProblemTypeValidator(CrossValidator):
    """Implementation of a CrossValidator to validate an artifacts problem type against the custom list store."""

    def __init__(
        self,
        custom_list_store: CustomListStore,
    ):
        """
        Initialize a ArtifactProblemTypeValidator instance.
        :param custom_list_store: Custom list store store to use for validation.
        """
        self.custom_list_store = custom_list_store

    def validate(self, new_artifact: ArtifactModel) -> None:
        with ManagedCustomListSession(
            self.custom_list_store.session()
        ) as session:
            if new_artifact.header.type == ArtifactType.NEGOTIATION_CARD:
                card = typing.cast(NegotiationCardModel, new_artifact.body)
                if card.system.problem_type != "":
                    try:
                        session.custom_list_entry_mapper.read(
                            card.system.problem_type,
                            CustomListName.PROBLEM_TYPES,
                        )
                    except ErrorNotFound:
                        raise RuntimeError(
                            f"Artifact problem type validation failure. Problem type: {card.system.problem_type} not found. For artifact {new_artifact.header.identifier}."
                        )

__init__(custom_list_store)

Initialize a ArtifactProblemTypeValidator instance.

Parameters:

Name Type Description Default
custom_list_store CustomListStore

Custom list store store to use for validation.

required
Source code in mlte/store/validators/cross_validators/artifact_problem_type_validator.py
18
19
20
21
22
23
24
25
26
def __init__(
    self,
    custom_list_store: CustomListStore,
):
    """
    Initialize a ArtifactProblemTypeValidator instance.
    :param custom_list_store: Custom list store store to use for validation.
    """
    self.custom_list_store = custom_list_store