Search in sources :

Example 21 with FeatureTypeMapping

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.

the class AppSchemaMappingWrapper method purgeTypeMappings.

private void purgeTypeMappings(AppSchemaDataAccessType mapping, Set<FeatureTypeMapping> toBeRemoved) {
    Set<String> usedStores = new HashSet<String>();
    Iterator<FeatureTypeMapping> featureIt = mapping.getTypeMappings().getFeatureTypeMapping().iterator();
    while (featureIt.hasNext()) {
        FeatureTypeMapping ftMapping = featureIt.next();
        if (lookupTypeMapping(ftMapping, toBeRemoved) != null) {
            featureIt.remove();
        } else {
            usedStores.add(ftMapping.getSourceDataStore());
        }
    }
    // remove unnecessary DataStores
    Iterator<DataStore> storeIt = mapping.getSourceDataStores().getDataStore().iterator();
    while (storeIt.hasNext()) {
        if (!usedStores.contains(storeIt.next().getId())) {
            storeIt.remove();
        }
    }
}
Also used : DataStore(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) HashSet(java.util.HashSet)

Example 22 with FeatureTypeMapping

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.

the class AppSchemaMappingWrapper method getOrCreateFeatureTypeMapping.

/**
 * Return the feature type mapping associated to the provided type and
 * mapping name.
 *
 * <p>
 * If a feature type mapping for the provided type and mapping name already
 * exists, it is returned; otherwise, a new one is created.
 * </p>
 *
 * @param targetType the target type
 * @param mappingName the mapping name
 * @return the feature type mapping
 */
FeatureTypeMapping getOrCreateFeatureTypeMapping(TypeDefinition targetType, String mappingName) {
    if (targetType == null) {
        return null;
    }
    Integer hashKey = getFeatureTypeMappingHashKey(targetType, mappingName);
    if (!featureTypeMappings.containsKey(hashKey)) {
        // create
        FeatureTypeMapping featureTypeMapping = new FeatureTypeMapping();
        // initialize attribute mappings member
        featureTypeMapping.setAttributeMappings(new AttributeMappings());
        // TODO: how do I know the datasource from which data will be read?
        featureTypeMapping.setSourceDataStore(getDefaultDataStore().getId());
        // Retrieve namespace this feature type belongs to and prepend its
        // prefix to the feature type name; if a namespace with the same URI
        // already existed with a valid prefix, that will be used instead of
        // the one passed here
        Namespace ns = getOrCreateNamespace(targetType.getName().getNamespaceURI(), targetType.getName().getPrefix());
        // TODO: I'm getting the element name with
        // targetType.getDisplayName():
        // isn't there a more elegant (and perhaps more reliable) way to
        // know which element corresponds to a type?
        featureTypeMapping.setTargetElement(ns.getPrefix() + ":" + targetType.getDisplayName());
        if (mappingName != null && !mappingName.isEmpty()) {
            featureTypeMapping.setMappingName(mappingName);
        }
        appSchemaMapping.getTypeMappings().getFeatureTypeMapping().add(featureTypeMapping);
        featureTypeMappings.put(hashKey, featureTypeMapping);
        addToFeatureTypeMappings(targetType, featureTypeMapping);
    }
    return featureTypeMappings.get(hashKey);
}
Also used : AttributeMappings(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping.AttributeMappings) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Namespace(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)

Example 23 with FeatureTypeMapping

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.

the class AppSchemaMappingWrapper method cloneFeatureTypeMapping.

static FeatureTypeMapping cloneFeatureTypeMapping(FeatureTypeMapping ftMapping) {
    FeatureTypeMapping clone = new FeatureTypeMapping();
    clone.setAttributeMappings(new AttributeMappings());
    if (ftMapping.getAttributeMappings() != null) {
        for (AttributeMappingType attrMapping : ftMapping.getAttributeMappings().getAttributeMapping()) {
            clone.getAttributeMappings().getAttributeMapping().add(cloneAttributeMapping(attrMapping));
        }
    }
    clone.setIsDenormalised(ftMapping.isIsDenormalised());
    clone.setIsXmlDataStore(ftMapping.isIsXmlDataStore());
    clone.setItemXpath(ftMapping.getItemXpath());
    clone.setMappingName(ftMapping.getMappingName());
    clone.setSourceDataStore(ftMapping.getSourceDataStore());
    clone.setSourceType(ftMapping.getSourceType());
    clone.setTargetElement(ftMapping.getTargetElement());
    return clone;
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) AttributeMappings(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping.AttributeMappings) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)

Aggregations

FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)23 Test (org.junit.Test)8 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)7 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)5 AppSchemaDataAccessType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType)5 HashSet (java.util.HashSet)5 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)4 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)4 Namespace (eu.esdihumboldt.hale.io.geoserver.Namespace)4 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)3 Namespace (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)2 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)2 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 DataStore (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore)2 AttributeMappings (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping.AttributeMappings)2 FeatureChaining (eu.esdihumboldt.hale.io.appschema.model.FeatureChaining)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)1