use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class AbstractMergeCellMigrator method applySourceContexts.
/**
* Apply contexts/conditions from the original source to the source of the
* new mapping cell that replaces it.
*
* @param newCell the cell to adapt
* @param originalSource the original source
* @param log the cell log
*/
private void applySourceContexts(MutableCell newCell, Entity originalSource, SimpleLog log) {
if (originalSource != null) {
EntityDefinition original = originalSource.getDefinition();
boolean isDefault = AlignmentUtil.isDefaultEntity(original);
if (!isDefault) {
ListMultimap<String, ? extends Entity> newSource = newCell.getSource();
if (newSource == null || newSource.size() == 0) {
// new cell does not have a source -> drop contexts
log.warn("Any conditions/contexts on the original source have been dropped because the new mapping does not have a source: " + MergeUtil.getContextInfoString(original));
} else if (newSource.size() == 1) {
// try to transfer contexts
Entity singleSource = CellUtil.getFirstEntity(newSource);
if (singleSource != null) {
EntityDefinition transferedSource = AbstractMigration.translateContexts(original, singleSource.getDefinition(), log);
ListMultimap<String, Entity> s = ArrayListMultimap.create();
s.put(newSource.keySet().iterator().next(), AlignmentUtil.createEntity(transferedSource));
newCell.setSource(s);
}
} else {
// no idea where to add contexts -> report
log.warn("Any conditions/contexts on the original source have been dropped because the new mapping has multiple sources and it is not clear where they should be attached: " + MergeUtil.getContextInfoString(original));
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class GeoJSONConfigurationPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(final Composite page) {
page.setLayout(new GridLayout(1, false));
Label explanation = new Label(page, SWT.NONE);
explanation.setText("If a geometry is set to \"none\", instances will still be included as GeoJSON features,\nbut without default geometries.");
final DynamicScrolledComposite sc = new DynamicScrolledComposite(page, SWT.V_SCROLL);
sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Composite parent = new Composite(sc, SWT.NONE);
sc.setExpandHorizontal(true);
GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(parent);
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
Set<TypeDefinition> types = is.getInstanceTypes(DataSet.TRANSFORMED);
for (final TypeDefinition type : types) {
Label label = new Label(parent, SWT.NONE);
label.setText(type.getDisplayName() + ":");
PropertyCondition condition = new PropertyOrChildrenTypeCondition(new GeometryCondition());
PropertyParameterDefinition param = new PropertyParameter("", 0, 1, "Geometry", null, Collections.singletonList(condition), false);
PropertyEntitySelector selector = new PropertyEntitySelector(SchemaSpaceID.TARGET, param, parent, new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
selector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
PropertyEntityDefinition property = (PropertyEntityDefinition) selection.getFirstElement();
config.addDefaultGeometry(type, property);
} else {
config.addDefaultGeometry(type, null);
}
}
});
selector.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// initial selection
List<QName> path = gss.getDefaultGeometry(type);
if (path != null) {
EntityDefinition entityDef = new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null);
for (QName child : path) entityDef = AlignmentUtil.getChild(entityDef, child);
selector.setSelection(new StructuredSelection(entityDef));
}
}
sc.setContent(parent);
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class GroovyTransformationPage method validate.
@Override
protected boolean validate(String document) {
super.validate(document);
List<PropertyValue> values = new ArrayList<PropertyValue>();
for (EntityDefinition var : getVariables()) {
if (var instanceof PropertyEntityDefinition) {
PropertyEntityDefinition property = (PropertyEntityDefinition) var;
values.add(new PropertyValueImpl(testValues.get(property), property));
}
}
Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetProperty == null) {
// not yet selected (NewRelationWizard)
return false;
}
InstanceBuilder builder = GroovyTransformation.createBuilder(targetProperty.getDefinition());
Cell cell = getWizard().getUnfinishedCell();
boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
GroovyService gs = HaleUI.getServiceProvider().getService(GroovyService.class);
Script script = null;
try {
Collection<? extends Cell> typeCells = as.getAlignment().getTypeCells(cell);
// select one matching type cell, the script has to run for all
// matching cells
// if there is no matching cell it may produce a npe, which is okay
Cell typeCell = null;
if (!typeCells.isEmpty()) {
typeCell = typeCells.iterator().next();
}
CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
groovy.lang.Binding binding;
if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID)) {
binding = GroovyGreedyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
} else {
binding = GroovyTransformation.createGroovyBinding(values, null, cell, typeCell, builder, useInstanceValues, log, context, targetProperty.getDefinition().getDefinition().getPropertyType());
}
script = gs.parseScript(document, binding);
GroovyTransformation.evaluate(script, builder, targetProperty.getDefinition().getDefinition().getPropertyType(), gs, log);
} catch (NoResultException e) {
// continue
} catch (final Exception e) {
return handleValidationResult(script, e);
}
return handleValidationResult(script, null);
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class PropertyDefinitionDialog method getObjectFromSelection.
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
return (EntityDefinition) element;
}
}
if (!selection.isEmpty() && selection instanceof ITreeSelection) {
// create property definition w/ default contexts
TreePath path = ((ITreeSelection) selection).getPaths()[0];
// get parent type
TypeDefinition type = ((ChildDefinition<?>) path.getFirstSegment()).getParentType();
// determine definition path
List<ChildContext> defPath = new ArrayList<ChildContext>();
for (int i = 0; i < path.getSegmentCount(); i++) {
defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
}
// TODO check if property entity definition is applicable?
return new PropertyEntityDefinition(type, defPath, ssid, null);
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class DefinitionLabelProvider method getText.
/**
* @see LabelProvider#getText(Object)
*/
@Override
public String getText(Object element) {
if (element instanceof EntityDefinition) {
EntityDefinition entityDef = (EntityDefinition) element;
element = entityDef.getDefinition();
List<ChildContext> path = entityDef.getPropertyPath();
if (path != null && !path.isEmpty()) {
if (!longNames) {
path = Collections.singletonList(path.get(path.size() - 1));
}
StringBuffer name = new StringBuffer();
boolean first = true;
for (ChildContext context : path) {
if (first) {
first = false;
} else {
name.append('.');
}
boolean defContext = context.getContextName() == null && context.getIndex() == null && context.getCondition() == null;
if (!defContext) {
name.append('(');
}
name.append(getText(context.getChild()));
if (!defContext) {
name.append(')');
}
}
return name.toString();
} else {
if (entityDef.getFilter() != null) {
return "(" + getText(element) + ")";
}
}
}
if (element instanceof Definition<?>) {
return ((Definition<?>) element).getDisplayName();
}
return super.getText(element);
}
Aggregations