use of eu.esdihumboldt.hale.common.instance.model.MutableInstance in project hale by halestudio.
the class GroovyCreate method execute.
@Override
public void execute(String transformationIdentifier, TransformationEngine engine, Map<String, String> executionParameters, TransformationLog log, Cell cell) throws TransformationException {
// get number of executions
int num;
String numberExpr = getOptionalParameter(PARAM_NUMBER, Value.of(1)).as(String.class);
if (numberExpr != null) {
// replace variables
numberExpr = getExecutionContext().getVariables().replaceVariables(numberExpr);
try {
num = Integer.parseInt(numberExpr);
} catch (NumberFormatException e) {
log.error(log.createMessage("Unable to parse expression for number of instances to create", e));
num = 1;
}
} else {
num = 1;
}
TypeDefinition targetType = getTarget().values().iterator().next().getDefinition().getDefinition();
for (int i = 0; i < num; i++) {
Iterable<MutableInstance> target = createInstances(targetType, log, cell, i);
for (MutableInstance instance : target) {
getPropertyTransformer().publish(null, instance, log, cell);
}
}
}
use of eu.esdihumboldt.hale.common.instance.model.MutableInstance in project hale by halestudio.
the class TargetCollector method toMultiValue.
/**
* Transforms the closures added to this collector to a {@link MultiValue}
* using the supplied builder.
*
* @param builder the instance builder for creating target instances
* @param type the type of the instance to create
* @param log the log
* @return a result value for all closures added to this collector
* @throws TransformationException if some of the collected targets do not
* match the specified type
*/
public MultiValue toMultiValue(InstanceBuilder builder, TypeDefinition type, SimpleLog log) throws TransformationException {
MultiValue result = new MultiValue(size());
// a) closures not allowed if the target is no instance
if (containsClosures && type.getChildren().isEmpty()) {
throw new TransformationException("An instance is not applicable for the target.");
}
// b) values not allowed if the target may not have a value
if (containsValues && !type.getConstraint(HasValueFlag.class).isEnabled() && !type.getConstraint(AugmentedValueFlag.class).isEnabled()) {
// this may be desired, e.g. when producing geometries for GML
if (containsGeometries) {
// only warning message for geometries
log.warn("Value provided for target that does not allow a value according to the schema, contains geometries");
} else {
// instead of a hard error, we just log an error
log.error("Value provided for target that does not allow a value according to the schema");
}
}
for (TargetData data : targetData) {
Object value;
if (data.instance != null) {
Instance instance = data.instance;
// value as instance value
if (data.value != null && instance instanceof MutableInstance) {
((MutableInstance) instance).setValue(data.value);
}
value = instance;
} else {
value = data.value;
}
result.add(value);
}
return result;
}
use of eu.esdihumboldt.hale.common.instance.model.MutableInstance in project hale by halestudio.
the class FilterTest method simpleFilterTestECQL.
@Test
public void simpleFilterTestECQL() throws CQLException {
DefaultTypeDefinition stringType = new DefaultTypeDefinition(new QName("StringType"));
stringType.setConstraint(Binding.get(String.class));
DefaultTypeDefinition personDef = new DefaultTypeDefinition(new QName("PersonType"));
personDef.addChild(new DefaultPropertyDefinition(new QName("Name"), personDef, stringType));
DefaultTypeDefinition autoDef = new DefaultTypeDefinition(new QName("AutoType"));
autoDef.addChild(new DefaultPropertyDefinition(new QName("Name"), autoDef, stringType));
autoDef.addChild(new DefaultPropertyDefinition(new QName("Besitzer"), autoDef, personDef));
MutableInstance auto = new DefaultInstance(autoDef, null);
auto.addProperty(new QName("Name"), "Mein Porsche");
MutableInstance ich = new DefaultInstance(personDef, null);
ich.addProperty(new QName("Name"), "Ich");
auto.addProperty(new QName("Besitzer"), ich);
Filter filter;
filter = new FilterGeoECqlImpl("Name = 'Mein Porsche'");
assertTrue(filter.match(auto));
Filter filter1 = new FilterGeoECqlImpl("Name like '%Porsche%'");
assertTrue(filter1.match(auto));
}
use of eu.esdihumboldt.hale.common.instance.model.MutableInstance in project hale by halestudio.
the class AlignmentUtil method matchCondition.
/**
* Match a property condition against a property value.
*
* @param condition the property condition
* @param value the property value
* @param parent the parent of the property value, may be <code>null</code>
* if there is none
* @return if the value matched the property condition
*/
public static boolean matchCondition(Condition condition, Object value, Object parent) {
// create dummy instance
MutableInstance dummy = new DefaultInstance(null, null);
// add value as property
dummy.addProperty(new QName("value"), value);
// add parent value as property
if (parent != null) {
dummy.addProperty(new QName("parent"), parent);
}
return condition.getFilter().match(dummy);
}
use of eu.esdihumboldt.hale.common.instance.model.MutableInstance in project hale by halestudio.
the class Rename method structuralRename.
/**
* Performs a structural rename on the given source object to the given
* target definition.
*
* @param source the source value (or group/instance)
* @param targetDefinition the target definition
* @param allowIgnoreNamespaces if for the structure comparison, namespaces
* may be ignored
* @param instanceFactory the instance factory
* @param copyGeometries specifies if geometry objects should be copied
* @return the transformed value (or group/instance) or NO_MATCH
*/
public static Object structuralRename(Object source, ChildDefinition<?> targetDefinition, boolean allowIgnoreNamespaces, InstanceFactory instanceFactory, boolean copyGeometries) {
if (!(source instanceof Group)) {
// source simple value
if (targetDefinition.asProperty() != null) {
// target can have value
TypeDefinition propertyType = targetDefinition.asProperty().getPropertyType();
if (copyGeometries || !isGeometry(source)) {
if (propertyType.getChildren().isEmpty()) {
// simple value
return convertValue(source, targetDefinition.asProperty().getPropertyType());
} else {
// instance with value
MutableInstance instance = instanceFactory.createInstance(propertyType);
instance.setDataSet(DataSet.TRANSFORMED);
instance.setValue(convertValue(source, propertyType));
return instance;
}
} else {
return Result.NO_MATCH;
}
}
}
// source is group or instance
if (targetDefinition.asProperty() != null) {
// target can have value
TypeDefinition propertyType = targetDefinition.asProperty().getPropertyType();
if (source instanceof Instance) {
// source has value
if (propertyType.getChildren().isEmpty()) {
// simple value
return convertValue(((Instance) source).getValue(), targetDefinition.asProperty().getPropertyType());
} else {
// instance with value
MutableInstance instance = instanceFactory.createInstance(targetDefinition.asProperty().getPropertyType());
instance.setDataSet(DataSet.TRANSFORMED);
if (copyGeometries || !isGeometry(((Instance) source).getValue())) {
instance.setValue(convertValue(((Instance) source).getValue(), targetDefinition.asProperty().getPropertyType()));
}
renameChildren((Group) source, instance, targetDefinition, allowIgnoreNamespaces, instanceFactory, copyGeometries);
return instance;
}
} else {
// source has no value
if (targetDefinition.asProperty().getPropertyType().getChildren().isEmpty())
// no match possible
return Result.NO_MATCH;
else {
// instance with no value set
MutableInstance instance = instanceFactory.createInstance(targetDefinition.asProperty().getPropertyType());
instance.setDataSet(DataSet.TRANSFORMED);
if (renameChildren((Group) source, instance, targetDefinition, allowIgnoreNamespaces, instanceFactory, copyGeometries))
return instance;
else
// no child matched and no value
return Result.NO_MATCH;
}
}
} else if (targetDefinition.asGroup() != null) {
// target can not have a value
if (targetDefinition.asGroup().getDeclaredChildren().isEmpty())
// target neither has a value nor
return Result.NO_MATCH;
else // children?
{
// group
MutableGroup group = new DefaultGroup(targetDefinition.asGroup());
if (renameChildren((Group) source, group, targetDefinition, allowIgnoreNamespaces, instanceFactory, copyGeometries))
return group;
else
// no child matched and no value
return Result.NO_MATCH;
}
} else {
// neither asProperty nor asGroup -> illegal ChildDefinition
throw new IllegalStateException("Illegal child type.");
}
}
Aggregations