Search in sources :

Example 26 with IOReport

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

the class SpatiaLiteTestSuite method readInstances.

/**
 * Reads instances from from a SpatiaLite database file with the provided
 * schema.
 *
 * @param sourceSchema the schema of the source database
 * @param sourceFilePath the path to the source database file
 * @return the read instances
 * @throws Exception any exception thrown by
 *             {@link SpatiaLiteInstanceReader}
 */
public InstanceCollection readInstances(Schema sourceSchema, String sourceFilePath) throws Exception {
    SpatiaLiteInstanceReader instanceReader = new SpatiaLiteInstanceReader();
    instanceReader.setSource(new FileIOSupplier(new File(sourceFilePath)));
    instanceReader.setSourceSchema(sourceSchema);
    // Test instances
    IOReport report = instanceReader.execute(new LogProgressIndicator());
    assertTrue("Data import was not successfull.", report.isSuccess());
    return instanceReader.getInstances();
}
Also used : SpatiaLiteInstanceReader(eu.esdihumboldt.hale.io.jdbc.spatialite.reader.internal.SpatiaLiteInstanceReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) LogProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator) File(java.io.File)

Example 27 with IOReport

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

the class AbstractDBTest method readSchema.

/**
 * Load the database schema for a SQL statement.
 *
 * @param sql the SQL query
 * @param typeName the type name for the query
 *
 * @return the schema
 * @throws Exception if reading the schema fails
 */
protected Schema readSchema(String sql, String typeName) throws Exception {
    SQLSchemaReader schemaReader = new SQLSchemaReader();
    schemaReader.setSource(new NoStreamInputSupplier(jdbcUri));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_USER, Value.of(dbi.getUser()));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    schemaReader.setParameter(SQLSchemaReader.PARAM_SQL, Value.of(sql));
    schemaReader.setParameter(SQLSchemaReader.PARAM_TYPE_NAME, Value.of(typeName));
    IOReport report = schemaReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
    Schema schema = schemaReader.getSchema();
    assertNotNull(schema);
    return schema;
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) SQLSchemaReader(eu.esdihumboldt.hale.io.jdbc.SQLSchemaReader) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 28 with IOReport

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

the class AbstractDBTest method readSchema.

/**
 * Load the database schema.
 *
 * @return the schema
 * @throws Exception if reading the schema fails
 */
protected Schema readSchema() throws Exception {
    JDBCSchemaReader schemaReader = new JDBCSchemaReader();
    schemaReader.setSource(new NoStreamInputSupplier(jdbcUri));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_USER, Value.of(dbi.getUser()));
    schemaReader.setParameter(JDBCSchemaReader.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    // This is set for setting inclusion rule for reading schema
    if (dbi.getDatabase().equalsIgnoreCase("ORCL")) {
        schemaReader.setParameter(JDBCSchemaReader.SCHEMAS, Value.of(dbi.getUser().toUpperCase()));
    }
    IOReport report = schemaReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
    Schema schema = schemaReader.getSchema();
    assertNotNull(schema);
    return schema;
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) JDBCSchemaReader(eu.esdihumboldt.hale.io.jdbc.JDBCSchemaReader) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 29 with IOReport

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

the class AbstractDBTest method readInstances.

/**
 * Read instances from the database.
 *
 * @param schema the source schema
 * @return the database instances
 *
 * @throws Exception if reading the instances fails
 */
protected InstanceCollection readInstances(Schema schema) throws Exception {
    JDBCInstanceReader reader = new JDBCInstanceReader();
    reader.setSource(new NoStreamInputSupplier(jdbcUri));
    reader.setParameter(JDBCInstanceWriter.PARAM_USER, Value.of(dbi.getUser()));
    reader.setParameter(JDBCInstanceWriter.PARAM_PASSWORD, Value.of(dbi.getPassword()));
    DefaultSchemaSpace sourceSchema = new DefaultSchemaSpace();
    sourceSchema.addSchema(schema);
    reader.setSourceSchema(sourceSchema);
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue(report.getErrors().isEmpty());
    return reader.getInstances();
}
Also used : JDBCInstanceReader(eu.esdihumboldt.hale.io.jdbc.JDBCInstanceReader) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NoStreamInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamInputSupplier)

Example 30 with IOReport

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

the class OMLReaderTest method readXMLSchema.

/**
 * Reads a XML schema
 *
 * @param input the input supplier
 * @return the schema
 * @throws IOProviderConfigurationException if the configuration of the
 *             reader is invalid
 * @throws IOException if reading the schema fails
 */
private static Schema readXMLSchema(LocatableInputSupplier<? extends InputStream> input) throws IOProviderConfigurationException, IOException {
    XmlSchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(new DefaultTypeIndex());
    reader.setSource(input);
    reader.validate();
    IOReport report = reader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return reader.getSchema();
}
Also used : DefaultTypeIndex(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)102 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)34 Test (org.junit.Test)33 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)25 List (java.util.List)23 QName (javax.xml.namespace.QName)23 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)22 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)22 HashMap (java.util.HashMap)22 File (java.io.File)14 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)11 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)8 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)8 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)8 IOException (java.io.IOException)8 Ignore (org.junit.Ignore)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)7 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)7