예제 #1
0
    def updateMovie(self, params, recordForUndo=True):
        """
		updates the title of a movie with a given ID
		input: the params read from the keyboard
		raise: error if there are missing parameters
		"""
        if params == "" or len(params) < 2:
            raise TypeError("Missing parameters!")

        ID = params[0]
        title = params[1]
        description = params[2]
        genre = params[3]
        self.validateNr(ID)
        if recordForUndo == True:
            mv = self._movieRepo.getByID(int(ID))
            undo = functionCall(self.updateMovie, [
                str(mv.getID()),
                mv.getTitle(),
                mv.getDescription(),
                mv.getGenre()
            ], False)
            redo = functionCall(self.updateMovie,
                                [ID, title, description, genre], False)
            operation = op(redo, undo)
            self._undoController.recordOperation(operation)
        self._movieRepo.updateElement(
            int(ID), movie(int(ID), title, description, genre))
예제 #2
0
    def removeMovie(self, params, recordForUndo=True):
        """
		removes a movie by ID and the rentals associated with it
		input: the params read from the keyboard
		raise: error if there are missing parameters
		"""
        if params == "" or len(params[0]) == 0:
            raise TypeError("Missing parameters!")
        ID = params[0]
        self.validateNr(ID)

        redo = functionCall(self._movieRepo.removeElement, int(ID))
        mv = self._movieRepo.getByID(int(ID))
        undo = functionCall(self._movieRepo.addElement, mv)
        operation = op(redo, undo)
        cascadedOperation = cascadedOp(operation)

        self._movieRepo.removeElement(int(ID))
        rents = self._rentalRepo.getList().keys()
        toDelete = []
        for i in rents:
            if self._rentalRepo.getList()[i].getMovieID() == int(ID):
                toDelete.append(i)
        for i in toDelete:

            rt = self._rentalRepo.getByID(i)
            undo = functionCall(self._rentalRepo.addElement, rt)
            redo = functionCall(self._rentalRepo.removeElement, i)
            operation = op(redo, undo)
            cascadedOperation.add(operation)

            self._rentalRepo.removeElement(i)

        self._undoController.recordOperation(cascadedOperation)
	def Return(self, params, recordForUndo = True):
		"""
		performs the return of a movie
		input: the params read from the keyboard
		"""
		IDrent = params[0]
		self.validateNr(IDrent)
		returnDate = self.buildDate(params[1])

		redo = functionCall(self._store.checkReturn, int(IDrent), returnDate, self._rentalRepo)
		undo = functionCall(self._rentalRepo.updateElement, int(IDrent), 0)
		operation = op(redo, undo)
		self._undoController.recordOperation(operation)
		
		self._store.checkReturn(int(IDrent), returnDate, self._rentalRepo)
예제 #4
0
    def addMovie(self, params, recordForUndo=True):
        """
		adds a new movie to the store
		"""
        if params == "" or len(params) < 3:
            raise TypeError("Missing parameters!")
        ID = params[0]
        name = params[1]
        description = params[2]
        genre = params[3]
        self.validateNr(ID)
        mv = movie(int(ID), name, description, genre)
        self._movieRepo.addElement(mv)
        if recordForUndo == False:
            return
        undo = functionCall(self._movieRepo.removeElement, int(ID))
        redo = functionCall(self.addMovie, [ID, name, description, genre],
                            False)
        operation = op(redo, undo)
        self._undoController.recordOperation(operation)
	def rent(self, params, recordForUndo = True):
		"""
		performs the rent of a movie
		input: the params read from the keyboard
		"""
		IDclient = params[0]
		IDmovie = params[1]
		self.validateNr(IDclient)
		self.validateNr(IDmovie)
		rentDate = self.buildDate(params[2])
		dueDate = self.buildDate(params[3])
		rt = rental(int(IDmovie), int(IDclient), rentDate, dueDate)
		self._store.checkRent(rt, self._clientRepo, self._movieRepo, self._rentalRepo)
		
		redo = functionCall(self._rentalRepo.addElement, rt)
		undo = functionCall(self._rentalRepo.removeElement, rt.getID())
		operation = op(redo, undo)
		self._undoController.recordOperation(operation)
		
		self._rentalRepo.addElement(rt)