Search in sources :

Example 16 with DefaultAlignment

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment in project hale by halestudio.

the class AlignmentServiceUndoSupport method clean.

/**
 * @see AlignmentServiceDecorator#clean()
 */
@Override
public synchronized void clean() {
    // XXX problem: what about cleans that should not be undone? e.g. when
    // the schemas have changed
    // XXX -> currently on project clean the workbench history is reset
    Alignment alignment = getAlignment();
    if (alignment.getCells().isEmpty()) {
        return;
    }
    if (alignment instanceof MutableAlignment) {
        /*
			 * As long as there is no copy constructor in DefaultAlignment, undo
			 * only supported if the current alignment is a MutableAlignment.
			 */
        IUndoableOperation operation = new CleanOperation((MutableAlignment) alignment);
        executeOperation(operation);
    } else {
        super.clean();
    }
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment)

Example 17 with DefaultAlignment

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment 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)

Example 18 with DefaultAlignment

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment in project hale by halestudio.

the class TransformDataWizard method performFinish.

/**
 * @see org.eclipse.jface.wizard.Wizard#performFinish()
 */
@Override
public boolean performFinish() {
    InstanceCollection rawSources = new MultiInstanceCollection(sourceSelectionPage.getSourceInstances());
    // Create a copy of the current alignment to be independent and run
    // everything in a job.
    AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = new DefaultAlignment(alignmentService.getAlignment());
    // schema service for getting source schema
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    Transformation.transform(rawSources, targetSink, sourceSelectionPage.getExportJob(), sourceSelectionPage.getValidationJob(), alignment, ss.getSchemas(SchemaSpaceID.SOURCE), DefaultReportHandler.getInstance(), HaleUI.getServiceProvider(), null);
    return true;
}
Also used : MultiInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) MultiInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.MultiInstanceCollection) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)

Aggregations

DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)18 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)11 Cell (eu.esdihumboldt.hale.common.align.model.Cell)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)8 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 Test (org.junit.Test)7 Type (eu.esdihumboldt.hale.common.align.model.Type)5 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)5 ArrayList (java.util.ArrayList)5 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)4 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 BufferedOutputStream (java.io.BufferedOutputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 QName (javax.xml.namespace.QName)4 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)3