Search in sources :

Example 16 with MutableCell

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

the class GenerateDefaults method generateMapping.

private void generateMapping() {
    System.out.println("Generating default value mapping cells for");
    // collect all ADE feature types
    List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(schema);
    // visit ADE properties and create cells
    DefaultsVisitor defs = new DefaultsVisitor(defaultValues);
    for (TypeDefinition type : featureTypes) {
        System.out.println(type.getDisplayName() + "...");
        defs.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
    }
    if (defs.getCells().isEmpty()) {
        System.out.println("WARNING: no cells were created");
    } else {
        System.out.println(defs.getCells().size() + " cells were created.");
    }
    // create alignment
    MutableAlignment align = new DefaultAlignment();
    for (MutableCell cell : defs.getCells()) {
        align.addCell(cell);
    }
    this.alignment = align;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 17 with MutableCell

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

the class GenerateDuplicates method generateMapping.

private void generateMapping() {
    System.out.println("Indexing example cells...");
    // index all cells based on the target property name
    SetMultimap<String, Cell> exampleCells = HashMultimap.create();
    for (Cell cell : examples.getCells()) {
        if (cell.getTarget().size() == 1) {
            // only supports cells with one target
            EntityDefinition entityDef = CellUtil.getFirstEntity(cell.getTarget()).getDefinition();
            if (entityDef.getDefinition() instanceof PropertyDefinition) {
                if (ADE_NS.equals(entityDef.getDefinition().getName().getNamespaceURI())) {
                    exampleCells.put(entityDef.getDefinition().getName().getLocalPart(), cell);
                } else
                    System.out.println("WARNING: ignoring cell with non-ADE target property");
            } else
                System.out.println("WARNING: ignoring type cell");
        } else
            System.out.println("WARNING: ignoring cell with multiple or no targets");
    }
    // collect all ADE feature types
    List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(targetSchema);
    // visit ADE properties and create cells
    System.out.println("Generating mapping from example cells for");
    String cellNote = MessageFormat.format("Generated through duplication of example cells on BGIS ADE feature types.\n" + "{0,date,medium}", new Date());
    DuplicateVisitor visitor = new DuplicateVisitor(exampleCells, cellNote);
    for (TypeDefinition type : featureTypes) {
        System.out.println(type.getDisplayName() + "...");
        visitor.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
    }
    if (visitor.getCells().isEmpty()) {
        System.out.println("WARNING: no cells were created");
    } else {
        System.out.println(visitor.getCells().size() + " cells were created.");
    }
    // create alignment
    MutableAlignment align = new DefaultAlignment();
    for (MutableCell cell : visitor.getCells()) {
        align.addCell(cell);
    }
    this.alignment = align;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Date(java.util.Date) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell)

Example 18 with MutableCell

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

the class DefaultAlignmentMigrator method updateAligmment.

@Override
public MutableAlignment updateAligmment(Alignment originalAlignment, AlignmentMigration migration, MigrationOptions options, SimpleLog log) {
    MutableAlignment result = new DefaultAlignment(originalAlignment);
    // XXX TODO adapt custom functions?!
    // result.getCustomPropertyFunctions();
    Collection<? extends Cell> cellList = new ArrayList<>(result.getCells());
    for (Cell cell : cellList) {
        // XXX
        if (cell instanceof MutableCell) {
            CellMigrator cm = getCellMigrator(cell.getTransformationIdentifier());
            MutableCell newCell = cm.updateCell(cell, migration, options, log);
            MigrationUtil.removeIdPrefix(newCell, options.transferBase(), options.transferBase());
            result.removeCell(cell);
            if (newCell != null) {
                result.addCell(newCell);
            }
        } else {
            // XXX can we deal with other cases? (Base alignment cells)
            if (options.transferBase()) {
                // include base alignment cell as mutable mapping cell
                CellMigrator cm = getCellMigrator(cell.getTransformationIdentifier());
                MutableCell newCell = cm.updateCell(cell, migration, options, log);
                MigrationUtil.removeIdPrefix(newCell, true, true);
                result.removeCell(cell);
                if (newCell != null) {
                    result.addCell(newCell);
                }
            }
        }
    }
    if (options.transferBase()) {
        MigrationUtil.removeBaseCells(result);
    } else {
    // does something need to be done to correctly retain base
    // alignments?
    }
    return result;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ArrayList(java.util.ArrayList) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell)

Example 19 with MutableCell

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

the class DefaultCellMigrator method updateCell.

@Override
public MutableCell updateCell(final Cell originalCell, final AlignmentMigration migration, final MigrationOptions options, SimpleLog log) {
    MutableCell result = new DefaultCell(originalCell);
    SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));
    final AtomicBoolean replacedEntities = new AtomicBoolean(false);
    EntryTransformer<String, Entity, Entity> entityTransformer = new EntryTransformer<String, Entity, Entity>() {

        @Override
        public Entity transformEntry(String key, Entity value) {
            EntityDefinition org = value.getDefinition();
            Optional<EntityDefinition> replace = migration.entityReplacement(org, cellLog);
            EntityDefinition entity = replace.orElse(org);
            if (!Objects.equal(entity, org)) {
                replacedEntities.set(true);
            }
            if (entity instanceof PropertyEntityDefinition) {
                return new DefaultProperty((PropertyEntityDefinition) entity);
            } else if (entity instanceof TypeEntityDefinition) {
                return new DefaultType((TypeEntityDefinition) entity);
            } else {
                throw new IllegalStateException("Invalid entity definition for creating entity");
            }
        }
    };
    // update source entities
    if (options.updateSource() && result.getSource() != null && !result.getSource().isEmpty()) {
        result.setSource(ArrayListMultimap.create(Multimaps.transformEntries(result.getSource(), entityTransformer)));
    }
    // update target entities
    if (options.updateTarget() && result.getTarget() != null && !result.getTarget().isEmpty()) {
        result.setTarget(ArrayListMultimap.create(Multimaps.transformEntries(result.getTarget(), entityTransformer)));
    }
    // TODO anything else?
    postUpdateCell(result, options, replacedEntities.get(), cellLog);
    return result;
}
Also used : SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) Entity(eu.esdihumboldt.hale.common.align.model.Entity) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) EntryTransformer(com.google.common.collect.Maps.EntryTransformer) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) CellLog(eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)

