@Test public void testMap() throws RepositoryLocaleCreationException, 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("testMap")); repositoryService.addRepositoryLocale(testRepository, "fr-FR"); repositoryService.addRepositoryLocale(testRepository, "ja-JP"); TM tm = testRepository.getTm(); Asset asset = assetService.createAssetWithContent(testRepository.getId(), "fake_for_test", "fake for test"); AssetExtraction assetExtraction = new AssetExtraction(); assetExtraction.setAsset(asset); assetExtraction = assetExtractionRepository.save(assetExtraction); assetExtractionService.createAssetTextUnit(assetExtraction, "TEST1A", "Content1A", "Comment1A"); logger.debug("Done creating data for test, start testing"); assertEquals("Nothing should be mapped yet", 1, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction.getId()).size()); assertEquals("No TMTextUnit should be present in the TM", 0, tmTextUnitRepository.findByTm_id(tm.getId()).size()); assetMappingService.mapAssetTextUnitAndCreateTMTextUnit(assetExtraction.getId(), tm.getId(), asset.getId(), null, PollableTask.INJECT_CURRENT_TASK); assertEquals("All AssetTextUnit must be mapped", 0, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction.getId()).size()); Iterator<AssetTextUnitToTMTextUnit> iterator = getAssetTextUnitToTMTextUnit(assetExtraction); AssetTextUnitToTMTextUnit next = iterator.next(); checkMapping(next, assetExtraction, tm); assertFalse("There shouldn't be any other mapping reccords", iterator.hasNext()); Asset updatedAsset = assetRepository.findById(asset.getId()).orElse(null); assertEquals("Last successfulAssetExtraction should be set", asset.getId(), updatedAsset.getId()); logger.debug("Perform mapping on a second asset extraction that has more AssetTextUnit with same TM (what will happen when we keep updating documents)"); AssetExtraction assetExtraction2 = new AssetExtraction(); assetExtraction2.setAsset(asset); assetExtraction2 = assetExtractionRepository.save(assetExtraction2); assetExtractionService.createAssetTextUnit(assetExtraction2, "TEST2A", "Content2A", "Comment2A"); assetExtractionService.createAssetTextUnit(assetExtraction2, "TEST2B", "Content2B", "Comment2B"); assetExtractionService.createAssetTextUnit(assetExtraction2, "TEST2C", "Content2C", "Comment2C"); assetMappingService.mapAssetTextUnitAndCreateTMTextUnit(assetExtraction2.getId(), tm.getId(), asset.getId(), null, PollableTask.INJECT_CURRENT_TASK); assertEquals("All AssetTextUnit must be mapped", 0, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction2.getId()).size()); iterator = getAssetTextUnitToTMTextUnit(assetExtraction2); next = iterator.next(); checkMapping(next, assetExtraction2, tm); checkMapping(iterator.next(), assetExtraction2, tm); checkMapping(iterator.next(), assetExtraction2, tm); assertFalse("There shouldn't be any other mapping reccords", iterator.hasNext()); logger.debug("Perform mapping on a third asset extraction where some AssetTextUnit were removed with same TM (what will happen when we keep updating documents and removing some resources)"); AssetExtraction assetExtraction3 = new AssetExtraction(); assetExtraction3.setAsset(asset); assetExtraction3 = assetExtractionRepository.save(assetExtraction3); assetExtractionService.createAssetTextUnit(assetExtraction3, "TEST3A", "Content3A", "Comment3A"); assetExtractionService.createAssetTextUnit(assetExtraction3, "TEST3C", "Content3C", "Comment3C"); assetMappingService.mapAssetTextUnitAndCreateTMTextUnit(assetExtraction3.getId(), tm.getId(), asset.getId(), null, PollableTask.INJECT_CURRENT_TASK); assertEquals("All AssetTextUnit must be mapped", 0, assetTextUnitRepository.getUnmappedAssetTextUnits(assetExtraction3.getId()).size()); iterator = getAssetTextUnitToTMTextUnit(assetExtraction3); next = iterator.next(); checkMapping(next, assetExtraction3, tm); checkMapping(iterator.next(), assetExtraction3, tm); assertFalse("There shouldn't be any other mapping reccords", iterator.hasNext()); }
@Pollable(message = "Mapping AssetTextUnit to TMTextUnit") public void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask) { logger.debug("Map exact matches a first time to map to existing text units"); long mapExactMatches = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the first time for asset extraction id: {} and tmId: {}", mapExactMatches, assetExtractionId, tmId); logger.debug("Create text units for unmapped asset text units"); List<TMTextUnit> newlyCreatedTMTextUnits = createTMTextUnitForUnmappedAssetTextUnitsWithRetry(assetExtractionId, tmId, assetId, createdByUser); logger.debug("Map exact matches a second time to map newly created text units"); int mapExactMatches2 = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the second time for asset extraction id: {} and tmId: {}", mapExactMatches2, assetExtractionId, tmId); logger.debug("All AssetTextUnits are now mapped to TMTextUnits, start source leveraging"); leveragingService.performSourceLeveraging(newlyCreatedTMTextUnits); logger.debug("Asset text unit and tm text unit mapping complete"); }
AssetMappingService { @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") public void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask) { logger.debug("Map exact matches a first time to map to existing text units"); long mapExactMatches = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the first time for asset extraction id: {} and tmId: {}", mapExactMatches, assetExtractionId, tmId); logger.debug("Create text units for unmapped asset text units"); List<TMTextUnit> newlyCreatedTMTextUnits = createTMTextUnitForUnmappedAssetTextUnitsWithRetry(assetExtractionId, tmId, assetId, createdByUser); logger.debug("Map exact matches a second time to map newly created text units"); int mapExactMatches2 = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the second time for asset extraction id: {} and tmId: {}", mapExactMatches2, assetExtractionId, tmId); logger.debug("All AssetTextUnits are now mapped to TMTextUnits, start source leveraging"); leveragingService.performSourceLeveraging(newlyCreatedTMTextUnits); logger.debug("Asset text unit and tm text unit mapping complete"); } }
AssetMappingService { @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") public void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask) { logger.debug("Map exact matches a first time to map to existing text units"); long mapExactMatches = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the first time for asset extraction id: {} and tmId: {}", mapExactMatches, assetExtractionId, tmId); logger.debug("Create text units for unmapped asset text units"); List<TMTextUnit> newlyCreatedTMTextUnits = createTMTextUnitForUnmappedAssetTextUnitsWithRetry(assetExtractionId, tmId, assetId, createdByUser); logger.debug("Map exact matches a second time to map newly created text units"); int mapExactMatches2 = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the second time for asset extraction id: {} and tmId: {}", mapExactMatches2, assetExtractionId, tmId); logger.debug("All AssetTextUnits are now mapped to TMTextUnits, start source leveraging"); leveragingService.performSourceLeveraging(newlyCreatedTMTextUnits); logger.debug("Asset text unit and tm text unit mapping complete"); }  }
AssetMappingService { @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") public void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask) { logger.debug("Map exact matches a first time to map to existing text units"); long mapExactMatches = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the first time for asset extraction id: {} and tmId: {}", mapExactMatches, assetExtractionId, tmId); logger.debug("Create text units for unmapped asset text units"); List<TMTextUnit> newlyCreatedTMTextUnits = createTMTextUnitForUnmappedAssetTextUnitsWithRetry(assetExtractionId, tmId, assetId, createdByUser); logger.debug("Map exact matches a second time to map newly created text units"); int mapExactMatches2 = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the second time for asset extraction id: {} and tmId: {}", mapExactMatches2, assetExtractionId, tmId); logger.debug("All AssetTextUnits are now mapped to TMTextUnits, start source leveraging"); leveragingService.performSourceLeveraging(newlyCreatedTMTextUnits); logger.debug("Asset text unit and tm text unit mapping complete"); }  @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask); }
AssetMappingService { @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") public void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask) { logger.debug("Map exact matches a first time to map to existing text units"); long mapExactMatches = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the first time for asset extraction id: {} and tmId: {}", mapExactMatches, assetExtractionId, tmId); logger.debug("Create text units for unmapped asset text units"); List<TMTextUnit> newlyCreatedTMTextUnits = createTMTextUnitForUnmappedAssetTextUnitsWithRetry(assetExtractionId, tmId, assetId, createdByUser); logger.debug("Map exact matches a second time to map newly created text units"); int mapExactMatches2 = mapExactMatches(assetExtractionId, tmId, assetId); logger.debug("{} text units were mapped the second time for asset extraction id: {} and tmId: {}", mapExactMatches2, assetExtractionId, tmId); logger.debug("All AssetTextUnits are now mapped to TMTextUnits, start source leveraging"); leveragingService.performSourceLeveraging(newlyCreatedTMTextUnits); logger.debug("Asset text unit and tm text unit mapping complete"); }  @Pollable(message = "Mapping AssetTextUnit to TMTextUnit") void mapAssetTextUnitAndCreateTMTextUnit(Long assetExtractionId, Long tmId, Long assetId, User createdByUser, @ParentTask PollableTask parentTask);  }