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