Exemple #1
0
    def store(self, discipline_id, student_id, grade_value):
        """
        Stores a Grade instance in the repository
        :param discipline_id: The ID of the discipline at which the grade is given
        :param student_id: The ID of the graded student
        :param grade_value: The value of the grade
        :return: -
        :exceptions: RepoException; GradeException
        """
        self.__grade_validator.validate_discipline(discipline_id)
        self.__grade_validator.validate_student_id(student_id)

        if self.__student_repository.find_by_id(student_id) is None:
            raise RepositoryException("Invalid student ID!")
        if self.__discipline_repository.find_by_id(discipline_id) is None:
            raise RepositoryException("Invalid discipline ID!")

        student_name = self.__student_repository.find_by_id(
            student_id).get_name()
        discipline_name = self.__discipline_repository.find_by_id(
            discipline_id).get_name()

        self.__grade_validator.validate_grade_value(grade_value)

        grade = Grade(discipline_id, discipline_name, student_id, student_name,
                      grade_value)
        self.__grades_list.append(grade)
Exemple #2
0
    def test_add_grade(self, discipline_id, student_id, grade_value):
        """
        Simulates an add_grade, raises any eventual exceptions
        :param discipline_id: Discipline's ID
        :param student_id: Student's ID
        :param grade_value: Grade value
        :return: -
        """
        self.__grade_validator.validate_discipline(discipline_id)
        self.__grade_validator.validate_student_id(student_id)

        if self.__student_repository.find_by_id(student_id) is None:
            raise RepositoryException("Invalid student ID!")
        if self.__discipline_repository.find_by_id(discipline_id) is None:
            raise RepositoryException("Invalid discipline ID!")

        self.__grade_validator.validate_grade_value(grade_value)
Exemple #3
0
    def test_remove(self, discipline_id):
        """
        Simulates a delete, raises any eventual exceptions
        :param discipline_id: Discipline's ID
        :return: -
        """
        self.__validator.validate_id(discipline_id)

        discipline = self.find_by_id(discipline_id)
        if discipline is None:
            raise RepositoryException("Discipline not found!")
    def test_remove_student(self, student_id):
        """
        Simulates a delete, raises any eventual exceptions
        :param student_id: Student's ID
        :return: -
        """
        self.__validator.validate_id(student_id)

        student = self.find_by_id(student_id)
        if student is None:
            raise RepositoryException("Student not in repository!")
Exemple #5
0
    def test_update(self, discipline_id, discipline_name):
        """
        Simulates an update_discipline, raises any eventual exceptions
        :param discipline_id: Discipline's ID
        :param discipline_name: Discipline's name
        :return: -
        """
        self.__validator.validate_id(discipline_id)
        self.__validator.validate_name(discipline_name)

        discipline = self.find_by_id(discipline_id)
        if discipline is None:
            raise RepositoryException("Discipline not found!")
    def test_update(self, student_id, new_name, new_disciplines_list):
        """
        Simulates an update, raises any eventual exceptions
        :param student_id: Student's ID
        :param new_name: Student's new name
        :param new_disciplines_list: The new discipline list for the student
        :return: -
        """
        self.__validator.validate_id(student_id)
        self.__validator.validate_name(new_name)

        student = self.find_by_id(student_id)
        if student is None:
            raise RepositoryException("Student not found!")
    def test_add_student(self, student_id, student_name, disciplines_list):
        """
        Simulates a store, raises any eventual exceptions
        :param student_id: Student's ID
        :param student_name: Student's name
        :param disciplines_list: list of Disciplines the new student is enrolled to
        :return: -
        """
        self.__validator.validate_name(student_name)
        self.__validator.validate_id(student_id)

        if self.find_by_id(student_id) is not None:
            raise RepositoryException("Student having id=" + str(student_id) +
                                      " already stored!")
    def __str__(self):
        """
        Override of the str function for the repository
        :return: A string containing all the students in the repository
        :exception RepoException: Student repository is empty
        """
        if len(self.__students) == 0:
            raise RepositoryException("Student repository is empty!")

        return_string = "Students:\n"
        for st in self.__students:
            return_string += str(st)
            return_string += "\n"
        return return_string
    def get_all(self):
        """
        Gets a list of all the students contained in the repository
        :return: A list containing all students stored in the repository
        """
        return_list = []

        for st in self.__students:
            return_list.append(st)

        if len(return_list) == 0:
            raise RepositoryException("The repository is empty!")

        return return_list
