use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class AppSchemaMappingWrapper method getOrCreateAttributeMapping.
/**
* Return the attribute mapping associated to the provided property.
*
* <p>
* If an attribute mapping for the provided property already exists, it is
* returned; otherwise, a new one is created.
* </p>
*
* @param owningType the type owning the property
* @param mappingName the mapping name
* @param propertyPath the property path
* @return the attribute mapping
*/
AttributeMappingType getOrCreateAttributeMapping(TypeDefinition owningType, String mappingName, List<ChildContext> propertyPath) {
if (propertyPath == null || propertyPath.isEmpty()) {
return null;
}
Integer hashKey = getAttruteMappingHashKey(owningType, propertyPath);
if (!attributeMappings.containsKey(hashKey)) {
// create
AttributeMappingType attrMapping = new AttributeMappingType();
// add to owning type mapping
FeatureTypeMapping ftMapping = getOrCreateFeatureTypeMapping(owningType, mappingName);
ftMapping.getAttributeMappings().getAttributeMapping().add(attrMapping);
// put into internal map
attributeMappings.put(hashKey, attrMapping);
}
return attributeMappings.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 cloneMapping.
static AppSchemaDataAccessType cloneMapping(AppSchemaDataAccessType mapping) {
AppSchemaDataAccessType clone = new AppSchemaDataAccessType();
initMapping(clone);
clone.setCatalog(mapping.getCatalog());
clone.getIncludedTypes().getInclude().addAll(mapping.getIncludedTypes().getInclude());
for (Namespace ns : mapping.getNamespaces().getNamespace()) {
clone.getNamespaces().getNamespace().add(cloneNamespace(ns));
}
for (DataStore ds : mapping.getSourceDataStores().getDataStore()) {
clone.getSourceDataStores().getDataStore().add(cloneDataStore(ds));
}
clone.getTargetTypes().getFeatureType().getSchemaUri().addAll(mapping.getTargetTypes().getFeatureType().getSchemaUri());
for (FeatureTypeMapping ftMapping : mapping.getTypeMappings().getFeatureTypeMapping()) {
clone.getTypeMappings().getFeatureTypeMapping().add(cloneFeatureTypeMapping(ftMapping));
}
return clone;
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class AppSchemaMappingWrapper method groupTypeMappings.
private void groupTypeMappings(Set<FeatureTypeMapping> mainTypes, Set<FeatureTypeMapping> includedTypes) {
// the top level feature type mappings
for (Set<FeatureTypeMapping> ftMappings : featureTypesByTargetElement.values()) {
if (ftMappings.size() > 1) {
FeatureTypeMapping topLevelMapping = null;
for (FeatureTypeMapping m : ftMappings) {
if (topLevelMapping != null) {
// top level mapping already found, drop the others
includedTypes.add(m);
} else {
if (m.getMappingName() == null || m.getMappingName().trim().isEmpty()) {
// use this as top level mapping
// TODO: there's no guarantee this is the right one
// to pick
topLevelMapping = m;
}
}
}
if (topLevelMapping == null) {
// pick the first one (it's pretty much a random choice)
topLevelMapping = ftMappings.iterator().next();
}
mainTypes.add(topLevelMapping);
} else {
mainTypes.add(ftMappings.iterator().next());
}
}
// non-feature type mappings go in the "included types" group
for (Set<FeatureTypeMapping> ftMappings : nonFeatureTypesByTargetElement.values()) {
includedTypes.addAll(ftMappings);
}
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class AppSchemaIsolatedWorkspacesMappingTest method testBothIsolated.
/**
* Isolated attribute must be true, names must match those specified in the
* workspace configuration, unique mapping names must be generated.
*
* @throws IOException
*/
@Test
public void testBothIsolated() throws IOException {
workspaceConf.getWorkspaces().forEach(ws -> ws.setIsolated(true));
AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, workspaceConf);
IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
generator.generateMapping(reporter);
assertEquals(STATIONS_WS_RENAMED, generator.getMainNamespace().name());
assertTrue((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
assertEquals(STATIONS_WS_RENAMED, generator.getMainWorkspace().name());
assertTrue((boolean) generator.getMainWorkspace().getAttribute(Namespace.ISOLATED));
boolean measurementsNsFound = false;
for (Namespace ns : generator.getSecondaryNamespaces()) {
if (MEASUREMENTS_NS_URI.equals(ns.getAttribute(Namespace.URI))) {
measurementsNsFound = true;
assertEquals(MEASUREMENTS_WS_RENAMED, ns.name());
assertTrue((boolean) ns.getAttribute(Namespace.ISOLATED));
assertEquals(MEASUREMENTS_WS_RENAMED, generator.getWorkspace(ns).name());
assertTrue((boolean) generator.getWorkspace(ns).getAttribute(Namespace.ISOLATED));
}
}
assertTrue(measurementsNsFound);
List<FeatureTypeMapping> typeMappings = generator.getGeneratedMapping().getAppSchemaMapping().getTypeMappings().getFeatureTypeMapping();
assertEquals(2, typeMappings.size());
Set<String> mappingNames = new HashSet<String>();
for (FeatureTypeMapping typeMapping : typeMappings) {
assertFalse(Strings.isNullOrEmpty(typeMapping.getMappingName()));
mappingNames.add(typeMapping.getMappingName());
}
assertEquals(2, mappingNames.size());
}
use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping in project hale by halestudio.
the class AppSchemaIsolatedWorkspacesMappingTest method testNonIsolatedRenamed.
/**
* Isolated attribute must be false, names must match those specified in the
* workspace configuration, unique mapping names must not be generated.
*
* @throws IOException
*/
@Test
public void testNonIsolatedRenamed() throws IOException {
AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, workspaceConf);
IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
generator.generateMapping(reporter);
assertEquals(STATIONS_WS_RENAMED, generator.getMainNamespace().name());
assertFalse((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
assertEquals(STATIONS_WS_RENAMED, generator.getMainWorkspace().name());
assertFalse((boolean) generator.getMainWorkspace().getAttribute(Namespace.ISOLATED));
boolean measurementsNsFound = false;
for (Namespace ns : generator.getSecondaryNamespaces()) {
if (MEASUREMENTS_NS_URI.equals(ns.getAttribute(Namespace.URI))) {
measurementsNsFound = true;
assertEquals(MEASUREMENTS_WS_RENAMED, ns.name());
assertFalse((boolean) ns.getAttribute(Namespace.ISOLATED));
assertEquals(MEASUREMENTS_WS_RENAMED, generator.getWorkspace(ns).name());
assertFalse((boolean) generator.getWorkspace(ns).getAttribute(Namespace.ISOLATED));
}
}
assertTrue(measurementsNsFound);
List<FeatureTypeMapping> typeMappings = generator.getGeneratedMapping().getAppSchemaMapping().getTypeMappings().getFeatureTypeMapping();
assertEquals(2, typeMappings.size());
for (FeatureTypeMapping typeMapping : typeMappings) {
assertTrue(Strings.isNullOrEmpty(typeMapping.getMappingName()));
}
}
Aggregations