Exemple #1
0
    def removeBook(self, id, recordForUndo=True):
        """
        Removes the book with a given id
        :param id: the id of the book that will be removed
        :return: the removed book if book was removed
                Exception otherwise
        """
        book = self.findBookByBookId(id)
        index = self.findIndexInRepo(id)
        cascadeOp = CascadeOperation()

        if recordForUndo:
            list = self._rentalController.removeRentalByBookId(id)
            for i in range(len(list) - 1, -1, -1):
                undo_casc = FunctionCall(self._rentalController.addRental,
                                         list[i].getId(), list[i].getBookId(),
                                         list[i].getClientId(),
                                         list[i].getRentedDate(),
                                         list[i].getDueDate(),
                                         list[i].getReturnedDate(), False)
                redo_casc = FunctionCall(self._rentalController.removeRental,
                                         list[i].getId(), False)
                op = Operation(redo_casc, undo_casc)
                cascadeOp.add(op)

            undo = FunctionCall(self.addBook, book.getId(), book.getTitle(),
                                book.getDescription(), book.getAuthor(), False)
            redo = FunctionCall(self.removeBook, book.getId(), False)
            operation = Operation(redo, undo)
            cascadeOp.add(operation)
            self._undoController.recordOperation(cascadeOp)

        self._bookRepo.remove(book)
        return book
    def updateRental(self,
                     id,
                     bookId,
                     clientId,
                     rentedDate,
                     dueDate,
                     returnedDate,
                     recordForUndo=True):
        """
        Updates the rental with a given id with the given data
        """
        rental = Rental(id, bookId, clientId, rentedDate, dueDate,
                        returnedDate)
        oldRental = copy.deepcopy(self.getRentalById(id))
        index = self.getIndexById(oldRental.getId())
        self._rentalRepo.update(index, rental)
        if recordForUndo == True:
            undo = FunctionCall(self.updateRental, oldRental.getId(),
                                oldRental.getBookId(), oldRental.getClientId(),
                                oldRental.getRentedDate(),
                                oldRental.getDueDate(),
                                oldRental.getReturnedDate(), False)
            redo = FunctionCall(self.updateRental, id, bookId, clientId,
                                rentedDate, dueDate, returnedDate, False)
            operation = Operation(redo, undo)
            self._undoController.recordOperation(operation)

        return oldRental
    def rent(self, rentalId, clientId, movieId, n, client_repo, movie_repo):
        """
        Creates a new rental with the given parameters
        The function checks if the movie is available (either has not been rented or the return dat is set != None
        Takes the number of days for the rental and uses it to create a due_date
        """
        returned_date = None  # None
        # fa-l input cu numarul de zile
        rented_date = datetime.now()
        due_date = datetime.now() + timedelta(days=n)
        print(clientId, movieId, client_repo.get_position(clientId))

        if client_repo.find_by_id(clientId):
            if movie_repo.find_by_id(movieId) == True:
                client = client_repo[client_repo.get_position(clientId)]
                movie = movie_repo[movie_repo.get_position(movieId)]

                print("The Client:", client.name, "rented the movie: ",
                      movie.title, " ")
                rental = Rental(rentalId, movie.id, client.id, rented_date,
                                due_date, returned_date)

                undo = FunctionCall(self.remove_by_clientId,
                                    self.__rentalList.size() - 1)
                redo = FunctionCall(self.add, rental)
                op = Operation(undo, redo)
                self.__undo_controller.addOperation(op)

                self.__rentalList.add(rental)
Exemple #4
0
    def updateBook(self, id, title, description, author, recordForUndo=True):
        """
        Updates the book with the given id with a new book
        :param id: int
        :param title: the new title
        :param description: the new description
        :param author: the new author
        :return:the book before it was updated
        """
        okId = False
        for i in self._bookRepo.getAll():
            if id == i.getId():
                okId = True
        if not okId:
            raise InvalidIdException
        lastBook = copy.deepcopy(self.findBookByBookId(id))
        index = self.findIndexInRepo(id)
        book = Book(id, title, description, author)

        if recordForUndo == True:
            undo = FunctionCall(self.updateBook, id, lastBook.getTitle(),
                                lastBook.getDescription(),
                                lastBook.getAuthor(), False)
            redo = FunctionCall(self.updateBook, id, title, description,
                                author, False)
            operation = Operation(redo, undo)
            self._undoController.recordOperation(operation)
        self._bookRepo.update(index, book)
        return lastBook
    def addRental(self,
                  id,
                  bookId,
                  clientId,
                  rentalDate=datetime.timedelta(0),
                  dueDate=datetime.timedelta(0),
                  returnedDate="",
                  recordForUndo=True):
        """
        Adds a new rent to repository
        :param rent: rent class
        :return: rental
        """
        if self.checkId(id) == False:
            raise InvalidIdException
        if rentalDate == datetime.timedelta(0):
            rentalDate = datetime.datetime.now().date()
        if dueDate == datetime.timedelta(0):
            dueDate = rentalDate + datetime.timedelta(days=10)
        rental = self.validation(id, bookId, clientId, rentalDate, dueDate,
                                 returnedDate)
        self._rentalRepo.add(rental)
        if recordForUndo == True:
            undo = FunctionCall(self.removeRental, id, False)
            redo = FunctionCall(self.addRental, id, bookId, clientId,
                                rentalDate, dueDate, returnedDate, False)
            operation = Operation(redo, undo)
            self._undoController.recordOperation(operation)

        return rental
