コード例 #1
0
    def delete(self, carId):
        '''
            1. Delete the car from the repository
        '''
        car = self.__repository.delete(carId)

        '''
            2. Delete its rentals
            NB! This implementation is not transactional, i.e. the two delete operations are performed separately
        '''
        rentals = self._rentalController.filterRentals(None, car)
        for rent in rentals:
            self._rentalController.deleteRental(rent.id, False)

        '''
        If the operation did not raise an Exception, then we record it for Undo/Redo
        '''
        cascadeOp = CascadedOperation()

        redo = FunctionCall(self.delete, carId)
        undo = FunctionCall(self.create, car.id,
                            car.license, car.make, car.model)
        cascadeOp.add(Operation(redo, undo))

        for rent in rentals:
            redo = FunctionCall(self._rentalController.deleteRental, rent.id)
            undo = FunctionCall(self._rentalController.createRental,
                                rent.id, rent.client, rent.car, rent.start, rent.end)
            cascadeOp.add(Operation(redo, undo))
        self._undoController.recordOperation(cascadeOp)

        return car
コード例 #2
0
    def delete(self, clientId):
        '''
            1. Delete the client
        '''
        client = self.__repository.delete(clientId)
        '''
            2. Delete their rentals
            NB! This implementation is not transactional, i.e. the two delete operations are performed separately
        '''
        rentals = self._rentalController.filterRentals(client, None)
        for rent in rentals:
            self._rentalController.deleteRental(rent.getId(), False)
        '''
        If the operation did not raise an Exception, then we record it for Undo/Redo
        '''
        cascadeOp = CascadedOperation()

        redo = FunctionCall(self.delete, clientId)
        undo = FunctionCall(self.create, client.id, client.cnp, client.name)
        cascadeOp.add(Operation(redo, undo))

        for rent in rentals:
            redo = FunctionCall(self._rentalController.deleteRentalNoUndo,
                                rent.id)
            undo = FunctionCall(self._rentalController.createRental, rent.id,
                                rent.client, rent.car, rent.start, rent.end)
            cascadeOp.add(Operation(redo, undo))
        self._undoController.recordOperation(cascadeOp)

        return client
コード例 #3
0
 def updateDiscipline(self, ident, newName):
     oldName = self._disciplineRepo[ident].name
     DisciplineController.updateDiscipline(self, ident, newName)
     redo = FunctionCall(self.updateDiscipline, ident, newName)
     undo = FunctionCall(self.updateDiscipline, ident, oldName)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
コード例 #4
0
 def updateStudent(self, ident, newName):
     oldName = self._studentRepo[ident].name
     StudentController.updateStudent(self, ident, newName)
     redo = FunctionCall(self.updateStudent, ident, newName)
     undo = FunctionCall(self.updateStudent, ident, oldName)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
コード例 #5
0
 def addGrade(self, disciplineId, studentId, grade):
     GradeController.addGrade(self, disciplineId, studentId, grade)
     '''
     '''
     redo = FunctionCall(self.addGrade, disciplineId, studentId, grade)
     undo = FunctionCall(self.removeLastGrade, disciplineId, studentId)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
コード例 #6
0
 def removeDiscipline(self, ident):
     name = self._disciplineRepo[ident].name
     DisciplineController.removeDiscipline(self, ident)
     redo = FunctionCall(self.removeDiscipline, ident)
     undo = FunctionCall(self.addDiscipline, ident, name)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
     self._gradeController.removeDiscipline(ident)
コード例 #7
0
 def enrollStudent(self, disciplineId, studentId, grade):
     GradeController.enrollStudent(self, disciplineId, studentId, grade)
     '''
     '''
     redo = FunctionCall(self.enrollStudent, disciplineId, studentId, grade)
     undo = FunctionCall(self.newRemove, disciplineId, studentId)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
コード例 #8
0
 def addDiscipline(self, ident, name):
     d = DisciplineController.addDiscipline(self, ident, name)
     '''
     '''
     redo = FunctionCall(self.addDiscipline, ident, name)
     undo = FunctionCall(self.removeDiscipline, ident, name)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
     return d
コード例 #9
0
 def updateRent(self, rentId, date, recordForUndo=True):
     self.__repo.updateRent(rentId, date)
     if recordForUndo == False:
         return
     undo = FunctionCall(self.updateRent, rentId, '0', False)
     redo = FunctionCall(self.updateRent, rentId, date, False)
     operation = []
     operation.append(Operation(redo, undo))
     self._undoController.recordOperation(operation)
コード例 #10
0
 def create(self, clientId, clientCNP, clientName):
     client = Client(clientId, clientCNP, clientName)
     self.__validator.validate(client)
     self.__repository.store(client)
     undo = FunctionCall(self.delete, clientId)
     redo = FunctionCall(self.create, clientId, clientCNP, clientName)
     op = Operation(undo, redo)
     self._undoController.recordOperation(op)
     return client
