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