use of eu.esdihumboldt.hale.common.align.migrate.impl.DefaultAlignmentMigrator 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;
}
Aggregations