Search in sources :

Example 6 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 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);
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)

Example 7 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 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;
}
Also used : AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) 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) Namespace(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)

Example 8 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 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);
    }
}
Also used : FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)

Example 9 with FeatureTypeMapping

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());
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with FeatureTypeMapping

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()));
    }
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Namespace(eu.esdihumboldt.hale.io.geoserver.Namespace) Test(org.junit.Test)

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