Search in sources :

Example 1 with AppSchemaDataAccessType

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

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

the class AppSchemaMappingGenerator method generateMapping.

/**
 * Generates the app-schema mapping configuration.
 *
 * @param reporter status reporter
 * @return the generated app-schema mapping configuration
 * @throws IOException if an error occurs loading the mapping template file
 */
public AppSchemaMappingWrapper generateMapping(IOReporter reporter) throws IOException {
    // reset wrapper
    resetMappingState();
    try {
        AppSchemaDataAccessType mapping = loadMappingTemplate();
        mappingWrapper = new AppSchemaMappingWrapper(mapping);
        context = new AppSchemaMappingContext(mappingWrapper, alignment, targetSchema.getMappingRelevantTypes(), chainingConf, workspaceConf);
        // create namespace objects for all target types / properties
        // TODO: this removes all namespaces that were defined in the
        // template file, add code to cope with pre-configured namespaces
        // instead
        mapping.getNamespaces().getNamespace().clear();
        createNamespaces();
        // apply datastore configuration, if any
        // TODO: for now, only a single datastore is supported
        applyDataStoreConfig();
        // populate targetTypes element
        createTargetTypes();
        // populate typeMappings element
        createTypeMappings(context, reporter);
        // cache mainMapping and includedTypesMapping for performance
        mainMapping = mappingWrapper.getMainMapping();
        includedTypesMapping = mappingWrapper.getIncludedTypesMapping();
        return mappingWrapper;
    } catch (Exception e) {
        // making sure state is reset in case an exception is thrown
        resetMappingState();
        throw e;
    }
}
Also used : AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) AppSchemaMappingWrapper(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper) JAXBException(javax.xml.bind.JAXBException) UnsupportedTransformationException(eu.esdihumboldt.hale.io.appschema.writer.internal.UnsupportedTransformationException) IOException(java.io.IOException)

Example 3 with AppSchemaDataAccessType

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

the class AppSchemaMappingGenerator method loadMappingTemplate.

private AppSchemaDataAccessType loadMappingTemplate() throws IOException {
    InputStream is = getClass().getResourceAsStream(AppSchemaIO.MAPPING_TEMPLATE);
    JAXBElement<AppSchemaDataAccessType> templateElement = null;
    try {
        JAXBContext context = createJaxbContext();
        Unmarshaller unmarshaller = context.createUnmarshaller();
        templateElement = unmarshaller.unmarshal(new StreamSource(is), AppSchemaDataAccessType.class);
    } catch (JAXBException e) {
        throw new IOException(e);
    }
    return templateElement.getValue();
}
Also used : AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 4 with AppSchemaDataAccessType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType 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)

Example 5 with AppSchemaDataAccessType

use of eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType 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)

Aggregations

AppSchemaDataAccessType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType)8 FeatureTypeMapping (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping)4 Namespace (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.NamespacesPropertyType.Namespace)2 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)2 AppSchemaMappingWrapper (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingWrapper)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBException (javax.xml.bind.JAXBException)2 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 ObjectFactory (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.ObjectFactory)1 DataStore (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore)1 WorkspaceMetadata (eu.esdihumboldt.hale.io.appschema.model.WorkspaceMetadata)1 AbstractAppSchemaConfigurator (eu.esdihumboldt.hale.io.appschema.writer.AbstractAppSchemaConfigurator)1 AppSchemaMappingGenerator (eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingGenerator)1 UnsupportedTransformationException (eu.esdihumboldt.hale.io.appschema.writer.internal.UnsupportedTransformationException)1 InputStream (java.io.InputStream)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1