def check_users_and_validation()

in annotation/annotation/schemas/jobs.py [0:0]


    def check_users_and_validation(cls, values):
        """
        If the validation type is cross validation, annotators field should
        have min 2 annotators and validators field should be empty. If the
        validation type is hierarchical, annotators and validators should not
        be empty at the same time. If the validation type is validation_only,
        annotators field should be empty and validators field should not be
        empty.
        """
        validation_type, validators, annotators, extensive_coverage = (
            values.get("validation_type"),
            values.get("validators"),
            values.get("annotators"),
            values.get("extensive_coverage"),
        )
        job_type = values.get("job_type")
        if job_type in AUTOMATIC_JOBS:
            if annotators or validators:
                raise ValueError(
                    f"If the job type is {job_type}, annotators and "
                    "validators field should be empty."
                )
            return values
        if validation_type == ValidationSchema.cross and (
            len(annotators) < CROSS_MIN_ANNOTATORS_NUMBER or validators
        ):
            raise ValueError(
                "If the validation type is cross validation, annotators "
                "field should have min 2 annotators and the validators field "
                "should be empty."
            )
        if validation_type == ValidationSchema.hierarchical and (
            not annotators or not validators
        ):
            raise ValueError(
                "If the validation type is hierarchical, annotators field "
                "and validators field should not be empty at the same time."
            )
        if validation_type == ValidationSchema.validation_only and (
            annotators or not validators
        ):
            raise ValueError(
                "If the validation type is validation_only, annotators field "
                "should be empty and validators field should not be empty."
            )
        if (
            validation_type == ValidationSchema.extensive_coverage
            and not extensive_coverage
        ):
            raise ValueError(
                "If the validation type is extensive_coverage value "
                "configuring this field should be provided to "
                "extensive_coverage parameter."
            )
        if validation_type == ValidationSchema.extensive_coverage and (
            len(annotators) < extensive_coverage
        ):
            raise ValueError(
                "If the validation type is extensive_coverage number of "
                "annotators should equal or less then provided "
                "extensive_coverage number."
            )
        return values