Exemplo n.º 1
0
    def validate_update(self, data: dict) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        start = data.get('start')
        start_volume = data.get('startVolume')
        finish = data.get('finish')
        repeat_point = data.get('repeatPoint')
        confirm_point = data.get('confirmPoint')
        next_point = data.get('nextPoint')
        next_speaker = data.get('nextSpeaker')

        if data.get('room') is None or isinstance(data.get('room'),
                                                  dict) is False:
            ack.add_error('Room id must not be empty')
        elif validate.integer(data.get('room').get('id'),
                              label='Room id',
                              min_value=1):
            room = self.config.room_repository.get_room(
                data.get('room').get('id'))
            if room is None:
                ack.add_error('A room with this id does not exist')
            elif len(room.nodes) != 2:
                ack.add_error('A room needs exactly two nodes')
        if start is not None:
            validate.boolean(start, label='Start')
            if start and self.config.room_repository.get_room(
                    data.get('room').get('id')).calibrating:
                ack.add_error('The room is already calibrating currently')
            elif start and start_volume is None:
                ack.add_error('Calibration start volume is required')
            elif start:
                validate.integer(start_volume,
                                 label='Calibration Start Volume')

        if finish is not None:
            validate.boolean(finish, label='Finish')
            if finish and not self.config.room_repository.get_room(
                    data.get('room').get('id')).calibrating:
                ack.add_error('The room wasn\'t beeing calibrated')
        if repeat_point is not None:
            validate.boolean(repeat_point, label='Repeat Point')
        if confirm_point is not None:
            validate.boolean(confirm_point, label='Confirm Point')
        if next_point is not None:
            validate.boolean(next_point, label='Next Point')
        if next_speaker is not None:
            validate.boolean(next_speaker, label='Next Speaker')

        return ack
    def validate(self, data: dict) -> Acknowledgment:  # pylint: disable=no-self-use
        """Validates the input data.

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        start = data.get('start')
        finish = data.get('finish')
        repeat = data.get('repeat')

        if start is not None:
            validate.boolean(start, label='Start')
        if finish is not None:
            validate.boolean(finish, label='Finish')
        if repeat is not None:
            validate.boolean(repeat, label='Repeat')
        if data.get('node') is None or isinstance(data.get('node'),
                                                  dict) is False:
            ack.add_error('Node id must not be empty')
        elif validate.integer(data.get('node').get('id'),
                              label='Node id',
                              min_value=1):
            if self.config.node_repository.get_node(
                    data.get('node').get('id')) is None:
                ack.add_error('A node with this id does not exist')

        return ack
Exemplo n.º 3
0
    def validate_result(self, data: dict) -> Acknowledgment:
        """Validates the input data

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        volume = data.get('volume')

        if data.get('room') is None or isinstance(data.get('room'),
                                                  dict) is False:
            ack.add_error('Room id must not be empty')
        elif validate.integer(data.get('room').get('id'),
                              label='Room id',
                              min_value=1):
            room = self.config.room_repository.get_room(
                data.get('room').get('id'))
            if room is None:
                ack.add_error('A room with this id does not exist')
            elif len(room.nodes) != 2:
                ack.add_error('A room needs exactly two nodes')
        validate.float(volume, label="Volume", min_value=0.0)

        return ack
Exemplo n.º 4
0
    def validate(self, data: dict, create: bool) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :param bool create: If a new node will be created from this data or an existing updated.
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        node_id = data.get('id')
        name = data.get('name')
        detector = data.get('detector')

        validate.string(name, label='Name', min_value=1, max_value=50)

        if self.config.balance:
            ack.add_error('No configuration changes can be made when balancing is active')

        if detector is not None:
            validate.string(detector, label='Detection Algorithm', min_value=3, max_value=8)

        if data.get('room') is None or isinstance(data.get('room'), dict) is False:
            ack.add_error('Room id must not be empty')
        elif validate.integer(data.get('room').get('id'), label='Room id', min_value=1):
            if self.config.room_repository.get_room(data.get('room').get('id')) is None:
                ack.add_error('A room with this id does not exist')

        if create:
            if self.config.node_repository.get_node_by_name(name) is not None:
                ack.add_error('A node with this name already exists')
        elif validate.integer(node_id, label='Node id', min_value=1):
            existing_name = self.config.node_repository.get_node_by_name(name)

            if self.config.node_repository.get_node(node_id) is None:
                ack.add_error('Node with this id does not exist')
            elif existing_name and existing_name.node_id != node_id:
                ack.add_error('A node with this name already exists')

        return ack
Exemplo n.º 5
0
    def validate(self, data: dict, create: bool) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :param bool create: If a new room will be created from this data or an existing updated.
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        room_id = data.get('id')
        name = data.get('name')
        people_group = data.get('people_group')

        validate.string(name, label='Name', min_value=1, max_value=50)

        if self.config.balance:
            ack.add_error(
                'No configuration changes can be made when balancing is active'
            )

        if people_group is not None:
            validate.string(people_group,
                            label='Handle multiple people',
                            min_value=5,
                            max_value=10)

        if create:
            if self.config.room_repository.get_room_by_name(name) is not None:
                ack.add_error('A room with this name already exists')
        elif validate.integer(room_id, label='Room id', min_value=1):
            existing = self.config.room_repository.get_room_by_name(name)

            if self.config.room_repository.get_room(room_id) is None:
                ack.add_error('Room with this id does not exist')
            elif existing and existing.room_id != room_id:
                ack.add_error('A room with this name already exists')

        return ack