Search in sources :

Example 16 with IOProviderConfigurationException

use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.

the class AbstractAppSchemaConfigurator method generateMapping.

/**
 * Uses a fresh {@link AppSchemaMappingGenerator} instance to generates the
 * mapping configuration based on the current provider's configuration
 * parameters.
 *
 * @param reporter the status reporter
 * @throws IOProviderConfigurationException if something is wrong with the
 *             provider configuration
 * @throws IOException if an error occurs loading the mapping template file
 */
public void generateMapping(IOReporter reporter) throws IOProviderConfigurationException, IOException {
    if (getAlignment() == null) {
        throw new IOProviderConfigurationException("No alignment was provided.");
    }
    if (getTargetSchema() == null) {
        throw new IOProviderConfigurationException("No target schema was provided.");
    }
    if (getTarget() == null) {
        throw new IOProviderConfigurationException("No target was provided.");
    }
    DataStore dataStoreParam = getDataStoreParameter();
    FeatureChaining featureChainingParam = getFeatureChainingParameter();
    // resolve property entity definitions here, could't do it on project
    // loading
    resolvePropertyTypes(featureChainingParam, getTargetSchema(), SchemaSpaceID.TARGET);
    WorkspaceConfiguration workspaceConfParam = getWorkspaceConfigurationParameter();
    generator = new AppSchemaMappingGenerator(getAlignment(), getTargetSchema(), dataStoreParam, featureChainingParam, workspaceConfParam);
    generator.generateMapping(reporter);
}
Also used : IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) FeatureChaining(eu.esdihumboldt.hale.io.appschema.model.FeatureChaining) DataStore(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.SourceDataStoresPropertyType.DataStore) WorkspaceConfiguration(eu.esdihumboldt.hale.io.appschema.model.WorkspaceConfiguration)

Example 17 with IOProviderConfigurationException

use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.

the class AbstractCachedSchemaReaderBase method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    if (validCache(cache) && useCache(cache)) {
        reporter.info(new IOMessageImpl("Loading schema from cached result...", null));
        schema = loadFromCache(cache, progress, reporter);
    } else {
        try {
            schema = loadFromSource(progress, reporter);
        } catch (Exception e) {
            reporter.error("Error loading schema from source", e);
            if (reporter.isSuccess()) {
                reporter.setSuccess(false);
            }
        }
        if (provideCache && schema != null && reporter.isSuccess()) {
            try {
                cache = storeInCache(schema);
                reporter.info(new IOMessageImpl("Created cached schema representation", null));
            } catch (Exception e) {
                reporter.error(new IOMessageImpl("Failed to create a representation of the schema for caching", e));
                // invalidate cache
                cache = null;
            }
            cacheUpdate = true;
        }
        if (!reporter.isSuccess() && validCache(cache) && useCacheAsFallback()) {
            schema = loadFromCache(cache, progress, reporter);
        }
    }
    return reporter;
}
Also used : IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 18 with IOProviderConfigurationException

use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.

the class HaleSchemaWriter method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save schema", ProgressIndicator.UNKNOWN);
    try (OutputStream out = getTarget().getOutput()) {
        // create DOM
        NSDOMBuilder builder = SchemaToXml.createBuilder();
        Element root = new SchemaToXml().schemasToXml(builder, getSchemas().getSchemas());
        // configure transformer for serialization
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        // TODO configurable?!
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // serialize DOM
        DOMSource source = new DOMSource(root);
        StreamResult result = new StreamResult(out);
        transformer.transform(source, result);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) NSDOMBuilder(eu.esdihumboldt.util.groovy.xml.NSDOMBuilder) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) Element(org.w3c.dom.Element) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 19 with IOProviderConfigurationException

use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.

the class HaleSchemaReaderJson method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Load schema", ProgressIndicator.UNKNOWN);
    try (InputStream in = getSource().getInput();
        Reader reader = new InputStreamReader(in, getCharset())) {
        Iterable<Schema> schemas = new JsonToSchema(null, new OsgiClassResolver(), reporter).parseSchemas(reader);
        List<Schema> schemaList = StreamSupport.stream(schemas.spliterator(), false).collect(Collectors.toList());
        if (!schemaList.isEmpty()) {
            schema = HaleSchemaUtil.combineSchema(schemaList, reporter);
            reporter.setSuccess(true);
        } else {
            reporter.setSuccess(false);
            reporter.setSummary("No schema definition found");
        }
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AbstractSchemaReader(eu.esdihumboldt.hale.common.schema.io.impl.AbstractSchemaReader) OsgiClassResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.OsgiClassResolver) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 20 with IOProviderConfigurationException

use of eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException in project hale by halestudio.

the class HaleSchemaWriterJson method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save schema", ProgressIndicator.UNKNOWN);
    try (OutputStream out = getTarget().getOutput();
        Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
        // create DOM
        JsonStreamBuilder builder = new JsonStreamBuilder(writer, true);
        new SchemaToJson().schemasToJson(builder, getSchemas().getSchemas(), null);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : JsonStreamBuilder(eu.esdihumboldt.util.groovy.json.JsonStreamBuilder) OutputStream(java.io.OutputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) AbstractSchemaWriter(eu.esdihumboldt.hale.common.schema.io.impl.AbstractSchemaWriter) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Aggregations

IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)44 IOException (java.io.IOException)38 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)27 InputStream (java.io.InputStream)14 URI (java.net.URI)13 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)6 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)6 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)6 File (java.io.File)6 OutputStream (java.io.OutputStream)6 ArrayList (java.util.ArrayList)6 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)5 QName (javax.xml.namespace.QName)5 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)4 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)4 InputStreamReader (java.io.InputStreamReader)4 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)3