コード例 #11
0
 def delete(self, id):
     act = self.find(id)
     if act != None:
         f1 = Function(self.__repo.store, act)
         f2 = Function(self.__repo.delete, act)
         o = Operation(f1, f2)
         self.__undoController.addOperation(o)
         return self.__repo.delete(act)
     else:
         return "Activity not found!"
コード例 #12
0
 def addStudent(self, ident, name):
     s = StudentController.addStudent(self, ident, name)
     '''
     If the operation did not raise an Exception, then we record it for Undo/Redo
     '''
     redo = FunctionCall(self.addStudent, ident, name)
     undo = FunctionCall(self.removeStudent, ident)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
     return s
コード例 #13
0
 def removeStudent(self, ident):
     '''
     Removes a student
     '''
     name = self._studentRepo[ident].name
     StudentController.removeStudent(self, ident)
     redo = FunctionCall(self.removeStudent, ident)
     undo = FunctionCall(self.addStudent, ident, name)
     operation = Operation(redo, undo)
     self._undoController.recordOperation(operation)
     self._gradeController.removeStudent(ident)
コード例 #14
0
    def removeDiscipline(self, ident):
        i = 0
        ranOneTime = False
        while i < len(self._gradeRepo._objects):
            if self._gradeRepo._objects[i].disciplineId == ident:
                ranOneTime = True
                l = self._gradeRepo._objects[i]
                del self._gradeRepo._objects[i]
                undo = FunctionCall(self.add, l)
                redo = FunctionCall(self.doNothing)
                operation = Operation(redo, undo)
                self._undoController.recordOperation(operation)
                i -= 1
            i += 1

        if ranOneTime == True:
            undo = FunctionCall(self.doNothing)
            redo = FunctionCall(self.removeDiscipline, ident)
            operation = Operation(redo, undo)
            self._undoController.recordOperation(operation)
コード例 #15
0
    def update(self, player, recordForUndo=True):
        old_player = self._repository.find(player.getFirstName())
        new_player = self._repository.update(player)

        if recordForUndo == True:
            undo = FunctionCall(self.update, new_player, False)
            redo = FunctionCall(self.update, old_player, True)
            casOP = CascadedOp(Operation(redo, undo))
            self._undoController.recordOperation(casOP)

        return new_player
コード例 #16
0
 def addRent(self, item, recordForUndo=True):
     self.__repo.addRent(item)
     if recordForUndo == False:
         return
     undo = FunctionCall(self.removeRent, self.findIdRent(item.get_id()),
                         False)
     redo = FunctionCall(
         self.addRent,
         rent(item.get_id(), item.get_bookId(), item.get_client(),
              item.getRent(), item.getDue(), item.getRet()), False)
     operation = [Operation(redo, undo)]
     self._undoController.recordOperation(operation)
コード例 #17
0
 def removeRent(self, id, recordForUndo=True):
     rento = self.__repo.getRentById(id)
     self.__repo.removeRent(id)
     if recordForUndo == False:
         return
     undo = FunctionCall(
         self.addRent,
         rent(rento.get_id(), rento.get_bookId(), rento.get_client(),
              rento.getRent(), rento.getDue(), rento.getRet()), False)
     redo = FunctionCall(self.removeRent, id, False)
     operation = [Operation(redo, undo)]
     self._undoController.recordOperation(operation)
コード例 #18
0
 def deleteRental(self, rentalId, recordUndo=True):
     rental = self.__repository.delete(rentalId)
     '''
     If the operation did not raise an Exception, then we record it for Undo/Redo
     '''
     if recordUndo == True:
         redo = FunctionCall(self.deleteRental, rentalId)
         undo = FunctionCall(self.createRental, rental.id, rental.client,
                             rental.car, rental.start, rental.end)
         cascadeOp = CascadedOperation(Operation(redo, undo))
         self._undoController.recordOperation(cascadeOp)
     return rental
コード例 #19
0
    def create(self, clientId, clientCNP, clientName):
        client = Client(clientId, clientCNP, clientName)
        self.__repository.store(client)
        '''
        If the operation did not raise an Exception, then we record it for Undo/Redo
        '''
        redo = FunctionCall(self.create, clientId, clientCNP, clientName)
        undo = FunctionCall(self.delete, clientId)
        cascadeOp = CascadedOperation(Operation(redo, undo))
        self._undoController.recordOperation(cascadeOp)

        return client
コード例 #20
0
    def updateBook(self, abook):
        """

        :param abook:
        :return:
        """
        redo = FunctionCall(self.updateBook, abook)
        undo = FunctionCall(self.updateBook,
                            self.__bookRepo.get(abook.getID()))
        operation = Operation(redo, undo)
        self._undoController.recordOperation(operation)
        self.validator.validateBook(abook)
        self.__bookRepo.update(abook)
コード例 #21
0
    def create(self, carId, licensePlate, carMake, carModel):
        car = Car(carId, licensePlate, carMake, carModel)
        self.__repository.store(car)

        '''
        If the operation did not raise an Exception, then we record it for Undo/Redo
        '''
        redo = FunctionCall(self.create, carId,
                            licensePlate, carMake, carModel)
        undo = FunctionCall(self.delete, carId)
        cascadeOp = CascadedOperation(Operation(redo, undo))
        self._undoController.recordOperation(cascadeOp)
        return car
