@Test public void rollback_ADDED_FILES() throws IOException { ContentFileTransactionContext context = new ContentFileTransactionContext(contentDir, deletedTmpDir); context.addAddedFile("file1.txt"); context.addAddedFile("file2.txt"); File file1 = createFile(contentDir, "file1.txt", "content1"); File file2 = createFile(contentDir, "file2.txt", "content2"); file1.createNewFile(); file2.createNewFile(); contentFileCommitRollbackService.rollback(context); assertFalse(file1.exists()); assertFalse(file2.exists()); assertFalse(deletedTmpDir.exists()); }
public void rollback(ContentFileTransactionContext context) throws IOException { Preconditions.checkNotNull(context); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); while(!context.containsAnyAddedFile()) { String addedFilePath = context.pollAddedFile(); File addedFile = new File(contentDirectory, addedFilePath); addedFile.delete(); } FileUtils.copyDirectory(deletedTmpDirectory, contentDirectory); FileUtils.deleteDirectory(deletedTmpDirectory); }
ContentFileCommitRollbackService { public void rollback(ContentFileTransactionContext context) throws IOException { Preconditions.checkNotNull(context); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); while(!context.containsAnyAddedFile()) { String addedFilePath = context.pollAddedFile(); File addedFile = new File(contentDirectory, addedFilePath); addedFile.delete(); } FileUtils.copyDirectory(deletedTmpDirectory, contentDirectory); FileUtils.deleteDirectory(deletedTmpDirectory); } }
ContentFileCommitRollbackService { public void rollback(ContentFileTransactionContext context) throws IOException { Preconditions.checkNotNull(context); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); while(!context.containsAnyAddedFile()) { String addedFilePath = context.pollAddedFile(); File addedFile = new File(contentDirectory, addedFilePath); addedFile.delete(); } FileUtils.copyDirectory(deletedTmpDirectory, contentDirectory); FileUtils.deleteDirectory(deletedTmpDirectory); }  }
ContentFileCommitRollbackService { public void rollback(ContentFileTransactionContext context) throws IOException { Preconditions.checkNotNull(context); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); while(!context.containsAnyAddedFile()) { String addedFilePath = context.pollAddedFile(); File addedFile = new File(contentDirectory, addedFilePath); addedFile.delete(); } FileUtils.copyDirectory(deletedTmpDirectory, contentDirectory); FileUtils.deleteDirectory(deletedTmpDirectory); }  void commit(ContentFileTransactionContext context); void rollback(ContentFileTransactionContext context); }
ContentFileCommitRollbackService { public void rollback(ContentFileTransactionContext context) throws IOException { Preconditions.checkNotNull(context); File contentDirectory = context.getContentDirectory(); File deletedTmpDirectory = context.getDeletedTmpDirectory(); while(!context.containsAnyAddedFile()) { String addedFilePath = context.pollAddedFile(); File addedFile = new File(contentDirectory, addedFilePath); addedFile.delete(); } FileUtils.copyDirectory(deletedTmpDirectory, contentDirectory); FileUtils.deleteDirectory(deletedTmpDirectory); }  void commit(ContentFileTransactionContext context); void rollback(ContentFileTransactionContext context);  }