Search in sources :

Example 6 with MutableCell

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

the class EditRelationHandler method execute.

/**
 * @see IHandler#execute(ExecutionEvent)
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        Object selected = ((IStructuredSelection) selection).getFirstElement();
        if (selected instanceof Cell) {
            final Cell originalCell = (Cell) selected;
            FunctionWizard wizard = null;
            List<FunctionWizardDescriptor<?>> factories = FunctionWizardExtension.getInstance().getFactories(new FactoryFilter<FunctionWizardFactory, FunctionWizardDescriptor<?>>() {

                @Override
                public boolean acceptFactory(FunctionWizardDescriptor<?> factory) {
                    return factory.getFunctionId().equals(originalCell.getTransformationIdentifier());
                }

                @Override
                public boolean acceptCollection(ExtensionObjectFactoryCollection<FunctionWizardFactory, FunctionWizardDescriptor<?>> collection) {
                    return true;
                }
            });
            if (!factories.isEmpty()) {
                // create registered wizard
                FunctionWizardDescriptor<?> fwd = factories.get(0);
                wizard = fwd.createEditWizard(originalCell);
            }
            if (wizard == null) {
                FunctionDefinition<?> function = FunctionUtil.getFunction(originalCell.getTransformationIdentifier(), HaleUI.getServiceProvider());
                if (function == null) {
                    log.userError(MessageFormat.format("Function with identifier ''{0}'' is unknown.", originalCell.getTransformationIdentifier()));
                    return null;
                }
                // create generic wizard
                if (function instanceof TypeFunction) {
                    wizard = new GenericTypeFunctionWizard(originalCell);
                } else {
                    wizard = new GenericPropertyFunctionWizard(originalCell);
                }
            }
            // initialize wizard
            wizard.init();
            HaleWizardDialog dialog = new HaleWizardDialog(HandlerUtil.getActiveShell(event), wizard);
            if (dialog.open() == WizardDialog.OK) {
                MutableCell cell = wizard.getResult();
                AlignmentService alignmentService = PlatformUI.getWorkbench().getService(AlignmentService.class);
                // remove the original cell
                // and add the new cell
                alignmentService.replaceCell(originalCell, cell);
            }
        }
    }
    return null;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) FunctionWizardDescriptor(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardDescriptor) FunctionWizardFactory(eu.esdihumboldt.hale.ui.function.extension.FunctionWizardFactory) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) FunctionWizard(eu.esdihumboldt.hale.ui.function.FunctionWizard) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) GenericTypeFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericTypeFunctionWizard) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) GenericPropertyFunctionWizard(eu.esdihumboldt.hale.ui.function.generic.GenericPropertyFunctionWizard) TypeFunction(eu.esdihumboldt.hale.common.align.extension.function.TypeFunction) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 7 with MutableCell

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

the class DefaultsVisitor method addAugmentationCell.

/**
 * Add a simple cell using an augmentation w/o parameters.
 *
 * @param ped the property entity definition
 * @param functionId the function identifier
 * @param priority the cell priority
 */
private void addAugmentationCell(PropertyEntityDefinition ped, String functionId, Priority priority) {
    // create cell template
    MutableCell cell = new DefaultCell();
    cell.setPriority(priority);
    ListMultimap<String, Entity> target = ArrayListMultimap.create();
    cell.setTarget(target);
    // set transformation identifier (Function ID)
    cell.setTransformationIdentifier(functionId);
    // set cell target (Property)
    target.put(null, new DefaultProperty(ped));
    BGISAppUtil.appendNote(cell, "Generated default mapping.");
    cells.add(cell);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 8 with MutableCell

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

the class CityGMLPropagate method generateMapping.

private void generateMapping() {
    System.out.println("Indexing example cells...");
    // index all cells based on the target property name
    SetMultimap<String, Cell> bgisExamples = HashMultimap.create();
    SetMultimap<QName, Cell> cityGMLExamples = 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();
            // XXX check source?!
            if (entityDef.getDefinition() instanceof PropertyDefinition) {
                QName name = entityDef.getDefinition().getName();
                if (ADE_NS.equals(name.getNamespaceURI())) {
                    bgisExamples.put(name.getLocalPart(), cell);
                } else if (name.getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE)) {
                    // XXX only support level 1 properties?
                    cityGMLExamples.put(name, cell);
                } else
                    System.out.println("WARNING: ignoring cell with target property neither from CityGML nor from BGIS ADE");
            } 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);
    // collect ADE display names
    Set<String> adeTypeNames = new HashSet<String>();
    for (TypeDefinition type : featureTypes) {
        adeTypeNames.add(type.getDisplayName());
    }
    // collect possibly relevant target CityGML feature types
    for (TypeDefinition type : targetSchema.getTypes()) {
        if (type.getName().getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE) && BGISAppUtil.isFeatureType(type)) {
            if (!adeTypeNames.contains(type.getDisplayName())) {
                /*
					 * But ensure to only add those that do not share the
					 * display name with an ADE type, as in the feature map the
					 * type identification is only done on based on the display
					 * name, and ADE types take precedent.
					 */
                featureTypes.add(type);
            }
        }
    }
    // visit ADE properties and create cells
    System.out.println("Generating mapping from example cells for");
    String cellNote = MessageFormat.format("Generated through propagation of example cells on CityGML and BGIS ADE feature types.\n" + "{0,date,medium}", new Date());
    CityGMLPropagateVisitor visitor = new CityGMLPropagateVisitor(cityGMLSource, bgisExamples, cityGMLExamples, config, 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) QName(javax.xml.namespace.QName) 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) HashSet(java.util.HashSet)