Exemple #10
0
    def add_discipline_to_student(self, student_id, discipline_name):
        """
        Adds the given discipline to the list of disciplines the given student (by id) is enrolled to
        :param student_id: Student's ID
        :param discipline_name: New discipline's name
        :return: -
        :exceptions: StudentException, RepoException
        """
        if self.__student_repository.find_by_id(student_id) is None:
            raise RepositoryException(
                "Student with the given ID not in the repository!")

        self.__student_repository.find_by_id(student_id).add_discipline(
            discipline_name)
Exemple #11
0
    def get_all(self):
        """
        Getter for the list of Discipline instances in the repository
        :return: The list of Discipline instances in the repository
        :exceptions: RepoException: The repository is empty
        """
        return_list = []

        for discipline in self.__disciplines:
            return_list.append(discipline)

        if len(return_list) == 0:
            raise RepositoryException("The repository is empty!")
        return return_list
Exemple #12
0
    def remove_discipline_for_student(self, student_id, discipline_name):
        """
        Removes the given discipline from the list of disciplines the given student (by id) is enrolled to
        :param student_id: Student's ID
        :param discipline_name: Discipline's name
        :return: -
        :exceptions: RepoException, StudentException
        """
        if self.__student_repository.find_by_id(student_id) is None:
            raise RepositoryException(
                "Student with the given ID not in the repository!")

        self.__student_repository.find_by_id(student_id).remove_discipline(
            discipline_name)
Exemple #13
0
    def test_discipline(self, discipline_id, discipline_name):
        """
        Simulates a store, raises any eventual exceptions
        :param discipline_id: Discipline's ID
        :param discipline_name: Discipline's name
        :return: -
        """
        self.__validator.validate_id(discipline_id)
        self.__validator.validate_name(discipline_name)

        if self.find_by_id(discipline_id) is not None:
            raise RepositoryException("Discipline having ID " +
                                      str(discipline_id) +
                                      " already in the repository!")
Exemple #14
0
    def get_id_by_name(self, discipline_name):
        """
        Getter for the ID of the Discipline instance with the given discipline_name
        :param discipline_name: The name of the Discipline instance to be searched for
        :return: The ID of the searched discipline if it exists
        :raises: RepoException: Discipline with the given name not in the repository
        """
        self.__validator.validate_name(discipline_name)

        for discipline in self.__disciplines:
            if discipline_name == discipline.get_name():
                return discipline.get_id()

        raise RepositoryException(
            "Discipline with the given discipline_name not in the repository!")
Exemple #15
0
    def __str__(self):
        """
        Overrides the str function for DisciplineRepository objects
        :return: A string containing the string form of all the Discipline objects in the repository
        :raises: RepoException: The discipline repository is empty
        """
        if len(self.__disciplines) == 0:
            raise RepositoryException("Discipline repository is empty!")

        return_string = "Disciplines:\n"
        for disc in self.__disciplines:
            return_string += str(disc)
            return_string += "\n"

        return return_string
Exemple #16
0
    def delete(self, discipline_id):
        """
        Deletes a Discipline instance from the repository based on the ID
        :param discipline_id: The ID of the Discipline instance to  be removed from the repository
        :return: The removed Discipline instance
        :raises: RepoException: No Discipline instance with the given ID found in repository
        """
        self.__validator.validate_id(discipline_id)

        discipline = self.find_by_id(discipline_id)
        if discipline is None:
            raise RepositoryException("Discipline not found!")
        self.__disciplines.remove(discipline)

        return discipline
    def delete(self, student_id):
        """
        Deletes the student with the given ID from the repository
        :param student_id: The ID of the student to be removed
        :return: The deleted student
        :exception RepoException, StudentException
        """
        self.__validator.validate_id(student_id)

        student = self.find_by_id(student_id)
        if student is None:
            raise RepositoryException("Student not in the repository!")

        self.__students.remove(student)
        return student
