Search in sources :

Example 1 with TargetIndex

use of eu.esdihumboldt.hale.common.align.merge.impl.TargetIndex in project hale by halestudio.

the class AbstractMergeCellMigratorTest method mergeWithMigrator.

/**
 * Perform merging using a specific merge migrator.
 *
 * @param migrator the migrator to test, <code>null</code> if the migrator
 *            configured in the system should be used
 * @param cellToMigrate the cell to migrate
 * @param matchingProject the project providing the matching information
 * @return the merge result
 */
protected List<MutableCell> mergeWithMigrator(MergeCellMigrator migrator, Cell cellToMigrate, ProjectTransformationEnvironment matchingProject) {
    MergeIndex mergeIndex = new TargetIndex(matchingProject.getAlignment());
    AlignmentMigration migration = new MatchingMigration(matchingProject, true);
    List<MutableCell> cells = new ArrayList<>();
    if (migrator == null) {
        try {
            migrator = MigratorExtension.getInstance().getMigrator(cellToMigrate.getTransformationIdentifier()).orElse(null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    if (migrator == null) {
        CellMigrator mig = getCellMigrator(cellToMigrate.getTransformationIdentifier());
        if (mig instanceof MergeCellMigrator) {
            migrator = (MergeCellMigrator) mig;
        } else if (mig == null) {
            throw new IllegalStateException("No cell migrator could be retrieved");
        } else {
            // perform migration with "ordinary" CellMigrator
            MigrationOptions options = new MigrationOptions() {

                @Override
                public boolean updateTarget() {
                    return false;
                }

                @Override
                public boolean updateSource() {
                    return true;
                }

                @Override
                public boolean transferBase() {
                    return false;
                }
            };
            cells.add(mig.updateCell(cellToMigrate, migration, options, SimpleLog.CONSOLE_LOG));
        }
    }
    if (migrator != null) {
        // perform merge with MergeCellMigrator
        Iterable<MutableCell> result = migrator.mergeCell(cellToMigrate, mergeIndex, migration, this::getCellMigrator, SimpleLog.CONSOLE_LOG);
        Iterables.addAll(cells, result);
    }
    return cells;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ArrayList(java.util.ArrayList) MergeIndex(eu.esdihumboldt.hale.common.align.merge.MergeIndex) MergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.MergeCellMigrator) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) DefaultMergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.impl.DefaultMergeCellMigrator) MergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.MergeCellMigrator) DefaultMergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.impl.DefaultMergeCellMigrator) MatchingMigration(eu.esdihumboldt.hale.common.align.merge.impl.MatchingMigration) IOException(java.io.IOException) TargetIndex(eu.esdihumboldt.hale.common.align.merge.impl.TargetIndex) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) MigrationOptions(eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)

Aggregations

MergeCellMigrator (eu.esdihumboldt.hale.common.align.merge.MergeCellMigrator)1 MergeIndex (eu.esdihumboldt.hale.common.align.merge.MergeIndex)1 DefaultMergeCellMigrator (eu.esdihumboldt.hale.common.align.merge.impl.DefaultMergeCellMigrator)1 MatchingMigration (eu.esdihumboldt.hale.common.align.merge.impl.MatchingMigration)1 TargetIndex (eu.esdihumboldt.hale.common.align.merge.impl.TargetIndex)1 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)1 CellMigrator (eu.esdihumboldt.hale.common.align.migrate.CellMigrator)1 MigrationOptions (eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)1 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1