/** * Merges chunks found in a target translation Project that do not exist in the source translation * to a sibling chunk so that no data is lost. * * @param library * @param targetTranslation target translation to merge * @return */ public static boolean migrateChunkChanges( final Library library, final TargetTranslation targetTranslation) { try { Logger.i( TargetTranslationMigrator.class.getName(), "Migrating chunks in target translation " + targetTranslation.getProjectId()); final SourceTranslation sourceTranslation = library.getDefaultSourceTranslation(targetTranslation.getProjectId(), "en"); if (sourceTranslation == null) { Logger.w( TargetTranslationMigrator.class.getName(), "Could not find a source translation for the target translation " + targetTranslation.getId()); return false; } if (targetTranslation.getPath().exists()) { boolean migrationSuccess = true; // perform the chunk migration on each chapter of the target translation for (ChapterTranslation chapterTranslation : targetTranslation.getChapterTranslations()) { Chapter chapter = library.getChapter(sourceTranslation, chapterTranslation.getId()); if (chapter != null) { boolean success = mergeInvalidChunksInChapter(library, sourceTranslation, targetTranslation, chapter); migrationSuccess = migrationSuccess && success; } } return migrationSuccess; } } catch (Exception e) { Logger.e( TargetTranslationMigrator.class.getName(), "Failed to merge the chunks in the target translation " + targetTranslation.getProjectId()); } return false; }