AssetMappingService { @Transactional protected List<TMTextUnit> createTMTextUnitForUnmappedAssetTextUnits(User createdByUser, Long assetExtractionId, Long tmId, Long assetId) { logger.debug("Create TMTextUnit for unmapped AssetTextUnits, assetExtractionId: {} tmId: {}", assetExtractionId, tmId); List<TMTextUnit> newlyCreatedTMTextUnits = new ArrayList<>(); Asset asset = assetRepository.findById(assetId).orElse(null); TM tm = tmRepository.findById(tmId).orElse(null); for (AssetTextUnit unmappedAssetTextUnit : assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtractionId)) { TMTextUnit addTMTextUnit = tmService.addTMTextUnit( tm, asset, unmappedAssetTextUnit.getName(), unmappedAssetTextUnit.getContent(), unmappedAssetTextUnit.getComment(), createdByUser, null, unmappedAssetTextUnit.getPluralForm(), unmappedAssetTextUnit.getPluralFormOther()); newlyCreatedTMTextUnits.add(addTMTextUnit); } logger.debug("Created {} TMTextUnits", newlyCreatedTMTextUnits.size()); return newlyCreatedTMTextUnits; }  @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask);  }
@Test public void testCreateTMTextUnitForUnmappedAssetTextUnits() throws RepositoryNameAlreadyUsedException { logger.debug("Create data for test"); createOtherTMAssetAndTextUnit("other-repository", "other asset content", "other-asset-path", "TEST1", "Content1", "Comment1"); AssetExtraction assetExtractionOther = assetExtractionRepository.save(new AssetExtraction()); assetExtractionService.createAssetTextUnit(assetExtractionOther, "TEST2", "Content2", "Comment2"); Repository testRepository = repositoryService.createRepository(testIdWatcher.getEntityName("testCreateTMTextUnitForUnmappedAssetTextUnits")); TM tm = testRepository.getTm(); Asset asset = assetService.createAssetWithContent(testRepository.getId(), "test-asset-path", "test asset content"); AssetExtraction assetExtraction = assetExtractionRepository.save(new AssetExtraction()); assetExtractionService.createAssetTextUnit(assetExtraction, "TEST1", "Content1", "Comment1"); assetExtractionService.createAssetTextUnit(assetExtraction, "TEST2", "Content2", "Comment2"); assetExtractionService.createAssetTextUnit(assetExtraction, "TEST3", "Content3", "Comment3"); logger.debug("Done creating data for test, start testing"); assertEquals("Nothing should be mapped yet", 3, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction.getId()).size()); assertEquals("No TMTextUnit should be present in the TM", 0, tmTextUnitRepository.findByTm_id(tm.getId()).size()); assetMappingService.createTMTextUnitForUnmappedAssetTextUnitsWithRetry(assetExtraction.getId(), tm.getId(), asset.getId(), null); assertEquals("A TMTextUnit should have been created for each AssetTextUnit", 3, tmTextUnitRepository.findByTm_id(tm.getId()).size()); }