Search in sources :

Example 86 with TypeDefinition

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);
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) Value(eu.esdihumboldt.hale.common.core.io.Value) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 87 with TypeDefinition

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);
        }
    }
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 88 with TypeDefinition

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);
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Reference(eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference) HasValueFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 89 with TypeDefinition

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);
    }
}
Also used : MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 90 with TypeDefinition

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;
}
Also used : TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)192 QName (javax.xml.namespace.QName)58 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)38 ArrayList (java.util.ArrayList)32 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)26 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)26 Test (org.junit.Test)24 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)22 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)21 HashSet (java.util.HashSet)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)20 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)16 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)15 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)14 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)12 Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)12 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)12