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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations