use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class ElementTypeFactory method restore.
@Override
public ElementType restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
ValueProperties props = value.as(ValueProperties.class);
// try type definition
Value index = props.getSafe(P_TYPE);
if (index != null) {
Optional<TypeDefinition> def = typeIndex.resolve(index);
if (def.isPresent()) {
return ElementType.createFromType(def.get());
}
}
// fall back to binding
String binding = props.getSafe(P_BINDING).as(String.class);
Class<?> clazz = resolver.loadClass(binding);
if (clazz == null) {
throw new IllegalStateException(MessageFormat.format("Could not resolve class {0} for element type binding", binding));
}
return ElementType.get(clazz);
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class DefaultSchemaSpace method toggleMappingRelevant.
/**
* @see eu.esdihumboldt.hale.common.schema.model.TypeIndex#toggleMappingRelevant(java.util.Collection)
*/
@Override
public void toggleMappingRelevant(Collection<? extends TypeDefinition> types) {
synchronized (this) {
for (TypeDefinition type : types) {
Schema container = null;
for (Schema schema : schemas) if (schema.getTypes().contains(type)) {
container = schema;
break;
}
// toggle type in its schema
if (container != null)
container.toggleMappingRelevant(Collections.singletonList(type));
else {
// shouldn't happen, but to be safe toggle it in this case
// too
Definition<TypeConstraint> def = type;
((AbstractDefinition<TypeConstraint>) def).setConstraint(MappingRelevantFlag.get(!type.getConstraint(MappingRelevantFlag.class).isEnabled()));
}
// was toggled, update own list
if (mappingRelevantTypes != null)
if (type.getConstraint(MappingRelevantFlag.class).isEnabled())
mappingRelevantTypes.add(type);
else
mappingRelevantTypes.remove(type);
}
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class AssignFromCollectorExplanation method customizeBinding.
@Override
protected void customizeBinding(Map<String, Object> binding, Cell cell, boolean html, ServiceProvider provider, Locale locale) {
// Default values for all bindings
binding.put("_constraintsEvaluated", false);
binding.put("_hasValue", false);
binding.put("_isReference", false);
Entity entity = CellUtil.getFirstEntity(cell.getTarget());
if (entity != null && entity.getDefinition().getDefinition() instanceof PropertyDefinition) {
PropertyDefinition resultProperty = (PropertyDefinition) entity.getDefinition().getDefinition();
TypeDefinition resultPropertyType = resultProperty.getPropertyType();
boolean isReference = resultProperty.getConstraint(Reference.class).isReference();
binding.put("_isReference", isReference);
// determine this.
if (isReference) {
binding.put("_hasValue", true);
} else {
boolean hasValue = resultPropertyType.getConstraint(HasValueFlag.class).isEnabled();
binding.put("_hasValue", hasValue);
}
binding.put("_constraintsEvaluated", true);
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class Create 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;
}
for (int i = 0; i < num; i++) {
// create <number> of instances of the target type
TypeDefinition targetType = getTarget().values().iterator().next().getDefinition().getDefinition();
MutableInstance target = createInstance(targetType, i, log, cell);
getPropertyTransformer().publish(null, target, log, cell);
}
}
use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.
the class GenerateUID method evaluate.
@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
TypeDefinition type = resultProperty.getType();
String typeName = type.getDisplayName();
String localName = resultProperty.getDefinition().getName().getLocalPart();
String name = typeName + "_" + localName + "_" + UUID.randomUUID().toString();
return name;
}
Aggregations