Search in sources :

Example 1 with UserMigration

use of eu.esdihumboldt.hale.ui.service.align.migrate.UserMigration in project hale by halestudio.

the class ReplaceEntitiesHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // collect cells from selection
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        List<?> list = ((IStructuredSelection) selection).toList();
        // create dummy alignment
        DefaultAlignment dummy = new DefaultAlignment();
        for (Object object : list) {
            if (object instanceof MutableCell) {
                dummy.addCell((MutableCell) object);
            // FIXME what about others?
            }
        }
        /*
			 * Replace entities on cells
			 */
        SimpleReporter reporter = new SimpleReporter("Replace entities for cells", null, false);
        try {
            // create migrator
            AlignmentMigrator migrator = new DefaultAlignmentMigrator(HaleUI.getServiceProvider());
            AlignmentMigration migration = new UserMigration(schemaSpace);
            MigrationOptions options = new MigrationOptionsImpl(schemaSpace.equals(SchemaSpaceID.SOURCE), schemaSpace.equals(SchemaSpaceID.TARGET), false);
            Alignment updated = migrator.updateAligmment(dummy, migration, options, reporter);
            AlignmentService as = HaleUI.getServiceProvider().getService(AlignmentService.class);
            Map<Cell, MutableCell> replacements = new HashMap<>();
            for (Cell newCell : updated.getCells()) {
                Cell oldCell = dummy.getCell(newCell.getId());
                if (oldCell == null) {
                    reporter.error("No original cell with ID {0} found", newCell.getId());
                } else {
                    // TODO detect where there has been no change?
                    replacements.put(oldCell, (MutableCell) newCell);
                }
            }
            as.replaceCells(replacements);
            reporter.setSuccess(true);
        } catch (Throwable e) {
            reporter.error("Fatal error when trying to replace entities", e);
            reporter.setSuccess(false);
        } finally {
            HaleUI.getServiceProvider().getService(ReportService.class).addReport(reporter);
        }
    }
    return null;
}
Also used : AlignmentMigrator(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrator) DefaultAlignmentMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultAlignmentMigrator) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashMap(java.util.HashMap) UserMigration(eu.esdihumboldt.hale.ui.service.align.migrate.UserMigration) SimpleReporter(eu.esdihumboldt.hale.common.core.report.impl.SimpleReporter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DefaultAlignmentMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultAlignmentMigrator) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) MigrationOptionsImpl(eu.esdihumboldt.hale.common.align.migrate.impl.MigrationOptionsImpl) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) MigrationOptions(eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)

Aggregations

AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)1 AlignmentMigrator (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrator)1 MigrationOptions (eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)1 DefaultAlignmentMigrator (eu.esdihumboldt.hale.common.align.migrate.impl.DefaultAlignmentMigrator)1 MigrationOptionsImpl (eu.esdihumboldt.hale.common.align.migrate.impl.MigrationOptionsImpl)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)1 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)1 SimpleReporter (eu.esdihumboldt.hale.common.core.report.impl.SimpleReporter)1 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)1 UserMigration (eu.esdihumboldt.hale.ui.service.align.migrate.UserMigration)1 ReportService (eu.esdihumboldt.hale.ui.service.report.ReportService)1 HashMap (java.util.HashMap)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1