Exemplo n.º 1
0
    def run(self, workarea, validators, stop_at_failure=True):
        workarea = Workarea.objects.get(pk=workarea)
        workarea.successfully_validated = {}

        for validator in validators:
            workarea.successfully_validated[validator] = None

        workarea.save(update_fields=['successfully_validated'])
        ip = workarea.ip
        sa = ip.submission_agreement
        validation_profile = ip.get_profile('validation')
        profile_data = fill_specification_data(data=ip.get_profile_data('validation'), sa=sa, ip=ip)
        responsible = User.objects.get(pk=self.responsible)

        try:
            validation.validate_path(workarea.path, validators, validation_profile, data=profile_data, ip=ip,
                                     task=self.task_id, stop_at_failure=stop_at_failure, responsible=responsible)
        except ValidationError:
            self.create_notification(ip)
        else:
            self.create_notification(ip)
        finally:
            validations = ip.validation_set.all()
            failed_validators = validations.values('validator').filter(
                passed=False, required=True
            ).values_list('validator', flat=True)

            for k, v in workarea.successfully_validated.items():
                class_name = validation.AVAILABLE_VALIDATORS[k].split('.')[-1]
                workarea.successfully_validated[k] = class_name not in failed_validators

            workarea.save(update_fields=['successfully_validated'])
Exemplo n.º 2
0
def ValidateWorkarea(self, workarea, validators, stop_at_failure=True):
    def create_notification(ip):
        errcount = Validation.objects.filter(information_package=ip,
                                             passed=False,
                                             required=True).count()

        if errcount:
            Notification.objects.create(
                message='Validation of "{ip}" failed with {errcount} error(s)'.
                format(ip=ip.object_identifier_value, errcount=errcount),
                level=logging.ERROR,
                user_id=self.responsible,
                refresh=True)
        else:
            Notification.objects.create(
                message='"{ip}" was successfully validated'.format(
                    ip=ip.object_identifier_value),
                level=logging.INFO,
                user_id=self.responsible,
                refresh=True)

    workarea = Workarea.objects.get(pk=workarea)
    workarea.successfully_validated = {}

    for validator in validators:
        workarea.successfully_validated[validator] = None

    workarea.save(update_fields=['successfully_validated'])
    ip = workarea.ip
    sa = ip.submission_agreement
    validation_profile = ip.get_profile('validation')
    profile_data = fill_specification_data(
        data=ip.get_profile_data('validation'), sa=sa, ip=ip)
    responsible = User.objects.get(pk=self.responsible)

    try:
        validation.validate_path(workarea.path,
                                 validators,
                                 validation_profile,
                                 data=profile_data,
                                 ip=ip,
                                 task=self.get_processtask(),
                                 stop_at_failure=stop_at_failure,
                                 responsible=responsible)
    except ValidationError:
        create_notification(ip)
    else:
        create_notification(ip)
    finally:
        validations = ip.validation_set.all()
        failed_validators = validations.values('validator').filter(
            passed=False, required=True).values_list('validator', flat=True)

        for k, _v in workarea.successfully_validated.items():
            class_name = validation.AVAILABLE_VALIDATORS[k].split('.')[-1]
            workarea.successfully_validated[
                k] = class_name not in failed_validators

        workarea.save(update_fields=['successfully_validated'])