Exemple #6
0
    def removeStudent(self, studentID):
        name_up = self.searchByID(studentID).name

        self.__student_repository.delete(studentID)

        redo = FunctionCall(self.removeStudent, studentID)
        undo = FunctionCall(self.addStudent, studentID, name_up)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Exemple #7
0
    def updateStudent(self, studentID, name):
        student = Student(studentID, name)

        name_up = self.searchByID(studentID).name
        self.__student_repository.update(student)

        redo = FunctionCall(self.updateStudent, studentID, name)
        undo = FunctionCall(self.updateStudent, studentID, name_up)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
    def add(self, new_rental):
        """
        Adds a new rental to the list
        """
        undo = FunctionCall(self.remove_by_clientId, new_rental.clientId)
        redo = FunctionCall(self.add, new_rental)
        op = Operation(undo, redo)
        self.__undo_controller.addOperation(op)

        self.__rentalList.add(new_rental)
Exemple #9
0
    def addGrade(self, disciplineID, studentID, gradeValue):
        grade = Grade(disciplineID, studentID, gradeValue)
        self.checkExistentIdInRepository(grade, self.__student_repository,
                                         self.__discipline_repository)
        self.__grade_repository.save(grade)

        redo = FunctionCall(self.addGrade, disciplineID, studentID, gradeValue)
        undo = FunctionCall(self.removeGrade, disciplineID, studentID,
                            gradeValue)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Exemple #10
0
 def _return(self, pos):
     """
     Function for returning a movie
     The returned_date is set to datetime.now()
     """
     returned_date = datetime.now()
     self.__rentalList[pos].set_returned_date(returned_date)
     undo = FunctionCall(self.__rentalList[pos].set_returned_date, None)
     redo = FunctionCall(self.__rentalList[pos].set_returned_date,
                         datetime.now())
     operation = Operation(undo, redo)
     self.__undo_controller.addOperation(operation)
Exemple #11
0
    def remove_by_disciplineID(self, disciplineID):
        lstGrade = self.get_all_grade()
        lst_removed_disciplines = []
        for i in lstGrade:
            if int(i.disciplineID) == int(disciplineID):
                self.__grade_repository.delete(i.entity_ID)
                lst_removed_disciplines.append(i)

        redo = FunctionCall(self.remove_by_studentID, disciplineID)
        undo = FunctionCall(self.add_removed, lst_removed_disciplines)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Exemple #12
0
    def updateDiscipline(self, disciplineID, name):
        """
        Update a discipline from the repository
        :param args: the discipline arguments
        :return: None.
        """
        discipline = Discipline(disciplineID, name)
        self.__discipline_repository.update(discipline)

        redo = FunctionCall(self.updateDiscipline, disciplineID, name)
        undo = FunctionCall(self.updateDiscipline, disciplineID)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Exemple #13
0
    def removeDiscipline(self, disciplineID):
        """
        Remove a discipline from the repository
        :param args: the discipline arguments
        :return: None.
        """
        name_up = self.searchByID(disciplineID).name
        self.__discipline_repository.delete(disciplineID)

        redo = FunctionCall(self.removeDiscipline, disciplineID)
        undo = FunctionCall(self.addDiscipline, disciplineID, name_up)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Exemple #14
0
    def addDiscipline(self, disciplineID, name):
        """
        Add a discipline to the repository
        :param args: the discipline arguments
        :return: None.
        """

        discipline = Discipline(disciplineID, name)
        self.__discipline_repository.save(discipline)

        redo = FunctionCall(self.addDiscipline, disciplineID, name)
        undo = FunctionCall(self.removeDiscipline, disciplineID)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
Exemple #15
0
    def addStudent(self, studentID, name):
        """
        Add a student to the repository
        :param args: the student arguments
        :return: None.
        """

        student = Student(studentID, name)
        self.__student_repository.save(student)

        redo = FunctionCall(self.addStudent, studentID, name)
        undo = FunctionCall(self.removeStudent, studentID)
        operation = Operation(redo, undo)
        self.__undoController.recordOperation(operation)
    def removeRental(self, id, recordForUndo=True):

        rental = self.getRentalById(id)
        oldRental = copy.deepcopy(rental)
        if recordForUndo:
            undo = FunctionCall(self.addRental, oldRental.getId(),
                                oldRental.getBookId(), oldRental.getClientId(),
                                oldRental.getRentedDate(),
                                oldRental.getDueDate(),
                                oldRental.getReturnedDate(), False)
            redo = FunctionCall(self.removeRental, oldRental.getId(), False)
            operation = Operation(redo, undo)
            self._undoController.recordOperation(operation)

        self._rentalRepo.remove(rental)

        return oldRental
Exemple #17
0
    def addBook(self, id, title, description, author, recordForUndo=True):
        """
        Adds a new book
        :param book: class Book
        :return: book - for undo/redo
        """
        if self.checkId(id) == False:
            raise InvalidIdException
        book = Book(id, title, description, author)
        self._bookRepo.add(book)

        if recordForUndo == True:
            undo = FunctionCall(self.removeBook, id, False)
            redo = FunctionCall(self.addBook, id, title, description, author,
                                False)
            operation = Operation(redo, undo)
            self._undoController.recordOperation(operation)

        return book