Search in sources :

Example 16 with Alignment

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

the class AbstractBaseAlignmentLoader method migrateCells.

private List<MutableCell> migrateCells(List<MutableCell> cells, SimpleLog log) {
    List<MutableCell> result = new ArrayList<>();
    // Collect mappings from all UnmigratedCells
    Map<EntityDefinition, EntityDefinition> allMappings = new HashMap<>();
    cells.stream().filter(c -> c instanceof UnmigratedCell).map(c -> (UnmigratedCell) c).forEach(uc -> allMappings.putAll(uc.getEntityMappings()));
    // Add cells to the alignment, migrate UnmigratedCells
    for (MutableCell cell : cells) {
        if (cell instanceof UnmigratedCell) {
            result.add(((UnmigratedCell) cell).migrate(allMappings, log));
        } else {
            result.add(cell);
        }
    }
    return result;
}
Also used : IOUtils(eu.esdihumboldt.util.io.IOUtils) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) HashMap(java.util.HashMap) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Map(java.util.Map) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) URI(java.net.URI) LinkedList(java.util.LinkedList) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Collection(java.util.Collection) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) Set(java.util.Set) IOException(java.io.IOException) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) List(java.util.List) Entry(java.util.Map.Entry) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeIndex(eu.esdihumboldt.hale.common.schema.model.TypeIndex) InputStream(java.io.InputStream) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 17 with Alignment

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

the class InlineTransformation method evaluate.

@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
    List<PropertyValue> sources = variables.get(null);
    if (sources.isEmpty()) {
        throw new NoResultException("No source available to transform");
    }
    PropertyValue source = sources.get(0);
    Object sourceValue = source.getValue();
    if (sourceValue == null) {
        throw new NoResultException("Source value is null");
    }
    if (!(sourceValue instanceof Instance)) {
        throw new TransformationException("Sources for inline transformation must be instances");
    }
    Instance sourceInstance = (Instance) sourceValue;
    TypeDefinition sourceType = sourceInstance.getDefinition();
    // get the original alignment
    Alignment orgAlignment = getExecutionContext().getAlignment();
    MutableAlignment alignment = new DefaultAlignment(orgAlignment);
    // identify relevant type cell(s)
    MutableCell queryCell = new DefaultCell();
    ListMultimap<String, Type> sourceEntities = ArrayListMultimap.create();
    sourceEntities.put(null, new DefaultType(new TypeEntityDefinition(sourceType, SchemaSpaceID.SOURCE, null)));
    queryCell.setSource(sourceEntities);
    ListMultimap<String, Type> targetEntities = ArrayListMultimap.create();
    targetEntities.put(null, new DefaultType(new TypeEntityDefinition(resultProperty.getDefinition().getPropertyType(), SchemaSpaceID.TARGET, null)));
    queryCell.setTarget(targetEntities);
    Collection<? extends Cell> candidates = alignment.getTypeCells(queryCell);
    if (candidates.isEmpty()) {
        log.error(log.createMessage("No type transformations found for inline transformation", null));
        throw new NoResultException();
    }
    // filter alignment -> only keep relevant type relations
    List<Cell> allTypeCells = new ArrayList<>(alignment.getTypeCells());
    for (Cell cell : allTypeCells) {
        // remove cell
        alignment.removeCell(cell);
        if (!cell.getTransformationMode().equals(TransformationMode.disabled)) {
            // only readd if not disabled
            MutableCell copy = new DefaultCell(cell);
            if (candidates.contains(cell)) {
                // readd as active
                copy.setTransformationMode(TransformationMode.active);
            } else {
                // readd as passive
                copy.setTransformationMode(TransformationMode.passive);
            }
            alignment.addCell(copy);
        }
    }
    // prepare transformation input/output
    DefaultInstanceCollection sourceInstances = new DefaultInstanceCollection();
    sourceInstances.add(sourceInstance);
    DefaultInstanceSink target = new DefaultInstanceSink();
    // run transformation
    TransformationService ts = getExecutionContext().getService(TransformationService.class);
    if (ts == null) {
        throw new TransformationException("Transformation service not available for inline transformation");
    }
    ProgressIndicator progressIndicator = new LogProgressIndicator();
    TransformationReport report = ts.transform(alignment, sourceInstances, new ThreadSafeInstanceSink<InstanceSink>(target), getExecutionContext(), progressIndicator);
    // copy report messages
    log.importMessages(report);
    if (!report.isSuccess()) {
        // copy report messages
        log.importMessages(report);
        throw new TransformationException("Inline transformation failed");
    }
    // extract result
    List<Instance> targetList = target.getInstances();
    if (targetList.isEmpty()) {
        log.error(log.createMessage("Inline transformation yielded no result", null));
        throw new NoResultException("No result from inline transformation");
    }
    if (targetList.size() > 1) {
        log.error(log.createMessage("Inline transformation yielded multiple results, only first result is used", null));
    }
    return targetList.get(0);
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink) ArrayList(java.util.ArrayList) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) 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) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) ProgressIndicator(eu.esdihumboldt.hale.common.core.io.ProgressIndicator) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) TransformationService(eu.esdihumboldt.hale.common.align.transformation.service.TransformationService) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) TransformationReport(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReport) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ThreadSafeInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.ThreadSafeInstanceSink) DefaultInstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.impl.DefaultInstanceSink) InstanceSink(eu.esdihumboldt.hale.common.align.transformation.service.InstanceSink)

Example 18 with Alignment

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

the class SchemaExplorerLabelProvider method getBackground.

/**
 * @see IColorProvider#getBackground(Object)
 */
@Override
public Color getBackground(Object element) {
    if (element instanceof EntityDefinition) {
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        Alignment alignment = as.getAlignment();
        EntityDefinition entityDef = (EntityDefinition) element;
        return getEntityBackground(entityDef, alignment, entityDef.getPropertyPath().isEmpty());
    }
    return null;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService)

Example 19 with Alignment

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

the class TransformationView method update.

/**
 * Set the current alignment
 */
private void update() {
    final Display display = PlatformUI.getWorkbench().getDisplay();
    // TODO add configuration option if instances should be included?
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
            Alignment alignment = as.getAlignment();
            InstanceSampleService iss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
            Collection<Instance> instances = iss.getReferenceInstances();
            if (instanceAction.isChecked()) {
                if (instances != null && !instances.isEmpty()) {
                    instances = new ArrayList<Instance>(instances);
                    // alignment paired with instances as input
                    getViewer().setInput(new Pair<Object, Object>(alignment, instances));
                } else {
                    getViewer().setInput(null);
                }
            } else {
                // only the alignment as input
                getViewer().setInput(alignment);
            }
            getViewer().applyLayout();
        }
    });
}
Also used : Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ArrayList(java.util.ArrayList) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService) Collection(java.util.Collection) Display(org.eclipse.swt.widgets.Display) Pair(eu.esdihumboldt.util.Pair)

Example 20 with Alignment

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

Aggregations

Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)23 Cell (eu.esdihumboldt.hale.common.align.model.Cell)12 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)10 ArrayList (java.util.ArrayList)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)6 CustomPropertyFunction (eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction)5 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)5 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)4 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)3 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)3 URI (java.net.URI)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ATransaction (de.fhg.igd.slf4jplus.ATransaction)2 PropertyFunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.PropertyFunctionDefinition)2 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)2