use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class XPathParameterPage method determineDefaultVariableNames.
@Override
protected Map<EntityDefinition, String> determineDefaultVariableNames(List<EntityDefinition> variables) {
Map<EntityDefinition, String> result = new LinkedHashMap<EntityDefinition, String>();
// variable names depend on order for GenericXPath
int number = 1;
for (EntityDefinition var : variables) {
result.put(var, "$" + GenericXPath.PREFIX_VAR + number++);
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class XPathFilterField method selectVariable.
/**
* @see eu.esdihumboldt.hale.ui.filter.TypeFilterField#selectVariable()
*/
@Override
protected String selectVariable() {
XPathPropertyDefinitionDialog dialog = new XPathPropertyDefinitionDialog(Display.getCurrent().getActiveShell(), entity, "Insert attribute name", null);
if (dialog.open() == XPathPropertyDefinitionDialog.OK && dialog.getObject() != null) {
EntityDefinition entityDef = dialog.getObject();
StringBuilder var = new StringBuilder();
for (int i = 0; i < dialog.getParentCount(); i++) var.append("../");
// skip the first path element if we didn't start at top level
int start = dialog.atTopLevel() ? 0 : 1;
// if the element itself was selected simply use a single dot
if (dialog.getParentCount() == 0 && entityDef.getPropertyPath().size() == start)
var.append(".");
boolean first = true;
for (int i = start; i < entityDef.getPropertyPath().size(); i++) {
PropertyDefinition propDef = entityDef.getPropertyPath().get(i).getChild().asProperty();
if (propDef != null) {
if (first)
first = false;
else
var.append("/");
if (propDef.getConstraint(XmlAttributeFlag.class).isEnabled())
var.append('@');
QName name = entityDef.getPropertyPath().get(i).getChild().getName();
if (!XMLConstants.NULL_NS_URI.equals(name.getNamespaceURI()))
var.append("\"").append(name.getNamespaceURI()).append("\":");
var.append(name.getLocalPart());
}
}
return var.toString();
} else
return null;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class GroovyTransformation method createGroovyBinding.
/**
* Create a Groovy binding from the list of variables.
*
* @param vars the variable values
* @param varDefs definition of the assigned variables, in case some
* variable values are not set, may be <code>null</code>
* @param cell the cell the binding is created for
* @param typeCell the type cell the binding is created for, may be
* <code>null</code>
* @param builder the instance builder for creating target instances, or
* <code>null</code> if not applicable
* @param useInstanceVariables if instances should be used as variables for
* the binding instead of extracting the instance values
* @param log the transformation log
* @param context the execution context
* @param targetInstanceType the type of the target instance
* @return the binding for use with {@link GroovyShell}
*/
public static Binding createGroovyBinding(List<PropertyValue> vars, List<? extends Entity> varDefs, Cell cell, Cell typeCell, InstanceBuilder builder, boolean useInstanceVariables, TransformationLog log, ExecutionContext context, TypeDefinition targetInstanceType) {
Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, context, targetInstanceType);
// collect definitions to check if all were provided
Set<EntityDefinition> notDefined = new HashSet<>();
if (varDefs != null) {
for (Entity entity : varDefs) {
notDefined.add(entity.getDefinition());
}
}
// keep only defs where no value is provided
if (!notDefined.isEmpty()) {
for (PropertyValue var : vars) {
notDefined.remove(var.getProperty());
}
}
// add null value for missing variables
if (!notDefined.isEmpty()) {
vars = new ArrayList<>(vars);
for (EntityDefinition entityDef : notDefined) {
if (entityDef instanceof PropertyEntityDefinition) {
vars.add(new PropertyValueImpl(null, (PropertyEntityDefinition) entityDef));
}
}
}
for (PropertyValue var : vars) {
// add the variable to the environment
addToBinding(binding, var.getProperty(), getUseValue(var.getValue(), useInstanceVariables));
}
return binding;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class DefaultCellMigrator method updateCell.
@Override
public MutableCell updateCell(final Cell originalCell, final AlignmentMigration migration, final MigrationOptions options, SimpleLog log) {
MutableCell result = new DefaultCell(originalCell);
SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));
final AtomicBoolean replacedEntities = new AtomicBoolean(false);
EntryTransformer<String, Entity, Entity> entityTransformer = new EntryTransformer<String, Entity, Entity>() {
@Override
public Entity transformEntry(String key, Entity value) {
EntityDefinition org = value.getDefinition();
Optional<EntityDefinition> replace = migration.entityReplacement(org, cellLog);
EntityDefinition entity = replace.orElse(org);
if (!Objects.equal(entity, org)) {
replacedEntities.set(true);
}
if (entity instanceof PropertyEntityDefinition) {
return new DefaultProperty((PropertyEntityDefinition) entity);
} else if (entity instanceof TypeEntityDefinition) {
return new DefaultType((TypeEntityDefinition) entity);
} else {
throw new IllegalStateException("Invalid entity definition for creating entity");
}
}
};
// update source entities
if (options.updateSource() && result.getSource() != null && !result.getSource().isEmpty()) {
result.setSource(ArrayListMultimap.create(Multimaps.transformEntries(result.getSource(), entityTransformer)));
}
// update target entities
if (options.updateTarget() && result.getTarget() != null && !result.getTarget().isEmpty()) {
result.setTarget(ArrayListMultimap.create(Multimaps.transformEntries(result.getTarget(), entityTransformer)));
}
// TODO anything else?
postUpdateCell(result, options, replacedEntities.get(), cellLog);
return result;
}
use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.
the class PropertyOrChildrenTypeCondition method accept.
private boolean accept(EntityDefinition entityDef, Set<TypeDefinition> tested) {
Definition<?> def = entityDef.getDefinition();
if (def instanceof PropertyDefinition) {
// test the property definition and its property type
TypeDefinition type = ((PropertyDefinition) def).getPropertyType();
if (tested.contains(type)) {
// we already tested that type
return false;
}
if (accept(type, entityDef.getSchemaSpace())) {
return true;
}
tested.add(type);
}
// test the children
for (ChildDefinition<?> child : DefinitionUtil.getAllChildren(DefinitionUtil.getDefinitionGroup(def))) {
EntityDefinition childDef = AlignmentUtil.getChild(entityDef, child.getName());
if (accept(childDef, tested)) {
return true;
}
}
return false;
}
Aggregations