Search in sources :

Example 1 with AttributeMappings

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping.AttributeMappings 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 2 with AttributeMappings

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping.AttributeMappings 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)2 AttributeMappings (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping.AttributeMappings)2 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)1 Namespace (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)1