Search in sources :

Example 1 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 testNullWorkspaceConfiguration.

/**
 * Isolated attribute must be false, names must match the default ones,
 * unique mapping names must not be generated.
 *
 * @throws IOException
 */
@Test
public void testNullWorkspaceConfiguration() throws IOException {
    AppSchemaMappingGenerator generator = new AppSchemaMappingGenerator(alignment, targetSchemaSpace, null, featureChainingConf, null);
    IOReporter reporter = new DefaultIOReporter(targetSchemaSpace.getSchemas().iterator().next(), "Generate App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, false);
    generator.generateMapping(reporter);
    assertEquals(STATIONS_WS_DEFAULT, generator.getMainNamespace().name());
    assertFalse((boolean) generator.getMainNamespace().getAttribute(Namespace.ISOLATED));
    assertEquals(STATIONS_WS_DEFAULT, 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_DEFAULT, ns.name());
            assertFalse((boolean) ns.getAttribute(Namespace.ISOLATED));
            assertEquals(MEASUREMENTS_WS_DEFAULT, 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)

Example 2 with FeatureTypeMapping

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

the class AppSchemaMappingTest method testNestedJoinHandler.

@Test
public void testNestedJoinHandler() {
    DefaultCell joinCell = buildJoinCell(null);
    // create minimal alignment and pass it to JoinHandler
    DefaultCell renameCell = new DefaultCell();
    renameCell.setTransformationIdentifier(RenameFunction.ID);
    renameCell.setSource(getUuidSourceProperty(unitDenormType));
    renameCell.setTarget(getNestedUnitLocalIdTargetProperty());
    DefaultAlignment alignment = new DefaultAlignment();
    alignment.addCell(joinCell);
    alignment.addCell(renameCell);
    processJoinAlignment(alignment, null);
    // logMapping(mappingWrapper.getMainMapping());
    List<FeatureTypeMapping> ftMappings = mappingWrapper.getMainMapping().getTypeMappings().getFeatureTypeMapping();
    assertEquals(2, ftMappings.size());
    FeatureTypeMapping lcdMapping = null, lcuMapping = null;
    for (FeatureTypeMapping ftMapping : ftMappings) {
        if (SOURCE_DATASET.equals(ftMapping.getSourceType()) && "lcv:LandCoverDataset".equals(ftMapping.getTargetElement())) {
            lcdMapping = ftMapping;
        }
        if (SOURCE_UNIT_DENORM.equals(ftMapping.getSourceType()) && "lcv:LandCoverUnit".equals(ftMapping.getTargetElement())) {
            lcuMapping = ftMapping;
        }
    }
    assertNotNull(lcdMapping);
    assertNotNull(lcuMapping);
    // check feature chaining configuration
    List<AttributeMappingType> lcdAttrMappings = lcdMapping.getAttributeMappings().getAttributeMapping();
    List<AttributeMappingType> lcuAttrMappings = lcuMapping.getAttributeMappings().getAttributeMapping();
    assertNotNull(lcdAttrMappings);
    assertNotNull(lcuAttrMappings);
    assertEquals(1, lcdAttrMappings.size());
    assertEquals(2, lcuAttrMappings.size());
    AttributeMappingType containerMapping = lcdAttrMappings.get(0);
    assertEquals("lcv:member", containerMapping.getTargetAttribute());
    assertEquals("lcv:LandCoverUnit", containerMapping.getSourceExpression().getLinkElement());
    assertEquals("FEATURE_LINK[1]", containerMapping.getSourceExpression().getLinkField());
    assertEquals(SOURCE_DATASET_ID, containerMapping.getSourceExpression().getOCQL());
    assertTrue(containerMapping.isIsMultiple());
    AttributeMappingType nestedMapping = lcuAttrMappings.get(0);
    assertEquals("FEATURE_LINK[1]", nestedMapping.getTargetAttribute());
    assertEquals(SOURCE_DATASET_ID, nestedMapping.getSourceExpression().getOCQL());
    assertNull(nestedMapping.getSourceExpression().getLinkElement());
    assertNull(nestedMapping.getSourceExpression().getLinkField());
}
Also used : AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) Test(org.junit.Test)

Example 3 with FeatureTypeMapping

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

the class WorkspaceConfigurationPage method updateWorkspaceTable.

private void updateWorkspaceTable() {
    AbstractAppSchemaConfigurator configurator = getWizard().getProvider();
    DefaultIOReporter reporter = new DefaultIOReporter(configurator.getTarget(), "Generate Temporary App-Schema Mapping", AppSchemaIO.CONTENT_TYPE_MAPPING, true);
    AppSchemaMappingGenerator generator;
    try {
        configurator.generateMapping(reporter);
        generator = configurator.getMappingGenerator();
        AppSchemaDataAccessType appSchemaMapping = generator.getGeneratedMapping().getAppSchemaMapping();
        List<FeatureTypeMapping> typeMappings = appSchemaMapping.getTypeMappings().getFeatureTypeMapping();
        for (FeatureTypeMapping typeMapping : typeMappings) {
            String[] workspaceAndType = typeMapping.getTargetElement().split(":");
            String workspaceName = workspaceAndType[0];
            String typeName = workspaceAndType[1];
            List<Namespace> namespaces = appSchemaMapping.getNamespaces().getNamespace();
            for (Namespace namespace : namespaces) {
                if (workspaceName.equals(namespace.getPrefix())) {
                    String uri = namespace.getUri();
                    if (workspaceConf.hasWorkspace(uri)) {
                        workspaceConf.getWorkspace(uri).getFeatureTypes().add(typeName);
                    } else {
                        WorkspaceMetadata workspace = new WorkspaceMetadata(workspaceName, uri);
                        workspace.getFeatureTypes().add(typeName);
                        workspaceConf.addWorkspace(workspace);
                    }
                }
            }
        }
        // remove workspaces that contain no features
        workspaceConf.getWorkspaces().forEach((ws) -> {
            if (ws.getFeatureTypes().isEmpty()) {
                workspaceConf.removeWorkspace(ws.getNamespaceUri());
            }
        });
        workspaceTableViewer.setInput(workspaceConf.getWorkspaces());
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    }
}
Also used : DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) WorkspaceMetadata(eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) AbstractAppSchemaConfigurator(eu.esdihumboldt.hale.io.appschema.writer.AbstractAppSchemaConfigurator) Namespace(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace) AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) AppSchemaMappingGenerator(eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingGenerator)

