AssetService { @Transactional public void deleteAsset(Asset asset) { logger.debug("Delete an asset with path: {}", asset.getPath()); asset.setDeleted(true); assetRepository.save(asset); int numberOfAssetExtractionByBranchUpdated = assetExtractionByBranchRepository.setDeletedTrue(asset); logger.debug("Deleted asset with path: {} (Number of AssetExtractionByBranchUpdated: {})", asset.getPath(), numberOfAssetExtractionByBranchUpdated); }  PollableFuture<Asset> addOrUpdateAssetAndProcessIfNeeded(
            Long repositoryId,
            String assetPath,
            String assetContent,
            boolean extractedContent,
            String branch,
            String branchCreatedByUsername,
            FilterConfigIdOverride filterConfigIdOverride,
            List<String> filterOptions); Asset createAsset(Long repositoryId, String assetPath, boolean virtualContent); Asset createAssetWithContent(Long repositoryId, String assetPath, String assetContent); @Transactional void deleteAsset(Asset asset); @Transactional void deleteAssets(Set<Long> assetIds); PollableFuture<Void> asyncDeleteAssetsOfBranch(Set<Long> assetIds, Long branchId); void deleteAssetsOfBranch(Set<Long> assetIds, Long branchId); void deleteAssetOfBranch(Long assetId, Long branchId); List<Asset> findAll(Long repositoryId, String path, Boolean deleted, Boolean virtual, Long branchId); Set<Long> findAllAssetIds(Long repositoryId, String path, Boolean deleted, Boolean virtual, Long branchId);  }
@Test public void testAddOrUpdateAssetAndProcessIfNeededShouldUpdateAssetContentAndStartExtractionIfAssetDeletedAndAssetExtractionIsOutdated() throws Exception { String content = "content"; String newContent = "newContent"; String path = "path/to/asset.csv"; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); Asset asset = addAssetAndWaitUntilDoneProcessing(repository.getId(), content, path, null); List<AssetExtraction> assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("There should be one assetExtraction created when the adding an asset with initial content", 1, assetExtractions.size()); Long assetId = asset.getId(); assetService.deleteAsset(asset); asset = assetRepository.findById(assetId).orElse(null); assertTrue("The asset should have been deleted", asset.getDeleted()); asset = addAssetAndWaitUntilDoneProcessing(repository.getId(), newContent, path, null); asset = assetRepository.findById(assetId).orElse(null); assertEquals("Content of existing asset should be updated if changed", newContent, asset.getLastSuccessfulAssetExtraction().getAssetContent().getContent()); assertEquals("Asset id should have remained the same", assetId, asset.getId()); assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("There should be one more assetExtraction created when the adding an asset with changed content", 2, assetExtractions.size()); assertFalse("The asset extraction process should un-delete the deleted asset", assetRepository.findById(assetId).orElse(null).getDeleted()); }
@Test public void testAddOrUpdateAssetAndProcessIfNeededReAddingAsset() throws Exception { String content = "content"; String path = "path/to/asset.csv"; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); Asset asset = addAssetAndWaitUntilDoneProcessing(repository.getId(), content, path, null); List<AssetExtraction> assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("There should be one assetExtraction created when the adding an asset with initial content", 1, assetExtractions.size()); Long assetId = asset.getId(); assetService.deleteAsset(asset); assertTrue("The asset should have been deleted", assetRepository.findById(assetId).orElse(null).getDeleted()); addAssetAndWaitUntilDoneProcessing(repository.getId(), content, path, null); assetExtractions = assetExtractionRepository.findByAsset(asset); assertEquals("When re-adding an asset (same content as previously deleted), it will get processed as normal", 2, assetExtractions.size()); assertFalse("The asset extraction process should un-delete the deleted asset", assetRepository.findById(assetId).orElse(null).getDeleted()); }
@Test public void testDeleteAsset() throws Exception { String content1 = "content1"; String content2 = "content2"; String content3 = "content3"; String path1 = "path/to/asset1.csv"; String path2 = "path/to/asset2.csv"; String path3 = "path/to/asset3.csv"; Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("repository")); Asset asset1 = assetService.createAssetWithContent(repository.getId(), path1, content1); addAssetAndWaitUntilDoneProcessing(repository.getId(), content1, path1, null); Asset asset2 = assetService.createAssetWithContent(repository.getId(), path2, content2); addAssetAndWaitUntilDoneProcessing(repository.getId(), content2, path2, null); Asset asset3 = assetService.createAssetWithContent(repository.getId(), path3, content3); addAssetAndWaitUntilDoneProcessing(repository.getId(), content3, path3, null); assertFalse("asset1 should not be deleted yet", asset1.getDeleted()); assertFalse("asset2 should not be deleted yet", asset2.getDeleted()); assertFalse("asset3 should not be deleted", asset3.getDeleted()); assetService.deleteAssets(Sets.newHashSet(asset1.getId(), asset2.getId())); asset1 = assetRepository.findByPathAndRepositoryId(path1, repository.getId()); assertTrue("asset1 should have been deleted", asset1.getDeleted()); asset2 = assetRepository.findByPathAndRepositoryId(path2, repository.getId()); assertTrue("asset2 should have been deleted", asset2.getDeleted()); asset3 = assetRepository.findByPathAndRepositoryId(path3, repository.getId()); assertFalse("asset3 should not be deleted", asset3.getDeleted()); Set<Long> assetIds = assetRepository.findIdByRepositoryId(repository.getId()); assertEquals("There should be 3 asset ids", 3, assetIds.size()); assetIds = assetRepository.findIdByRepositoryIdAndDeleted(repository.getId(), false); assertEquals("There should be one undeleted asset id", 1, assetIds.size()); assertEquals(asset3.getId(), assetIds.iterator().next()); assetIds = assetRepository.findIdByRepositoryIdAndDeleted(repository.getId(), true); assertEquals("There should be two deleted asset ids", 2, assetIds.size()); }