use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.
the class NestedCellRelationshipContentProvider method getElements.
/**
* @see CellRelationshipContentProvider#getElements(Object)
*/
@Override
public Object[] getElements(Object input) {
List<Object> elements = new ArrayList<Object>();
entityMap.clear();
Multimap<TypeDefinition, Type> types = HashMultimap.create();
Collection<Property> properties = new ArrayList<Property>();
for (Object element : super.getElements(input)) {
if (element instanceof Type) {
Type type = (Type) element;
types.put(type.getDefinition().getDefinition(), type);
elements.add(element);
} else if (element instanceof Property) {
properties.add((Property) element);
} else {
elements.add(element);
}
}
// assign properties to corresponding parents
for (Property property : properties) {
// find association through type definition
TypeDefinition parentType = property.getDefinition().getType();
Collection<Type> typeList = types.get(parentType);
for (Type type : typeList) {
entityMap.put(type, property);
}
}
return elements.toArray();
}
use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.
the class GroovyTransformationPage method addActions.
@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
super.addActions(toolbar, viewer);
PageHelp.createToolItem(toolbar, this);
TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {
@Override
public Collection<? extends TypeDefinition> getTypes() {
// create a dummy type with the variables as children
DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
Cell cell = getWizard().getUnfinishedCell();
boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
for (EntityDefinition variable : getVariables()) {
if (variable.getDefinition() instanceof PropertyDefinition) {
PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
TypeDefinition propertyType;
if (useInstanceValues) {
// use instance type
propertyType = prop.getPropertyType();
} else {
// use dummy type with only the
// binding/HasValueFlag copied
DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
propertyType = crippledType;
}
DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(getVariableName(variable)), dummy, propertyType);
// number of times
if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID))
dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
}
}
return Collections.singleton(dummy);
}
});
TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {
@Override
public Collection<? extends TypeDefinition> getTypes() {
Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetProperty != null) {
return Collections.singleton(targetProperty.getDefinition().getDefinition().getPropertyType());
}
return Collections.emptyList();
}
});
PageFunctions.createToolItem(toolbar, this);
}
use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.
the class GroovyTransformationPage method createConfiguration.
@Override
protected SourceViewerConfiguration createConfiguration() {
InstanceBuilderCompletions targetCompletions = new InstanceBuilderCompletions(definitionImages) {
@Override
protected TypeDefinition getTargetType() {
Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
if (targetProperty != null) {
return targetProperty.getDefinition().getDefinition().getPropertyType();
}
return null;
}
};
HelperFunctionsCompletions functionCompletions = new HelperFunctionsCompletions(HaleUI.getServiceProvider().getService(HelperFunctionsService.class));
return new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_BUILDER, BINDING_TARGET, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT, BINDING_HELPER_FUNCTIONS), ImmutableList.of(targetCompletions, functionCompletions));
}
use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.
the class UserMigration method entityReplacement.
@Override
public Optional<EntityDefinition> entityReplacement(EntityDefinition entity, SimpleLog log) {
// use functionality from entity resolver
if (entity instanceof TypeEntityDefinition) {
EntityDefinition candidate = entity;
Type type = UserFallbackEntityResolver.resolveType((TypeEntityDefinition) entity, candidate, schemaSpace);
return Optional.ofNullable(type).map(e -> e.getDefinition());
} else if (entity instanceof PropertyEntityDefinition) {
EntityDefinition candidate = entity;
candidate = EntityCandidates.find((PropertyEntityDefinition) entity);
Property property = UserFallbackEntityResolver.resolveProperty((PropertyEntityDefinition) entity, candidate, schemaSpace);
return Optional.ofNullable(property).map(e -> e.getDefinition());
} else {
log.error("Unrecognised entity type: " + entity.getClass());
return Optional.empty();
}
}
use of eu.esdihumboldt.hale.common.align.model.Property in project hale by halestudio.
the class AppSchemaMappingTest method testAssignHandler.
@Test
public void testAssignHandler() {
final String ASSIGN_VALUE = "LCU_1234";
final String OCQL = "'" + ASSIGN_VALUE + "'";
final String OCQL_BOUND = "if_then_else(isNull(" + SOURCE_UUID_V1 + "), Expression.NIL, '" + ASSIGN_VALUE + "')";
Cell typeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
DefaultCell cell = new DefaultCell();
cell.setTransformationIdentifier(AssignFunction.ID);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(ASSIGN_VALUE));
cell.setTarget(getLocalIdTargetProperty());
cell.setTransformationParameters(parameters);
AssignHandler assignHandler = new AssignHandler();
AttributeMappingType attrMapping = assignHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
// bound version of "Assign"
DefaultCell cellCopy = new DefaultCell(cell);
Collection<Property> anchor = getUuidSourceProperty(unitDenormType).values();
ListMultimap<String, Property> source = ArrayListMultimap.create();
source.putAll(AssignFunction.ENTITY_ANCHOR, anchor);
cellCopy.setSource(source);
cellCopy.setTransformationIdentifier(AssignFunction.ID_BOUND);
attrMapping = assignHandler.handlePropertyTransformation(typeCell, cellCopy, new AppSchemaMappingContext(mappingWrapper));
assertEquals(OCQL_BOUND, attrMapping.getSourceExpression().getOCQL());
assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
}
Aggregations