Search in sources :

Example 46 with EntityDefinition

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));
            }
        }
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Entity(eu.esdihumboldt.hale.common.align.model.Entity) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap)

Example 47 with EntityDefinition

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);
}
Also used : Label(org.eclipse.swt.widgets.Label) PropertyEntitySelector(eu.esdihumboldt.hale.ui.function.common.PropertyEntitySelector) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) PropertyParameterDefinition(eu.esdihumboldt.hale.common.align.extension.function.PropertyParameterDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GeometrySchemaService(eu.esdihumboldt.hale.ui.geometry.service.GeometrySchemaService) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyCondition) PropertyOrChildrenTypeCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyOrChildrenTypeCondition) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) DynamicScrolledComposite(eu.esdihumboldt.hale.ui.util.components.DynamicScrolledComposite) QName(javax.xml.namespace.QName) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) 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) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) GridData(org.eclipse.swt.layout.GridData) InstanceService(eu.esdihumboldt.hale.ui.service.instance.InstanceService) GeometryCondition(eu.esdihumboldt.hale.common.align.model.condition.impl.GeometryCondition) PropertyParameter(eu.esdihumboldt.hale.common.align.extension.function.PropertyParameter)

Example 48 with EntityDefinition

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);
}
Also used : Script(groovy.lang.Script) ArrayList(java.util.ArrayList) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) NoResultException(eu.esdihumboldt.hale.common.align.transformation.function.impl.NoResultException) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ExecutionContext(eu.esdihumboldt.hale.common.align.transformation.function.ExecutionContext) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) Property(eu.esdihumboldt.hale.common.align.model.Property) Cell(eu.esdihumboldt.hale.common.align.model.Cell) CellLog(eu.esdihumboldt.hale.common.align.transformation.report.impl.CellLog) PropertyValueImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.PropertyValueImpl) InstanceBuilder(eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder)

Example 49 with EntityDefinition

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;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 50 with EntityDefinition

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);
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5