Example 20 with MutableCell

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

the class EffectiveMapping method expand.

/**
 * Convert an alignment into an expanded version where all effective
 * mappings are defined explicitly, i.e. mappings effective due to
 * inheritance are converted to use the respective sub-types. Also, base
 * alignment cells are converted into normal cells.
 *
 * @param alignment the alignment to convert
 * @return the expanded copy of the alignment
 */
public static MutableAlignment expand(Alignment alignment) {
    MutableAlignment result = new DefaultAlignment(alignment);
    // remove base alignment cells keeping custom functions
    MigrationUtil.removeBaseCells(result);
    // remove other cells
    result.clearCells();
    // transfer cells based on effective mapping
    // set of all cells used as they are in the resulting alignment
    Set<Cell> usedAsIs = new HashSet<>();
    for (Cell typeCell : alignment.getTypeCells()) {
        // transfer type cell unchanged
        MutableCell typeCellNew = new DefaultCell(typeCell);
        MigrationUtil.removeIdPrefix(typeCellNew, true, true);
        result.addCell(typeCellNew);
        usedAsIs.add(typeCell);
        Collection<? extends Cell> propertyCells = alignment.getPropertyCells(typeCell, true, false);
        for (Cell propertyCell : propertyCells) {
            // FIXME what does this do in case of a join where there are
            // potentially multiple cells to be handled?
            Cell reparented = AlignmentUtil.reparentCell(propertyCell, typeCell, true);
            if (reparented == propertyCell) {
                // use as is
                if (!usedAsIs.contains(propertyCell)) {
                    // only add if not done yet
                    // transfer unchanged
                    MutableCell newCell = new DefaultCell(propertyCell);
                    MigrationUtil.removeIdPrefix(newCell, true, true);
                    result.addCell(newCell);
                    usedAsIs.add(propertyCell);
                }
            } else {
                // inherited cell
                // add the reparented cell
                // TODO check if similar cell has been added already?
                MutableCell rCell = (MutableCell) reparented;
                MigrationUtil.removeIdPrefix(rCell, true, true);
                // avoid ID collision
                // no updates needed in other places because it's a property
                // cell
                rCell.setId(rCell.getId() + '_' + typeCellNew.getId());
                result.addCell(rCell);
            }
        }
    }
    return result;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) 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) HashSet(java.util.HashSet)

Aggregations

MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)35 Cell (eu.esdihumboldt.hale.common.align.model.Cell)17 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 ArrayList (java.util.ArrayList)11 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)6 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)5 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)5 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)5 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)5 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)4 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)4 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)4 HashSet (java.util.HashSet)4