Example 4 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 lookupTypeMapping.

private FeatureTypeMapping lookupTypeMapping(FeatureTypeMapping ftMapping, Set<FeatureTypeMapping> candidates) {
    for (FeatureTypeMapping candidate : candidates) {
        boolean sameElement = ftMapping.getTargetElement().equals(candidate.getTargetElement());
        boolean noMappingName = ftMapping.getMappingName() == null && candidate.getMappingName() == null;
        boolean sameMappingName = false;
        if (!noMappingName) {
            sameMappingName = ftMapping.getMappingName() != null && ftMapping.getMappingName().equals(candidate.getMappingName());
        }
        if (sameElement && (noMappingName || sameMappingName)) {
            return candidate;
        }
    }
    return null;
}
Also used : FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)

Example 5 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 getMainMapping.

/**
 * Returns the mapping configuration for the main mapping file.
 *
 * <p>
 * If the mapping does not require multiple files, this method is equivalent
 * to {@link #getAppSchemaMapping()}.
 * </p>
 *
 * @return a copy of the main mapping configuration
 */
public AppSchemaDataAccessType getMainMapping() {
    AppSchemaDataAccessType mainMapping = cloneMapping(appSchemaMapping);
    if (requiresMultipleFiles()) {
        // add included types configuration
        mainMapping.getIncludedTypes().getInclude().add(AppSchemaIO.INCLUDED_TYPES_MAPPING_FILE);
        Set<FeatureTypeMapping> toBeRemoved = new HashSet<FeatureTypeMapping>();
        Set<FeatureTypeMapping> toBeKept = new HashSet<FeatureTypeMapping>();
        groupTypeMappings(toBeKept, toBeRemoved);
        purgeTypeMappings(mainMapping, toBeRemoved);
    }
    return mainMapping;
}
Also used : AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) HashSet(java.util.HashSet)

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