Example 9 with MutableCell

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

the class MergeMigrator method updateCell.

@Override
public MutableCell updateCell(Cell originalCell, AlignmentMigration migration, MigrationOptions options, SimpleLog log) {
    MutableCell result = super.updateCell(originalCell, migration, options, log);
    SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));
    if (options.updateSource() && originalCell.getSource() != null) {
        Entity sourceType = CellUtil.getFirstEntity(originalCell.getSource());
        if (sourceType != null) {
            TypeDefinition sourceDef = sourceType.getDefinition().getType();
            ListMultimap<String, ParameterValue> modParams = ArrayListMultimap.create(result.getTransformationParameters());
            for (String property : PROPERTY_PATH_PARAMETERS) {
                updateProperties(modParams, migration, sourceDef, property, cellLog);
            }
            result.setTransformationParameters(modParams);
        }
    }
    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) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) CellLog(eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 10 with MutableCell

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

the class AbstractMergeCellMigratorTest method mergeWithMigrator.

/**
 * Perform merging using a specific merge migrator.
 *
 * @param migrator the migrator to test, <code>null</code> if the migrator
 *            configured in the system should be used
 * @param cellToMigrate the cell to migrate
 * @param matchingProject the project providing the matching information
 * @return the merge result
 */
protected List<MutableCell> mergeWithMigrator(MergeCellMigrator migrator, Cell cellToMigrate, ProjectTransformationEnvironment matchingProject) {
    MergeIndex mergeIndex = new TargetIndex(matchingProject.getAlignment());
    AlignmentMigration migration = new MatchingMigration(matchingProject, true);
    List<MutableCell> cells = new ArrayList<>();
    if (migrator == null) {
        try {
            migrator = MigratorExtension.getInstance().getMigrator(cellToMigrate.getTransformationIdentifier()).orElse(null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    if (migrator == null) {
        CellMigrator mig = getCellMigrator(cellToMigrate.getTransformationIdentifier());
        if (mig instanceof MergeCellMigrator) {
            migrator = (MergeCellMigrator) mig;
        } else if (mig == null) {
            throw new IllegalStateException("No cell migrator could be retrieved");
        } else {
            // perform migration with "ordinary" CellMigrator
            MigrationOptions options = new MigrationOptions() {

                @Override
                public boolean updateTarget() {
                    return false;
                }

                @Override
                public boolean updateSource() {
                    return true;
                }

                @Override
                public boolean transferBase() {
                    return false;
                }
            };
            cells.add(mig.updateCell(cellToMigrate, migration, options, SimpleLog.CONSOLE_LOG));
        }
    }
    if (migrator != null) {
        // perform merge with MergeCellMigrator
        Iterable<MutableCell> result = migrator.mergeCell(cellToMigrate, mergeIndex, migration, this::getCellMigrator, SimpleLog.CONSOLE_LOG);
        Iterables.addAll(cells, result);
    }
    return cells;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) ArrayList(java.util.ArrayList) MergeIndex(eu.esdihumboldt.hale.common.align.merge.MergeIndex) MergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.MergeCellMigrator) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) DefaultMergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.impl.DefaultMergeCellMigrator) MergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.MergeCellMigrator) DefaultMergeCellMigrator(eu.esdihumboldt.hale.common.align.merge.impl.DefaultMergeCellMigrator) MatchingMigration(eu.esdihumboldt.hale.common.align.merge.impl.MatchingMigration) IOException(java.io.IOException) TargetIndex(eu.esdihumboldt.hale.common.align.merge.impl.TargetIndex) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) MigrationOptions(eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)

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