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);
}
}
}
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);
}
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);
}
}
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;
}
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();
}
Aggregations