Search in sources :

Example 26 with TypeEntityDefinition

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

the class DefaultAlignmentIOTest method testIDSaveLoad.

/**
 * Tests id generation, save and load.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testIDSaveLoad() throws Exception {
    DefaultAlignment alignment = new DefaultAlignment();
    Schema schema = TestUtil.loadSchema(getClass().getResource("/testdata/simple/t1.xsd").toURI());
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier("trans1");
    ListMultimap<String, Type> source = ArrayListMultimap.create();
    source.put(null, new DefaultType(new TypeEntityDefinition(schema.getMappingRelevantTypes().iterator().next(), SchemaSpaceID.SOURCE, null)));
    cell.setSource(source);
    ListMultimap<String, Type> target = ArrayListMultimap.create();
    target.put(null, new DefaultType(new TypeEntityDefinition(schema.getMappingRelevantTypes().iterator().next(), SchemaSpaceID.TARGET, null)));
    cell.setTarget(target);
    // add cell and check id generation
    assertNull(cell.getId());
    alignment.addCell(cell);
    assertNotNull(cell.getId());
    assertNotNull(alignment.getCell(cell.getId()));
    // save / load
    File alignmentFile = tmp.newFile("alignment.xml");
    System.out.println(alignmentFile.getAbsolutePath());
    saveAlignment(alignment, new BufferedOutputStream(new FileOutputStream(alignmentFile)));
    MutableAlignment alignment2 = loadAlignment(new FileInputStream(alignmentFile), schema, schema);
    // check cell id
    assertEquals(cell.getId(), alignment2.getCells().iterator().next().getId());
}
Also used : DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) FileInputStream(java.io.FileInputStream) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) FileOutputStream(java.io.FileOutputStream) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Test(org.junit.Test)

Example 27 with TypeEntityDefinition

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

the class TGraphFactory method setVertexProperties.

private static void setVertexProperties(Vertex vertex, TransformationTree node) {
    // create a type entity definition
    // TODO also include the filter
    TypeEntityDefinition ted = new TypeEntityDefinition(node.getType(), SchemaSpaceID.TARGET, null);
    vertex.setProperty(P_ENTITY, ted);
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)

Example 28 with TypeEntityDefinition

use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition 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 29 with TypeEntityDefinition

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

the class SpatialJoinParameterPage method swapTypes.

/**
 * Swaps the given types, their pages and validates all affected pages
 * conditions after the change.
 *
 * @param lowerTypeIndex the lower type index
 * @param higherTypeIndex the higher type index
 */
private void swapTypes(int lowerTypeIndex, int higherTypeIndex) {
    TypeEntityDefinition lowerType = types.get(lowerTypeIndex);
    types.set(lowerTypeIndex, types.get(higherTypeIndex));
    types.set(higherTypeIndex, lowerType);
    table.refresh();
    // swap pages accordingly
    int lowerPageIndex = lowerTypeIndex - 1;
    int higherPageIndex = higherTypeIndex - 1;
    if (lowerPageIndex != -1) {
        // swap the page positions together with their types
        // so it is possible to keep some conditions from before
        ConditionPage lowerPage = pages.get(lowerPageIndex);
        ConditionPage higherPage = pages.get(higherPageIndex);
        lowerPage.typeIndex = higherTypeIndex;
        pages.set(higherPageIndex, lowerPage);
        higherPage.typeIndex = lowerTypeIndex;
        pages.set(lowerPageIndex, higherPage);
    }
    // check and refresh pages in between
    for (ConditionPage page : pages.subList(Math.max(0, lowerPageIndex), higherPageIndex + 1)) page.checkAndRefresh();
    getContainer().updateButtons();
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Point(org.eclipse.swt.graphics.Point)

Example 30 with TypeEntityDefinition

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

the class SpatialJoinParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    Cell cell = getWizard().getUnfinishedCell();
    List<? extends Entity> sourceEntities = cell.getSource().get(JOIN_TYPES);
    List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>();
    Iterator<? extends Entity> iter = sourceEntities.iterator();
    while (iter.hasNext()) types.add(AlignmentUtil.getTypeEntity(iter.next().getDefinition()));
    if (sameTypes(this.types, types))
        return;
    if (containsDuplicateType(types)) {
        setPageComplete(false);
        setErrorMessage("The selected source types contain duplicates.");
        this.types.clear();
        table.setInput(null);
        return;
    } else {
        setErrorMessage(null);
    }
    SpatialJoinParameter initialValue = null;
    if (firstShow && !getInitialValues().isEmpty()) {
        initialValue = getInitialValues().get(PARAMETER_SPATIAL_JOIN).get(0).as(SpatialJoinParameter.class);
        if (initialValue != null && (initialValue.validate() != null || !sameTypes(types, initialValue.types)))
            initialValue = null;
    }
    for (ConditionPage page : pages) page.dispose();
    pages.clear();
    if (initialValue != null) {
        // use ordering of the initial value (needs to be modifiable)
        types = new ArrayList<>(initialValue.types);
    }
    this.types = types;
    if (table != null)
        table.setInput(types);
    for (int i = 1; i < types.size(); i++) {
        ConditionPage conditionPage = new ConditionPage(i);
        conditionPage.setWizard(getWizard());
        pages.add(conditionPage);
    }
    if (initialValue != null) {
        // add initial conditions
        for (SpatialJoinCondition condition : initialValue.conditions) {
            TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
            int typeIndex = types.indexOf(joinType);
            int pageIndex = typeIndex - 1;
            pages.get(pageIndex).conditions.add(condition);
            pages.get(pageIndex).updateCompletionStatus();
        }
    }
    // order is always valid, will trigger updateButtons
    setPageComplete(true);
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SpatialJoinParameter(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter) SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) ArrayList(java.util.ArrayList) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Point(org.eclipse.swt.graphics.Point)

Aggregations

TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)64 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)23 ArrayList (java.util.ArrayList)19 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)16 Type (eu.esdihumboldt.hale.common.align.model.Type)16 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)16 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)11 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)10 QName (javax.xml.namespace.QName)9 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)8 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)6 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 LinkedList (java.util.LinkedList)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)5