Exemple #18
0
    def get_all(self):
        """
        Getter for the list of Grade instances in the repository
        :return: The list of Grade instances in the repository
        :exceptions: RepoException
        """
        return_list = []

        for grade in self.__grades_list:
            return_list.append(grade)

        if len(return_list) == 0:
            raise RepositoryException("The repository is empty!")

        return return_list
Exemple #19
0
    def update(self, discipline_id, discipline_name):
        """
        Updates a Discipline instance in the repository
        :param discipline_id: The ID of the discipline in the repository to be updated
        :param discipline_name: The new name of the discipline to be updated
        :return: -
        :raises: RepoException: The Discipline instance to be updated was not found
        """
        self.__validator.validate_id(discipline_id)
        self.__validator.validate_name(discipline_name)

        old_discipline = self.delete(discipline_id)
        if old_discipline is None:
            raise RepositoryException("No discipline with the given ID!")

        self.store(discipline_id, discipline_name)
    def search_by_name(self, search_substring):
        """
        Creates a new list of all students with the search_substring string contained in the Name attribute
        :param search_substring: The string to be searched for in the Name attribute of each student
        :return: A list containing the searched students
        :exception RepoException: No student found
        """
        result = []

        for student in self.__students:
            if search_substring in student.get_name():
                result.append(student)

        if len(result) == 0:
            raise RepositoryException("No student was found.")

        return result
Exemple #21
0
    def store(self, discipline_id, discipline_name):
        """
        Stores a Discipline instance in the repository
        :param discipline_id: The ID of the discipline to be stored in the repository
        :param discipline_name: The name of the discipline to be stored in the repository
        :return: -
        :raises: RepoException: Discipline having the given ID already in the repository
        """
        self.__validator.validate_id(discipline_id)
        self.__validator.validate_name(discipline_name)

        if self.find_by_id(discipline_id) is not None:
            raise RepositoryException("Discipline having ID " +
                                      str(discipline_id) +
                                      " already in the repository!")

        self.__disciplines.append(Discipline(discipline_id, discipline_name))
    def update(self, student_id, new_name, new_disciplines_list):
        """
        Updates the student with the new data if a student with the given ID exists in the repository
        :param student_id: ID of the student to be updated
        :param new_name: The new name of the student
        :param new_disciplines_list: The new discipline list for the student
        :return: -
        :exception RepoException, StudentException
        """
        self.__validator.validate_id(student_id)
        self.__validator.validate_name(new_name)

        old_student = self.delete(student_id)
        if old_student is None:
            raise RepositoryException("No student with the given ID!")

        self.store(student_id, new_name, new_disciplines_list)
Exemple #23
0
    def search_disciplines_by_id_substring(self, search_substring):
        """
        Searches for Discipline instances in the repository by a substring to be contained in the ID attribute
        :param search_substring: The substring to be contained by the ID attribute
        :return: A list of all the Discipline instances that contain the given substring in
         the ID attribute
        :exception: RepoException: No discipline was found
        """
        result = []

        for discipline in self.__disciplines:
            if search_substring in discipline.get_id():
                result.append(discipline)

        if len(result) == 0:
            raise RepositoryException("No discipline was found.")

        return result
    def store(self, student_id, student_name, disciplines_list):
        """
        Stores the student in the repository if a student with the same ID is not already stored
        :param student_id: Student's ID
        :param student_name: Student's name
        :param disciplines_list: The list of disciplines the student is enrolled to
        :return: -
        :exception RepoException, StudentException
        """
        self.__validator.validate_name(student_name)
        self.__validator.validate_id(student_id)

        if self.find_by_id(student_id) is not None:
            raise RepositoryException("Student having id=" + str(student_id) +
                                      " already stored!")

        student = Student(student_id, student_name, disciplines_list)
        self.__students.append(student)
Exemple #25
0
    def student_has_discipline(self, student_id, discipline_name):
        """
        Checks if the given students is enrolled at the given discipline
        :param student_id: Student's ID
        :param discipline_name: Discipline's name
        :return: True if the student is enrolled at the given discipline, False otherwise
        :exceptions: RepoException, StudentException
        """
        if self.__student_repository.find_by_id(student_id) is None:
            raise RepositoryException(
                "Student with the given ID not in the repository!")

        for discipline in self.__student_repository.find_by_id(
                student_id).get_disciplines():
            if discipline_name == discipline:
                return True

        return False