use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class MarkTypeUnmappableHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
SchemaService schemaService = PlatformUI.getWorkbench().getService(SchemaService.class);
Iterator<?> it = ((IStructuredSelection) selection).iterator();
List<TypeDefinition> sourceTypes = new ArrayList<>();
List<TypeDefinition> targetTypes = new ArrayList<>();
while (it.hasNext()) {
Object selected = it.next();
TypeDefinition type = null;
if (selected instanceof TypeEntityDefinition) {
type = ((TypeEntityDefinition) selected).getDefinition();
} else if (selected instanceof TypeDefinition) {
type = (TypeDefinition) selected;
}
if (type != null) {
if (schemaService.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes().contains(type)) {
sourceTypes.add(type);
} else {
targetTypes.add(type);
}
}
}
if (!sourceTypes.isEmpty()) {
schemaService.toggleMappable(SchemaSpaceID.SOURCE, sourceTypes);
}
if (!targetTypes.isEmpty()) {
schemaService.toggleMappable(SchemaSpaceID.TARGET, targetTypes);
}
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class TypeEntityDefinitionTester method test.
/**
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
* java.lang.String, java.lang.Object[], java.lang.Object)
*/
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver == null)
return false;
if (property.equals(PROPERTY_TYPE_ALLOW_MARK_UNMAPPABLE) && receiver instanceof TypeEntityDefinition) {
AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
TypeEntityDefinition entityDef = (TypeEntityDefinition) receiver;
return as.getAlignment().getCells(entityDef.getType(), entityDef.getSchemaSpace()).isEmpty();
}
return false;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class PropertyEntitySelector method setParentType.
/**
* Set the parent type
*
* @param parentType the parentType to set
*/
public void setParentType(TypeEntityDefinition parentType) {
// reset candidates?? refresh viewer?
if (!Objects.equal(this.parentType, parentType)) {
this.parentType = parentType;
// reset selection if necessary
EntityDefinition selection = getSelectedObject();
if (selection != null && parentType != null) {
// parentType, which also got the selected property?
if (!AlignmentUtil.getTypeEntity(selection).equals(parentType)) {
setSelection(StructuredSelection.EMPTY);
}
}
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class SpatialJoinHandler method partitionInstances.
/**
* @see eu.esdihumboldt.hale.common.align.transformation.function.InstanceHandler#partitionInstances(eu.esdihumboldt.hale.common.instance.model.InstanceCollection,
* java.lang.String,
* eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
* com.google.common.collect.ListMultimap, java.util.Map,
* eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
*/
@Override
public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances, String transformationIdentifier, TransformationEngine engine, ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
if (transformationParameters == null || !transformationParameters.containsKey(PARAMETER_SPATIAL_JOIN) || transformationParameters.get(PARAMETER_SPATIAL_JOIN).isEmpty()) {
throw new TransformationException("No join parameter defined");
}
if (services == null) {
throw new IllegalStateException("ServiceProvider must be set before calling partitionInstances");
}
SpatialJoinParameter joinParameter = transformationParameters.get(PARAMETER_SPATIAL_JOIN).get(0).as(SpatialJoinParameter.class);
String validation = joinParameter.validate();
if (validation != null) {
throw new TransformationException("Spatial Join parameter invalid: " + validation);
}
List<TypeEntityDefinition> types = joinParameter.types;
// ChildType -> DirectParentType
int[] directParent = new int[joinParameter.types.size()];
// ChildType -> (ParentType -> Collection<JoinCondition>)
Map<Integer, Multimap<Integer, SpatialJoinCondition>> joinTable = new HashMap<>();
for (SpatialJoinCondition condition : joinParameter.conditions) {
int baseTypeIndex = types.indexOf(AlignmentUtil.getTypeEntity(condition.baseProperty));
int joinTypeIndex = types.indexOf(AlignmentUtil.getTypeEntity(condition.joinProperty));
Multimap<Integer, SpatialJoinCondition> typeTable = joinTable.get(joinTypeIndex);
if (typeTable == null) {
typeTable = ArrayListMultimap.create(2, 2);
joinTable.put(joinTypeIndex, typeTable);
}
typeTable.put(baseTypeIndex, condition);
// update highest type if necessary
if (directParent[joinTypeIndex] < baseTypeIndex) {
directParent[joinTypeIndex] = baseTypeIndex;
}
}
// remember instances of first type to start join afterwards
Collection<InstanceReference> startInstances = new LinkedList<InstanceReference>();
// iterate once over all instances
ResourceIterator<Instance> iterator = instances.iterator();
try {
while (iterator.hasNext()) {
Instance next = iterator.next();
// remember instances of first type
if (next.getDefinition().equals(types.get(0).getDefinition())) {
startInstances.add(instances.getReference(next));
}
}
} finally {
iterator.close();
}
return new SpatialJoinIterator(instances, startInstances, directParent, services, joinTable);
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class SpatialJoinParameter method validate.
/**
* Checks whether this join parameter is valid.<br>
* <br>
* Valid means, that there has to be at least two types, with each type
* after the first having at least one join condition on previous types.
*
* @return a error description or <code>null</code> if the parameter is
* valid.
*/
public String validate() {
// enough types?
if (types.size() < 2)
return "Less than two types.";
// Check that each type is only in here once.
Set<TypeDefinition> typeSet = new HashSet<>();
for (TypeEntityDefinition type : types) {
if (typeSet.contains(type.getDefinition())) {
return "Same base type is used twice.";
} else {
typeSet.add(type.getDefinition());
}
}
// direct parent map
int[] parent = new int[types.size()];
// marker for found conditions for each type
boolean[] conditionFound = new boolean[types.size()];
// use sorted conditions (by join type)
List<SpatialJoinCondition> sortedConditions = new ArrayList<>(conditions);
Collections.sort(sortedConditions, new Comparator<SpatialJoinCondition>() {
@Override
public int compare(SpatialJoinCondition o1, SpatialJoinCondition o2) {
TypeEntityDefinition o1Type = AlignmentUtil.getTypeEntity(o1.baseProperty);
TypeEntityDefinition o2Type = AlignmentUtil.getTypeEntity(o2.baseProperty);
return types.indexOf(o1Type) - types.indexOf(o2Type);
}
});
// check types of each condition
for (SpatialJoinCondition condition : sortedConditions) {
TypeEntityDefinition baseType = AlignmentUtil.getTypeEntity(condition.baseProperty);
TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
int baseIndex = types.indexOf(baseType);
int joinIndex = types.indexOf(joinType);
// types have to exist, and join has to be after base
if (baseIndex == -1 || joinIndex == -1) {
return "Property references no specified type.";
}
if (joinIndex <= baseIndex) {
return "Invalid condition for type order.";
}
conditionFound[joinIndex] = true;
// sorted conditions allow this dependsOn-check
if (parent[joinIndex] < baseIndex) {
if (!dependsOn(baseIndex, parent[joinIndex], parent)) {
return "A join type depends on two types which do not depend on each other.";
}
parent[joinIndex] = baseIndex;
}
}
// check whether each type (except the first) has a join condition
for (int i = 1; i < conditionFound.length; i++) {
if (!conditionFound[i]) {
return "A joined type does not have any join conditions.";
}
}
return null;
}
Aggregations