Search in sources :

Example 81 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class CityGMLPropagateVisitor method propagateCell.

/**
 * Propagate a given cell to the given target property and possible source
 * types.
 *
 * @param exampleCell the example cell
 * @param ped the target property
 */
private void propagateCell(Cell exampleCell, PropertyEntityDefinition ped) {
    /*
		 * Find the type where the property actually is defined, as if possible
		 * a super type mapping should be used.
		 */
    TypeDefinition targetType = findTypeDefining(ped);
    if (!targetType.equals(ped.getType())) {
        ped = new PropertyEntityDefinition(targetType, ped.getPropertyPath(), ped.getSchemaSpace(), ped.getFilter());
    }
    // check if the cell was already handled for the type
    if (handledTargets.get(exampleCell).contains(targetType)) {
        // don't produce any duplicates
        return;
    }
    handledTargets.put(exampleCell, targetType);
    TypeEntityIndex<List<ChildContext>> index = new TypeEntityIndex<List<ChildContext>>();
    Collection<TypeDefinition> sourceTypes = findSourceTypes(exampleCell, targetType, index);
    if (sourceTypes != null) {
        for (TypeDefinition sourceType : sourceTypes) {
            // copy cell
            DefaultCell cell = new DefaultCell(exampleCell);
            // reset ID
            cell.setId(null);
            // assign new target
            ListMultimap<String, Entity> target = ArrayListMultimap.create();
            target.put(cell.getTarget().keys().iterator().next(), new DefaultProperty(ped));
            cell.setTarget(target);
            // assign new source(s)
            ListMultimap<String, Entity> source = ArrayListMultimap.create();
            for (Entry<String, ? extends Entity> entry : cell.getSource().entries()) {
                // create new source entity
                List<ChildContext> path = index.get(sourceType, entry.getValue());
                if (path == null) {
                    throw new IllegalStateException("No replacement property path computed");
                }
                Property newSource = new DefaultProperty(new PropertyEntityDefinition(sourceType, path, SchemaSpaceID.SOURCE, null));
                source.put(entry.getKey(), newSource);
            }
            cell.setSource(source);
            BGISAppUtil.appendNote(cell, cellNote);
            cells.add(cell);
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityIndex(eu.esdihumboldt.hale.app.bgis.ade.propagate.internal.TypeEntityIndex) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 82 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class FilteredInstanceCollection method applyFilter.

/**
 * Create an instance collection that applies a filter to the given instance
 * collection.
 *
 * @param instances the instance collection to filter
 * @param filter the filter
 * @return the filtered instance collection
 */
public static InstanceCollection applyFilter(InstanceCollection instances, Filter filter) {
    if (filter instanceof TypeFilter && instances instanceof InstanceCollection2) {
        /*
			 * For type filters check if we can make use of fan-out.
			 */
        InstanceCollection2 instances2 = (InstanceCollection2) instances;
        if (instances2.supportsFanout()) {
            TypeDefinition type = ((TypeFilter) filter).getType();
            InstanceCollection result = instances2.fanout().get(type);
            if (result == null) {
                result = EmptyInstanceCollection.INSTANCE;
            }
            return result;
        }
    }
    // create a filtered collection
    return new FilteredInstanceCollection(instances, filter);
}
Also used : EmptyInstanceCollection(eu.esdihumboldt.hale.common.instance.model.ext.helper.EmptyInstanceCollection) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) InstanceCollection2(eu.esdihumboldt.hale.common.instance.model.ext.InstanceCollection2) TypeFilter(eu.esdihumboldt.hale.common.instance.model.TypeFilter) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 83 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class SchemaIO method loadMappingRelevantTypesConfig.

/**
 * Load the configuration of mapping relevant types.
 *
 * @param types the types
 * @param spaceID the schema space identifier
 * @param configurationService the configuration service
 */
public static void loadMappingRelevantTypesConfig(TypeIndex types, SchemaSpaceID spaceID, IConfigurationService configurationService) {
    String paramName = getMappingRelevantTypesParameterName(spaceID);
    List<String> config = configurationService.getList(paramName);
    if (config != null) {
        Set<String> mappableConfig = new HashSet<>(config);
        // collect types to be toggled
        List<TypeDefinition> toToggle = new ArrayList<>();
        for (TypeDefinition type : types.getTypes()) {
            boolean relevant = type.getConstraint(MappingRelevantFlag.class).isEnabled();
            boolean shouldBeRelevant = mappableConfig.contains(type.getName().toString());
            if (relevant != shouldBeRelevant) {
                toToggle.add(type);
            }
        }
        types.toggleMappingRelevant(toToggle);
    }
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Example 84 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class ReferenceFactory method restore.

@Override
public Reference restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    ValueProperties props = value.as(ValueProperties.class);
    Reference ref = new Reference(props.get(P_IS_REF).as(Boolean.class, false));
    Value types = props.get(P_TYPES);
    if (types.isComplex()) {
        ValueList list = types.as(ValueList.class);
        if (list != null) {
            for (Value entry : list) {
                Optional<TypeDefinition> type = typeIndex.resolve(entry);
                if (type.isPresent()) {
                    ref.addReferencedType(type.get());
                } else {
                    throw new IllegalStateException("Could not resolve type definition for index " + entry);
                }
            }
        }
    }
    return ref;
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Reference(eu.esdihumboldt.hale.common.schema.model.constraint.property.Reference) Value(eu.esdihumboldt.hale.common.core.io.Value) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 85 with TypeDefinition

use of eu.esdihumboldt.hale.common.schema.model.TypeDefinition in project hale by halestudio.

the class ReferenceFactory method store.

@Override
public Value store(Reference constraint, TypeReferenceBuilder typeIndex) {
    ValueProperties props = new ValueProperties();
    props.put(P_IS_REF, Value.of(constraint.isReference()));
    if (constraint.getReferencedTypes() == null) {
        // referenced types are unknown
        props.put(P_TYPES, Value.of(V_TYPES_UNKNOWN));
    } else {
        // store type list
        ValueList types = new ValueList();
        for (TypeDefinition type : constraint.getReferencedTypes()) {
            // add each type index
            Optional<Value> ref = typeIndex.createReference(type);
            if (ref.isPresent()) {
                types.add(ref.get());
            } else {
                throw new IllegalStateException(MessageFormat.format("Type {0} could not be resolved in type index", type.getName()));
            }
        }
        props.put(P_TYPES, types.toValue());
    }
    return props.toValue();
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) Value(eu.esdihumboldt.hale.common.core.io.Value) 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