コード例 #22
0
    def create(self, firstname, surname, height, position, recordForUndo=True):
        player = Player(firstname, surname, height, position)
        try:
            self._validator.validate(player)
            self._repository.store(player)
        except Exception as e:
            print(e)

        if recordForUndo == True:
            undo = FunctionCall(self.delete, firstname, False)
            redo = FunctionCall(self.create, firstname, surname, height,
                                position, True)
            casOP = CascadedOp(Operation(redo, undo))
            self._undoController.recordOperation(casOP)
コード例 #23
0
    def updateClient(self, aclient):
        """

        :param aclient:
        :return:
        """
        redo = FunctionCall(self.updateClient, aclient)
        undo = FunctionCall(self.updateClient,
                            self.__clientRepo.get(aclient.getID()))
        operation = Operation(redo, undo)

        self._undoController.recordOperation(operation)
        self.validator.validateClient(aclient)
        self.__clientRepo.update(aclient)
コード例 #24
0
    def addBook(self, book):
        """
        function that adds book to repo
        input: book of type Book
        """
        self.validator.validateBook(book)
        self.__bookRepo.add(book)

        # IF there are no errors we continue to append data for undo/repo

        redo = FunctionCall(self.addBook, book)
        undo = FunctionCall(self.removeBook, book.getID())
        operation = Operation(redo, undo)

        self._undoController.recordOperation(operation)
コード例 #25
0
 def delete_by_discipline(self, discipline_id):
     """
     Override for the delete_by_discipline method in the super class, also records the corresponding
      methods and their parameters for undo/redo
     :param discipline_id: Discipline's ID
     :return:
     """
     self.__grade_validator.validate_discipline(discipline_id)
     list_of_grades = self.get_grades_by_discipline(discipline_id)
     self.__undoController.new_operation()
     undo_function = FunctionCall(self.add_grades, list_of_grades)
     redo_function = FunctionCall(self.get_grade_repository().delete_by_discipline, discipline_id)
     operation = Operation(redo_function, undo_function)
     self.__undoController.record_operation(operation)
     self.get_grade_repository().delete_by_discipline(discipline_id)
コード例 #26
0
 def add_discipline(self, discipline_id, discipline_name):
     """
     Override for the add_discipline method in the super class, also records the corresponding methods and their
     params for undo/redo capability
     :param discipline_id: Discipline's ID
     :param discipline_name: Discipline's name
     :return: -
     """
     self.create_discipline(discipline_id, discipline_name)
     self.__undoController.new_operation()
     undo_function = FunctionCall(self.get_repository().delete, discipline_id)
     redo_function = FunctionCall(self.get_repository().store, discipline_id, discipline_name)
     operation = Operation(redo_function, undo_function)
     self.__undoController.record_operation(operation)
     self.get_repository().store(discipline_id, discipline_name)
コード例 #27
0
 def remove_discipline(self, discipline_id):
     """
     Override for the test_remove method in the super class, also records the corresponding methods and their
     params for undo/redo capability
     :param discipline_id: Discipline's ID
     :return: -
     """
     self.test_remove_discipline(discipline_id)
     self.__undoController.new_operation()
     discipline = self.find(discipline_id)
     undo_function = FunctionCall(self.get_repository().store, discipline.get_id(), discipline.get_name())
     redo_function = FunctionCall(self.get_repository().delete, discipline.get_id())
     operation = Operation(redo_function, undo_function)
     self.__undoController.record_operation(operation)
     self.__discipline_repository.delete(discipline_id)
コード例 #28
0
    def removeBook(self, ID):
        """
        handles removal of element from repository
        :param ID: ID for book to be removed
        :return:
        """
        redo = FunctionCall(self.removeBook, ID)
        undo = FunctionCall(self.addBook, self.__bookRepo.get(ID))
        operation = Operation(redo, undo)

        self.__bookRepo.remove(ID)

        for rental in self.__rentalrepo.getAll():
            if rental.getBookID() == ID:
                self.__rentalrepo.remove(rental.getID())
        self._undoController.recordOperation(operation)
コード例 #29
0
    def delete(self, firstname, recordForUndo=True):
        try:
            player = self._repository.delete(firstname)

            if recordForUndo == True:
                undo = FunctionCall(self.create, firstname,
                                    player.getLastName(), player.getHeight(),
                                    player.getPosition(), False)
                redo = FunctionCall(self.delete, firstname, True)
                casOP = CascadedOp(Operation(redo, undo))
                self._undoController.recordOperation(casOP)

                return player

        except Exception as e:
            print(e)
コード例 #30
0
    def addClient(self, client):
        """

        :param client:
        :return:
        """
        self.validator.validateClient(client)
        self.__clientRepo.add(client)

        # IF there are no errors we continue to append data for undo/repo

        redo = FunctionCall(self.addClient, client)
        undo = FunctionCall(self.removeClient, client.getID())
        operation = Operation(redo, undo)

        self._undoController.recordOperation(operation)